From 24bb66a1c5a435ab0c55b4a97e788bdc2595bf84 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Tue, 21 Mar 2017 15:12:01 -0700 Subject: [PATCH] Removing the profile extra from intent and using the profile id from the profile column The intent extra is not always correct as the profile id can change during backup restore. This allows us to use a consistant behavior everywhere. Change-Id: I004bd244204ca91758b1d42488e1fc13b0ccb998 --- src/com/android/launcher3/AppInfo.java | 14 +++++------- .../launcher3/InstallShortcutReceiver.java | 4 ++-- src/com/android/launcher3/ItemInfo.java | 5 ----- src/com/android/launcher3/Launcher.java | 6 +---- src/com/android/launcher3/LauncherModel.java | 5 +---- .../android/launcher3/LauncherProvider.java | 22 ++++++++++++++++++- src/com/android/launcher3/ShortcutInfo.java | 2 +- src/com/android/launcher3/Utilities.java | 9 ++------ .../shortcuts/ShortcutInfoCompat.java | 5 +---- .../util/ManagedProfileHeuristic.java | 2 +- .../launcher3/util/PackageManagerHelper.java | 2 +- 11 files changed, 36 insertions(+), 40 deletions(-) diff --git a/src/com/android/launcher3/AppInfo.java b/src/com/android/launcher3/AppInfo.java index 2a620370fd..9ec26e26a5 100644 --- a/src/com/android/launcher3/AppInfo.java +++ b/src/com/android/launcher3/AppInfo.java @@ -56,11 +56,10 @@ public class AppInfo extends ItemInfoWithIcon { * Must not hold the Context. */ public AppInfo(Context context, LauncherActivityInfo info, UserHandle user) { - this(context, info, user, UserManagerCompat.getInstance(context).isQuietModeEnabled(user)); + this(info, user, UserManagerCompat.getInstance(context).isQuietModeEnabled(user)); } - public AppInfo(Context context, LauncherActivityInfo info, UserHandle user, - boolean quietModeEnabled) { + public AppInfo(LauncherActivityInfo info, UserHandle user, boolean quietModeEnabled) { this.componentName = info.getComponentName(); this.container = ItemInfo.NO_ID; this.user = user; @@ -71,7 +70,7 @@ public class AppInfo extends ItemInfoWithIcon { isDisabled |= ShortcutInfo.FLAG_DISABLED_QUIET_USER; } - intent = makeLaunchIntent(context, info, user); + intent = makeLaunchIntent(info); } public AppInfo(AppInfo info) { @@ -95,14 +94,11 @@ public class AppInfo extends ItemInfoWithIcon { return new ComponentKey(componentName, user); } - public static Intent makeLaunchIntent(Context context, LauncherActivityInfo info, - UserHandle user) { - long serialNumber = UserManagerCompat.getInstance(context).getSerialNumberForUser(user); + public static Intent makeLaunchIntent(LauncherActivityInfo info) { return new Intent(Intent.ACTION_MAIN) .addCategory(Intent.CATEGORY_LAUNCHER) .setComponent(info.getComponentName()) - .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) - .putExtra(EXTRA_PROFILE, serialNumber); + .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); } @Override diff --git a/src/com/android/launcher3/InstallShortcutReceiver.java b/src/com/android/launcher3/InstallShortcutReceiver.java index 80dec16700..ce8557065e 100644 --- a/src/com/android/launcher3/InstallShortcutReceiver.java +++ b/src/com/android/launcher3/InstallShortcutReceiver.java @@ -328,7 +328,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver { user = info.getUser(); mContext = context; - launchIntent = AppInfo.makeLaunchIntent(context, info, user); + launchIntent = AppInfo.makeLaunchIntent(info); label = info.getLabel().toString(); } @@ -344,7 +344,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver { mContext = context; user = info.getUserHandle(); - launchIntent = info.makeIntent(context); + launchIntent = info.makeIntent(); label = info.getShortLabel().toString(); } diff --git a/src/com/android/launcher3/ItemInfo.java b/src/com/android/launcher3/ItemInfo.java index aec6c7dc2d..0779a3d206 100644 --- a/src/com/android/launcher3/ItemInfo.java +++ b/src/com/android/launcher3/ItemInfo.java @@ -29,11 +29,6 @@ import com.android.launcher3.util.ContentWriter; */ public class ItemInfo { - /** - * Intent extra to store the profile. Format: UserHandle - */ - public static final String EXTRA_PROFILE = "profile"; - public static final int NO_ID = -1; /** diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index d4bfc4913c..731237af7a 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -2701,11 +2701,7 @@ public class Launcher extends BaseActivity !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION); Bundle optsBundle = useLaunchAnimation ? getActivityLaunchOptions(v) : null; - UserHandle user = null; - if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) { - long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1); - user = UserManagerCompat.getInstance(this).getUserForSerialNumber(serialNumber); - } + UserHandle user = item == null ? null : item.user; // Prepare intent intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index dc668e6a41..5a41eeb1fa 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -1069,9 +1069,6 @@ public class LauncherModel extends BroadcastReceiver info.rank = c.getInt(rankIndex); info.spanX = 1; info.spanY = 1; - // TODO: Remove this extra. Instead we should be using - // itemInfo#user. - info.intent.putExtra(ItemInfo.EXTRA_PROFILE, c.serialNumber); info.isDisabled |= disabledState; if (isSafeMode && !Utilities.isSystemApp(context, intent)) { info.isDisabled |= ShortcutInfo.FLAG_DISABLED_SAFEMODE; @@ -1685,7 +1682,7 @@ public class LauncherModel extends BroadcastReceiver for (int i = 0; i < apps.size(); i++) { LauncherActivityInfo app = apps.get(i); // This builds the icon bitmaps. - mBgAllAppsList.add(new AppInfo(mContext, app, user, quietMode), app); + mBgAllAppsList.add(new AppInfo(app, user, quietMode), app); } final ManagedProfileHeuristic heuristic = ManagedProfileHeuristic.get(mContext, user); diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java index e250b3f29f..a750406570 100644 --- a/src/com/android/launcher3/LauncherProvider.java +++ b/src/com/android/launcher3/LauncherProvider.java @@ -72,7 +72,7 @@ public class LauncherProvider extends ContentProvider { private static final String TAG = "LauncherProvider"; private static final boolean LOGD = false; - private static final int DATABASE_VERSION = 27; + private static final int DATABASE_VERSION = 28; public static final String AUTHORITY = ProviderConfig.AUTHORITY; @@ -791,6 +791,26 @@ public class LauncherProvider extends ContentProvider { break; } case 27: { + // Remove "profile extra" + db.beginTransaction(); + try { + UserManagerCompat um = UserManagerCompat.getInstance(mContext); + for (UserHandle user : um.getUserProfiles()) { + long serial = um.getSerialNumberForUser(user); + String sql = "update favorites set intent = replace(intent, " + + "';l.profile=" + serial + ";', ';') where itemType = 0;"; + db.execSQL(sql); + } + db.setTransactionSuccessful(); + } catch (SQLException ex) { + Log.e(TAG, ex.getMessage(), ex); + // Old version remains, which means we wipe old data + break; + } finally { + db.endTransaction(); + } + } + case 28: { // DB Upgraded successfully return; } diff --git a/src/com/android/launcher3/ShortcutInfo.java b/src/com/android/launcher3/ShortcutInfo.java index f0bb1c0c19..6f0417c08a 100644 --- a/src/com/android/launcher3/ShortcutInfo.java +++ b/src/com/android/launcher3/ShortcutInfo.java @@ -199,7 +199,7 @@ public class ShortcutInfo extends ItemInfoWithIcon { public void updateFromDeepShortcutInfo(ShortcutInfoCompat shortcutInfo, Context context) { // {@link ShortcutInfoCompat#getActivity} can change during an update. Recreate the intent - intent = shortcutInfo.makeIntent(context); + intent = shortcutInfo.makeIntent(); title = shortcutInfo.getShortLabel(); CharSequence label = shortcutInfo.getLongLabel(); diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index abc53673b9..207a7d4af8 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -468,13 +468,8 @@ public final class Utilities { && TextUtils.isEmpty(launchIntent.getDataString())) { // An app target can either have no extra or have ItemInfo.EXTRA_PROFILE. Bundle extras = launchIntent.getExtras(); - if (extras == null) { - return true; - } else { - Set keys = extras.keySet(); - return keys.size() == 1 && keys.contains(ItemInfo.EXTRA_PROFILE); - } - }; + return extras == null || extras.keySet().isEmpty(); + } return false; } diff --git a/src/com/android/launcher3/shortcuts/ShortcutInfoCompat.java b/src/com/android/launcher3/shortcuts/ShortcutInfoCompat.java index dac2160546..37047bb36a 100644 --- a/src/com/android/launcher3/shortcuts/ShortcutInfoCompat.java +++ b/src/com/android/launcher3/shortcuts/ShortcutInfoCompat.java @@ -44,15 +44,12 @@ public class ShortcutInfoCompat { } @TargetApi(Build.VERSION_CODES.N) - public Intent makeIntent(Context context) { - long serialNumber = UserManagerCompat.getInstance(context) - .getSerialNumberForUser(getUserHandle()); + public Intent makeIntent() { return new Intent(Intent.ACTION_MAIN) .addCategory(INTENT_CATEGORY) .setComponent(getActivity()) .setPackage(getPackage()) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) - .putExtra(ItemInfo.EXTRA_PROFILE, serialNumber) .putExtra(EXTRA_SHORTCUT_ID, getId()); } diff --git a/src/com/android/launcher3/util/ManagedProfileHeuristic.java b/src/com/android/launcher3/util/ManagedProfileHeuristic.java index 85a000cd82..ce603c4c2d 100644 --- a/src/com/android/launcher3/util/ManagedProfileHeuristic.java +++ b/src/com/android/launcher3/util/ManagedProfileHeuristic.java @@ -121,7 +121,7 @@ public class ManagedProfileHeuristic { .isQuietModeEnabled(user); for (int i = 0; i < count; i++) { LauncherActivityInstallInfo info = apps.get(i); - AppInfo appInfo = new AppInfo(mContext, info.info, user, quietModeEnabled); + AppInfo appInfo = new AppInfo(info.info, user, quietModeEnabled); mIconCache.getTitleAndIcon(appInfo, info.info, false /* useLowResIcon */); ShortcutInfo si = appInfo.makeShortcut(); ((info.installTime <= folderCreationTime) ? workFolderApps : homescreenApps).add(si); diff --git a/src/com/android/launcher3/util/PackageManagerHelper.java b/src/com/android/launcher3/util/PackageManagerHelper.java index 7629f7822e..e12b2d4f18 100644 --- a/src/com/android/launcher3/util/PackageManagerHelper.java +++ b/src/com/android/launcher3/util/PackageManagerHelper.java @@ -76,7 +76,7 @@ public class PackageManagerHelper { public Intent getAppLaunchIntent(String pkg, UserHandle user) { List activities = mLauncherApps.getActivityList(pkg, user); return activities.isEmpty() ? null : - AppInfo.makeLaunchIntent(mContext, activities.get(0), user); + AppInfo.makeLaunchIntent(activities.get(0)); } /**