From a051308d622cd877e1ef3ba1f0b5ac2bbe19cc43 Mon Sep 17 00:00:00 2001 From: Jean-Michel Trivi Date: Tue, 22 Sep 2020 18:43:53 -0700 Subject: AudioManager: clean up resource query in constructor Remove unused mUseVolumeKeySounds and associated resource query. Don't query fixed volume prop until value is needed. Bug: 168815124 Test: atest AudioManagerTest Change-Id: I008eb3582135209e95778ef3c88df9564988b4c0 --- media/java/android/media/AudioManager.java | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java index e1e55c25b3fa..22b5ca53e7e9 100644 --- a/media/java/android/media/AudioManager.java +++ b/media/java/android/media/AudioManager.java @@ -96,8 +96,8 @@ public class AudioManager { private Context mOriginalContext; private Context mApplicationContext; private long mVolumeKeyUpTime; - private final boolean mUseVolumeKeySounds; - private final boolean mUseFixedVolume; + private boolean mUseFixedVolumeInitialized; + private boolean mUseFixedVolume; private static final String TAG = "AudioManager"; private static final boolean DEBUG = false; private static final AudioPortEventHandler sAudioPortEventHandler = new AudioPortEventHandler(); @@ -711,8 +711,6 @@ public class AudioManager { */ @UnsupportedAppUsage public AudioManager() { - mUseVolumeKeySounds = true; - mUseFixedVolume = false; } /** @@ -721,10 +719,6 @@ public class AudioManager { @UnsupportedAppUsage public AudioManager(Context context) { setContext(context); - mUseVolumeKeySounds = getContext().getResources().getBoolean( - com.android.internal.R.bool.config_useVolumeKeySounds); - mUseFixedVolume = getContext().getResources().getBoolean( - com.android.internal.R.bool.config_useFixedVolume); } private Context getContext() { @@ -823,6 +817,18 @@ public class AudioManager { * */ public boolean isVolumeFixed() { + synchronized (this) { + try { + if (!mUseFixedVolumeInitialized) { + mUseFixedVolume = getContext().getResources().getBoolean( + com.android.internal.R.bool.config_useFixedVolume); + } + } catch (Exception e) { + } finally { + // only ever try once, so always consider initialized even if query failed + mUseFixedVolumeInitialized = true; + } + } return mUseFixedVolume; } -- cgit v1.2.3-59-g8ed1b