Skip to content

Commit

Permalink
Added command / binder method to temporarily disable VoiceInteraction.
Browse files Browse the repository at this point in the history
It will be used by Automotive when the display is off.

Test: adb shell cmd voiceinteraction disable true && \
      adb shell cmd voiceinteraction show
Test: atest CtsVoiceInteractionTestCases CtsAssistTestCases
Bug: 154011437

Change-Id: Ia87b0544b242c356c4f9180e250e2df54279803f
  • Loading branch information
the-felipeal committed Jun 4, 2020
1 parent c43f49d commit 755578a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
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;
Expand Down Expand Up @@ -230,6 +231,10 @@ class VoiceInteractionManagerServiceStub extends IVoiceInteractionManagerService
private int mCurUser;
private boolean mCurUserUnlocked;
private boolean mCurUserSupported;

@GuardedBy("this")
private boolean mTemporarilyDisabled;

private final boolean mEnableService;

VoiceInteractionManagerServiceStub() {
Expand Down Expand Up @@ -316,8 +321,12 @@ private void initForUserNoTracing(@UserIdInt int userHandle) {
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
Expand Down Expand Up @@ -472,10 +481,11 @@ void switchImplementationIfNeeded(boolean force) {
}

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();
Expand Down Expand Up @@ -928,6 +938,25 @@ public int getUserDisabledShowContext() {
}
}

@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
Expand Down Expand Up @@ -1378,6 +1407,7 @@ public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public int onCommand(String cmd) {
return requestShow(pw);
case "hide":
return requestHide(pw);
case "disable":
return requestDisable(pw);
default:
return handleDefaultCommands(cmd);
}
Expand All @@ -69,6 +71,8 @@ public void onHelp() {
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("");
}
}
Expand Down Expand Up @@ -127,6 +131,17 @@ private int requestHide(PrintWriter pw) {
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);
Expand Down

0 comments on commit 755578a

Please sign in to comment.