Merge "Fixing accessibility description for all-apps grid adapter. Only counting app icons towards various collection related info" into ub-launcher3-master
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 14b9c82..624ea4a 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -3209,6 +3209,9 @@
         if (LauncherAppState.PROFILE_STARTUP) {
             Trace.beginSection("Starting page bind");
         }
+
+        AbstractFloatingView.closeAllOpenViews(this);
+
         setWorkspaceLoading(true);
 
         // Clear the workspace because it's going to be rebound
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 34d576d..5fd5081 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -26,7 +26,6 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.pm.LauncherActivityInfo;
-import android.content.pm.PackageManager;
 import android.net.Uri;
 import android.os.Handler;
 import android.os.HandlerThread;
@@ -85,7 +84,6 @@
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
 import java.lang.ref.WeakReference;
-import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
@@ -1034,6 +1032,11 @@
                                         info = new ShortcutInfo(pinnedShortcut, context);
                                         info.iconBitmap = LauncherIcons
                                                 .createShortcutIcon(pinnedShortcut, context);
+                                        if (pmHelper.isAppSuspended(
+                                                info.getTargetComponent().getPackageName(),
+                                                info.user)) {
+                                            info.isDisabled |= ShortcutInfo.FLAG_DISABLED_SUSPENDED;
+                                        }
                                         intent = info.intent;
                                     } else {
                                         // Create a shortcut info in disabled mode for now.
diff --git a/src/com/android/launcher3/compat/LauncherAppsCompat.java b/src/com/android/launcher3/compat/LauncherAppsCompat.java
index b9142ed..44a3686 100644
--- a/src/com/android/launcher3/compat/LauncherAppsCompat.java
+++ b/src/com/android/launcher3/compat/LauncherAppsCompat.java
@@ -19,6 +19,7 @@
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
+import android.content.pm.ApplicationInfo;
 import android.content.pm.LauncherActivityInfo;
 import android.graphics.Rect;
 import android.os.Bundle;
@@ -72,6 +73,7 @@
             UserHandle user);
     public abstract void startActivityForProfile(ComponentName component, UserHandle user,
             Rect sourceBounds, Bundle opts);
+    public abstract ApplicationInfo getApplicationInfo(String packageName, UserHandle user);
     public abstract void showAppDetailsForProfile(ComponentName component, UserHandle user);
     public abstract void addOnAppsChangedCallback(OnAppsChangedCallbackCompat listener);
     public abstract void removeOnAppsChangedCallback(OnAppsChangedCallbackCompat listener);
diff --git a/src/com/android/launcher3/compat/LauncherAppsCompatVL.java b/src/com/android/launcher3/compat/LauncherAppsCompatVL.java
index 3cb721c..776f593 100644
--- a/src/com/android/launcher3/compat/LauncherAppsCompatVL.java
+++ b/src/com/android/launcher3/compat/LauncherAppsCompatVL.java
@@ -19,6 +19,7 @@
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
+import android.content.pm.ApplicationInfo;
 import android.content.pm.LauncherActivityInfo;
 import android.content.pm.LauncherApps;
 import android.content.pm.PackageManager;
@@ -65,6 +66,12 @@
     }
 
     @Override
+    public ApplicationInfo getApplicationInfo(String packageName, UserHandle user) {
+        List<LauncherActivityInfo> activityList = mLauncherApps.getActivityList(packageName, user);
+        return activityList.size() > 0 ? activityList.get(0).getApplicationInfo() : null;
+    }
+
+    @Override
     public void showAppDetailsForProfile(ComponentName component, UserHandle user) {
         mLauncherApps.startAppDetailsActivity(component, user, null, null);
     }
diff --git a/src/com/android/launcher3/compat/LauncherAppsCompatVO.java b/src/com/android/launcher3/compat/LauncherAppsCompatVO.java
index 0610726..377907a 100644
--- a/src/com/android/launcher3/compat/LauncherAppsCompatVO.java
+++ b/src/com/android/launcher3/compat/LauncherAppsCompatVO.java
@@ -17,6 +17,7 @@
 package com.android.launcher3.compat;
 
 import android.content.Context;
+import android.content.pm.ApplicationInfo;
 import android.content.pm.LauncherActivityInfo;
 import android.content.pm.LauncherApps;
 import android.os.UserHandle;
@@ -34,6 +35,11 @@
     }
 
     @Override
+    public ApplicationInfo getApplicationInfo(String packageName, UserHandle user) {
+        return mLauncherApps.getApplicationInfo(packageName, 0, user);
+    }
+
+    @Override
     public List<ShortcutConfigActivityInfo> getCustomShortcutActivityList() {
         List<ShortcutConfigActivityInfo> result = new ArrayList<>();
 
diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java
index 3d28f22..4ad13d0 100644
--- a/src/com/android/launcher3/folder/Folder.java
+++ b/src/com/android/launcher3/folder/Folder.java
@@ -535,7 +535,6 @@
         }
 
         mIsOpen = true;
-        mFolderIcon.growAndFadeOut();
 
         mContent.completePendingPageChanges();
         if (!mDragInProgress) {
@@ -552,6 +551,8 @@
         prepareReveal();
         centerAboutIcon();
 
+        mFolderIcon.growAndFadeOut();
+
         AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
         int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
         int height = getFolderHeight();
@@ -1088,6 +1089,7 @@
         int folderPivotY = height / 2 + (centeredTop - top);
         setPivotX(folderPivotX);
         setPivotY(folderPivotY);
+
         mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() *
                 (1.0f * folderPivotX / width));
         mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() *
diff --git a/src/com/android/launcher3/notification/NotificationListener.java b/src/com/android/launcher3/notification/NotificationListener.java
index 5c16176..a627d23 100644
--- a/src/com/android/launcher3/notification/NotificationListener.java
+++ b/src/com/android/launcher3/notification/NotificationListener.java
@@ -40,7 +40,7 @@
  * A {@link NotificationListenerService} that sends updates to its
  * {@link NotificationsChangedListener} when notifications are posted or canceled,
  * as well and when this service first connects. An instance of NotificationListener,
- * and its methods for getting notifications, can be obtained via {@link #getInstance()}.
+ * and its methods for getting notifications, can be obtained via {@link #getInstanceIfConnected()}.
  */
 public class NotificationListener extends NotificationListenerService {
 
@@ -50,6 +50,7 @@
 
     private static NotificationListener sNotificationListenerInstance = null;
     private static NotificationsChangedListener sNotificationsChangedListener;
+    private static boolean sIsConnected;
 
     private final Handler mWorkerHandler;
     private final Handler mUiHandler;
@@ -65,8 +66,9 @@
                     mUiHandler.obtainMessage(message.what, message.obj).sendToTarget();
                     break;
                 case MSG_NOTIFICATION_FULL_REFRESH:
-                    final List<StatusBarNotification> activeNotifications
-                            = filterNotifications(getActiveNotifications());
+                    final List<StatusBarNotification> activeNotifications = sIsConnected
+                            ? filterNotifications(getActiveNotifications())
+                            : new ArrayList<StatusBarNotification>();
                     mUiHandler.obtainMessage(message.what, activeNotifications).sendToTarget();
                     break;
             }
@@ -107,10 +109,11 @@
         super();
         mWorkerHandler = new Handler(LauncherModel.getWorkerLooper(), mWorkerCallback);
         mUiHandler = new Handler(Looper.getMainLooper(), mUiCallback);
+        sNotificationListenerInstance = this;
     }
 
-    public static @Nullable NotificationListener getInstance() {
-        return sNotificationListenerInstance;
+    public static @Nullable NotificationListener getInstanceIfConnected() {
+        return sIsConnected ? sNotificationListenerInstance : null;
     }
 
     public static void setNotificationsChangedListener(NotificationsChangedListener listener) {
@@ -119,9 +122,8 @@
         }
         sNotificationsChangedListener = listener;
 
-        NotificationListener notificationListener = getInstance();
-        if (notificationListener != null) {
-            notificationListener.onNotificationFullRefresh();
+        if (sNotificationListenerInstance != null) {
+            sNotificationListenerInstance.onNotificationFullRefresh();
         }
     }
 
@@ -132,7 +134,7 @@
     @Override
     public void onListenerConnected() {
         super.onListenerConnected();
-        sNotificationListenerInstance = this;
+        sIsConnected = true;
         onNotificationFullRefresh();
     }
 
@@ -143,7 +145,7 @@
     @Override
     public void onListenerDisconnected() {
         super.onListenerDisconnected();
-        sNotificationListenerInstance = null;
+        sIsConnected = false;
     }
 
     @Override
diff --git a/src/com/android/launcher3/popup/PopupDataProvider.java b/src/com/android/launcher3/popup/PopupDataProvider.java
index e314b64..ee2930f 100644
--- a/src/com/android/launcher3/popup/PopupDataProvider.java
+++ b/src/com/android/launcher3/popup/PopupDataProvider.java
@@ -172,7 +172,7 @@
     private boolean updateBadgeIcon(BadgeInfo badgeInfo) {
         boolean hadNotificationToShow = badgeInfo.hasNotificationToShow();
         NotificationInfo notificationInfo = null;
-        NotificationListener notificationListener = NotificationListener.getInstance();
+        NotificationListener notificationListener = NotificationListener.getInstanceIfConnected();
         if (notificationListener != null && badgeInfo.getNotificationKeys().size() == 1) {
             StatusBarNotification[] activeNotifications = notificationListener
                     .getActiveNotifications(new String[] {badgeInfo.getNotificationKeys().get(0)});
@@ -222,13 +222,13 @@
 
     /** This makes a potentially expensive binder call and should be run on a background thread. */
     public List<StatusBarNotification> getStatusBarNotificationsForKeys(String[] notificationKeys) {
-        NotificationListener notificationListener = NotificationListener.getInstance();
+        NotificationListener notificationListener = NotificationListener.getInstanceIfConnected();
         return notificationListener == null ? Collections.EMPTY_LIST
                 : notificationListener.getNotificationsForKeys(notificationKeys);
     }
 
     public void cancelNotification(String notificationKey) {
-        NotificationListener notificationListener = NotificationListener.getInstance();
+        NotificationListener notificationListener = NotificationListener.getInstanceIfConnected();
         if (notificationListener == null) {
             return;
         }
diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutManager.java b/src/com/android/launcher3/shortcuts/DeepShortcutManager.java
index 9413913..df7f695 100644
--- a/src/com/android/launcher3/shortcuts/DeepShortcutManager.java
+++ b/src/com/android/launcher3/shortcuts/DeepShortcutManager.java
@@ -65,7 +65,8 @@
     }
 
     public static boolean supportsShortcuts(ItemInfo info) {
-        return info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
+        return info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION
+                && !info.isDisabled();
     }
 
     public boolean wasLastCallSuccess() {
diff --git a/src/com/android/launcher3/util/PackageManagerHelper.java b/src/com/android/launcher3/util/PackageManagerHelper.java
index e89fc0c..bfa932b 100644
--- a/src/com/android/launcher3/util/PackageManagerHelper.java
+++ b/src/com/android/launcher3/util/PackageManagerHelper.java
@@ -71,6 +71,10 @@
         }
     }
 
+  /**
+   * Returns whether a package is suspended for the current user as per
+   * {@link android.app.admin.DevicePolicyManager#isPackageSuspended}.
+   */
     public boolean isAppSuspended(String packageName) {
         try {
             ApplicationInfo info = mPm.getApplicationInfo(packageName, 0);
@@ -80,6 +84,16 @@
         }
     }
 
+  /**
+   * Returns whether the target app is suspended for a given user as per
+   * {@link android.app.admin.DevicePolicyManager#isPackageSuspended}.
+   */
+    public boolean isAppSuspended(String packageName, UserHandle user) {
+        ApplicationInfo info =
+                LauncherAppsCompat.getInstance(mContext).getApplicationInfo(packageName, user);
+        return info != null && isAppSuspended(info);
+    }
+
     public boolean isSafeMode() {
         return mPm.isSafeMode();
     }
@@ -91,6 +105,10 @@
                 AppInfo.makeLaunchIntent(mContext, activities.get(0), user);
     }
 
+  /**
+   * Returns whether an application is suspended as per
+   * {@link android.app.admin.DevicePolicyManager#isPackageSuspended}.
+   */
     public static boolean isAppSuspended(ApplicationInfo info) {
         // The value of FLAG_SUSPENDED was reused by a hidden constant
         // ApplicationInfo.FLAG_PRIVILEGED prior to N, so only check for suspended flag on N