Added command / binder method to temporarily disable VoiceInteraction.

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
This commit is contained in:
felipeal
2020-05-27 14:20:12 -07:00
committed by Felipe Leme
parent c43f49dfc4
commit 755578ac28
3 changed files with 62 additions and 5 deletions

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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);