diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2015-04-02 10:27:03 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2015-04-10 19:01:32 -0700 |
commit | 0b037789662d1c16627dc5b509d1ac55bc76971b (patch) | |
tree | 7d6d8d9d7b175f9c10fbfa69f60d09c5929fc299 /src/com/android/launcher3/InstallShortcutReceiver.java | |
parent | 85e3d4cc5ea4e554639868069f4fd409731f7bbb (diff) | |
download | android_packages_apps_Trebuchet-0b037789662d1c16627dc5b509d1ac55bc76971b.tar.gz android_packages_apps_Trebuchet-0b037789662d1c16627dc5b509d1ac55bc76971b.tar.bz2 android_packages_apps_Trebuchet-0b037789662d1c16627dc5b509d1ac55bc76971b.zip |
Deduping shortcuts to app-shortcuts if they have a valid intent
> Only deduping shortcuts for the primary user as custom shortcuts
for secondary users is not supported.
Change-Id: If129dee64a395602006ebb996d4b09b93b89084f
Diffstat (limited to 'src/com/android/launcher3/InstallShortcutReceiver.java')
-rw-r--r-- | src/com/android/launcher3/InstallShortcutReceiver.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/com/android/launcher3/InstallShortcutReceiver.java b/src/com/android/launcher3/InstallShortcutReceiver.java index 0db22a499..5422de951 100644 --- a/src/com/android/launcher3/InstallShortcutReceiver.java +++ b/src/com/android/launcher3/InstallShortcutReceiver.java @@ -22,6 +22,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.text.TextUtils; @@ -147,6 +148,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver { if (DBG) Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0)); PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, context); + info = convertToLauncherActivityIfPossible(info); queuePendingShortcutInfo(info, context); } @@ -373,6 +375,10 @@ public class InstallShortcutReceiver extends BroadcastReceiver { } return packageName; } + + public boolean isLuncherActivity() { + return activityInfo != null; + } } private static PendingInstallShortcutInfo decode(String encoded, Context context) { @@ -420,4 +426,40 @@ public class InstallShortcutReceiver extends BroadcastReceiver { } return null; } + + /** + * Tries to create a new PendingInstallShortcutInfo which represents the same target, + * but is an app target and not a shortcut. + * @return the newly created info or the original one. + */ + private static PendingInstallShortcutInfo convertToLauncherActivityIfPossible( + PendingInstallShortcutInfo original) { + if (original.isLuncherActivity()) { + // Already an activity target + return original; + } + if (isValidShortcutLaunchIntent(original.launchIntent) + || !original.user.equals(UserHandleCompat.myUserHandle())) { + // We can only convert shortcuts which point to a main activity in the current user. + return original; + } + + PackageManager pm = original.mContext.getPackageManager(); + ResolveInfo info = pm.resolveActivity(original.launchIntent, 0); + + if (info == null) { + return original; + } + + // Ignore any conflicts in the label name, as that can change based on locale. + LauncherActivityInfoCompat launcherInfo = LauncherActivityInfoCompat + .fromResolveInfo(info, original.mContext); + return new PendingInstallShortcutInfo(launcherInfo, original.mContext); + } + + public static boolean isLauncherActivity(Intent intent, Context context) { + Intent data = new Intent().putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent); + PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, context); + return convertToLauncherActivityIfPossible(info).isLuncherActivity(); + } } |