Just get VoiceInteractionManagerService once in Activity.java

During testing the testActivityTransitionsAnimation, it usually
takes 400us ~ 1ms to get the VoiceInteractionManagerService, it
would be better to get VoiceInteractionManagerService once
and keep it instead of getting VoiceInteractionManagerService
again in the other stages.

Test: atest CtsVoiceInteractionTestCases
Bug: 261791888
Change-Id: I46daa11f2281a8db96056ca99520a0c3fe41e4ec
(cherry picked from commit efc66d30ab)
This commit is contained in:
lpeter
2022-11-22 07:44:58 +08:00
committed by Peter Li
parent a27acd1622
commit 9010646b3d

View File

@@ -997,6 +997,8 @@ public class Activity extends ContextThemeWrapper
private ComponentCallbacksController mCallbacksController;
@Nullable private IVoiceInteractionManagerService mVoiceInteractionManagerService;
private final WindowControllerCallback mWindowControllerCallback =
new WindowControllerCallback() {
/**
@@ -1606,18 +1608,17 @@ public class Activity extends ContextThemeWrapper
private void notifyVoiceInteractionManagerServiceActivityEvent(
@VoiceInteractionSession.VoiceInteractionActivityEventType int type) {
final IVoiceInteractionManagerService service =
IVoiceInteractionManagerService.Stub.asInterface(
ServiceManager.getService(Context.VOICE_INTERACTION_MANAGER_SERVICE));
if (service == null) {
Log.w(TAG, "notifyVoiceInteractionManagerServiceActivityEvent: Can not get "
+ "VoiceInteractionManagerService");
return;
if (mVoiceInteractionManagerService == null) {
mVoiceInteractionManagerService = IVoiceInteractionManagerService.Stub.asInterface(
ServiceManager.getService(Context.VOICE_INTERACTION_MANAGER_SERVICE));
if (mVoiceInteractionManagerService == null) {
Log.w(TAG, "notifyVoiceInteractionManagerServiceActivityEvent: Can not get "
+ "VoiceInteractionManagerService");
return;
}
}
try {
service.notifyActivityEventChanged(mToken, type);
mVoiceInteractionManagerService.notifyActivityEventChanged(mToken, type);
} catch (RemoteException e) {
// Empty
}