Loading core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl +12 −0 Original line number Diff line number Diff line Loading @@ -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); } services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java +35 −5 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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() { Loading Loading @@ -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 Loading Loading @@ -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(); Loading Loading @@ -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 Loading Loading @@ -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); Loading services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceShellCommand.java +15 −0 Original line number Diff line number Diff line Loading @@ -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); } Loading @@ -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(""); } } Loading Loading @@ -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); Loading Loading
core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl +12 −0 Original line number Diff line number Diff line Loading @@ -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); }
services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java +35 −5 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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() { Loading Loading @@ -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 Loading Loading @@ -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(); Loading Loading @@ -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 Loading Loading @@ -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); Loading
services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceShellCommand.java +15 −0 Original line number Diff line number Diff line Loading @@ -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); } Loading @@ -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(""); } } Loading Loading @@ -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); Loading