summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ricky Wai <rickywai@google.com> 2019-09-25 11:12:40 -0700
committer android-build-merger <android-build-merger@google.com> 2019-09-25 11:12:40 -0700
commitede2e771f5338d577a45d945a32e84c011c32ba6 (patch)
treeda59d03df0270e216f2d191005fd769d205f5eeb
parentd10fe94410e12ee1dfaf4eab0e633e3aa3f6e0ef (diff)
parent835504011f685e6c1d75bc4c8620d790875fddb5 (diff)
Merge "Do not return synthetic launcher activity for completely headless apps"
am: 835504011f Change-Id: I6f3a7ad712fb73c3ec0983dc4ea8bbd11ae4e56c
-rw-r--r--services/core/java/com/android/server/pm/LauncherAppsService.java54
1 files changed, 24 insertions, 30 deletions
diff --git a/services/core/java/com/android/server/pm/LauncherAppsService.java b/services/core/java/com/android/server/pm/LauncherAppsService.java
index 9b6333d7bef4..3464cab99d93 100644
--- a/services/core/java/com/android/server/pm/LauncherAppsService.java
+++ b/services/core/java/com/android/server/pm/LauncherAppsService.java
@@ -443,45 +443,39 @@ public class LauncherAppsService extends SystemService {
if (isManagedProfileAdmin(user, appInfo.packageName)) {
return false;
}
- // If app does not have any components or any permissions, the app can legitimately
- // have no icon so we do not show the synthetic activity.
- return hasComponentsAndRequestsPermissions(appInfo.packageName);
- }
-
- private boolean hasComponentsAndRequestsPermissions(@NonNull String packageName) {
final PackageManagerInternal pmInt =
LocalServices.getService(PackageManagerInternal.class);
- final PackageParser.Package pkg = pmInt.getPackage(packageName);
+ final PackageParser.Package pkg = pmInt.getPackage(appInfo.packageName);
if (pkg == null) {
// Should not happen, but we shouldn't be failing if it does
return false;
}
- if (ArrayUtils.isEmpty(pkg.requestedPermissions)) {
- return false;
- }
- if (!hasApplicationDeclaredActivities(pkg)
- && ArrayUtils.isEmpty(pkg.receivers)
- && ArrayUtils.isEmpty(pkg.providers)
- && ArrayUtils.isEmpty(pkg.services)) {
- return false;
- }
- return true;
+ // If app does not have any default enabled launcher activity or any permissions,
+ // the app can legitimately have no icon so we do not show the synthetic activity.
+ return requestsPermissions(pkg) && hasDefaultEnableLauncherActivity(
+ appInfo.packageName);
}
- private boolean hasApplicationDeclaredActivities(@NonNull PackageParser.Package pkg) {
- if (pkg.activities == null) {
- return false;
- }
- if (ArrayUtils.isEmpty(pkg.activities)) {
- return false;
- }
- // If it only contains synthetic AppDetailsActivity only, it means application does
- // not have actual activity declared in manifest.
- if (pkg.activities.size() == 1 && PackageManager.APP_DETAILS_ACTIVITY_CLASS_NAME.equals(
- pkg.activities.get(0).className)) {
- return false;
+ private boolean requestsPermissions(@NonNull PackageParser.Package pkg) {
+ return !ArrayUtils.isEmpty(pkg.requestedPermissions);
+ }
+
+ private boolean hasDefaultEnableLauncherActivity(@NonNull String packageName) {
+ final PackageManagerInternal pmInt =
+ LocalServices.getService(PackageManagerInternal.class);
+ final Intent matchIntent = new Intent(Intent.ACTION_MAIN);
+ matchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
+ matchIntent.setPackage(packageName);
+ final List<ResolveInfo> infoList = pmInt.queryIntentActivities(matchIntent,
+ PackageManager.MATCH_DISABLED_COMPONENTS, Binder.getCallingUid(),
+ getCallingUserId());
+ final int size = infoList.size();
+ for (int i = 0; i < size; i++) {
+ if (infoList.get(i).activityInfo.enabled) {
+ return true;
+ }
}
- return true;
+ return false;
}
private boolean isManagedProfileAdmin(UserHandle user, String packageName) {