diff options
author | John Reck <jreck@google.com> | 2011-05-18 14:25:08 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-05-18 14:25:08 -0700 |
commit | 31faddc3fa92d51a642249d86df7f769178f7e92 (patch) | |
tree | ea1f4191b435aaf2734223ba9fc3d7dbbf331584 /src | |
parent | 1eafdc9123d5923768959ea2cec624a0335f6b8b (diff) | |
parent | 8706008824a86cd28f6911be26dde2602a4b4a6a (diff) | |
download | packages_apps_browser-31faddc3fa92d51a642249d86df7f769178f7e92.zip packages_apps_browser-31faddc3fa92d51a642249d86df7f769178f7e92.tar.gz packages_apps_browser-31faddc3fa92d51a642249d86df7f769178f7e92.tar.bz2 |
Merge "Transfer data from BP1 to BP2"
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/browser/BrowserSettings.java | 1 | ||||
-rw-r--r-- | src/com/android/browser/Controller.java | 1 | ||||
-rw-r--r-- | src/com/android/browser/InstantSearchEngine.java | 1 | ||||
-rw-r--r-- | src/com/android/browser/provider/BrowserProvider.java (renamed from src/com/android/browser/BrowserProvider.java) | 16 | ||||
-rw-r--r-- | src/com/android/browser/provider/BrowserProvider2.java | 76 |
5 files changed, 87 insertions, 8 deletions
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java index 7d64cfc..e6bd759 100644 --- a/src/com/android/browser/BrowserSettings.java +++ b/src/com/android/browser/BrowserSettings.java @@ -17,6 +17,7 @@ package com.android.browser; import com.android.browser.homepages.HomeProvider; +import com.android.browser.provider.BrowserProvider; import com.android.browser.search.SearchEngine; import com.android.browser.search.SearchEngines; diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java index 2a7e8eb..06f00c7 100644 --- a/src/com/android/browser/Controller.java +++ b/src/com/android/browser/Controller.java @@ -18,6 +18,7 @@ package com.android.browser; import com.android.browser.IntentHandler.UrlData; import com.android.browser.UI.DropdownChangeListener; +import com.android.browser.provider.BrowserProvider; import com.android.browser.search.SearchEngine; import com.android.common.Search; diff --git a/src/com/android/browser/InstantSearchEngine.java b/src/com/android/browser/InstantSearchEngine.java index 6ff7db7..e2e9c8a 100644 --- a/src/com/android/browser/InstantSearchEngine.java +++ b/src/com/android/browser/InstantSearchEngine.java @@ -18,6 +18,7 @@ package com.android.browser; import com.android.browser.Controller; import com.android.browser.R; import com.android.browser.UI.DropdownChangeListener; +import com.android.browser.provider.BrowserProvider; import com.android.browser.search.SearchEngine; import android.app.SearchManager; diff --git a/src/com/android/browser/BrowserProvider.java b/src/com/android/browser/provider/BrowserProvider.java index 6ebc2c2..b55b84a 100644 --- a/src/com/android/browser/BrowserProvider.java +++ b/src/com/android/browser/provider/BrowserProvider.java @@ -14,8 +14,10 @@ * limitations under the License. */ -package com.android.browser; +package com.android.browser.provider; +import com.android.browser.BrowserSettings; +import com.android.browser.R; import com.android.browser.search.SearchEngine; import android.app.SearchManager; @@ -57,14 +59,14 @@ public class BrowserProvider extends ContentProvider { private SQLiteOpenHelper mOpenHelper; private BackupManager mBackupManager; - private static final String sDatabaseName = "browser.db"; + static final String sDatabaseName = "browser.db"; private static final String TAG = "BrowserProvider"; private static final String ORDER_BY = "visits DESC, date DESC"; private static final String PICASA_URL = "http://picasaweb.google.com/m/" + "viewer?source=androidclient"; - private static final String[] TABLE_NAMES = new String[] { + static final String[] TABLE_NAMES = new String[] { "bookmarks", "searches" }; private static final String[] SUGGEST_PROJECTION = new String[] { @@ -112,7 +114,7 @@ public class BrowserProvider extends ContentProvider { // make sure that these match the index of TABLE_NAMES - private static final int URI_MATCH_BOOKMARKS = 0; + static final int URI_MATCH_BOOKMARKS = 0; private static final int URI_MATCH_SEARCHES = 1; // (id % 10) should match the table name index private static final int URI_MATCH_BOOKMARKS_ID = 10; @@ -178,7 +180,7 @@ public class BrowserProvider extends ContentProvider { // XXX: This is a major hack to remove our dependency on gsf constants and // its content provider. http://b/issue?id=2425179 - static String getClientId(ContentResolver cr) { + public static String getClientId(ContentResolver cr) { String ret = "android-google"; Cursor legacyClientIdCursor = null; Cursor searchClientIdCursor = null; @@ -244,7 +246,7 @@ public class BrowserProvider extends ContentProvider { return sb; } - private static class DatabaseHelper extends SQLiteOpenHelper { + static class DatabaseHelper extends SQLiteOpenHelper { private Context mContext; public DatabaseHelper(Context context) { @@ -838,7 +840,7 @@ public class BrowserProvider extends ContentProvider { * by the SearchDialog when the BrowserActivity is in voice search mode. * @param results Strings to display in the dropdown from the SearchDialog */ - /* package */ void setQueryResults(ArrayList<String> results) { + public /* package */ void setQueryResults(ArrayList<String> results) { synchronized (mResultsCursorLock) { if (results == null) { mResultsCursor = null; diff --git a/src/com/android/browser/provider/BrowserProvider2.java b/src/com/android/browser/provider/BrowserProvider2.java index 7a6dfbb..a8739ca 100644 --- a/src/com/android/browser/provider/BrowserProvider2.java +++ b/src/com/android/browser/provider/BrowserProvider2.java @@ -64,6 +64,7 @@ import android.provider.SyncStateContract; import android.text.TextUtils; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; @@ -398,7 +399,80 @@ public class BrowserProvider2 extends SQLiteContentProvider { mSyncHelper.createDatabase(db); - createDefaultBookmarks(db); + if (!importFromBrowserProvider(db)) { + createDefaultBookmarks(db); + } + } + + boolean importFromBrowserProvider(SQLiteDatabase db) { + Context context = getContext(); + File oldDbFile = context.getDatabasePath(BrowserProvider.sDatabaseName); + if (oldDbFile.exists()) { + BrowserProvider.DatabaseHelper helper = + new BrowserProvider.DatabaseHelper(context); + SQLiteDatabase oldDb = helper.getWritableDatabase(); + Cursor c = null; + try { + String table = BrowserProvider.TABLE_NAMES[BrowserProvider.URI_MATCH_BOOKMARKS]; + // Import bookmarks + c = oldDb.query(table, + new String[] { + BookmarkColumns.URL, // 0 + BookmarkColumns.TITLE, // 1 + BookmarkColumns.FAVICON, // 2 + BookmarkColumns.TOUCH_ICON, // 3 + }, BookmarkColumns.BOOKMARK + "!=0", null, + null, null, null); + if (c != null) { + while (c.moveToNext()) { + ContentValues values = new ContentValues(); + values.put(Bookmarks.URL, c.getString(0)); + values.put(Bookmarks.TITLE, c.getString(1)); + values.put(Bookmarks.POSITION, 0); + values.put(Bookmarks.PARENT, FIXED_ID_ROOT); + ContentValues imageValues = new ContentValues(); + imageValues.put(Images.URL, c.getString(0)); + imageValues.put(Images.FAVICON, c.getBlob(2)); + imageValues.put(Images.TOUCH_ICON, c.getBlob(3)); + db.insertOrThrow(TABLE_IMAGES, Images.THUMBNAIL, imageValues); + db.insertOrThrow(TABLE_BOOKMARKS, Bookmarks.DIRTY, values); + } + c.close(); + } + // Import history + c = oldDb.query(table, + new String[] { + BookmarkColumns.URL, // 0 + BookmarkColumns.TITLE, // 1 + BookmarkColumns.VISITS, // 2 + BookmarkColumns.DATE, // 3 + BookmarkColumns.CREATED, // 4 + }, null, null, null, null, null); + if (c != null) { + while (c.moveToNext()) { + ContentValues values = new ContentValues(); + values.put(History.URL, c.getString(0)); + values.put(History.TITLE, c.getString(1)); + values.put(History.VISITS, c.getInt(2)); + values.put(History.DATE_LAST_VISITED, c.getLong(3)); + values.put(History.DATE_CREATED, c.getLong(4)); + db.insertOrThrow(TABLE_HISTORY, History.FAVICON, values); + } + c.close(); + } + // Wipe the old DB, in case the delete fails. + oldDb.delete(table, null, null); + } finally { + if (c != null) c.close(); + oldDb.close(); + helper.close(); + } + if (!oldDbFile.delete()) { + oldDbFile.deleteOnExit(); + } + return true; + } + return false; } void createAccountsView(SQLiteDatabase db) { |