Fix crash when "Add contact" shortcut is pinned
am: 5d1ec1da58
Change-Id: I6b13180ef7409a774c20f433c92cea4ac309e26b
diff --git a/src/com/android/contacts/DynamicShortcuts.java b/src/com/android/contacts/DynamicShortcuts.java
index 0481be6..49798c4 100644
--- a/src/com/android/contacts/DynamicShortcuts.java
+++ b/src/com/android/contacts/DynamicShortcuts.java
@@ -85,6 +85,13 @@
private static final int LONG_LABEL_MAX_LENGTH = 30;
private static final int MAX_SHORTCUTS = 3;
+ private static final String EXTRA_SHORTCUT_TYPE = "extraShortcutType";
+
+ // Because pinned shortcuts persist across app upgrades these values should not be changed
+ // though new ones may be added
+ private static final int SHORTCUT_TYPE_UNKNOWN = 0;
+ private static final int SHORTCUT_TYPE_CONTACT_URI = 1;
+
// The spec specifies that it should be 44dp @ xxxhdpi
// Note that ShortcutManager.getIconMaxWidth and ShortcutManager.getMaxHeight return different
// (larger) values.
@@ -154,10 +161,16 @@
final List<String> enable = new ArrayList<>();
for (ShortcutInfo shortcut : mShortcutManager.getPinnedShortcuts()) {
-
final PersistableBundle extras = shortcut.getExtras();
+
+ if (!shortcut.isDynamic() || extras == null ||
+ extras.getInt(EXTRA_SHORTCUT_TYPE, SHORTCUT_TYPE_UNKNOWN) !=
+ SHORTCUT_TYPE_CONTACT_URI) {
+ continue;
+ }
+
// The contact ID may have changed but that's OK because it is just an optimization
- final long contactId = extras == null ? 0 : extras.getLong(Contacts._ID);
+ final long contactId = extras.getLong(Contacts._ID);
final ShortcutInfo update = createShortcutForUri(
Contacts.getLookupUri(contactId, shortcut.getId()));
@@ -254,6 +267,7 @@
}
final PersistableBundle extras = new PersistableBundle();
extras.putLong(Contacts._ID, id);
+ extras.putInt(EXTRA_SHORTCUT_TYPE, SHORTCUT_TYPE_CONTACT_URI);
final ShortcutInfo.Builder builder = new ShortcutInfo.Builder(mContext, lookupKey)
.setIntent(ImplicitIntentsUtil.getIntentForQuickContactLauncherShortcut(mContext,