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

Commit 0f3a378b authored by Winson Chung's avatar Winson Chung
Browse files

Add shell command to trigger global action

Bug: 150817783
Test: adb shell cmd accessibility call-system-action <id>
Change-Id: Iaa85b7ada85d39305300b56b1a3725fcbfee4e95
parent 53e927f8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2732,7 +2732,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
    public void onShellCommand(FileDescriptor in, FileDescriptor out,
            FileDescriptor err, String[] args, ShellCallback callback,
            ResultReceiver resultReceiver) {
        new AccessibilityShellCommand(this).exec(this, in, out, err, args,
        new AccessibilityShellCommand(this, mSystemActionPerformer).exec(this, in, out, err, args,
                callback, resultReceiver);
    }

+27 −1
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.server.accessibility;

import android.annotation.NonNull;
import android.app.ActivityManager;
import android.os.Binder;
import android.os.Process;
import android.os.ShellCommand;
import android.os.UserHandle;

@@ -28,9 +30,12 @@ import java.io.PrintWriter;
 */
final class AccessibilityShellCommand extends ShellCommand {
    final @NonNull AccessibilityManagerService mService;
    final @NonNull SystemActionPerformer mSystemActionPerformer;

    AccessibilityShellCommand(@NonNull AccessibilityManagerService service) {
    AccessibilityShellCommand(@NonNull AccessibilityManagerService service,
            @NonNull SystemActionPerformer systemActionPerformer) {
        mService = service;
        mSystemActionPerformer = systemActionPerformer;
    }

    @Override
@@ -45,6 +50,9 @@ final class AccessibilityShellCommand extends ShellCommand {
            case "set-bind-instant-service-allowed": {
                return runSetBindInstantServiceAllowed();
            }
            case "call-system-action": {
                return runCallSystemAction();
            }
        }
        return -1;
    }
@@ -74,6 +82,22 @@ final class AccessibilityShellCommand extends ShellCommand {
        return 0;
    }

    private int runCallSystemAction() {
        final int callingUid = Binder.getCallingUid();
        if (callingUid != Process.ROOT_UID
                && callingUid != Process.SYSTEM_UID
                && callingUid != Process.SHELL_UID) {
            return -1;
        }
        final String option = getNextArg();
        if (option != null) {
            int actionId = Integer.parseInt(option);
            mSystemActionPerformer.performSystemAction(actionId);
            return 0;
        }
        return -1;
    }

    private Integer parseUserId() {
        final String option = getNextOption();
        if (option != null) {
@@ -97,5 +121,7 @@ final class AccessibilityShellCommand extends ShellCommand {
        pw.println("    Set whether binding to services provided by instant apps is allowed.");
        pw.println("  get-bind-instant-service-allowed [--user <USER_ID>]");
        pw.println("    Get whether binding to services provided by instant apps is allowed.");
        pw.println("  call-system-action <ACTION_ID>");
        pw.println("    Calls the system action with the given action id.");
    }
}
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
@@ -302,6 +302,7 @@ public class SystemActionPerformer {
                case AccessibilityService.GLOBAL_ACTION_TAKE_SCREENSHOT:
                    return takeScreenshot();
                default:
                    Slog.e(TAG, "Invalid action id: " + actionId);
                    return false;
            }
        } finally {