[VoiceInteraction] Add showSessionId
Test: atest CtsVoiceInteractionTestCases Bug: 236104300 Change-Id: Ibc05662cb978ec9c4d9dbde69e7371981796e41f
This commit is contained in:
@@ -40530,11 +40530,12 @@ package android.service.voice {
|
||||
method public void onLaunchVoiceAssistFromKeyguard();
|
||||
method public void onPrepareToShowSession(@NonNull android.os.Bundle, int);
|
||||
method public void onReady();
|
||||
method public void onShowSessionFailed();
|
||||
method public void onShowSessionFailed(@NonNull android.os.Bundle);
|
||||
method public void onShutdown();
|
||||
method public void setDisabledShowContext(int);
|
||||
method public final void setUiHints(@NonNull android.os.Bundle);
|
||||
method public void showSession(android.os.Bundle, int);
|
||||
field public static final String KEY_SHOW_SESSION_ID = "android.service.voice.SHOW_SESSION_ID";
|
||||
field public static final String SERVICE_INTERFACE = "android.service.voice.VoiceInteractionService";
|
||||
field public static final String SERVICE_META_DATA = "android.voice_interaction";
|
||||
}
|
||||
|
||||
@@ -31,5 +31,5 @@ oneway interface IVoiceInteractionService {
|
||||
void getActiveServiceSupportedActions(in List<String> voiceActions,
|
||||
in IVoiceActionCheckCallback callback);
|
||||
void prepareToShowSession(in Bundle args, int flags);
|
||||
void showSessionFailed();
|
||||
void showSessionFailed(in Bundle args);
|
||||
}
|
||||
|
||||
@@ -94,6 +94,20 @@ public class VoiceInteractionService extends Service {
|
||||
*/
|
||||
public static final String SERVICE_META_DATA = "android.voice_interaction";
|
||||
|
||||
/**
|
||||
* Bundle key used to specify the id when the system prepares to show session. It increases for
|
||||
* each request.
|
||||
* <p>
|
||||
* Type: int
|
||||
* </p>
|
||||
* @see #showSession(Bundle, int)
|
||||
* @see #onPrepareToShowSession(Bundle, int)
|
||||
* @see #onShowSessionFailed(Bundle)
|
||||
* @see VoiceInteractionSession#onShow(Bundle, int)
|
||||
* @see VoiceInteractionSession#show(Bundle, int)
|
||||
*/
|
||||
public static final String KEY_SHOW_SESSION_ID = "android.service.voice.SHOW_SESSION_ID";
|
||||
|
||||
/**
|
||||
* For apps targeting Build.VERSION_CODES.TRAMISU and above, implementors of this
|
||||
* service can create multiple AlwaysOnHotwordDetector instances in parallel. They will
|
||||
@@ -170,10 +184,10 @@ public class VoiceInteractionService extends Service {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showSessionFailed() {
|
||||
public void showSessionFailed(@NonNull Bundle args) {
|
||||
Handler.getMain().executeOrSendMessage(PooledLambda.obtainMessage(
|
||||
VoiceInteractionService::onShowSessionFailed,
|
||||
VoiceInteractionService.this));
|
||||
VoiceInteractionService.this, args));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -205,9 +219,10 @@ public class VoiceInteractionService extends Service {
|
||||
* bind the session service.
|
||||
*
|
||||
* @param args The arguments that were supplied to {@link #showSession(Bundle, int)}.
|
||||
* It always includes {@link #KEY_SHOW_SESSION_ID}.
|
||||
* @param flags The show flags originally provided to {@link #showSession(Bundle, int)}.
|
||||
* @see #showSession(Bundle, int)
|
||||
* @see #onShowSessionFailed()
|
||||
* @see #onShowSessionFailed(Bundle)
|
||||
* @see VoiceInteractionSession#onShow(Bundle, int)
|
||||
* @see VoiceInteractionSession#show(Bundle, int)
|
||||
*/
|
||||
@@ -217,12 +232,14 @@ public class VoiceInteractionService extends Service {
|
||||
/**
|
||||
* Called when the show session failed. E.g. When the system bound the session service failed.
|
||||
*
|
||||
* @param args Additional info about the show session attempt that failed. For now, includes
|
||||
* {@link #KEY_SHOW_SESSION_ID}.
|
||||
* @see #showSession(Bundle, int)
|
||||
* @see #onPrepareToShowSession(Bundle, int)
|
||||
* @see VoiceInteractionSession#onShow(Bundle, int)
|
||||
* @see VoiceInteractionSession#show(Bundle, int)
|
||||
*/
|
||||
public void onShowSessionFailed() {
|
||||
public void onShowSessionFailed(@NonNull Bundle args) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1763,7 +1763,8 @@ public class VoiceInteractionSession implements KeyEvent.Callback, ComponentCall
|
||||
* @param args The arguments that were supplied to
|
||||
* {@link VoiceInteractionService#showSession VoiceInteractionService.showSession}.
|
||||
* Some example keys include : "invocation_type", "invocation_phone_state",
|
||||
* "invocation_time_ms", Intent.EXTRA_TIME ("android.intent.extra.TIME") indicating timing
|
||||
* {@link VoiceInteractionService#KEY_SHOW_SESSION_ID}, "invocation_time_ms",
|
||||
* Intent.EXTRA_TIME ("android.intent.extra.TIME") indicating timing
|
||||
* in milliseconds of the KeyEvent that triggered Assistant and
|
||||
* Intent.EXTRA_ASSIST_INPUT_DEVICE_ID (android.intent.extra.ASSIST_INPUT_DEVICE_ID)
|
||||
* referring to the device that sent the request.
|
||||
|
||||
@@ -331,6 +331,12 @@ public class VoiceInteractionManagerService extends SystemService {
|
||||
@GuardedBy("this")
|
||||
private boolean mTemporarilyDisabled;
|
||||
|
||||
/** The start value of showSessionId */
|
||||
private static final int SHOW_SESSION_START_ID = 0;
|
||||
|
||||
@GuardedBy("this")
|
||||
private int mShowSessionId = SHOW_SESSION_START_ID;
|
||||
|
||||
private final boolean mEnableService;
|
||||
// TODO(b/226201975): remove reference once RoleService supports pre-created users
|
||||
private final RoleObserver mRoleObserver;
|
||||
@@ -350,6 +356,24 @@ public class VoiceInteractionManagerService extends SystemService {
|
||||
}
|
||||
}
|
||||
|
||||
int getNextShowSessionId() {
|
||||
synchronized (this) {
|
||||
// Reset the showSessionId to SHOW_SESSION_START_ID to avoid the value exceeds
|
||||
// Integer.MAX_VALUE
|
||||
if (mShowSessionId == Integer.MAX_VALUE - 1) {
|
||||
mShowSessionId = SHOW_SESSION_START_ID;
|
||||
}
|
||||
mShowSessionId++;
|
||||
return mShowSessionId;
|
||||
}
|
||||
}
|
||||
|
||||
int getShowSessionId() {
|
||||
synchronized (this) {
|
||||
return mShowSessionId;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull IVoiceInteractionSoundTriggerSession createSoundTriggerSessionAsOriginator(
|
||||
@NonNull Identity originatorIdentity, IBinder client) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import static android.app.ActivityManager.START_ASSISTANT_NOT_ACTIVE_SESSION;
|
||||
import static android.app.ActivityManager.START_VOICE_HIDDEN_SESSION;
|
||||
import static android.app.ActivityManager.START_VOICE_NOT_ACTIVE_SESSION;
|
||||
import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT;
|
||||
import static android.service.voice.VoiceInteractionService.KEY_SHOW_SESSION_ID;
|
||||
|
||||
import static com.android.server.policy.PhoneWindowManager.SYSTEM_DIALOG_REASON_ASSIST;
|
||||
|
||||
@@ -255,13 +256,17 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
|
||||
/* direct= */ true);
|
||||
}
|
||||
|
||||
public boolean showSessionLocked(@NonNull Bundle args, int flags,
|
||||
public boolean showSessionLocked(@Nullable Bundle args, int flags,
|
||||
@Nullable String attributionTag,
|
||||
@Nullable IVoiceInteractionSessionShowCallback showCallback,
|
||||
@Nullable IBinder activityToken) {
|
||||
final int sessionId = mServiceStub.getNextShowSessionId();
|
||||
final Bundle newArgs = args == null ? new Bundle() : args;
|
||||
newArgs.putInt(KEY_SHOW_SESSION_ID, sessionId);
|
||||
|
||||
try {
|
||||
if (mService != null) {
|
||||
mService.prepareToShowSession(args, flags);
|
||||
mService.prepareToShowSession(newArgs, flags);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
Slog.w(TAG, "RemoteException while calling prepareToShowSession", e);
|
||||
@@ -275,7 +280,9 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
|
||||
if (!mActiveSession.mBound) {
|
||||
try {
|
||||
if (mService != null) {
|
||||
mService.showSessionFailed();
|
||||
Bundle failedArgs = new Bundle();
|
||||
failedArgs.putInt(KEY_SHOW_SESSION_ID, sessionId);
|
||||
mService.showSessionFailed(failedArgs);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
Slog.w(TAG, "RemoteException while calling showSessionFailed", e);
|
||||
@@ -300,7 +307,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
|
||||
} else {
|
||||
visibleActivities = allVisibleActivities;
|
||||
}
|
||||
return mActiveSession.showLocked(args, flags, attributionTag, mDisabledShowContext,
|
||||
return mActiveSession.showLocked(newArgs, flags, attributionTag, mDisabledShowContext,
|
||||
showCallback, visibleActivities);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user