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

Commit b306001c authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 5688376 from bfb18441 to qt-release

Change-Id: I5b54221a275398d4cb54c1ecd1c60647bd7ae1fb
parents fe9b607c bfb18441
Loading
Loading
Loading
Loading
+48 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.Manifest;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PermissionInfo;
import android.permission.PermissionManager;
import android.text.TextUtils;
import android.util.Log;
@@ -54,6 +55,8 @@ class RuntimePermissionsUpgradeController {
                PermissionManager.class);
        final int currentVersion = permissionManager.getRuntimePermissionsVersion();

        whitelistAllSystemAppPermissions(context);

        final int upgradedVersion = onUpgradeLocked(context, currentVersion);

        if (upgradedVersion != LATEST_VERSION) {
@@ -69,6 +72,51 @@ class RuntimePermissionsUpgradeController {
        }
    }

    /**
     * Whitelist permissions of system-apps.
     *
     * <p>Apps that are updated via OTAs are never installed. Hence their permission are never
     * whitelisted. This code replaces that by always whitelisting them.
     *
     * @param context A context to talk to the platform
     */
    private static void whitelistAllSystemAppPermissions(@NonNull Context context) {
        // Only whitelist permissions that are in the OTA. For non-OTA updates the installer should
        // do the white-listing
        final List<PackageInfo> apps = context.getPackageManager()
                .getInstalledPackages(PackageManager.GET_PERMISSIONS
                        | PackageManager.MATCH_UNINSTALLED_PACKAGES
                        | PackageManager.MATCH_FACTORY_ONLY);

        final int appCount = apps.size();
        for (int i = 0; i < appCount; i++) {
            final PackageInfo app = apps.get(i);

            if (app.requestedPermissions == null) {
                continue;
            }

            for (String requestedPermission : app.requestedPermissions) {
                final PermissionInfo permInfo;
                try {
                    permInfo = context.getPackageManager().getPermissionInfo(
                            requestedPermission, 0);
                } catch (PackageManager.NameNotFoundException e) {
                    continue;
                }

                if ((permInfo.flags & (PermissionInfo.FLAG_HARD_RESTRICTED
                        | PermissionInfo.FLAG_SOFT_RESTRICTED)) == 0) {
                    continue;
                }

                context.getPackageManager().addWhitelistedRestrictedPermission(
                        app.packageName, requestedPermission,
                        PackageManager.FLAG_PERMISSION_WHITELIST_UPGRADE);
            }
        }
    }

    /**
     * You must perform all necessary mutations to bring the runtime permissions
     * database from the old to the new version. When you add a new upgrade step
+9 −0
Original line number Diff line number Diff line
@@ -320,6 +320,11 @@ public final class AppPermissionsFragment extends SettingsWithLargeHeader {
        for (int i = 0; i < numAllowed; i++) {
            Preference preference = allowed.getPreference(i);

            if (preference.getSummary() == null) {
                // R.string.no_permission_allowed was added to PreferenceCategory
                continue;
            }

            int category = APP_PERMISSIONS_FRAGMENT_VIEWED__CATEGORY__ALLOWED;
            if (permissionSubtitleOnlyInForeground.contentEquals(preference.getSummary())) {
                category = APP_PERMISSIONS_FRAGMENT_VIEWED__CATEGORY__ALLOWED_FOREGROUND;
@@ -333,6 +338,10 @@ public final class AppPermissionsFragment extends SettingsWithLargeHeader {
        int numDenied = denied.getPreferenceCount();
        for (int i = 0; i < numDenied; i++) {
            Preference preference = denied.getPreference(i);
            if (preference.getSummary() == null) {
                // R.string.no_permission_denied was added to PreferenceCategory
                continue;
            }
            logAppPermissionsFragmentViewEntry(sessionId, viewId, preference.getKey(),
                    APP_PERMISSIONS_FRAGMENT_VIEWED__CATEGORY__DENIED);
        }