diff options
| author | 2020-09-22 18:43:53 -0700 | |
|---|---|---|
| committer | 2020-09-22 19:03:04 -0700 | |
| commit | a051308d622cd877e1ef3ba1f0b5ac2bbe19cc43 (patch) | |
| tree | ef1383eddf6d38b89a3b01a805ec4d1b3c0958e9 | |
| parent | 973849d083c3c7472a3b994c083cee1c9c138869 (diff) | |
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
| -rw-r--r-- | media/java/android/media/AudioManager.java | 22 |
1 files 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 { * </ul> */ 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; } |