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

Commit 898e01c9 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: I497c3f4d93ddd0991f19bbfa44e3513bb2ac0dd1
parents 72bc5ff4 df98b270
Loading
Loading
Loading
Loading
+12 −0
Original line number Original line Diff line number Diff line
@@ -265,4 +265,16 @@ interface IVoiceInteractionManagerService {
    void performDirectAction(in IBinder token, String actionId, in Bundle arguments, int taskId,
    void performDirectAction(in IBinder token, String actionId, in Bundle arguments, int taskId,
            IBinder assistToken, in RemoteCallback cancellationCallback,
            IBinder assistToken, in RemoteCallback cancellationCallback,
            in RemoteCallback resultCallback);
            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 Original line Diff line number Diff line
@@ -73,6 +73,7 @@ import android.util.ArraySet;
import android.util.Log;
import android.util.Log;
import android.util.Slog;
import android.util.Slog;


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

        @GuardedBy("this")
        private boolean mTemporarilyDisabled;

        private final boolean mEnableService;
        private final boolean mEnableService;


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


        void switchImplementationIfNeededLocked(boolean force) {
        void switchImplementationIfNeededLocked(boolean force) {
            if (!mCurUserSupported) {
            if (!mCurUserSupported || mTemporarilyDisabled) {
                if (DEBUG_USER) {
                if (DEBUG_USER) {
                    Slog.d(TAG, "switchImplementationIfNeeded(): skipping on unsuported user "
                    Slog.d(TAG, "switchImplementationIfNeeded(): skipping: force= " + force
                            + mCurUser);
                            + "mCurUserSupported=" + mCurUserSupported
                            + "mTemporarilyDisabled=" + mTemporarilyDisabled);
                }
                }
                if (mImpl != null) {
                if (mImpl != null) {
                    mImpl.shutdownLocked();
                    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 --------------------------------//
        //----------------- Model management APIs --------------------------------//


        @Override
        @Override
@@ -1378,6 +1407,7 @@ public class VoiceInteractionManagerService extends SystemService {
            synchronized (this) {
            synchronized (this) {
                pw.println("VOICE INTERACTION MANAGER (dumpsys voiceinteraction)");
                pw.println("VOICE INTERACTION MANAGER (dumpsys voiceinteraction)");
                pw.println("  mEnableService: " + mEnableService);
                pw.println("  mEnableService: " + mEnableService);
                pw.println("  mTemporarilyDisabled: " + mTemporarilyDisabled);
                pw.println("  mCurUser: " + mCurUser);
                pw.println("  mCurUser: " + mCurUser);
                pw.println("  mCurUserUnlocked: " + mCurUserUnlocked);
                pw.println("  mCurUserUnlocked: " + mCurUserUnlocked);
                pw.println("  mCurUserSupported: " + mCurUserSupported);
                pw.println("  mCurUserSupported: " + mCurUserSupported);
+15 −0
Original line number Original line Diff line number Diff line
@@ -52,6 +52,8 @@ final class VoiceInteractionManagerServiceShellCommand extends ShellCommand {
                return requestShow(pw);
                return requestShow(pw);
            case "hide":
            case "hide":
                return requestHide(pw);
                return requestHide(pw);
            case "disable":
                return requestDisable(pw);
            default:
            default:
                return handleDefaultCommands(cmd);
                return handleDefaultCommands(cmd);
        }
        }
@@ -69,6 +71,8 @@ final class VoiceInteractionManagerServiceShellCommand extends ShellCommand {
            pw.println("");
            pw.println("");
            pw.println("  hide");
            pw.println("  hide");
            pw.println("    Hides the current session");
            pw.println("    Hides the current session");
            pw.println("  disable [true|false]");
            pw.println("    Temporarily disable (when true) service");
            pw.println("");
            pw.println("");
        }
        }
    }
    }
@@ -127,6 +131,17 @@ final class VoiceInteractionManagerServiceShellCommand extends ShellCommand {
        return 0;
        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) {
    private static int handleError(PrintWriter pw, String message, Exception e) {
        Slog.e(TAG,  "error calling " + message, e);
        Slog.e(TAG,  "error calling " + message, e);
        pw.printf("Error calling %s: %s\n", message, e);
        pw.printf("Error calling %s: %s\n", message, e);