summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2016-05-16 12:41:09 -0700
committerSunny Goyal <sunnygoyal@google.com>2016-05-18 09:41:27 -0700
commit1acb9e9e29bb06b6266781284ae60e9fd4d0962f (patch)
treee3ccbd9a23c08e7480d00891c99e452a0f88480b
parentae007814289a465be3df1ddca276e30f73460a97 (diff)
downloadandroid_packages_apps_Trebuchet-1acb9e9e29bb06b6266781284ae60e9fd4d0962f.tar.gz
android_packages_apps_Trebuchet-1acb9e9e29bb06b6266781284ae60e9fd4d0962f.tar.bz2
android_packages_apps_Trebuchet-1acb9e9e29bb06b6266781284ae60e9fd4d0962f.zip
Rearranging the provider checks to avoid packagemanager lookups
whenever launcher starts Bug: 28737985 Change-Id: I3ce3e2741b3224fa5419d7ceca496e1bb91f065c
-rw-r--r--src/com/android/launcher3/Launcher.java30
-rw-r--r--src/com/android/launcher3/LauncherClings.java9
-rw-r--r--src/com/android/launcher3/LauncherModel.java30
3 files changed, 22 insertions, 47 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index e93068ed2..b7dd98d1c 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -58,6 +58,7 @@ import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
+import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
@@ -201,6 +202,7 @@ public class Launcher extends Activity
private static final String QSB_WIDGET_PROVIDER = "qsb_widget_provider";
public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
+ private static final String MIGRATE_AUTHORITY = "com.android.launcher2.settings";
/** The different states that Launcher can be in. */
enum State { NONE, WORKSPACE, WORKSPACE_SPRING_LOADED, APPS, APPS_SPRING_LOADED,
@@ -4389,18 +4391,7 @@ public class Launcher extends Activity
}
protected boolean isLauncherPreinstalled() {
- PackageManager pm = getPackageManager();
- try {
- ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
- if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
- return true;
- } else {
- return false;
- }
- } catch (NameNotFoundException e) {
- e.printStackTrace();
- return false;
- }
+ return (getApplicationInfo().flags & ApplicationInfo.FLAG_SYSTEM) != 0)
}
/**
@@ -4522,7 +4513,7 @@ public class Launcher extends Activity
LauncherClings launcherClings = new LauncherClings(this);
if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
mClings = launcherClings;
- if (mModel.canMigrateFromOldLauncherDb(this)) {
+ if (canMigrateFromOldLauncherDb()) {
launcherClings.showMigrationCling();
} else {
launcherClings.showLongPressCling(true);
@@ -4530,6 +4521,19 @@ public class Launcher extends Activity
}
}
+ private boolean canMigrateFromOldLauncherDb() {
+ // Return true if launcher was not preinstalled and and old content provider exists.
+ return ((getApplicationInfo().flags & ApplicationInfo.FLAG_SYSTEM) == 0) &&
+ providerExists(MIGRATE_AUTHORITY) &&
+ providerExists(Uri.parse(getString(R.string.old_launcher_provider_uri)).getAuthority());
+
+ }
+
+ private boolean providerExists(String authority) {
+ return getPackageManager().resolveContentProvider(authority, 0) != null;
+ }
+
+
void showWorkspaceSearchAndHotseat() {
if (mWorkspace != null) mWorkspace.setAlpha(1f);
if (mHotseat != null) mHotseat.setAlpha(1f);
diff --git a/src/com/android/launcher3/LauncherClings.java b/src/com/android/launcher3/LauncherClings.java
index 9b8e89429..1cfa3f7b3 100644
--- a/src/com/android/launcher3/LauncherClings.java
+++ b/src/com/android/launcher3/LauncherClings.java
@@ -22,7 +22,9 @@ import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.content.Context;
import android.content.SharedPreferences;
+import android.content.pm.ApplicationInfo;
import android.graphics.drawable.Drawable;
+import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.UserManager;
@@ -48,9 +50,6 @@ class LauncherClings implements OnClickListener, OnKeyListener {
private static final int SHOW_CLING_DURATION = 250;
private static final int DISMISS_CLING_DURATION = 200;
- // New Secure Setting in L
- private static final String SKIP_FIRST_USE_HINTS = "skip_first_use_hints";
-
@Thunk Launcher mLauncher;
private LayoutInflater mInflater;
@Thunk boolean mIsVisible;
@@ -262,8 +261,8 @@ class LauncherClings implements OnClickListener, OnKeyListener {
return false;
}
}
- if (Settings.Secure.getInt(mLauncher.getContentResolver(), SKIP_FIRST_USE_HINTS, 0)
- == 1) {
+ if (Settings.Secure.getInt(mLauncher.getContentResolver(),
+ Settings.Secure.SKIP_FIRST_USE_HINTS, 0) == 1) {
return false;
}
return true;
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 3d31b4eb2..fec96ca2e 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -28,7 +28,6 @@ import android.content.Intent;
import android.content.Intent.ShortcutIconResource;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
-import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.graphics.Bitmap;
@@ -56,11 +55,11 @@ import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.dynamicui.ExtractionUtils;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderIcon;
+import com.android.launcher3.logging.FileLog;
import com.android.launcher3.model.GridSizeMigrationTask;
import com.android.launcher3.model.WidgetsModel;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.CursorIconInfo;
-import com.android.launcher3.logging.FileLog;
import com.android.launcher3.util.FlagOp;
import com.android.launcher3.util.LongArrayMap;
import com.android.launcher3.util.ManagedProfileHeuristic;
@@ -105,8 +104,6 @@ public class LauncherModel extends BroadcastReceiver
private static final int ITEMS_CHUNK = 6; // batch size for the workspace icons
private static final long INVALID_SCREEN_ID = -1L;
- private final boolean mOldContentProviderExists;
-
@Thunk final LauncherAppState mApp;
@Thunk final Object mLock = new Object();
@Thunk DeferredHandler mHandler = new DeferredHandler();
@@ -114,8 +111,6 @@ public class LauncherModel extends BroadcastReceiver
@Thunk boolean mIsLoaderTaskRunning;
@Thunk boolean mHasLoaderCompletedOnce;
- private static final String MIGRATE_AUTHORITY = "com.android.launcher2.settings";
-
@Thunk static final HandlerThread sWorkerThread = new HandlerThread("launcher-loader");
static {
sWorkerThread.start();
@@ -216,25 +211,6 @@ public class LauncherModel extends BroadcastReceiver
LauncherModel(LauncherAppState app, IconCache iconCache, AppFilter appFilter) {
Context context = app.getContext();
-
- String oldProvider = 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 = (providerInfo != null) && (redirectProvider != null);
-
- if (mOldContentProviderExists) {
- Log.d(TAG, "Old launcher provider exists.");
- } else {
- Log.d(TAG, "Old launcher provider does not exist.");
- }
-
mApp = app;
mBgAllAppsList = new AllAppsList(iconCache, appFilter);
mBgWidgetsModel = new WidgetsModel(context, iconCache, appFilter);
@@ -266,10 +242,6 @@ public class LauncherModel extends BroadcastReceiver
}
}
- boolean canMigrateFromOldLauncherDb(Launcher launcher) {
- return mOldContentProviderExists && !launcher.isLauncherPreinstalled() ;
- }
-
public void setPackageState(final PackageInstallInfo installInfo) {
Runnable updateRunnable = new Runnable() {