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

Commit 8c45367d authored by Winson Chung's avatar Winson Chung Committed by Automerger Merge Worker
Browse files

Merge "Add shell command to trigger global action" into rvc-dev am: 18c1d27d...

Merge "Add shell command to trigger global action" into rvc-dev am: 18c1d27d am: 755ad932 am: 3d5533d7 am: 2fdd19cd

Change-Id: I6e7b8a7e39079fd46f5360b48f707588aeb364ba
parents db51f7f9 2fdd19cd
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2779,7 +2779,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
@@ -305,6 +305,7 @@ public class SystemActionPerformer {
                    sendDownAndUpKeyEvents(KeyEvent.KEYCODE_HEADSETHOOK);
                    return true;
                default:
                    Slog.e(TAG, "Invalid action id: " + actionId);
                    return false;
            }
        } finally {