Merge "Add padding to pending widget background." into ub-launcher3-dorval
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index b388d28..d4bfc49 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -1451,9 +1451,14 @@
         }
 
         if (info == null) {
-            info = InstallShortcutReceiver.fromShortcutIntent(this, data);
+            // Legacy shortcuts are only supported for primary profile.
+            info = Process.myUserHandle().equals(args.user)
+                    ? InstallShortcutReceiver.fromShortcutIntent(this, data) : null;
 
-            if (info == null || !new PackageManagerHelper(this).hasPermissionForActivity(
+            if (info == null) {
+                Log.e(TAG, "Unable to parse a valid custom shortcut result");
+                return;
+            } else if (!new PackageManagerHelper(this).hasPermissionForActivity(
                     info.intent, args.getPendingIntent().getComponent().getPackageName())) {
                 // The app is trying to add a shortcut without sufficient permissions
                 Log.e(TAG, "Ignoring malicious intent " + info.intent.toUri(0));
diff --git a/src/com/android/launcher3/compat/LauncherAppsCompatVO.java b/src/com/android/launcher3/compat/LauncherAppsCompatVO.java
index 2743379..d7e35a2 100644
--- a/src/com/android/launcher3/compat/LauncherAppsCompatVO.java
+++ b/src/com/android/launcher3/compat/LauncherAppsCompatVO.java
@@ -20,6 +20,8 @@
 import android.content.pm.ApplicationInfo;
 import android.content.pm.LauncherActivityInfo;
 import android.content.pm.LauncherApps;
+import android.os.Build;
+import android.os.Process;
 import android.os.UserHandle;
 import android.util.Log;
 
@@ -44,15 +46,20 @@
     @Override
     public List<ShortcutConfigActivityInfo> getCustomShortcutActivityList() {
         List<ShortcutConfigActivityInfo> result = new ArrayList<>();
+        UserHandle myUser = Process.myUserHandle();
 
         try {
             Method m = LauncherApps.class.getDeclaredMethod("getShortcutConfigActivityList",
                     String.class, UserHandle.class);
             for (UserHandle user : UserManagerCompat.getInstance(mContext).getUserProfiles()) {
+                boolean ignoreTargetSdk = myUser.equals(user);
                 List<LauncherActivityInfo> activities =
                         (List<LauncherActivityInfo>) m.invoke(mLauncherApps, null, user);
                 for (LauncherActivityInfo activityInfo : activities) {
-                    result.add(new ShortcutConfigActivityInfoVO(activityInfo));
+                    if (ignoreTargetSdk || activityInfo.getApplicationInfo().targetSdkVersion >=
+                            Build.VERSION_CODES.O) {
+                        result.add(new ShortcutConfigActivityInfoVO(activityInfo));
+                    }
                 }
             }
         } catch (Exception e) {
diff --git a/src/com/android/launcher3/compat/PinItemRequestCompat.java b/src/com/android/launcher3/compat/PinItemRequestCompat.java
index 550bcc3..1308cba 100644
--- a/src/com/android/launcher3/compat/PinItemRequestCompat.java
+++ b/src/com/android/launcher3/compat/PinItemRequestCompat.java
@@ -24,6 +24,8 @@
 import android.os.Parcel;
 import android.os.Parcelable;
 
+import com.android.launcher3.Utilities;
+
 /**
  * A wrapper around platform implementation of PinItemRequestCompat until the
  * updated SDK is available.
@@ -115,6 +117,9 @@
             };
 
     public static PinItemRequestCompat getPinItemRequest(Intent intent) {
+        if (!Utilities.isAtLeastO()) {
+            return null;
+        }
         Parcelable extra = intent.getParcelableExtra(EXTRA_PIN_ITEM_REQUEST);
         return extra == null ? null : new PinItemRequestCompat(extra);
     }
diff --git a/src/com/android/launcher3/notification/NotificationInfo.java b/src/com/android/launcher3/notification/NotificationInfo.java
index 58e2e03..ba7675c 100644
--- a/src/com/android/launcher3/notification/NotificationInfo.java
+++ b/src/com/android/launcher3/notification/NotificationInfo.java
@@ -42,11 +42,6 @@
  */
 public class NotificationInfo implements View.OnClickListener {
 
-    // TODO: use Notification constants directly.
-    public static final int BADGE_ICON_NONE = 0;
-    public static final int BADGE_ICON_SMALL = 1;
-    public static final int BADGE_ICON_LARGE = 2;
-
     public final PackageUserKey packageUserKey;
     public final String notificationKey;
     public final CharSequence title;
@@ -69,10 +64,10 @@
         Notification notification = statusBarNotification.getNotification();
         title = notification.extras.getCharSequence(Notification.EXTRA_TITLE);
         text = notification.extras.getCharSequence(Notification.EXTRA_TEXT);
-        mBadgeIcon = BADGE_ICON_LARGE; // TODO: get from the Notification
+        mBadgeIcon = notification.getBadgeIcon();
         // Load the icon. Since it is backed by ashmem, we won't copy the entire bitmap
         // into our process as long as we don't touch it and it exists in systemui.
-        Icon icon = mBadgeIcon == BADGE_ICON_SMALL ? null : notification.getLargeIcon();
+        Icon icon = mBadgeIcon == Notification.BADGE_ICON_SMALL ? null : notification.getLargeIcon();
         if (icon == null) {
             // Use the small icon.
             icon = notification.getSmallIcon();
@@ -88,7 +83,7 @@
             mIconDrawable = new BitmapDrawable(context.getResources(), LauncherAppState
                     .getInstance(context).getIconCache()
                     .getDefaultIcon(statusBarNotification.getUser()));
-            mBadgeIcon = BADGE_ICON_NONE;
+            mBadgeIcon = Notification.BADGE_ICON_NONE;
         }
         intent = notification.contentIntent;
         autoCancel = (notification.flags & Notification.FLAG_AUTO_CANCEL) != 0;
@@ -133,7 +128,7 @@
     public boolean shouldShowIconInBadge() {
         // If the icon we're using for this notification matches what the Notification
         // specified should show in the badge, then return true.
-        return mIsIconLarge && mBadgeIcon == BADGE_ICON_LARGE
-                || !mIsIconLarge && mBadgeIcon == BADGE_ICON_SMALL;
+        return mIsIconLarge && mBadgeIcon == Notification.BADGE_ICON_LARGE
+                || !mIsIconLarge && mBadgeIcon == Notification.BADGE_ICON_SMALL;
     }
 }
diff --git a/src/com/android/launcher3/notification/NotificationListener.java b/src/com/android/launcher3/notification/NotificationListener.java
index d9f7d76..16cb5fb 100644
--- a/src/com/android/launcher3/notification/NotificationListener.java
+++ b/src/com/android/launcher3/notification/NotificationListener.java
@@ -17,6 +17,7 @@
 package com.android.launcher3.notification;
 
 import android.app.Notification;
+import android.app.NotificationChannel;
 import android.os.Handler;
 import android.os.Looper;
 import android.os.Message;
@@ -24,6 +25,7 @@
 import android.service.notification.StatusBarNotification;
 import android.support.annotation.Nullable;
 import android.support.v4.util.Pair;
+import android.text.TextUtils;
 
 import com.android.launcher3.LauncherModel;
 import com.android.launcher3.Utilities;
@@ -222,8 +224,17 @@
             }
         }
         Notification notification = sbn.getNotification();
+        if (mTempRanking.getChannel().getId().equals(NotificationChannel.DEFAULT_CHANNEL_ID)) {
+            // Special filtering for the default, legacy "Miscellaneous" channel.
+            if ((notification.flags & Notification.FLAG_ONGOING_EVENT) != 0) {
+                return true;
+            }
+        }
         boolean isGroupHeader = (notification.flags & Notification.FLAG_GROUP_SUMMARY) != 0;
-        return (notification.contentIntent == null || isGroupHeader);
+        CharSequence title = notification.extras.getCharSequence(Notification.EXTRA_TITLE);
+        CharSequence text = notification.extras.getCharSequence(Notification.EXTRA_TEXT);
+        boolean missingTitleOrText = TextUtils.isEmpty(title) || TextUtils.isEmpty(text);
+        return (notification.contentIntent == null || isGroupHeader || missingTitleOrText);
     }
 
     public interface NotificationsChangedListener {
diff --git a/src/com/android/launcher3/util/PendingRequestArgs.java b/src/com/android/launcher3/util/PendingRequestArgs.java
index 538e1df..dabd40d 100644
--- a/src/com/android/launcher3/util/PendingRequestArgs.java
+++ b/src/com/android/launcher3/util/PendingRequestArgs.java
@@ -53,6 +53,7 @@
 
     public PendingRequestArgs(Parcel parcel) {
         readFromValues(ContentValues.CREATOR.createFromParcel(parcel));
+        user = parcel.readParcelable(null);
 
         mArg1 = parcel.readInt();
         mObjectType = parcel.readInt();
@@ -69,6 +70,7 @@
         ContentValues itemValues = new ContentValues();
         writeToValues(new ContentWriter(itemValues, null));
         itemValues.writeToParcel(dest, flags);
+        dest.writeParcelable(user, flags);
 
         dest.writeInt(mArg1);
         dest.writeInt(mObjectType);