Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7340606d authored by Gary Mai's avatar Gary Mai
Browse files

Fix NPEs in shortcuts am: 9b1b9377

Change-Id: Iedd641ae9bbb18a9a1cbf5d64806ca24ce869e7d
parents 008122b6 9b1b9377
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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();
    }
+9 −5
Original line number Diff line number Diff line
@@ -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);
            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 Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey);

        final Intent shortcutIntent = ImplicitIntentsUtil.getIntentForQuickContactLauncherShortcut(
                mContext, contactUri);
@@ -346,8 +348,10 @@ public class ShortcutIntentBuilder {
            final DynamicShortcuts dynamicShortcuts = new DynamicShortcuts(mContext);
            final ShortcutInfo shortcutInfo = dynamicShortcuts.getActionShortcutInfo(
                    id, displayName, shortcutIntent, compatAdaptiveIcon.toIcon());
            if (shortcutInfo != null) {
                intent = sm.createShortcutResultIntent(shortcutInfo);
            }
        }

        intent = intent == null ? new Intent() : intent;
        // This will be non-null in O and above.
+23 −17
Original line number Diff line number Diff line
@@ -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() {

                    @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);
            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) {
                            // Broadcast the shortcutIntent to the launcher to create a
                            // shortcut to this contact
                            shortcutIntent.setAction(ACTION_INSTALL_SHORTCUT);
@@ -2727,10 +2733,10 @@ public class QuickContactActivity extends ContactsActivity {
                            Toast.makeText(QuickContactActivity.this, toastMessage,
                                    Toast.LENGTH_SHORT).show();
                        }
                    }
                    });
            builder.createContactShortcutIntent(mContactData.getLookupUri());
        }
    }

    private boolean isShortcutCreatable() {
        if (mContactData == null || mContactData.isUserProfile() ||