diff options
author | Daisuke Miyakawa <dmiyakawa@google.com> | 2011-06-03 16:22:13 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-06-03 16:22:13 -0700 |
commit | 6bf90e1bfe7d9e487ff5b35f7e48e6b8ccc346c2 (patch) | |
tree | f12979c034ad1c840dfdb8ce5f98d5b3f44f7f31 /src/com | |
parent | 09e69522745551522c55dff27424496f255def46 (diff) | |
parent | 37f0bdbb0a99b12abcc319f49a2caa5ab648add0 (diff) | |
download | packages_providers_ContactsProvider-6bf90e1bfe7d9e487ff5b35f7e48e6b8ccc346c2.zip packages_providers_ContactsProvider-6bf90e1bfe7d9e487ff5b35f7e48e6b8ccc346c2.tar.gz packages_providers_ContactsProvider-6bf90e1bfe7d9e487ff5b35f7e48e6b8ccc346c2.tar.bz2 |
am 37f0bdbb: Remove stale rows in directory table.
* commit '37f0bdbb0a99b12abcc319f49a2caa5ab648add0':
Remove stale rows in directory table.
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/providers/contacts/ContactDirectoryManager.java | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/src/com/android/providers/contacts/ContactDirectoryManager.java b/src/com/android/providers/contacts/ContactDirectoryManager.java index c014105..f2c8422 100644 --- a/src/com/android/providers/contacts/ContactDirectoryManager.java +++ b/src/com/android/providers/contacts/ContactDirectoryManager.java @@ -195,12 +195,44 @@ public class ContactDirectoryManager { List<PackageInfo> packages = pm.getInstalledPackages( PackageManager.GET_PROVIDERS | PackageManager.GET_META_DATA); if (packages != null) { + // Prepare query strings for removing stale rows which don't correspond to existing + // directories. + StringBuilder deleteWhereBuilder = new StringBuilder(); + ArrayList<String> deleteWhereArgs = new ArrayList<String>(); + deleteWhereBuilder.append("NOT (" + Directory._ID + "=? OR " + Directory._ID + "=?"); + deleteWhereArgs.add(String.valueOf(Directory.DEFAULT)); + deleteWhereArgs.add(String.valueOf(Directory.LOCAL_INVISIBLE)); + final String wherePart = "(" + Directory.PACKAGE_NAME + "=? AND " + + Directory.DIRECTORY_AUTHORITY + "=? AND " + + Directory.ACCOUNT_NAME + "=? AND " + + Directory.ACCOUNT_TYPE + "=?)"; + for (PackageInfo packageInfo : packages) { // Check all packages except the one containing ContactsProvider itself if (!packageInfo.packageName.equals(mContext.getPackageName())) { - count += updateDirectoriesForPackage(packageInfo, true); + List<DirectoryInfo> directories = + updateDirectoriesForPackage(packageInfo, true); + if (directories != null && !directories.isEmpty()) { + count += directories.size(); + + // We shouldn't delete rows for existing directories. + for (DirectoryInfo info : directories) { + deleteWhereBuilder.append(" OR "); + deleteWhereBuilder.append(wherePart); + deleteWhereArgs.add(info.packageName); + deleteWhereArgs.add(info.authority); + deleteWhereArgs.add(info.accountName); + deleteWhereArgs.add(info.accountType); + } + } } } + + deleteWhereBuilder.append(")"); // Close "NOT (" + int deletedRows = db.delete(Tables.DIRECTORIES, deleteWhereBuilder.toString(), + deleteWhereArgs.toArray(new String[0])); + Log.i(TAG, "deleted " + deletedRows + + " stale rows which don't have any relevant directory"); } return count; } @@ -258,7 +290,8 @@ public class ContactDirectoryManager { * Scans the specified package for content directories and updates the {@link Directory} * table accordingly. */ - private int updateDirectoriesForPackage(PackageInfo packageInfo, boolean initialScan) { + private List<DirectoryInfo> updateDirectoriesForPackage( + PackageInfo packageInfo, boolean initialScan) { ArrayList<DirectoryInfo> directories = Lists.newArrayList(); ProviderInfo[] providers = packageInfo.providers; @@ -275,7 +308,7 @@ public class ContactDirectoryManager { } if (directories.size() == 0 && initialScan) { - return 0; + return null; } SQLiteDatabase db = getDbHelper().getWritableDatabase(); @@ -299,7 +332,7 @@ public class ContactDirectoryManager { } mContactsProvider.resetDirectoryCache(); - return directories.size(); + return directories; } /** |