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

Commit 2584e802 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add API for instrumentations from root to override perms" into main

parents 2b57e1ab fbeceb0a
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -486,12 +486,16 @@ package android.app {
  }

  public final class UiAutomation {
    method public void addOverridePermissionState(int, @NonNull String, int);
    method public void clearAllOverridePermissionStates();
    method public void clearOverridePermissionStates(int);
    method public void destroy();
    method @NonNull public java.util.Set<java.lang.String> getAdoptedShellPermissions();
    method @Deprecated public boolean grantRuntimePermission(String, String, android.os.UserHandle);
    method public boolean injectInputEvent(@NonNull android.view.InputEvent, boolean, boolean);
    method public void injectInputEventToInputFilter(@NonNull android.view.InputEvent);
    method public boolean isNodeInCache(@NonNull android.view.accessibility.AccessibilityNodeInfo);
    method public void removeOverridePermissionState(int, @NonNull String);
    method @Deprecated public boolean revokeRuntimePermission(String, String, android.os.UserHandle);
    method public void syncInputTransactions();
    method public void syncInputTransactions(boolean);
+10 −8
Original line number Diff line number Diff line
@@ -53,9 +53,10 @@ public abstract class AppOpsManagerInternal {
         * @param superImpl The super implementation.
         * @return The app op check result.
         */
        int checkOperation(int code, int uid, String packageName, @Nullable String attributionTag,
                int virtualDeviceId, boolean raw, HexFunction<Integer, Integer, String, String,
                Integer, Boolean, Integer> superImpl);
        int checkOperation(int code, int uid, @Nullable String packageName,
                @Nullable String attributionTag, int virtualDeviceId, boolean raw,
                @NonNull HexFunction<Integer, Integer, String, String, Integer, Boolean, Integer>
                        superImpl);

        /**
         * Allows overriding check audio operation behavior.
@@ -67,8 +68,8 @@ public abstract class AppOpsManagerInternal {
         * @param superImpl The super implementation.
         * @return The app op check result.
         */
        int checkAudioOperation(int code, int usage, int uid, String packageName,
                QuadFunction<Integer, Integer, Integer, String, Integer> superImpl);
        int checkAudioOperation(int code, int usage, int uid, @Nullable String packageName,
                @NonNull QuadFunction<Integer, Integer, Integer, String, Integer> superImpl);

        /**
         * Allows overriding note operation behavior.
@@ -125,7 +126,7 @@ public abstract class AppOpsManagerInternal {
         * @param superImpl The super implementation.
         * @return The app op note result.
         */
        SyncNotedAppOp startOperation(IBinder token, int code, int uid,
        SyncNotedAppOp startOperation(@NonNull IBinder token, int code, int uid,
                @Nullable String packageName, @Nullable String attributionTag, int virtualDeviceId,
                boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp,
                @Nullable String message, boolean shouldCollectMessage,
@@ -152,8 +153,9 @@ public abstract class AppOpsManagerInternal {
         */
        SyncNotedAppOp startProxyOperation(@NonNull IBinder clientId, int code,
                @NonNull AttributionSource attributionSource, boolean startIfModeDefault,
                boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage,
                boolean skipProxyOperation, @AttributionFlags int proxyAttributionFlags,
                boolean shouldCollectAsyncNotedOp, @Nullable String message,
                boolean shouldCollectMessage, boolean skipProxyOperation,
                @AttributionFlags int proxyAttributionFlags,
                @AttributionFlags int proxiedAttributionFlags, int attributionChainId,
                @NonNull UndecFunction<IBinder, Integer, AttributionSource, Boolean,
                        Boolean, String, Boolean, Boolean, Integer, Integer, Integer,
+36 −0
Original line number Diff line number Diff line
@@ -970,4 +970,40 @@ interface IActivityManager {
     * time in the past.
     */
    long getUidLastIdleElapsedTime(int uid, in String callingPackage);

    /**
     * Adds permission to be overridden to the given state. Must be called from root user.
     *
     * @param originatingUid The UID of the instrumented app that initialized the override
     * @param uid The UID of the app whose permission will be overridden
     * @param permission The permission whose state will be overridden
     * @param result The state to override the permission to
     *
     * @see PackageManager.PermissionResult
     */
    void addOverridePermissionState(int originatingUid, int uid, String permission, int result);

    /**
     * Removes overridden permission. Must be called from root user.
     *
     * @param originatingUid The UID of the instrumented app that initialized the override
     * @param uid The UID of the app whose permission is overridden
     * @param permission The permission whose state will no longer be overridden
     */
    void removeOverridePermissionState(int originatingUid, int uid, String permission);

    /**
     * Clears all overridden permissions for the given UID. Must be called from root user.
     *
     * @param originatingUid The UID of the instrumented app that initialized the override
     * @param uid The UID of the app whose permissions will no longer be overridden
     */
    void clearOverridePermissionStates(int originatingUid, int uid);

    /**
     * Clears all overridden permissions on the device. Must be called from root user.
     *
     * @param originatingUid The UID of the instrumented app that initialized the override
     */
    void clearAllOverridePermissionStates(int originatingUid);
}
+4 −0
Original line number Diff line number Diff line
@@ -62,4 +62,8 @@ interface IUiAutomationConnection {
    void executeShellCommandWithStderr(String command, in ParcelFileDescriptor sink,
                in ParcelFileDescriptor source, in ParcelFileDescriptor stderrSink);
    List<String> getAdoptedShellPermissions();
    void addOverridePermissionState(int uid, String permission, int result);
    void removeOverridePermissionState(int uid, String permission);
    void clearOverridePermissionStates(int uid);
    void clearAllOverridePermissionStates();
}
+76 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.annotation.SuppressLint;
import android.annotation.TestApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.Rect;
@@ -652,6 +653,81 @@ public final class UiAutomation {
        }
    }

    /**
     * Adds permission to be overridden to the given state. UiAutomation must be connected to
     * root user.
     *
     * @param uid The UID of the app whose permission will be overridden
     * @param permission The permission whose state will be overridden
     * @param result The state to override the permission to
     *
     * @see PackageManager#PERMISSION_GRANTED
     * @see PackageManager#PERMISSION_DENIED
     *
     * @hide
     */
    @TestApi
    @SuppressLint("UnflaggedApi")
    public void addOverridePermissionState(int uid, @NonNull String permission,
            @PackageManager.PermissionResult int result) {
        try {
            mUiAutomationConnection.addOverridePermissionState(uid, permission, result);
        } catch (RemoteException re) {
            re.rethrowFromSystemServer();
        }
    }

    /**
     * Removes overridden permission. UiAutomation must be connected to root user.
     *
     * @param uid The UID of the app whose permission is overridden
     * @param permission The permission whose state will no longer be overridden
     *
     * @hide
     */
    @TestApi
    @SuppressLint("UnflaggedApi")
    public void removeOverridePermissionState(int uid, @NonNull String permission) {
        try {
            mUiAutomationConnection.removeOverridePermissionState(uid, permission);
        } catch (RemoteException re) {
            re.rethrowFromSystemServer();
        }
    }

    /**
     * Clears all overridden permissions for the given UID. UiAutomation must be connected to
     * root user.
     *
     * @param uid The UID of the app whose permissions will no longer be overridden
     *
     * @hide
     */
    @TestApi
    @SuppressLint("UnflaggedApi")
    public void clearOverridePermissionStates(int uid) {
        try {
            mUiAutomationConnection.clearOverridePermissionStates(uid);
        } catch (RemoteException re) {
            re.rethrowFromSystemServer();
        }
    }

    /**
     * Clears all overridden permissions on the device. UiAutomation must be connected to root user.
     *
     * @hide
     */
    @TestApi
    @SuppressLint("UnflaggedApi")
    public void clearAllOverridePermissionStates() {
        try {
            mUiAutomationConnection.clearAllOverridePermissionStates();
        } catch (RemoteException re) {
            re.rethrowFromSystemServer();
        }
    }

    /**
     * Performs a global action. Such an action can be performed at any moment
     * regardless of the current application or user location in that application.
Loading