Fix issue where always trying to migrate
Rather than check if the ContentProviderClient is null (which fails
in when using the Redirector), check the PackageManager directly
for the authority we are looking for.
Bug: 14466459
Change-Id: I7420352a15dcea5037196670f18705e7a34f0672
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 4b5e68b..cc87281 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -25,6 +25,7 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
@@ -103,6 +104,7 @@
private static final int MAIN_THREAD_NORMAL_RUNNABLE = 0;
private static final int MAIN_THREAD_BINDING_RUNNABLE = 1;
+ private static final String MIGRATE_AUTHORITY = "com.android.launcher2.settings";
private static final HandlerThread sWorkerThread = new HandlerThread("launcher-loader");
static {
@@ -197,15 +199,19 @@
LauncherModel(LauncherAppState app, IconCache iconCache, AppFilter appFilter) {
Context context = app.getContext();
- ContentResolver contentResolver = context.getContentResolver();
mAppsCanBeOnRemoveableStorage = Environment.isExternalStorageRemovable();
String oldProvider = context.getString(R.string.old_launcher_provider_uri);
- ContentProviderClient client = contentResolver.acquireContentProviderClient(
- Uri.parse(context.getString(R.string.old_launcher_provider_uri)));
+ // This may be the same as MIGRATE_AUTHORITY, or it may be replaced by a different
+ // resource string.
+ String redirectAuthority = Uri.parse(oldProvider).getAuthority();
+ ProviderInfo providerInfo =
+ context.getPackageManager().resolveContentProvider(MIGRATE_AUTHORITY, 0);
+ ProviderInfo redirectProvider =
+ context.getPackageManager().resolveContentProvider(redirectAuthority, 0);
Log.d(TAG, "Old launcher provider: " + oldProvider);
- mOldContentProviderExists = (client != null);
+ mOldContentProviderExists = (providerInfo != null) && (redirectProvider != null);
if (mOldContentProviderExists) {
Log.d(TAG, "Old launcher provider exists.");
@@ -213,9 +219,6 @@
Log.d(TAG, "Old launcher provider does not exist.");
}
- if (client != null) {
- client.release();
- }
mApp = app;
mBgAllAppsList = new AllAppsList(iconCache, appFilter);
mIconCache = iconCache;