From 94a327e6e4ceadcb698ec84409c0a64f184e381a Mon Sep 17 00:00:00 2001 From: Prabir Pradhan Date: Thu, 5 May 2022 11:21:20 +0000 Subject: [PATCH] IMS: Intialize static association map before initializing native service There is a possible race condition between map access from the native side and the map initialization. Bug: 231489654 Test: None Change-Id: Ia915a10ffdb21cbc242031e3f6a536077948659c --- .../java/com/android/server/input/InputManagerService.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java index 8ab0b931be11f..bf267a2a40a56 100644 --- a/services/core/java/com/android/server/input/InputManagerService.java +++ b/services/core/java/com/android/server/input/InputManagerService.java @@ -391,11 +391,14 @@ public class InputManagerService extends IInputManager.Stub @VisibleForTesting InputManagerService(Injector injector) { + // The static association map is accessed by both java and native code, so it must be + // initialized before initializing the native service. + mStaticAssociations = loadStaticInputPortAssociations(); + mContext = injector.getContext(); mHandler = new InputManagerHandler(injector.getLooper()); mNative = injector.getNativeService(this); - mStaticAssociations = loadStaticInputPortAssociations(); mUseDevInputEventForAudioJack = mContext.getResources().getBoolean(R.bool.config_useDevInputEventForAudioJack); Slog.i(TAG, "Initializing input manager, mUseDevInputEventForAudioJack="