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

Commit f25e6f10 authored by Felipe Leme's avatar Felipe Leme Committed by Automerger Merge Worker
Browse files

Merge "Added command / binder method to temporarily disable VoiceInteraction."...

Merge "Added command / binder method to temporarily disable VoiceInteraction." into rvc-dev am: df98b270

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11625271

Change-Id: Idb6388c53e0fd545ad758ea7893149960e80527e
parents fafc6643 df98b270
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -265,4 +265,16 @@ interface IVoiceInteractionManagerService {
    void performDirectAction(in IBinder token, String actionId, in Bundle arguments, int taskId,
            IBinder assistToken, in RemoteCallback cancellationCallback,
            in RemoteCallback resultCallback);

    /**
     * Temporarily disables voice interaction (for example, on Automotive when the display is off).
     *
     * It will shutdown the service, and only re-enable it after it's called again (or after a
     * system restart).
     *
     * NOTE: it's only effective when the service itself is available / enabled in the device, so
     * calling setDisable(false) would be a no-op when it isn't.
     */
    void setDisabled(boolean disabled);

}
+35 −5
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ import android.util.ArraySet;
import android.util.Log;
import android.util.Slog;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.app.IVoiceActionCheckCallback;
import com.android.internal.app.IVoiceInteractionManagerService;
import com.android.internal.app.IVoiceInteractionSessionListener;
@@ -230,6 +231,10 @@ public class VoiceInteractionManagerService extends SystemService {
        private int mCurUser;
        private boolean mCurUserUnlocked;
        private boolean mCurUserSupported;

        @GuardedBy("this")
        private boolean mTemporarilyDisabled;

        private final boolean mEnableService;

        VoiceInteractionManagerServiceStub() {
@@ -316,8 +321,12 @@ public class VoiceInteractionManagerService extends SystemService {
                    Settings.Secure.VOICE_INTERACTION_SERVICE, userHandle);
            ComponentName curRecognizer = getCurRecognizer(userHandle);
            VoiceInteractionServiceInfo curInteractorInfo = null;
            if (DEBUG) Slog.d(TAG, "curInteractorStr=" + curInteractorStr
                    + " curRecognizer=" + curRecognizer);
            if (DEBUG) {
                Slog.d(TAG, "curInteractorStr=" + curInteractorStr
                        + " curRecognizer=" + curRecognizer
                        + " mEnableService=" + mEnableService
                        + " mTemporarilyDisabled=" + mTemporarilyDisabled);
            }
            if (curInteractorStr == null && curRecognizer != null && mEnableService) {
                // If there is no interactor setting, that means we are upgrading
                // from an older platform version.  If the current recognizer is not
@@ -472,10 +481,11 @@ public class VoiceInteractionManagerService extends SystemService {
        }

        void switchImplementationIfNeededLocked(boolean force) {
            if (!mCurUserSupported) {
            if (!mCurUserSupported || mTemporarilyDisabled) {
                if (DEBUG_USER) {
                    Slog.d(TAG, "switchImplementationIfNeeded(): skipping on unsuported user "
                            + mCurUser);
                    Slog.d(TAG, "switchImplementationIfNeeded(): skipping: force= " + force
                            + "mCurUserSupported=" + mCurUserSupported
                            + "mTemporarilyDisabled=" + mTemporarilyDisabled);
                }
                if (mImpl != null) {
                    mImpl.shutdownLocked();
@@ -928,6 +938,25 @@ public class VoiceInteractionManagerService extends SystemService {
            }
        }

        @Override
        public void setDisabled(boolean disabled) {
            enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE);
            synchronized (this) {
                if (mTemporarilyDisabled == disabled) {
                    if (DEBUG) Slog.d(TAG, "setDisabled(): already " + disabled);
                    return;
                }
                Slog.i(TAG, "setDisabled(): changing to " + disabled);
                final long caller = Binder.clearCallingIdentity();
                try {
                    mTemporarilyDisabled = disabled;
                    switchImplementationIfNeeded(/* force= */ false);
                } finally {
                    Binder.restoreCallingIdentity(caller);
                }
            }
        }

        //----------------- Model management APIs --------------------------------//

        @Override
@@ -1378,6 +1407,7 @@ public class VoiceInteractionManagerService extends SystemService {
            synchronized (this) {
                pw.println("VOICE INTERACTION MANAGER (dumpsys voiceinteraction)");
                pw.println("  mEnableService: " + mEnableService);
                pw.println("  mTemporarilyDisabled: " + mTemporarilyDisabled);
                pw.println("  mCurUser: " + mCurUser);
                pw.println("  mCurUserUnlocked: " + mCurUserUnlocked);
                pw.println("  mCurUserSupported: " + mCurUserSupported);
+15 −0
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ final class VoiceInteractionManagerServiceShellCommand extends ShellCommand {
                return requestShow(pw);
            case "hide":
                return requestHide(pw);
            case "disable":
                return requestDisable(pw);
            default:
                return handleDefaultCommands(cmd);
        }
@@ -69,6 +71,8 @@ final class VoiceInteractionManagerServiceShellCommand extends ShellCommand {
            pw.println("");
            pw.println("  hide");
            pw.println("    Hides the current session");
            pw.println("  disable [true|false]");
            pw.println("    Temporarily disable (when true) service");
            pw.println("");
        }
    }
@@ -127,6 +131,17 @@ final class VoiceInteractionManagerServiceShellCommand extends ShellCommand {
        return 0;
    }

    private int requestDisable(PrintWriter pw) {
        boolean disabled = Boolean.parseBoolean(getNextArgRequired());
        Slog.i(TAG, "requestDisable(): " + disabled);
        try {
            mService.setDisabled(disabled);
        } catch (Exception e) {
            return handleError(pw, "requestDisable()", e);
        }
        return 0;
    }

    private static int handleError(PrintWriter pw, String message, Exception e) {
        Slog.e(TAG,  "error calling " + message, e);
        pw.printf("Error calling %s: %s\n", message, e);