summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNilesh Agrawal <nileshagrawal@google.com>2013-12-17 15:20:50 -0800
committerNilesh Agrawal <nileshagrawal@google.com>2013-12-17 15:26:00 -0800
commitdff0bfeb901e767ca9b57f9b8051c7fd077626e9 (patch)
tree88c22b901143b2ef8ab003da906b308e343162eb /src
parentf6a22ada816ae4f63576679f03472b0a984e82be (diff)
downloadandroid_packages_apps_Trebuchet-dff0bfeb901e767ca9b57f9b8051c7fd077626e9.tar.gz
android_packages_apps_Trebuchet-dff0bfeb901e767ca9b57f9b8051c7fd077626e9.tar.bz2
android_packages_apps_Trebuchet-dff0bfeb901e767ca9b57f9b8051c7fd077626e9.zip
Do not allow duplicate shortcuts when ALL_APPS is disabled.
When DISABLE_ALL_APPS is true, we want to have only one shortcut for each activityexposed via the Application's manifest. We ignore INSTALL_SHORTCUT broadcasts which have launch intents with ACTION_MAIN and CATEGORY_LAUNCHER. Applications can still create shortcuts pointing to an already exposed component if they provide data or extras in the intent. Change-Id: I0b05283ea6c522d197e0262c2997f7298e08740b
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher3/DeleteDropTarget.java15
-rw-r--r--src/com/android/launcher3/InstallShortcutReceiver.java32
2 files changed, 34 insertions, 13 deletions
diff --git a/src/com/android/launcher3/DeleteDropTarget.java b/src/com/android/launcher3/DeleteDropTarget.java
index a8ac0746c..c76425a5e 100644
--- a/src/com/android/launcher3/DeleteDropTarget.java
+++ b/src/com/android/launcher3/DeleteDropTarget.java
@@ -266,19 +266,8 @@ public class DeleteDropTarget extends ButtonDropTarget {
private boolean isUninstallFromWorkspace(DragObject d) {
if (AppsCustomizePagedView.DISABLE_ALL_APPS && isWorkspaceOrFolderApplication(d)) {
ShortcutInfo shortcut = (ShortcutInfo) d.dragInfo;
- if (shortcut.intent != null && shortcut.intent.getComponent() != null) {
- Set<String> categories = shortcut.intent.getCategories();
- boolean includesLauncherCategory = false;
- if (categories != null) {
- for (String category : categories) {
- if (category.equals(Intent.CATEGORY_LAUNCHER)) {
- includesLauncherCategory = true;
- break;
- }
- }
- }
- return includesLauncherCategory;
- }
+ // Only allow manifest shortcuts to initiate an un-install.
+ return !InstallShortcutReceiver.isValidShortcutLaunchIntent(shortcut.intent);
}
return false;
}
diff --git a/src/com/android/launcher3/InstallShortcutReceiver.java b/src/com/android/launcher3/InstallShortcutReceiver.java
index 140106af9..1ff94720b 100644
--- a/src/com/android/launcher3/InstallShortcutReceiver.java
+++ b/src/com/android/launcher3/InstallShortcutReceiver.java
@@ -24,6 +24,7 @@ import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
+import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.widget.Toast;
@@ -223,6 +224,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
if (intent == null) {
return;
}
+
// This name is only used for comparisons and notifications, so fall back to activity name
// if not supplied
String name = ensureValidName(context, intent,
@@ -269,6 +271,12 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
//final Intent data = pendingInfo.data;
final Intent intent = pendingInfo.launchIntent;
final String name = pendingInfo.name;
+
+ if (AppsCustomizePagedView.DISABLE_ALL_APPS && !isValidShortcutLaunchIntent(intent)) {
+ if (DBG) Log.d(TAG, "Ignoring shortcut with launchIntent:" + intent);
+ continue;
+ }
+
final boolean exists = LauncherModel.shortcutExists(context, name, intent);
//final boolean allowDuplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true);
@@ -301,6 +309,30 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
}
}
+ /**
+ * Returns true if the intent is a valid launch intent for a shortcut.
+ * This is used to identify shortcuts which are different from the ones exposed by the
+ * applications' manifest file.
+ *
+ * When DISABLE_ALL_APPS is true, shortcuts exposed via the app's manifest should never be
+ * duplicated or removed(unless the app is un-installed).
+ *
+ * @param launchIntent The intent that will be launched when the shortcut is clicked.
+ */
+ static boolean isValidShortcutLaunchIntent(Intent launchIntent) {
+ if (launchIntent != null
+ && Intent.ACTION_MAIN.equals(launchIntent.getAction())
+ && launchIntent.getComponent() != null
+ && launchIntent.getCategories() != null
+ && launchIntent.getCategories().size() == 1
+ && launchIntent.hasCategory(Intent.CATEGORY_LAUNCHER)
+ && launchIntent.getExtras() == null
+ && TextUtils.isEmpty(launchIntent.getDataString())) {
+ return false;
+ }
+ return true;
+ }
+
private static ShortcutInfo getShortcutInfo(Context context, Intent data,
Intent launchIntent) {
if (launchIntent.getAction() == null) {