Fix shortcut icons on O

Use IconCompat to create the adaptive icons. When attaching the icon
to the result intent for ACTION_SHORTCUT on >= O use
IconCompat.addToShortcutResult(). Otherwise continue to manually add
it for pre-O.

Test: Manually verified creating shortcuts on N M and O still work as
expected.

Bug: 62112388
Change-Id: I07f5a8ffd1f49edb4c21aaa572b42f641111e798
diff --git a/src/com/android/contacts/ShortcutIntentBuilder.java b/src/com/android/contacts/ShortcutIntentBuilder.java
index 0a4bb67..e90e786 100644
--- a/src/com/android/contacts/ShortcutIntentBuilder.java
+++ b/src/com/android/contacts/ShortcutIntentBuilder.java
@@ -40,6 +40,7 @@
 import android.provider.ContactsContract.CommonDataKinds.Photo;
 import android.provider.ContactsContract.Contacts;
 import android.provider.ContactsContract.Data;
+import android.support.v4.graphics.drawable.IconCompat;
 import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
 import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
 import android.support.v4.os.BuildCompat;
@@ -292,11 +293,15 @@
         final Intent shortcutIntent = ImplicitIntentsUtil.getIntentForQuickContactLauncherShortcut(
                 mContext, contactUri);
 
-        final Bitmap icon = generateQuickContactIcon(drawable);
-
-
         intent = intent == null ? new Intent() : intent;
-        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
+
+        final Bitmap icon = generateQuickContactIcon(drawable);
+        if (BuildCompat.isAtLeastO()) {
+            final IconCompat compatIcon = IconCompat.createWithAdaptiveBitmap(icon);
+            compatIcon.addToShortcutIntent(intent);
+        } else {
+            intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
+        }
         intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
         intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, displayName);
 
@@ -332,18 +337,25 @@
         shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
 
         Intent intent = null;
+        IconCompat compatAdaptiveIcon = null;
         if (BuildCompat.isAtLeastO()) {
+            compatAdaptiveIcon = IconCompat.createWithAdaptiveBitmap(icon);
             final ShortcutManager sm = (ShortcutManager)
                     mContext.getSystemService(Context.SHORTCUT_SERVICE);
             final String id = shortcutAction + lookupKey;
             final DynamicShortcuts dynamicShortcuts = new DynamicShortcuts(mContext);
             final ShortcutInfo shortcutInfo = dynamicShortcuts.getActionShortcutInfo(
-                    id, displayName, shortcutIntent, Icon.createWithAdaptiveBitmap(icon));
+                    id, displayName, shortcutIntent, compatAdaptiveIcon.toIcon());
             intent = sm.createShortcutResultIntent(shortcutInfo);
         }
 
         intent = intent == null ? new Intent() : intent;
-        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
+        // This will be non-null in O and above.
+        if (compatAdaptiveIcon != null) {
+            compatAdaptiveIcon.addToShortcutIntent(intent);
+        } else {
+            intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
+        }
         intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
         intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutName);