From e4cd4f8bb6035fd5463c5a44c267b0dd196c17fe Mon Sep 17 00:00:00 2001 From: Anthony Hugh Date: Mon, 26 Oct 2015 17:50:00 -0700 Subject: Add mechanism for determining if apps are system apps This is being added to help identify system apps so that the UI can filter on that type. BUG: 24955055 Change-Id: I8d843bae2d81329009c8cda8c25355d08ab9d1d7 --- .../permission/model/PermissionStatusReceiver.java | 19 +++++++++++++++++-- .../packageinstaller/permission/utils/Utils.java | 10 +++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/com/android/packageinstaller/permission/model/PermissionStatusReceiver.java b/src/com/android/packageinstaller/permission/model/PermissionStatusReceiver.java index 3604cd71..810ae8ec 100644 --- a/src/com/android/packageinstaller/permission/model/PermissionStatusReceiver.java +++ b/src/com/android/packageinstaller/permission/model/PermissionStatusReceiver.java @@ -69,11 +69,14 @@ public class PermissionStatusReceiver extends BroadcastReceiver { List appsList = new ArrayList<>(); List appLabelsList = new ArrayList<>(); - if (getAppsWithRuntimePermissions(context, appsList, appLabelsList)) { + List isSystemAppList = new ArrayList<>(); + if (getAppsWithRuntimePermissions(context, appsList, appLabelsList, isSystemAppList)) { responseIntent.putExtra(Intent.EXTRA_GET_PERMISSIONS_APP_LIST_RESULT, appsList.toArray(new String[appsList.size()])); responseIntent.putExtra(Intent.EXTRA_GET_PERMISSIONS_APP_LABEL_LIST_RESULT, appLabelsList.toArray(new String[appLabelsList.size()])); + responseIntent.putExtra(Intent.EXTRA_GET_PERMISSIONS_IS_SYSTEM_APP_LIST_RESULT, + toPrimitiveBoolArray(isSystemAppList)); } context.sendBroadcast(responseIntent); } @@ -122,13 +125,14 @@ public class PermissionStatusReceiver extends BroadcastReceiver { } public boolean getAppsWithRuntimePermissions(Context context, List appsList, - List appLabelsList) { + List appLabelsList, List isSystemAppList) { final List appInfos = Utils.getAllInstalledApplications(context); if (appInfos == null) { return false; } final int appInfosSize = appInfos.size(); try { + ArraySet launcherPackages = Utils.getLauncherPackages(context); for (int i = 0; i < appInfosSize; ++i) { final String packageName = appInfos.get(i).packageName; PackageInfo packageInfo = context.getPackageManager().getPackageInfo( @@ -146,6 +150,7 @@ public class PermissionStatusReceiver extends BroadcastReceiver { if (shouldShow) { appsList.add(packageName); appLabelsList.add(appPermissions.getAppLabel()); + isSystemAppList.add(Utils.isSystem(appPermissions, launcherPackages)); } } } catch (NameNotFoundException e) { @@ -180,4 +185,14 @@ public class PermissionStatusReceiver extends BroadcastReceiver { counts[1] = allApps.size(); return true; } + + private boolean[] toPrimitiveBoolArray(final List list) { + final int count = list.size(); + final boolean[] result = new boolean[count]; + for (int i = 0; i < count; ++i) { + result[i] = list.get(i); + } + + return result; + } } diff --git a/src/com/android/packageinstaller/permission/utils/Utils.java b/src/com/android/packageinstaller/permission/utils/Utils.java index 2cc5d8aa..21830378 100644 --- a/src/com/android/packageinstaller/permission/utils/Utils.java +++ b/src/com/android/packageinstaller/permission/utils/Utils.java @@ -31,6 +31,7 @@ import android.util.Log; import android.util.TypedValue; import com.android.packageinstaller.permission.model.AppPermissionGroup; +import com.android.packageinstaller.permission.model.AppPermissions; import com.android.packageinstaller.permission.model.PermissionApps.PermissionApp; import java.util.List; @@ -134,7 +135,14 @@ public class Utils { } public static boolean isSystem(PermissionApp app, ArraySet launcherPkgs) { - ApplicationInfo info = app.getAppInfo(); + return isSystem(app.getAppInfo(), launcherPkgs); + } + + public static boolean isSystem(AppPermissions app, ArraySet launcherPkgs) { + return isSystem(app.getPackageInfo().applicationInfo, launcherPkgs); + } + + public static boolean isSystem(ApplicationInfo info, ArraySet launcherPkgs) { return info.isSystemApp() && (info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0 && !launcherPkgs.contains(info.packageName); } -- cgit v1.2.3