From 214db8cb549ee19c7c8a9b8e9bd60d68f551592e Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Mon, 30 Apr 2012 13:40:27 -0700 Subject: [PATCH] Bug 743153 - Use ContentUris.parseId instead of RepoUtils.getAndroidIdFromUri. r=rnewman, a=android-only --- .../android/AndroidBrowserBookmarksDataAccessor.java | 3 ++- .../android/AndroidBrowserRepositorySession.java | 3 ++- .../repositories/android/PasswordsRepositorySession.java | 6 +++++- .../android/base/sync/repositories/android/RepoUtils.java | 8 -------- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksDataAccessor.java b/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksDataAccessor.java index adf54f77403..eab76f2f096 100644 --- a/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksDataAccessor.java +++ b/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksDataAccessor.java @@ -16,6 +16,7 @@ import org.mozilla.gecko.sync.repositories.NullCursorException; import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord; import org.mozilla.gecko.sync.repositories.domain.Record; +import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; @@ -249,7 +250,7 @@ public class AndroidBrowserBookmarksDataAccessor extends AndroidBrowserRepositor record.title = AndroidBrowserBookmarksRepositorySession.SPECIAL_GUIDS_MAP.get(guid); record.type = "folder"; record.androidParentID = parentId; - return(RepoUtils.getAndroidIdFromUri(insert(record))); + return ContentUris.parseId(insert(record)); } @Override diff --git a/mobile/android/base/sync/repositories/android/AndroidBrowserRepositorySession.java b/mobile/android/base/sync/repositories/android/AndroidBrowserRepositorySession.java index 3b6e779a2f7..4fb586debf8 100644 --- a/mobile/android/base/sync/repositories/android/AndroidBrowserRepositorySession.java +++ b/mobile/android/base/sync/repositories/android/AndroidBrowserRepositorySession.java @@ -26,6 +26,7 @@ import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionGuidsSince import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate; import org.mozilla.gecko.sync.repositories.domain.Record; +import android.content.ContentUris; import android.database.Cursor; import android.net.Uri; @@ -533,7 +534,7 @@ public abstract class AndroidBrowserRepositorySession extends StoreTrackingRepos protected Record insert(Record record) throws NoGuidForIdException, NullCursorException, ParentNotFoundException { Record toStore = prepareRecord(record); Uri recordURI = dbHelper.insert(toStore); - long id = RepoUtils.getAndroidIdFromUri(recordURI); + long id = ContentUris.parseId(recordURI); Logger.debug(LOG_TAG, "Inserted as " + id); toStore.androidID = id; diff --git a/mobile/android/base/sync/repositories/android/PasswordsRepositorySession.java b/mobile/android/base/sync/repositories/android/PasswordsRepositorySession.java index 1a7ee18666a..3218147ff55 100644 --- a/mobile/android/base/sync/repositories/android/PasswordsRepositorySession.java +++ b/mobile/android/base/sync/repositories/android/PasswordsRepositorySession.java @@ -28,6 +28,7 @@ import org.mozilla.gecko.sync.repositories.domain.PasswordRecord; import org.mozilla.gecko.sync.repositories.domain.Record; import android.content.ContentProviderClient; +import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; @@ -445,7 +446,10 @@ public class PasswordsRepositorySession extends // record.timeLastUsed = now(); ContentValues cv = getContentValues(record); Uri insertedUri = passwordsProvider.insert(BrowserContractHelpers.PASSWORDS_CONTENT_URI, cv); - record.androidID = RepoUtils.getAndroidIdFromUri(insertedUri); + if (insertedUri == null) { + throw new RemoteException(); // Not much to be done here, save throw. + } + record.androidID = ContentUris.parseId(insertedUri); return record; } diff --git a/mobile/android/base/sync/repositories/android/RepoUtils.java b/mobile/android/base/sync/repositories/android/RepoUtils.java index a6cb5a65174..daa4a2ec37b 100644 --- a/mobile/android/base/sync/repositories/android/RepoUtils.java +++ b/mobile/android/base/sync/repositories/android/RepoUtils.java @@ -119,14 +119,6 @@ public class RepoUtils { } } - // Returns android id from the URI that we get after inserting a - // bookmark into the local Android store. - public static long getAndroidIdFromUri(Uri uri) { - String path = uri.getPath(); - int lastSlash = path.lastIndexOf('/'); - return Long.parseLong(path.substring(lastSlash + 1)); - } - //Create a HistoryRecord object from a cursor on a row with a Moz History record in it public static HistoryRecord historyFromMirrorCursor(Cursor cur) {