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

Commit ca1ea17a authored by Todd Kennedy's avatar Todd Kennedy
Browse files

Move check permission methods

Bug: 135279435
Test: atest android.content.pm.PackageManagerTests
Test: atest CtsCameraApi25TestCases
Change-Id: Id96093e4106edcd5302fd8aaa020d1ab83f68258
parent 230c0a7e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -626,7 +626,7 @@ public class ApplicationPackageManager extends PackageManager {
    @Override
    public int checkPermission(String permName, String pkgName) {
        try {
            return mPM.checkPermission(permName, pkgName, getUserId());
            return mPermissionManager.checkPermission(permName, pkgName, getUserId());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+14 −5
Original line number Diff line number Diff line
@@ -96,11 +96,6 @@ interface IPackageManager {
    @UnsupportedAppUsage
    ProviderInfo getProviderInfo(in ComponentName className, int flags, int userId);

    @UnsupportedAppUsage
    int checkPermission(String permName, String pkgName, int userId);

    int checkUidPermission(String permName, int uid);

    @UnsupportedAppUsage
    void grantRuntimePermission(String packageName, String permissionName, int userId);

@@ -750,6 +745,10 @@ interface IPackageManager {
    // The following binder interfaces have been moved to IPermissionManager
    //
    //------------------------------------------------------------------------

    //------------------------------------------------------------------------
    // We need to keep these in IPackageManager for app compatibility
    //------------------------------------------------------------------------
    @UnsupportedAppUsage
    String[] getAppOpPermissionPackages(String permissionName);

@@ -764,4 +763,14 @@ interface IPackageManager {

    @UnsupportedAppUsage
    void removePermission(String name);

    @UnsupportedAppUsage
    int checkPermission(String permName, String pkgName, int userId);

    //------------------------------------------------------------------------
    // We need to keep these in IPackageManager for convenience in splitting
    // out the permission manager. This should be cleaned up, but, will require
    // a large change that modifies many repos.
    //------------------------------------------------------------------------
    int checkUidPermission(String permName, int uid);
}
+6 −43
Original line number Diff line number Diff line
@@ -32,13 +32,10 @@ import android.os.PersistableBundle;
import android.util.ArraySet;
import android.util.SparseArray;

import com.android.internal.util.function.TriFunction;

import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Consumer;

/**
@@ -86,32 +83,6 @@ public abstract class PackageManagerInternal {
        void onPackageRemoved(@NonNull String packageName, int uid);
    }

    /** Interface to override permission checks via composition */
    public interface CheckPermissionDelegate {
        /**
         * Allows overriding check permission behavior.
         *
         * @param permName The permission to check.
         * @param pkgName The package for which to check.
         * @param userId The user for which to check.
         * @param superImpl The super implementation.
         * @return The check permission result.
         */
        int checkPermission(String permName, String pkgName, int userId,
                TriFunction<String, String, Integer, Integer> superImpl);

        /**
         * Allows overriding check UID permission behavior.
         *
         * @param permName The permission to check.
         * @param uid The UID for which to check.
         * @param superImpl The super implementation.
         * @return The check permission result.
         */
        int checkUidPermission(String permName, int uid,
                BiFunction<String, Integer, Integer> superImpl);
    }

    /**
     * Provider for package names.
     */
@@ -667,6 +638,12 @@ public abstract class PackageManagerInternal {
     */
    public abstract @Nullable PackageParser.Package getPackage(@NonNull String packageName);

    /**
     * Returns a package for the given UID. If the UID is part of a shared user ID, one
     * of the packages will be chosen to be returned.
     */
    public abstract @Nullable PackageParser.Package getPackage(int uid);

    /**
     * Returns a list without a change observer.
     *
@@ -770,20 +747,6 @@ public abstract class PackageManagerInternal {
    public abstract boolean hasSignatureCapability(int serverUid, int clientUid,
            @PackageParser.SigningDetails.CertCapabilities int capability);

    /**
     * Get the delegate to influence permission checking.
     *
     * @return The delegate instance or null to clear.
     */
    public abstract @Nullable CheckPermissionDelegate getCheckPermissionDelegate();

    /**
     * Set a delegate to influence permission checking.
     *
     * @param delegate A delegate instance or null to clear.
     */
    public abstract void setCheckPermissionDelegate(@Nullable CheckPermissionDelegate delegate);

    /**
     * Get appIds of all available apps which specified android:sharedUserId in the manifest.
     *
+4 −0
Original line number Diff line number Diff line
@@ -46,4 +46,8 @@ interface IPermissionManager {
            int flagValues, boolean checkAdjustPolicyFlagPermission, int userId);

    void updatePermissionFlagsForAllApps(int flagMask, int flagValues, int userId);

    int checkPermission(String permName, String pkgName, int userId);

    int checkUidPermission(String permName, int uid);
}
+31 −0
Original line number Diff line number Diff line
@@ -21,6 +21,10 @@ import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.os.UserHandle;

import com.android.internal.util.function.TriFunction;

import java.util.function.BiFunction;

/**
 * Internal interfaces to be used by other components within the system server.
 *
@@ -46,6 +50,33 @@ public abstract class PermissionManagerInternal {
                @UserIdInt int userId);
    }

    /** Interface to override permission checks via composition */
    public interface CheckPermissionDelegate {
        /**
         * Checks whether the given package has been granted the specified permission.
         *
         * @return If the package has the permission, PERMISSION_GRANTED is
         * returned.  If it does not have the permission, PERMISSION_DENIED
         * is returned.
         *
         * @see android.content.pm.PackageManager#checkPermission(String, String)
         */
        int checkPermission(String permName, String pkgName, int userId,
                TriFunction<String, String, Integer, Integer> superImpl);

        /**
        /**
         * Checks whether the given uid has been granted the specified permission.
         *
         * @return If the package has the permission, PERMISSION_GRANTED is
         * returned.  If it does not have the permission, PERMISSION_DENIED
         * is returned.
         *
         */
        int checkUidPermission(String permName, int uid,
                BiFunction<String, Integer, Integer> superImpl);
    }

    /**
     * Get the state of the runtime permissions as xml file.
     *
Loading