Gracefully fallback to new ComponentName if one is renamed/removed

Previously, if a developer renamed their launcher activity, we removed
all instances of their icon from the home screen, since technically the
activity they pointed to no longer exists. However, in the vast majority
of cases, the developer simply renamed their activity and nothing should
change from a user's perspective. So instead of removing icons that no
longer point to a valid activity, we now redirect them to point to the
first activity in the manifest (or remove them if there is none).

Test:
- Install app with Activity A and place on home screen
- Rename A to B and reinstall - verify home screen icon remains
- Add new launcher activity C - verify icons still go to B
- Force stop launcher and rename B to A - verify icons go to A (same activity)
- Remove activity A - verify icons go to C
- Remove activity C - verify icons are removed

Bug: 28907647
Change-Id: If9da251bd588908c4c425e7dd32e38fcbe54bab2
This commit is contained in:
Tony Wickham
2018-09-05 12:48:13 -07:00
parent b75f5366f9
commit f9d9df7d3a
4 changed files with 38 additions and 44 deletions

View File

@@ -381,24 +381,16 @@ public class LoaderTask implements Runnable {
// no special handling necessary for this item
c.markRestored();
} else {
if (c.hasRestoreFlag(ShortcutInfo.FLAG_AUTOINSTALL_ICON)) {
// We allow auto install apps to have their intent
// updated after an install.
intent = pmHelper.getAppLaunchIntent(targetPkg, c.user);
if (intent != null) {
c.restoreFlag = 0;
c.updater().put(
LauncherSettings.Favorites.INTENT,
intent.toUri(0)).commit();
cn = intent.getComponent();
} else {
c.markDeleted("Unable to find a launch target");
continue;
}
// Gracefully try to find a fallback activity.
intent = pmHelper.getAppLaunchIntent(targetPkg, c.user);
if (intent != null) {
c.restoreFlag = 0;
c.updater().put(
LauncherSettings.Favorites.INTENT,
intent.toUri(0)).commit();
cn = intent.getComponent();
} else {
// The app is installed but the component is no
// longer available.
c.markDeleted("Invalid component removed: " + cn);
c.markDeleted("Unable to find a launch target");
continue;
}
}