- // Delete the current file if it exists.
- if (exportFile.exists()) {
- //noinspection ResultOfMethodCallIgnored
- exportFile.delete();
- }
-
- // Create the export database.
- SQLiteDatabase exportDatabase = SQLiteDatabase.openOrCreateDatabase(exportFile, null);
-
- // Set the export database version number.
- exportDatabase.setVersion(SCHEMA_VERSION);
-
- // Create the export database domains table.
- exportDatabase.execSQL(DomainsDatabaseHelper.CREATE_DOMAINS_TABLE);
-
- // Open the domains database. The `0` specifies the database version, but that is ignored and set instead using a constant in `DomainsDatabaseHelper`.
- DomainsDatabaseHelper domainsDatabaseHelper = new DomainsDatabaseHelper(context, null, null, 0);
-
- // Get a full domains database cursor.
- Cursor domainsCursor = domainsDatabaseHelper.getCompleteCursorOrderedByDomain();
-
- // Move to the first domain.
- domainsCursor.moveToFirst();
-
- // Copy the data from the domains cursor into the export database.
- for (int i = 0; i < domainsCursor.getCount(); i++) {
- // Extract the record from the cursor and store the data in a ContentValues.
- ContentValues domainsContentValues = new ContentValues();
- domainsContentValues.put(DomainsDatabaseHelper.DOMAIN_NAME, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.DOMAIN_NAME)));
- domainsContentValues.put(DomainsDatabaseHelper.ENABLE_JAVASCRIPT, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_JAVASCRIPT)));
- domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES)));
- domainsContentValues.put(DomainsDatabaseHelper.ENABLE_THIRD_PARTY_COOKIES, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_THIRD_PARTY_COOKIES)));
- domainsContentValues.put(DomainsDatabaseHelper.ENABLE_DOM_STORAGE, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_DOM_STORAGE)));
- domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FORM_DATA, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FORM_DATA)));
- domainsContentValues.put(DomainsDatabaseHelper.ENABLE_EASYLIST, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_EASYLIST)));
- domainsContentValues.put(DomainsDatabaseHelper.ENABLE_EASYPRIVACY, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_EASYPRIVACY)));
- domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FANBOYS_ANNOYANCE_LIST, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FANBOYS_ANNOYANCE_LIST)));
- domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST)));
- domainsContentValues.put(DomainsDatabaseHelper.ENABLE_ULTRAPRIVACY, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_ULTRAPRIVACY)));
- domainsContentValues.put(DomainsDatabaseHelper.BLOCK_ALL_THIRD_PARTY_REQUESTS, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.BLOCK_ALL_THIRD_PARTY_REQUESTS)));
- domainsContentValues.put(DomainsDatabaseHelper.USER_AGENT, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.USER_AGENT)));
- domainsContentValues.put(DomainsDatabaseHelper.FONT_SIZE, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.FONT_SIZE)));
- domainsContentValues.put(DomainsDatabaseHelper.SWIPE_TO_REFRESH, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SWIPE_TO_REFRESH)));
- domainsContentValues.put(DomainsDatabaseHelper.NIGHT_MODE, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.NIGHT_MODE)));
- domainsContentValues.put(DomainsDatabaseHelper.DISPLAY_IMAGES, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.DISPLAY_IMAGES)));
- domainsContentValues.put(DomainsDatabaseHelper.PINNED_SSL_CERTIFICATE, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.PINNED_SSL_CERTIFICATE)));
- domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_TO_COMMON_NAME, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_COMMON_NAME)));
- domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATION, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATION)));
- domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATIONAL_UNIT, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATIONAL_UNIT)));
- domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_BY_COMMON_NAME, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_BY_COMMON_NAME)));
- domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATION, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATION)));
- domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATIONAL_UNIT, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATIONAL_UNIT)));
- domainsContentValues.put(DomainsDatabaseHelper.SSL_START_DATE, domainsCursor.getLong(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_START_DATE)));
- domainsContentValues.put(DomainsDatabaseHelper.SSL_END_DATE, domainsCursor.getLong(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_END_DATE)));
- domainsContentValues.put(DomainsDatabaseHelper.PINNED_IP_ADDRESSES, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.PINNED_IP_ADDRESSES)));
- domainsContentValues.put(DomainsDatabaseHelper.IP_ADDRESSES, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.IP_ADDRESSES)));
-
- // Insert the record into the export database.
- exportDatabase.insert(DomainsDatabaseHelper.DOMAINS_TABLE, null, domainsContentValues);
-
- // Advance to the next record.
- domainsCursor.moveToNext();
- }
-
- // Close the domains database.
- domainsCursor.close();
- domainsDatabaseHelper.close();
-
-
- // Create the export database bookmarks table.
- exportDatabase.execSQL(BookmarksDatabaseHelper.CREATE_BOOKMARKS_TABLE);
-
- // Open the bookmarks database. The `0` specifies the database version, but that is ignored and set instead using a constant in `BookmarksDatabaseHelper`.
- BookmarksDatabaseHelper bookmarksDatabaseHelper = new BookmarksDatabaseHelper(context, null, null, 0);
-
- // Get a full bookmarks cursor.
- Cursor bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarks();
-
- // Move to the first bookmark.
- bookmarksCursor.moveToFirst();
-
- // Copy the data from the bookmarks cursor into the export database.
- for (int i = 0; i < bookmarksCursor.getCount(); i++) {
- // Extract the record from the cursor and store the data in a ContentValues.
- ContentValues bookmarksContentValues = new ContentValues();
- bookmarksContentValues.put(BookmarksDatabaseHelper.BOOKMARK_NAME, bookmarksCursor.getString(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME)));
- bookmarksContentValues.put(BookmarksDatabaseHelper.BOOKMARK_URL, bookmarksCursor.getString(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_URL)));
- bookmarksContentValues.put(BookmarksDatabaseHelper.PARENT_FOLDER, bookmarksCursor.getString(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.PARENT_FOLDER)));
- bookmarksContentValues.put(BookmarksDatabaseHelper.DISPLAY_ORDER, bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.DISPLAY_ORDER)));
- bookmarksContentValues.put(BookmarksDatabaseHelper.IS_FOLDER, bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)));
- bookmarksContentValues.put(BookmarksDatabaseHelper.FAVORITE_ICON, bookmarksCursor.getBlob(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON)));
-
- // Insert the record into the export database.
- exportDatabase.insert(BookmarksDatabaseHelper.BOOKMARKS_TABLE, null, bookmarksContentValues);
-
- // Advance to the next record.
- bookmarksCursor.moveToNext();
- }
-
- // Close the bookmarks database.
- bookmarksCursor.close();
- bookmarksDatabaseHelper.close();
-
-
- // Prepare the preferences table SQL creation string.
- String CREATE_PREFERENCES_TABLE = "CREATE TABLE " + PREFERENCES_TABLE + " (" +
- _ID + " INTEGER PRIMARY KEY, " +
- JAVASCRIPT + " BOOLEAN, " +
- FIRST_PARTY_COOKIES + " BOOLEAN, " +
- THIRD_PARTY_COOKIES + " BOOLEAN, " +
- DOM_STORAGE + " BOOLEAN, " +
- SAVE_FORM_DATA + " BOOLEAN, " +
- USER_AGENT + " TEXT, " +
- CUSTOM_USER_AGENT + " TEXT, " +
- INCOGNITO_MODE + " BOOLEAN, " +
- DO_NOT_TRACK + " BOOLEAN, " +
- ALLOW_SCREENSHOTS + " BOOLEAN, " +
- EASYLIST + " BOOLEAN, " +
- EASYPRIVACY + " BOOLEAN, " +
- FANBOYS_ANNOYANCE_LIST + " BOOLEAN, " +
- FANBOYS_SOCIAL_BLOCKING_LIST + " BOOLEAN, " +
- ULTRAPRIVACY + " BOOLEAN, " +
- BLOCK_ALL_THIRD_PARTY_REQUESTS + " BOOLEAN, " +
- PROXY_THROUGH_ORBOT + " BOOLEAN, " +
- TOR_HOMEPAGE + " TEXT, " +
- TOR_SEARCH + " TEXT, " +
- TOR_SEARCH_CUSTOM_URL + " TEXT, " +
- SEARCH + " TEXT, " +
- SEARCH_CUSTOM_URL + " TEXT, " +
- FULL_SCREEN_BROWSING_MODE + " BOOLEAN, " +
- HIDE_APP_BAR + " BOOLEAN, " +
- CLEAR_EVERYTHING + " BOOLEAN, " +
- CLEAR_COOKIES + " BOOLEAN, " +
- CLEAR_DOM_STORAGE + " BOOLEAN, " +
- CLEAR_FORM_DATA + " BOOLEAN, " +
- CLEAR_CACHE + " BOOLEAN, " +
- HOMEPAGE + " TEXT, " +
- FONT_SIZE + " TEXT, " +
- SWIPE_TO_REFRESH + " BOOLEAN, " +
- SCROLL_APP_BAR + " BOOLEAN, " +
- DISPLAY_ADDITIONAL_APP_BAR_ICONS + " BOOLEAN, " +
- DOWNLOAD_WITH_EXTERNAL_APP + " BOOLEAN, " +
- DARK_THEME + " BOOLEAN, " +
- NIGHT_MODE + " BOOLEAN, " +
- DISPLAY_WEBPAGE_IMAGES + " BOOLEAN)";