Fix crash when "Add contact" shortcut is pinned
Test: manually verified that app doesn't crash after pinning the "Add
contact" shortcut and then updating strequent shortcuts
Bug 33546024
Change-Id: I91e8070470ed6f7a1518d3c70264977b15230ec4
diff --git a/src/com/android/contacts/DynamicShortcuts.java b/src/com/android/contacts/DynamicShortcuts.java
index 49cc722..9ec416c 100644
--- a/src/com/android/contacts/DynamicShortcuts.java
+++ b/src/com/android/contacts/DynamicShortcuts.java
@@ -87,6 +87,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.
@@ -156,10 +163,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()));
@@ -256,6 +269,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,