From bbe1e24c5ff470a695510d23d67bcb6f2ad88d0e Mon Sep 17 00:00:00 2001 From: Jason Monk Date: Fri, 16 May 2014 17:37:34 -0400 Subject: [PATCH] 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 --- src/com/android/launcher3/LauncherModel.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index 4b5e68b721..cc87281fc0 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -25,6 +25,7 @@ import android.content.pm.ActivityInfo; 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 @@ public class LauncherModel extends BroadcastReceiver 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 @@ public class LauncherModel extends BroadcastReceiver 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 @@ public class LauncherModel extends BroadcastReceiver Log.d(TAG, "Old launcher provider does not exist."); } - if (client != null) { - client.release(); - } mApp = app; mBgAllAppsList = new AllAppsList(iconCache, appFilter); mIconCache = iconCache;