Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a051308d authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

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
parent 973849d0
Loading
Loading
Loading
Loading
+14 −8
Original line number Original line Diff line number Diff line
@@ -96,8 +96,8 @@ public class AudioManager {
    private Context mOriginalContext;
    private Context mOriginalContext;
    private Context mApplicationContext;
    private Context mApplicationContext;
    private long mVolumeKeyUpTime;
    private long mVolumeKeyUpTime;
    private final boolean mUseVolumeKeySounds;
    private boolean mUseFixedVolumeInitialized;
    private final boolean mUseFixedVolume;
    private boolean mUseFixedVolume;
    private static final String TAG = "AudioManager";
    private static final String TAG = "AudioManager";
    private static final boolean DEBUG = false;
    private static final boolean DEBUG = false;
    private static final AudioPortEventHandler sAudioPortEventHandler = new AudioPortEventHandler();
    private static final AudioPortEventHandler sAudioPortEventHandler = new AudioPortEventHandler();
@@ -711,8 +711,6 @@ public class AudioManager {
     */
     */
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    public AudioManager() {
    public AudioManager() {
        mUseVolumeKeySounds = true;
        mUseFixedVolume = false;
    }
    }


    /**
    /**
@@ -721,10 +719,6 @@ public class AudioManager {
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    public AudioManager(Context context) {
    public AudioManager(Context context) {
        setContext(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() {
    private Context getContext() {
@@ -823,6 +817,18 @@ public class AudioManager {
     * </ul>
     * </ul>
     */
     */
    public boolean isVolumeFixed() {
    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;
        return mUseFixedVolume;
    }
    }