Merge "Improved implementation of VoiceInteractionManagerService.setDisabled()" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
50bbe88967
@@ -562,11 +562,10 @@ public class VoiceInteractionManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void switchImplementationIfNeededLocked(boolean force) {
|
void switchImplementationIfNeededLocked(boolean force) {
|
||||||
if (!mCurUserSupported || mTemporarilyDisabled) {
|
if (!mCurUserSupported) {
|
||||||
if (DEBUG_USER) {
|
if (DEBUG_USER) {
|
||||||
Slog.d(TAG, "switchImplementationIfNeeded(): skipping: force= " + force
|
Slog.d(TAG, "switchImplementationIfNeeded(): skipping: force= " + force
|
||||||
+ "mCurUserSupported=" + mCurUserSupported
|
+ "mCurUserSupported=" + mCurUserSupported);
|
||||||
+ "mTemporarilyDisabled=" + mTemporarilyDisabled);
|
|
||||||
}
|
}
|
||||||
if (mImpl != null) {
|
if (mImpl != null) {
|
||||||
mImpl.shutdownLocked();
|
mImpl.shutdownLocked();
|
||||||
@@ -1048,13 +1047,16 @@ public class VoiceInteractionManagerService extends SystemService {
|
|||||||
if (DEBUG) Slog.d(TAG, "setDisabled(): already " + disabled);
|
if (DEBUG) Slog.d(TAG, "setDisabled(): already " + disabled);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Slog.i(TAG, "setDisabled(): changing to " + disabled);
|
mTemporarilyDisabled = disabled;
|
||||||
final long caller = Binder.clearCallingIdentity();
|
if (mTemporarilyDisabled) {
|
||||||
try {
|
Slog.i(TAG, "setDisabled(): temporarily disabling and hiding current session");
|
||||||
mTemporarilyDisabled = disabled;
|
try {
|
||||||
switchImplementationIfNeeded(/* force= */ false);
|
hideCurrentSession();
|
||||||
} finally {
|
} catch (RemoteException e) {
|
||||||
Binder.restoreCallingIdentity(caller);
|
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,
|
public boolean showSessionForActiveService(Bundle args, int sourceFlags,
|
||||||
IVoiceInteractionSessionShowCallback showCallback, IBinder activityToken) {
|
IVoiceInteractionSessionShowCallback showCallback, IBinder activityToken) {
|
||||||
enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE);
|
enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE);
|
||||||
|
if (DEBUG_USER) Slog.d(TAG, "showSessionForActiveService()");
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (mImpl == null) {
|
if (mImpl == null) {
|
||||||
Slog.w(TAG, "showSessionForActiveService without running voice interaction"
|
Slog.w(TAG, "showSessionForActiveService without running voice interaction"
|
||||||
+ "service");
|
+ "service");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (mTemporarilyDisabled) {
|
||||||
|
Slog.i(TAG, "showSessionForActiveService(): ignored while temporarily "
|
||||||
|
+ "disabled");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
final long caller = Binder.clearCallingIdentity();
|
final long caller = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
return mImpl.showSessionLocked(args,
|
return mImpl.showSessionLocked(args,
|
||||||
@@ -1530,22 +1540,21 @@ public class VoiceInteractionManagerService extends SystemService {
|
|||||||
@Override
|
@Override
|
||||||
public void hideCurrentSession() throws RemoteException {
|
public void hideCurrentSession() throws RemoteException {
|
||||||
enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE);
|
enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE);
|
||||||
synchronized (this) {
|
|
||||||
if (mImpl == null) {
|
if (mImpl == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final long caller = Binder.clearCallingIdentity();
|
final long caller = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
if (mImpl.mActiveSession != null && mImpl.mActiveSession.mSession != null) {
|
if (mImpl.mActiveSession != null && mImpl.mActiveSession.mSession != null) {
|
||||||
try {
|
try {
|
||||||
mImpl.mActiveSession.mSession.closeSystemDialogs();
|
mImpl.mActiveSession.mSession.closeSystemDialogs();
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.w(TAG, "Failed to call closeSystemDialogs", e);
|
Log.w(TAG, "Failed to call closeSystemDialogs", e);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
Binder.restoreCallingIdentity(caller);
|
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
Binder.restoreCallingIdentity(caller);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ 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("");
|
||||||
pw.println(" disable [true|false]");
|
pw.println(" disable [true|false]");
|
||||||
pw.println(" Temporarily disable (when true) service");
|
pw.println(" Temporarily disable (when true) service");
|
||||||
pw.println("");
|
pw.println("");
|
||||||
|
|||||||
Reference in New Issue
Block a user