Merge "Removing the profile extra from intent and using the profile id from the profile column" into ub-launcher3-dorval

This commit is contained in:
Sunny Goyal 2017-03-21 23:15:58 +00:00 committed by Android (Google) Code Review
commit 77ff9a4343
11 changed files with 36 additions and 40 deletions

View File

@ -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

View File

@ -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();
}

View File

@ -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;
/**

View File

@ -2706,11 +2706,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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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();

View File

@ -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<String> keys = extras.keySet();
return keys.size() == 1 && keys.contains(ItemInfo.EXTRA_PROFILE);
}
};
return extras == null || extras.keySet().isEmpty();
}
return false;
}

View File

@ -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());
}

View File

@ -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);

View File

@ -76,7 +76,7 @@ public class PackageManagerHelper {
public Intent getAppLaunchIntent(String pkg, UserHandle user) {
List<LauncherActivityInfo> activities = mLauncherApps.getActivityList(pkg, user);
return activities.isEmpty() ? null :
AppInfo.makeLaunchIntent(mContext, activities.get(0), user);
AppInfo.makeLaunchIntent(activities.get(0));
}
/**