Rearranging the provider checks to avoid packagemanager lookups whenever launcher starts
am: 1acb9e9e29
* commit '1acb9e9e29bb06b6266781284ae60e9fd4d0962f':
Rearranging the provider checks to avoid packagemanager lookups whenever launcher starts
Change-Id: I4717167af838e9ab30992f7eeaf8ef6d7b73e50b
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user