Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5b3d79ac authored by Anthony Hugh's avatar Anthony Hugh Committed by android-build-merger
Browse files

Merge "Add mechanism for determining if apps are system apps" into cw-e-dev

am: ae613967

* commit 'ae613967':
  Add mechanism for determining if apps are system apps
parents a7bd3497 ae613967
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -69,11 +69,14 @@ public class PermissionStatusReceiver extends BroadcastReceiver {

            List<String> appsList = new ArrayList<>();
            List<CharSequence> appLabelsList = new ArrayList<>();
            if (getAppsWithRuntimePermissions(context, appsList, appLabelsList)) {
            List<Boolean> 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<String> appsList,
            List<CharSequence> appLabelsList) {
            List<CharSequence> appLabelsList, List<Boolean> isSystemAppList) {
        final List<ApplicationInfo> appInfos = Utils.getAllInstalledApplications(context);
        if (appInfos == null) {
            return false;
        }
        final int appInfosSize = appInfos.size();
        try {
            ArraySet<String> 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<Boolean> 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;
    }
}
+9 −1
Original line number Diff line number Diff line
@@ -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<String> launcherPkgs) {
        ApplicationInfo info = app.getAppInfo();
        return isSystem(app.getAppInfo(), launcherPkgs);
    }

    public static boolean isSystem(AppPermissions app, ArraySet<String> launcherPkgs) {
        return isSystem(app.getPackageInfo().applicationInfo, launcherPkgs);
    }

    public static boolean isSystem(ApplicationInfo info, ArraySet<String> launcherPkgs) {
        return info.isSystemApp() && (info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0
                && !launcherPkgs.contains(info.packageName);
    }