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

Commit 2a42313c authored by Tarandeep Singh's avatar Tarandeep Singh Committed by Android (Google) Code Review
Browse files

Merge "Respect DISALLOW_DEBUGGING_FEATURES in IME shell commands"

parents 477a11de 87e2e514
Loading
Loading
Loading
Loading
+25 −1
Original line number Original line Diff line number Diff line
@@ -4690,9 +4690,11 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    private int handleShellCommandEnableDisableInputMethod(
    private int handleShellCommandEnableDisableInputMethod(
            @NonNull ShellCommand shellCommand, boolean enabled) {
            @NonNull ShellCommand shellCommand, boolean enabled) {
        final String id = shellCommand.getNextArgRequired();
        final String id = shellCommand.getNextArgRequired();

        final boolean previouslyEnabled;
        final boolean previouslyEnabled;
        synchronized (mMethodMap) {
        synchronized (mMethodMap) {
            if (!userHasDebugPriv(mSettings.getCurrentUserId(), shellCommand)) {
                return ShellCommandResult.SUCCESS;
            }
            previouslyEnabled = setInputMethodEnabledLocked(id, enabled);
            previouslyEnabled = setInputMethodEnabledLocked(id, enabled);
        }
        }
        final PrintWriter pr = shellCommand.getOutPrintWriter();
        final PrintWriter pr = shellCommand.getOutPrintWriter();
@@ -4714,6 +4716,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    private int handleShellCommandSetInputMethod(@NonNull ShellCommand shellCommand) {
    private int handleShellCommandSetInputMethod(@NonNull ShellCommand shellCommand) {
        final String id = shellCommand.getNextArgRequired();
        final String id = shellCommand.getNextArgRequired();
        synchronized (mMethodMap) {
        synchronized (mMethodMap) {
            if (!userHasDebugPriv(mSettings.getCurrentUserId(), shellCommand)) {
                return ShellCommandResult.SUCCESS;
            }
            setInputMethodLocked(id, NOT_A_SUBTYPE_ID);
            setInputMethodLocked(id, NOT_A_SUBTYPE_ID);
        }
        }
        final PrintWriter pr = shellCommand.getOutPrintWriter();
        final PrintWriter pr = shellCommand.getOutPrintWriter();
@@ -4732,6 +4737,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    @ShellCommandResult
    @ShellCommandResult
    private int handleShellCommandResetInputMethod(@NonNull ShellCommand shellCommand) {
    private int handleShellCommandResetInputMethod(@NonNull ShellCommand shellCommand) {
        synchronized (mMethodMap) {
        synchronized (mMethodMap) {
            if (!userHasDebugPriv(mSettings.getCurrentUserId(), shellCommand)) {
                return ShellCommandResult.SUCCESS;
            }
            final String nextIme;
            final String nextIme;
            final List<InputMethodInfo> nextEnabledImes;
            final List<InputMethodInfo> nextEnabledImes;
            hideCurrentInputLocked(0, null);
            hideCurrentInputLocked(0, null);
@@ -4769,6 +4777,22 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        }
        }
    }
    }


    /**
     * @param userId the actual user handle obtained by {@link UserHandle#getIdentifier()}
     * and *not* pseudo ids like {@link UserHandle#USER_ALL etc}.
     * @return {@code true} if userId has debugging privileges.
     * i.e. {@link UserManager#DISALLOW_DEBUGGING_FEATURES} is {@code false}.
     */
    private boolean userHasDebugPriv(int userId, final ShellCommand shellCommand) {
        if (mUserManager.hasUserRestriction(
                UserManager.DISALLOW_DEBUGGING_FEATURES, UserHandle.of(userId))) {
            shellCommand.getErrPrintWriter().println("User #" + userId
                    + " is restricted with DISALLOW_DEBUGGING_FEATURES.");
            return false;
        }
        return true;
    }

    private static final class InputMethodPrivilegedOperationsImpl
    private static final class InputMethodPrivilegedOperationsImpl
            extends IInputMethodPrivilegedOperations.Stub {
            extends IInputMethodPrivilegedOperations.Stub {
        private final InputMethodManagerService mImms;
        private final InputMethodManagerService mImms;