From 9010646b3de36e9ad55c45ae77a9244e0f6e7751 Mon Sep 17 00:00:00 2001 From: lpeter Date: Tue, 22 Nov 2022 07:44:58 +0800 Subject: [PATCH] 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 efc66d30ab6cbf6d6547a7c45ff13415e09146c5) --- core/java/android/app/Activity.java | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index d24b677b1d728..03a97ba1d9778 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -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 }