This CL fixes app shortcuts for suspended packages.
1) When DO/PO suspends an app, its pinned shortcuts are instantly grayed
out, but this is not persisted after the launcher restarts (e.g. device
reboot). We now enforce the launcher to check the suspended state when
loading the workspace, and gray out pinned shortcut icons accordingly.
2) When DO/PO suspends an app, its app shortcut popup is still
available. We now temporarily disable the popup when the app is
suspended, and persist the state across restarts.
Bug:
32365540
Test: manual, by following the steps in the bug above
Test: manual, by restarting the launcher package
Change-Id: I983d7c17fa198beca23b66459b50bd67b447bdd2
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;
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;
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.
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;
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);
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;
}
@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);
}
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;
}
@Override
+ public ApplicationInfo getApplicationInfo(String packageName, UserHandle user) {
+ return mLauncherApps.getApplicationInfo(packageName, 0, user);
+ }
+
+ @Override
public List<ShortcutConfigActivityInfo> getCustomShortcutActivityList() {
List<ShortcutConfigActivityInfo> result = new ArrayList<>();
}
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() {
}
}
+ /**
+ * 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);
}
}
+ /**
+ * 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();
}
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