diff options
author | Gary Mai <garymai@google.com> | 2017-06-14 01:08:59 +0000 |
---|---|---|
committer | Gary Mai <garymai@google.com> | 2017-06-14 01:08:59 +0000 |
commit | 7340606d918faa615bd4488d61924288550bc784 (patch) | |
tree | 98b8f2b826f20665750d42a55db2c35c39e300cf | |
parent | 008122b6497257508744f32f3f6923716cea87d0 (diff) | |
parent | 9b1b93772df8a52bcb22a1eccadfa9a31614fa3d (diff) | |
download | android_packages_apps_Contacts-7340606d918faa615bd4488d61924288550bc784.tar.gz android_packages_apps_Contacts-7340606d918faa615bd4488d61924288550bc784.tar.bz2 android_packages_apps_Contacts-7340606d918faa615bd4488d61924288550bc784.zip |
Fix NPEs in shortcuts am: 9b1b93772d
Change-Id: Iedd641ae9bbb18a9a1cbf5d64806ca24ce869e7d
-rw-r--r-- | src/com/android/contacts/DynamicShortcuts.java | 4 | ||||
-rw-r--r-- | src/com/android/contacts/ShortcutIntentBuilder.java | 14 | ||||
-rw-r--r-- | src/com/android/contacts/quickcontact/QuickContactActivity.java | 40 |
3 files changed, 36 insertions, 22 deletions
diff --git a/src/com/android/contacts/DynamicShortcuts.java b/src/com/android/contacts/DynamicShortcuts.java index fc0d05a7a..ac950d9b7 100644 --- a/src/com/android/contacts/DynamicShortcuts.java +++ b/src/com/android/contacts/DynamicShortcuts.java @@ -297,6 +297,7 @@ public class DynamicShortcuts { final ShortcutInfo.Builder builder = new ShortcutInfo.Builder(mContext, id) .setIntent(action) .setIcon(icon) + .setExtras(extras) .setDisabledMessage(mContext.getString(R.string.dynamic_shortcut_disabled_message)); setLabel(builder, label); @@ -305,6 +306,9 @@ public class DynamicShortcuts { public ShortcutInfo getQuickContactShortcutInfo(long id, String lookupKey, String displayName) { final ShortcutInfo.Builder builder = builderForContactShortcut(id, lookupKey, displayName); + if (builder == null) { + return null; + } addIconForContact(id, lookupKey, displayName, builder); return builder.build(); } diff --git a/src/com/android/contacts/ShortcutIntentBuilder.java b/src/com/android/contacts/ShortcutIntentBuilder.java index e90e786cd..b3bd85d88 100644 --- a/src/com/android/contacts/ShortcutIntentBuilder.java +++ b/src/com/android/contacts/ShortcutIntentBuilder.java @@ -276,6 +276,9 @@ public class ShortcutIntentBuilder { private void createContactShortcutIntent(Uri contactUri, String contentType, String displayName, String lookupKey, byte[] bitmapData) { Intent intent = null; + if (TextUtils.isEmpty(displayName)) { + displayName = mContext.getResources().getString(R.string.missing_name); + } if (BuildCompat.isAtLeastO()) { final long contactId = ContentUris.parseId(contactUri); final ShortcutManager sm = (ShortcutManager) @@ -283,12 +286,11 @@ public class ShortcutIntentBuilder { final DynamicShortcuts dynamicShortcuts = new DynamicShortcuts(mContext); final ShortcutInfo shortcutInfo = dynamicShortcuts.getQuickContactShortcutInfo( contactId, lookupKey, displayName); - intent = sm.createShortcutResultIntent(shortcutInfo); + if (shortcutInfo != null) { + intent = sm.createShortcutResultIntent(shortcutInfo); + } } final Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey); - if (TextUtils.isEmpty(displayName)) { - displayName = mContext.getResources().getString(R.string.missing_name); - } final Intent shortcutIntent = ImplicitIntentsUtil.getIntentForQuickContactLauncherShortcut( mContext, contactUri); @@ -346,7 +348,9 @@ public class ShortcutIntentBuilder { final DynamicShortcuts dynamicShortcuts = new DynamicShortcuts(mContext); final ShortcutInfo shortcutInfo = dynamicShortcuts.getActionShortcutInfo( id, displayName, shortcutIntent, compatAdaptiveIcon.toIcon()); - intent = sm.createShortcutResultIntent(shortcutInfo); + if (shortcutInfo != null) { + intent = sm.createShortcutResultIntent(shortcutInfo); + } } intent = intent == null ? new Intent() : intent; diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java index 3a69f23ef..5da750242 100644 --- a/src/com/android/contacts/quickcontact/QuickContactActivity.java +++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java @@ -35,6 +35,7 @@ import android.content.IntentFilter; import android.content.Loader; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; +import android.content.pm.ShortcutInfo; import android.content.pm.ShortcutManager; import android.content.res.Resources; import android.graphics.Bitmap; @@ -2697,21 +2698,26 @@ public class QuickContactActivity extends ContactsActivity { * Creates a launcher shortcut with the current contact. */ private void createLauncherShortcutWithContact() { - final ShortcutIntentBuilder builder = new ShortcutIntentBuilder(this, - new OnShortcutIntentCreatedListener() { + if (BuildCompat.isAtLeastO()) { + final ShortcutManager shortcutManager = (ShortcutManager) + getSystemService(SHORTCUT_SERVICE); + final DynamicShortcuts shortcuts = + new DynamicShortcuts(QuickContactActivity.this); + String displayName = mContactData.getDisplayName(); + if (displayName == null) { + displayName = getString(R.string.missing_name); + } + final ShortcutInfo shortcutInfo = shortcuts.getQuickContactShortcutInfo( + mContactData.getId(), mContactData.getLookupKey(), displayName); + if (shortcutInfo != null) { + shortcutManager.requestPinShortcut(shortcutInfo, null); + } + } else { + final ShortcutIntentBuilder builder = new ShortcutIntentBuilder(this, + new OnShortcutIntentCreatedListener() { - @Override - public void onShortcutIntentCreated(Uri uri, Intent shortcutIntent) { - if (BuildCompat.isAtLeastO()) { - final ShortcutManager shortcutManager = (ShortcutManager) - getSystemService(SHORTCUT_SERVICE); - final DynamicShortcuts shortcuts = - new DynamicShortcuts(QuickContactActivity.this); - shortcutManager.requestPinShortcut( - shortcuts.getQuickContactShortcutInfo( - mContactData.getId(), mContactData.getLookupKey(), - mContactData.getDisplayName()), null); - } else { + @Override + public void onShortcutIntentCreated(Uri uri, Intent shortcutIntent) { // Broadcast the shortcutIntent to the launcher to create a // shortcut to this contact shortcutIntent.setAction(ACTION_INSTALL_SHORTCUT); @@ -2727,9 +2733,9 @@ public class QuickContactActivity extends ContactsActivity { Toast.makeText(QuickContactActivity.this, toastMessage, Toast.LENGTH_SHORT).show(); } - } - }); - builder.createContactShortcutIntent(mContactData.getLookupUri()); + }); + builder.createContactShortcutIntent(mContactData.getLookupUri()); + } } private boolean isShortcutCreatable() { |