summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/launcher3/AppInfo.java3
-rw-r--r--src/com/android/launcher3/LauncherModel.java40
-rw-r--r--src/com/android/launcher3/compat/LauncherActivityInfoCompat.java2
-rw-r--r--src/com/android/launcher3/compat/LauncherAppsCompat.java16
-rw-r--r--src/com/android/launcher3/compat/LauncherAppsCompatV16.java4
-rw-r--r--src/com/android/launcher3/compat/LauncherAppsCompatVN.java57
-rw-r--r--src/com/android/launcher3/util/PackageManagerHelper.java62
7 files changed, 90 insertions, 94 deletions
diff --git a/src/com/android/launcher3/AppInfo.java b/src/com/android/launcher3/AppInfo.java
index b5b6897cc..28fd268cf 100644
--- a/src/com/android/launcher3/AppInfo.java
+++ b/src/com/android/launcher3/AppInfo.java
@@ -26,6 +26,7 @@ import com.android.launcher3.compat.LauncherActivityInfoCompat;
import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.util.ComponentKey;
+import com.android.launcher3.util.PackageManagerHelper;
import java.util.ArrayList;
@@ -87,7 +88,7 @@ public class AppInfo extends ItemInfo {
this.componentName = info.getComponentName();
this.container = ItemInfo.NO_ID;
flags = initFlags(info);
- if ((info.getApplicationInfo().flags & LauncherActivityInfoCompat.FLAG_SUSPENDED) != 0) {
+ if (PackageManagerHelper.isAppSuspended(info.getApplicationInfo())) {
isDisabled |= ShortcutInfo.FLAG_DISABLED_SUSPENDED;
}
if (quietModeEnabled) {
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index f2b307b12..884685c8a 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -33,7 +33,6 @@ import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
-import android.os.Environment;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
@@ -64,6 +63,7 @@ import com.android.launcher3.util.CursorIconInfo;
import com.android.launcher3.util.FlagOp;
import com.android.launcher3.util.LongArrayMap;
import com.android.launcher3.util.ManagedProfileHeuristic;
+import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.StringFilter;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.util.ViewOnDrawExecutor;
@@ -1749,6 +1749,7 @@ public class LauncherModel extends BroadcastReceiver
long serialNumber;
Intent intent;
UserHandleCompat user;
+ String targetPackage;
while (!mStopped && c.moveToNext()) {
try {
@@ -1767,6 +1768,7 @@ public class LauncherModel extends BroadcastReceiver
int promiseType = c.getInt(restoredIndex);
int disabledState = 0;
boolean itemReplaced = false;
+ targetPackage = null;
if (user == null) {
// User has been deleted remove the item.
itemsToRemove.add(id);
@@ -1780,6 +1782,9 @@ public class LauncherModel extends BroadcastReceiver
cn.getPackageName(), user);
boolean validComponent = validPkg &&
launcherApps.isActivityEnabledForProfile(cn, user);
+ if (validPkg) {
+ targetPackage = cn.getPackageName();
+ }
if (validComponent) {
if (restored) {
@@ -1787,13 +1792,8 @@ public class LauncherModel extends BroadcastReceiver
restoredRows.add(id);
restored = false;
}
- boolean isSuspended = launcherApps.isPackageSuspendedForProfile(
- cn.getPackageName(), user);
- if (isSuspended) {
- disabledState = ShortcutInfo.FLAG_DISABLED_SUSPENDED;
- }
if (quietMode.get(serialNumber)) {
- disabledState |= ShortcutInfo.FLAG_DISABLED_QUIET_USER;
+ disabledState = ShortcutInfo.FLAG_DISABLED_QUIET_USER;
}
} else if (validPkg) {
intent = null;
@@ -1859,9 +1859,8 @@ public class LauncherModel extends BroadcastReceiver
itemsToRemove.add(id);
continue;
}
- } else if (launcherApps.isAppEnabled(
- manager, cn.getPackageName(),
- PackageManager.GET_UNINSTALLED_PACKAGES)) {
+ } else if (PackageManagerHelper.isAppOnSdcard(
+ manager, cn.getPackageName())) {
// Package is present but not available.
allowMissingTarget = true;
disabledState = ShortcutInfo.FLAG_DISABLED_NOT_AVAILABLE;
@@ -1901,7 +1900,7 @@ public class LauncherModel extends BroadcastReceiver
if (itemReplaced) {
if (user.equals(UserHandleCompat.myUserHandle())) {
- info = getAppShortcutInfo(manager, intent, user, context, null,
+ info = getAppShortcutInfo(intent, user, context, null,
cursorIconInfo.iconIndex, titleIndex,
false, useLowResIcon);
} else {
@@ -1921,12 +1920,17 @@ public class LauncherModel extends BroadcastReceiver
}
} else if (itemType ==
LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
- info = getAppShortcutInfo(manager, intent, user, context, c,
+ info = getAppShortcutInfo(intent, user, context, c,
cursorIconInfo.iconIndex, titleIndex,
allowMissingTarget, useLowResIcon);
} else {
info = getShortcutInfo(c, context, titleIndex, cursorIconInfo);
+ // Shortcuts are only available on the primary profile
+ if (PackageManagerHelper.isAppSuspended(manager, targetPackage)) {
+ disabledState |= ShortcutInfo.FLAG_DISABLED_SUSPENDED;
+ }
+
// App shortcuts that used to be automatically added to Launcher
// didn't always have the correct intent flags set, so do that
// here
@@ -1954,7 +1958,7 @@ public class LauncherModel extends BroadcastReceiver
if (info.promisedIntent != null) {
info.promisedIntent.putExtra(ItemInfo.EXTRA_PROFILE, serialNumber);
}
- info.isDisabled = disabledState;
+ info.isDisabled |= disabledState;
if (isSafeMode && !Utilities.isSystemApp(context, intent)) {
info.isDisabled |= ShortcutInfo.FLAG_DISABLED_SAFEMODE;
}
@@ -2822,9 +2826,7 @@ public class LauncherModel extends BroadcastReceiver
packagesUnavailable.clear();
for (String pkg : entry.getValue()) {
if (!launcherApps.isPackageEnabledForProfile(pkg, user)) {
- boolean packageOnSdcard = launcherApps.isAppEnabled(
- manager, pkg, PackageManager.GET_UNINSTALLED_PACKAGES);
- if (packageOnSdcard) {
+ if (PackageManagerHelper.isAppOnSdcard(manager, pkg)) {
packagesUnavailable.add(pkg);
} else {
packagesRemoved.add(pkg);
@@ -3310,7 +3312,7 @@ public class LauncherModel extends BroadcastReceiver
*
* If c is not null, then it will be used to fill in missing data like the title and icon.
*/
- public ShortcutInfo getAppShortcutInfo(PackageManager manager, Intent intent,
+ public ShortcutInfo getAppShortcutInfo(Intent intent,
UserHandleCompat user, Context context, Cursor c, int iconIndex, int titleIndex,
boolean allowMissingTarget, boolean useLowResIcon) {
if (user == null) {
@@ -3340,6 +3342,10 @@ public class LauncherModel extends BroadcastReceiver
info.setIcon(icon == null ? mIconCache.getDefaultIcon(user) : icon);
}
+ if (lai != null && PackageManagerHelper.isAppSuspended(lai.getApplicationInfo())) {
+ info.isDisabled = ShortcutInfo.FLAG_DISABLED_SUSPENDED;
+ }
+
// from the db
if (TextUtils.isEmpty(info.title) && c != null) {
info.title = Utilities.trim(c.getString(titleIndex));
diff --git a/src/com/android/launcher3/compat/LauncherActivityInfoCompat.java b/src/com/android/launcher3/compat/LauncherActivityInfoCompat.java
index aaf756eda..0bc9588aa 100644
--- a/src/com/android/launcher3/compat/LauncherActivityInfoCompat.java
+++ b/src/com/android/launcher3/compat/LauncherActivityInfoCompat.java
@@ -24,8 +24,6 @@ import android.graphics.drawable.Drawable;
public abstract class LauncherActivityInfoCompat {
- public static final int FLAG_SUSPENDED = 1<<30;
-
LauncherActivityInfoCompat() {
}
diff --git a/src/com/android/launcher3/compat/LauncherAppsCompat.java b/src/com/android/launcher3/compat/LauncherAppsCompat.java
index bc900bcb5..237a9e9fb 100644
--- a/src/com/android/launcher3/compat/LauncherAppsCompat.java
+++ b/src/com/android/launcher3/compat/LauncherAppsCompat.java
@@ -19,9 +19,6 @@ package com.android.launcher3.compat;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Rect;
import android.os.Bundle;
@@ -59,9 +56,7 @@ public abstract class LauncherAppsCompat {
public static LauncherAppsCompat getInstance(Context context) {
synchronized (sInstanceLock) {
if (sInstance == null) {
- if (Utilities.isNycOrAbove()) {
- sInstance = new LauncherAppsCompatVN(context.getApplicationContext());
- } else if (Utilities.ATLEAST_LOLLIPOP) {
+ if (Utilities.ATLEAST_LOLLIPOP) {
sInstance = new LauncherAppsCompatVL(context.getApplicationContext());
} else {
sInstance = new LauncherAppsCompatV16(context.getApplicationContext());
@@ -84,13 +79,4 @@ public abstract class LauncherAppsCompat {
public abstract boolean isActivityEnabledForProfile(ComponentName component,
UserHandleCompat user);
public abstract boolean isPackageSuspendedForProfile(String packageName, UserHandleCompat user);
-
- public boolean isAppEnabled(PackageManager pm, String packageName, int flags) {
- try {
- ApplicationInfo info = pm.getApplicationInfo(packageName, flags);
- return info != null && info.enabled;
- } catch (NameNotFoundException e) {
- return false;
- }
- }
}
diff --git a/src/com/android/launcher3/compat/LauncherAppsCompatV16.java b/src/com/android/launcher3/compat/LauncherAppsCompatV16.java
index 2d0778d30..4e2fc055e 100644
--- a/src/com/android/launcher3/compat/LauncherAppsCompatV16.java
+++ b/src/com/android/launcher3/compat/LauncherAppsCompatV16.java
@@ -27,11 +27,11 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.graphics.Rect;
import android.net.Uri;
-import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import com.android.launcher3.Utilities;
+import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.Thunk;
import java.util.ArrayList;
@@ -114,7 +114,7 @@ public class LauncherAppsCompatV16 extends LauncherAppsCompat {
}
public boolean isPackageEnabledForProfile(String packageName, UserHandleCompat user) {
- return isAppEnabled(mPm, packageName, 0);
+ return PackageManagerHelper.isAppEnabled(mPm, packageName);
}
public boolean isActivityEnabledForProfile(ComponentName component, UserHandleCompat user) {
diff --git a/src/com/android/launcher3/compat/LauncherAppsCompatVN.java b/src/com/android/launcher3/compat/LauncherAppsCompatVN.java
deleted file mode 100644
index 0d883b6fd..000000000
--- a/src/com/android/launcher3/compat/LauncherAppsCompatVN.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.launcher3.compat;
-
-import android.content.Context;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.LauncherApps;
-import android.os.UserHandle;
-import android.util.Log;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-//TODO: Once gogole3 SDK is updated to N, add @TargetApi(Build.VERSION_CODES.N)
-public class LauncherAppsCompatVN extends LauncherAppsCompatVL {
-
- private static final String TAG = "LauncherAppsCompatVN";
-
- LauncherAppsCompatVN(Context context) {
- super(context);
- }
-
- @Override
- public boolean isPackageSuspendedForProfile(String packageName, UserHandleCompat user) {
- if (user != null && packageName != null) {
- try {
- //TODO: Replace with proper API call once google3 SDK is updated.
- Method getApplicationInfoMethod = LauncherApps.class.getMethod("getApplicationInfo",
- String.class, int.class, UserHandle.class);
-
- ApplicationInfo info = (ApplicationInfo) getApplicationInfoMethod.invoke(
- mLauncherApps, packageName, 0, user.getUser());
- if (info != null) {
- return (info.flags & LauncherActivityInfoCompat.FLAG_SUSPENDED) != 0;
- }
- } catch (NoSuchMethodError | NoSuchMethodException | IllegalAccessException
- | IllegalArgumentException | InvocationTargetException e) {
- Log.e(TAG, "Running on N without getApplicationInfo", e);
- }
- }
- return false;
- }
-}
diff --git a/src/com/android/launcher3/util/PackageManagerHelper.java b/src/com/android/launcher3/util/PackageManagerHelper.java
new file mode 100644
index 000000000..d0345727f
--- /dev/null
+++ b/src/com/android/launcher3/util/PackageManagerHelper.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.launcher3.util;
+
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+
+/**
+ * Utility methods using package manager
+ */
+public class PackageManagerHelper {
+
+ private static final int FLAG_SUSPENDED = 1<<30;
+
+ /**
+ * Returns true if the app can possibly be on the SDCard. This is just a workaround and doesn't
+ * guarantee that the app is on SD card.
+ */
+ public static boolean isAppOnSdcard(PackageManager pm, String packageName) {
+ return isAppEnabled(pm, packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
+ }
+
+ public static boolean isAppEnabled(PackageManager pm, String packageName) {
+ return isAppEnabled(pm, packageName, 0);
+ }
+
+ public static boolean isAppEnabled(PackageManager pm, String packageName, int flags) {
+ try {
+ ApplicationInfo info = pm.getApplicationInfo(packageName, flags);
+ return info != null && info.enabled;
+ } catch (PackageManager.NameNotFoundException e) {
+ return false;
+ }
+ }
+
+ public static boolean isAppSuspended(PackageManager pm, String packageName) {
+ try {
+ ApplicationInfo info = pm.getApplicationInfo(packageName, 0);
+ return info != null && isAppSuspended(info);
+ } catch (PackageManager.NameNotFoundException e) {
+ return false;
+ }
+ }
+
+ public static boolean isAppSuspended(ApplicationInfo info) {
+ return (info.flags & FLAG_SUSPENDED) != 0;
+ }
+}