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

Commit 7d717842 authored by Philip P. Moltmann's avatar Philip P. Moltmann Committed by Android (Google) Code Review
Browse files

Merge changes from topic "actuallyUsePermissionControllerToRestoreBackup"

* changes:
  Expose permission flag APIs for tests
  Move permission restore code into permission controller.
parents b5fd2e72 3e496175
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -516,13 +516,20 @@ package android.content.pm {
    method @RequiresPermission("android.permission.INTERACT_ACROSS_USERS_FULL") public abstract java.util.List<android.content.pm.PackageInfo> getInstalledPackagesAsUser(int, int);
    method @RequiresPermission("android.permission.INTERACT_ACROSS_USERS_FULL") public abstract java.util.List<android.content.pm.PackageInfo> getInstalledPackagesAsUser(int, int);
    method @Nullable public abstract String[] getNamesForUids(int[]);
    method @Nullable public abstract String[] getNamesForUids(int[]);
    method public abstract String getPermissionControllerPackageName();
    method public abstract String getPermissionControllerPackageName();
    method @RequiresPermission(anyOf={"android.permission.GRANT_RUNTIME_PERMISSIONS", "android.permission.REVOKE_RUNTIME_PERMISSIONS"}) public abstract int getPermissionFlags(String, String, @NonNull android.os.UserHandle);
    method @NonNull public abstract String getServicesSystemSharedLibraryPackageName();
    method @NonNull public abstract String getServicesSystemSharedLibraryPackageName();
    method @NonNull public abstract String getSharedSystemSharedLibraryPackageName();
    method @NonNull public abstract String getSharedSystemSharedLibraryPackageName();
    method public String getWellbeingPackageName();
    method public String getWellbeingPackageName();
    method @RequiresPermission("android.permission.GRANT_RUNTIME_PERMISSIONS") public abstract void grantRuntimePermission(@NonNull String, @NonNull String, @NonNull android.os.UserHandle);
    method @RequiresPermission("android.permission.GRANT_RUNTIME_PERMISSIONS") public abstract void grantRuntimePermission(@NonNull String, @NonNull String, @NonNull android.os.UserHandle);
    method @RequiresPermission("android.permission.REVOKE_RUNTIME_PERMISSIONS") public abstract void revokeRuntimePermission(@NonNull String, @NonNull String, @NonNull android.os.UserHandle);
    method @RequiresPermission("android.permission.REVOKE_RUNTIME_PERMISSIONS") public abstract void revokeRuntimePermission(@NonNull String, @NonNull String, @NonNull android.os.UserHandle);
    method @RequiresPermission(anyOf={"android.permission.GRANT_RUNTIME_PERMISSIONS", "android.permission.REVOKE_RUNTIME_PERMISSIONS"}) public abstract void updatePermissionFlags(String, String, int, int, @NonNull android.os.UserHandle);
    field public static final String FEATURE_ADOPTABLE_STORAGE = "android.software.adoptable_storage";
    field public static final String FEATURE_ADOPTABLE_STORAGE = "android.software.adoptable_storage";
    field public static final String FEATURE_FILE_BASED_ENCRYPTION = "android.software.file_based_encryption";
    field public static final String FEATURE_FILE_BASED_ENCRYPTION = "android.software.file_based_encryption";
    field public static final int FLAG_PERMISSION_REVIEW_REQUIRED = 64; // 0x40
    field public static final int FLAG_PERMISSION_REVOKE_ON_UPGRADE = 8; // 0x8
    field public static final int FLAG_PERMISSION_REVOKE_WHEN_REQUESTED = 128; // 0x80
    field public static final int FLAG_PERMISSION_USER_FIXED = 2; // 0x2
    field public static final int FLAG_PERMISSION_USER_SET = 1; // 0x1
    field public static final int MATCH_FACTORY_ONLY = 2097152; // 0x200000
    field public static final int MATCH_FACTORY_ONLY = 2097152; // 0x200000
    field public static final int MATCH_KNOWN_PACKAGES = 4202496; // 0x402000
    field public static final int MATCH_KNOWN_PACKAGES = 4202496; // 0x402000
    field public static final String SYSTEM_SHARED_LIBRARY_SERVICES = "android.ext.services";
    field public static final String SYSTEM_SHARED_LIBRARY_SERVICES = "android.ext.services";
+0 −2
Original line number Original line Diff line number Diff line
@@ -295,8 +295,6 @@ interface IPackageManager {
    void restoreDefaultApps(in byte[] backup, int userId);
    void restoreDefaultApps(in byte[] backup, int userId);
    byte[] getIntentFilterVerificationBackup(int userId);
    byte[] getIntentFilterVerificationBackup(int userId);
    void restoreIntentFilterVerification(in byte[] backup, int userId);
    void restoreIntentFilterVerification(in byte[] backup, int userId);
    byte[] getPermissionGrantBackup(int userId);
    void restorePermissionGrants(in byte[] backup, int userId);


    /**
    /**
     * Report the set of 'Home' activity candidates, plus (if any) which of them
     * Report the set of 'Home' activity candidates, plus (if any) which of them
+7 −0
Original line number Original line Diff line number Diff line
@@ -2943,6 +2943,7 @@ public abstract class PackageManager {
    * @hide
    * @hide
    */
    */
    @SystemApi
    @SystemApi
    @TestApi
    public static final int FLAG_PERMISSION_USER_SET = 1 << 0;
    public static final int FLAG_PERMISSION_USER_SET = 1 << 0;


    /**
    /**
@@ -2953,6 +2954,7 @@ public abstract class PackageManager {
     * @hide
     * @hide
     */
     */
    @SystemApi
    @SystemApi
    @TestApi
    public static final int FLAG_PERMISSION_USER_FIXED =  1 << 1;
    public static final int FLAG_PERMISSION_USER_FIXED =  1 << 1;


    /**
    /**
@@ -2976,6 +2978,7 @@ public abstract class PackageManager {
     * @hide
     * @hide
     */
     */
    @SystemApi
    @SystemApi
    @TestApi
    public static final int FLAG_PERMISSION_REVOKE_ON_UPGRADE =  1 << 3;
    public static final int FLAG_PERMISSION_REVOKE_ON_UPGRADE =  1 << 3;


    /**
    /**
@@ -3005,6 +3008,7 @@ public abstract class PackageManager {
     * @hide
     * @hide
     */
     */
    @SystemApi
    @SystemApi
    @TestApi
    public static final int FLAG_PERMISSION_REVIEW_REQUIRED =  1 << 6;
    public static final int FLAG_PERMISSION_REVIEW_REQUIRED =  1 << 6;


    /**
    /**
@@ -3014,6 +3018,7 @@ public abstract class PackageManager {
     *
     *
     * @hide
     * @hide
     */
     */
    @TestApi
    public static final int FLAG_PERMISSION_REVOKE_WHEN_REQUESTED =  1 << 7;
    public static final int FLAG_PERMISSION_REVOKE_WHEN_REQUESTED =  1 << 7;


    /**
    /**
@@ -3795,6 +3800,7 @@ public abstract class PackageManager {
     * @hide
     * @hide
     */
     */
    @SystemApi
    @SystemApi
    @TestApi
    @RequiresPermission(anyOf = {
    @RequiresPermission(anyOf = {
            android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS,
            android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS,
            android.Manifest.permission.REVOKE_RUNTIME_PERMISSIONS
            android.Manifest.permission.REVOKE_RUNTIME_PERMISSIONS
@@ -3815,6 +3821,7 @@ public abstract class PackageManager {
     * @hide
     * @hide
     */
     */
    @SystemApi
    @SystemApi
    @TestApi
    @RequiresPermission(anyOf = {
    @RequiresPermission(anyOf = {
            android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS,
            android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS,
            android.Manifest.permission.REVOKE_RUNTIME_PERMISSIONS
            android.Manifest.permission.REVOKE_RUNTIME_PERMISSIONS
+4 −3
Original line number Original line Diff line number Diff line
@@ -624,7 +624,7 @@ public final class PermissionControllerManager {
         *
         *
         * <p>Needs to be called when canceling this task as it might be hung.
         * <p>Needs to be called when canceling this task as it might be hung.
         */
         */
        void interruptRead() {
        void interruptWrite() {
            IoUtils.closeQuietly(mLocalPipe);
            IoUtils.closeQuietly(mLocalPipe);
        }
        }


@@ -806,18 +806,19 @@ public final class PermissionControllerManager {


        @Override
        @Override
        public void run(@NonNull IPermissionController service) {
        public void run(@NonNull IPermissionController service) {
            mBackupSender.execute(mBackup);

            ParcelFileDescriptor remotePipe = mBackupSender.getRemotePipe();
            ParcelFileDescriptor remotePipe = mBackupSender.getRemotePipe();
            try {
            try {
                service.restoreRuntimePermissionBackup(mUser, remotePipe);
                service.restoreRuntimePermissionBackup(mUser, remotePipe);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.e(TAG, "Error sending runtime permission backup", e);
                Log.e(TAG, "Error sending runtime permission backup", e);
                mBackupSender.cancel(false);
                mBackupSender.cancel(false);
                mBackupSender.interruptWrite();
            } finally {
            } finally {
                // Remote pipe end is duped by binder call. Local copy is not needed anymore
                // Remote pipe end is duped by binder call. Local copy is not needed anymore
                IoUtils.closeQuietly(remotePipe);
                IoUtils.closeQuietly(remotePipe);
            }
            }

            mBackupSender.execute(mBackup);
        }
        }
    }
    }


+62 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2019 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 android.permission;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.UserHandle;

/**
 * Internal interfaces to be used by other components within the system server.
 *
 * <p>Only for use within the system server.
 *
 * @hide
 */
public abstract class PermissionManagerInternal {
    /**
     * Get the state of the runtime permissions as xml file.
     *
     * @param user The user the data should be extracted for
     *
     * @return The state as a xml file
     */
    public abstract @Nullable byte[] backupRuntimePermissions(@NonNull UserHandle user);

    /**
     * Restore a permission state previously backed up via {@link #backupRuntimePermissions}.
     *
     * <p>If not all state can be restored, the un-restoreable state will be delayed and can be
     * re-tried via {@link #restoreDelayedRuntimePermissions}.
     *
     * @param backup The state as an xml file
     * @param user The user the data should be restored for
     */
    public abstract void restoreRuntimePermissions(@NonNull byte[] backup,
            @NonNull UserHandle user);

    /**
     * Try to apply permission backup of a package that was previously not applied.
     *
     * @param packageName The package that is newly installed
     * @param user The user the package is installed for
     *
     * @see #restoreRuntimePermissions
     */
    public abstract void restoreDelayedRuntimePermissions(@NonNull String packageName,
            @NonNull UserHandle user);
}
Loading