diff options
| author | 2021-06-15 21:45:38 +0000 | |
|---|---|---|
| committer | 2021-06-15 21:45:38 +0000 | |
| commit | 50bbe88967679a98be3e9a9a1d5732bcb10fe7da (patch) | |
| tree | 8614f8c13cd2cdf337e6b3691494a0a802e98291 | |
| parent | cac7ab9c5cc317a6b1f6ec6536495acf1b3ab608 (diff) | |
| parent | 07848e302b03d65ed7c340a28980eb3a5a85bdcb (diff) | |
Merge "Improved implementation of VoiceInteractionManagerService.setDisabled()" into sc-dev
2 files changed, 34 insertions, 24 deletions
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java index a14912e5593d..bc812c2ae4a7 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java @@ -562,11 +562,10 @@ public class VoiceInteractionManagerService extends SystemService { } void switchImplementationIfNeededLocked(boolean force) { - if (!mCurUserSupported || mTemporarilyDisabled) { + if (!mCurUserSupported) { if (DEBUG_USER) { Slog.d(TAG, "switchImplementationIfNeeded(): skipping: force= " + force - + "mCurUserSupported=" + mCurUserSupported - + "mTemporarilyDisabled=" + mTemporarilyDisabled); + + "mCurUserSupported=" + mCurUserSupported); } if (mImpl != null) { mImpl.shutdownLocked(); @@ -1048,13 +1047,16 @@ public class VoiceInteractionManagerService extends SystemService { 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); + mTemporarilyDisabled = disabled; + if (mTemporarilyDisabled) { + Slog.i(TAG, "setDisabled(): temporarily disabling and hiding current session"); + try { + hideCurrentSession(); + } catch (RemoteException e) { + Log.w(TAG, "Failed to call hideCurrentSession", e); + } + } else { + Slog.i(TAG, "setDisabled(): re-enabling"); } } } @@ -1508,12 +1510,20 @@ public class VoiceInteractionManagerService extends SystemService { public boolean showSessionForActiveService(Bundle args, int sourceFlags, IVoiceInteractionSessionShowCallback showCallback, IBinder activityToken) { enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE); + if (DEBUG_USER) Slog.d(TAG, "showSessionForActiveService()"); + synchronized (this) { if (mImpl == null) { Slog.w(TAG, "showSessionForActiveService without running voice interaction" + "service"); return false; } + if (mTemporarilyDisabled) { + Slog.i(TAG, "showSessionForActiveService(): ignored while temporarily " + + "disabled"); + return false; + } + final long caller = Binder.clearCallingIdentity(); try { return mImpl.showSessionLocked(args, @@ -1530,22 +1540,21 @@ public class VoiceInteractionManagerService extends SystemService { @Override public void hideCurrentSession() throws RemoteException { enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE); - synchronized (this) { - if (mImpl == null) { - return; - } - final long caller = Binder.clearCallingIdentity(); - try { - if (mImpl.mActiveSession != null && mImpl.mActiveSession.mSession != null) { - try { - mImpl.mActiveSession.mSession.closeSystemDialogs(); - } catch (RemoteException e) { - Log.w(TAG, "Failed to call closeSystemDialogs", e); - } + + if (mImpl == null) { + return; + } + final long caller = Binder.clearCallingIdentity(); + try { + if (mImpl.mActiveSession != null && mImpl.mActiveSession.mSession != null) { + try { + mImpl.mActiveSession.mSession.closeSystemDialogs(); + } catch (RemoteException e) { + Log.w(TAG, "Failed to call closeSystemDialogs", e); } - } finally { - Binder.restoreCallingIdentity(caller); } + } finally { + Binder.restoreCallingIdentity(caller); } } diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceShellCommand.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceShellCommand.java index 6c355a3b4b30..2e3ca0157a3b 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceShellCommand.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceShellCommand.java @@ -71,6 +71,7 @@ final class VoiceInteractionManagerServiceShellCommand extends ShellCommand { pw.println(""); pw.println(" hide"); pw.println(" Hides the current session"); + pw.println(""); pw.println(" disable [true|false]"); pw.println(" Temporarily disable (when true) service"); pw.println(""); |