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

Commit 84a4c1ba authored by Jean-Michel Trivi's avatar Jean-Michel Trivi Committed by Automerger Merge Worker
Browse files

Merge "SeekBarVolumizer: fix handling of routing change" into tm-qpr-dev am:...

Merge "SeekBarVolumizer: fix handling of routing change" into tm-qpr-dev am: c82fa1ff am: 4cf8ff36 am: f58c1ce7

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22133032



Change-Id: I141d52c9f502524ac229a5c75730b5dea311d5af
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents fce1861e f58c1ce7
Loading
Loading
Loading
Loading
+43 −7
Original line number Diff line number Diff line
@@ -141,12 +141,15 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba
    private int mRingerMode;
    private int mZenMode;
    private boolean mPlaySample;
    private final boolean mDeviceHasProductStrategies;

    private static final int MSG_SET_STREAM_VOLUME = 0;
    private static final int MSG_START_SAMPLE = 1;
    private static final int MSG_STOP_SAMPLE = 2;
    private static final int MSG_INIT_SAMPLE = 3;
    private static final int MSG_UPDATE_SLIDER_MAYBE_LATER = 4;
    private static final int CHECK_RINGTONE_PLAYBACK_DELAY_MS = 1000;
    private static final int CHECK_UPDATE_SLIDER_LATER_MS = 500;
    private static final long SET_STREAM_VOLUME_DELAY_MS = TimeUnit.MILLISECONDS.toMillis(500);
    private static final long START_SAMPLE_DELAY_MS = TimeUnit.MILLISECONDS.toMillis(500);
    private static final long DURATION_TO_START_DELAYING = TimeUnit.MILLISECONDS.toMillis(2000);
@@ -170,6 +173,7 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba
            boolean playSample) {
        mContext = context;
        mAudioManager = context.getSystemService(AudioManager.class);
        mDeviceHasProductStrategies = hasAudioProductStrategies();
        mNotificationManager = context.getSystemService(NotificationManager.class);
        mNotificationPolicy = mNotificationManager.getConsolidatedNotificationPolicy();
        mAllowAlarms = (mNotificationPolicy.priorityCategories & NotificationManager.Policy
@@ -186,7 +190,7 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba
        }
        mZenMode = mNotificationManager.getZenMode();

        if (hasAudioProductStrategies()) {
        if (mDeviceHasProductStrategies) {
            mVolumeGroupId = getVolumeGroupIdForLegacyStreamType(mStreamType);
            mAttributes = getAudioAttributesForLegacyStreamType(
                    mStreamType);
@@ -213,6 +217,12 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba
        mDefaultUri = defaultUri;
    }

    /**
     * DO NOT CALL every time this is needed, use once in constructor,
     * read mDeviceHasProductStrategies instead
     * @return true if stream types are used for volume management, false if volume groups are
     *     used for volume management
     */
    private boolean hasAudioProductStrategies() {
        return AudioManager.getAudioProductStrategies().size() > 0;
    }
@@ -330,6 +340,9 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba
                    onInitSample();
                }
                break;
            case MSG_UPDATE_SLIDER_MAYBE_LATER:
                onUpdateSliderMaybeLater();
                break;
            default:
                Log.e(TAG, "invalid SeekBarVolumizer message: "+msg.what);
        }
@@ -353,6 +366,21 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba
                        : isDelay() ? START_SAMPLE_DELAY_MS : 0);
    }

    private void onUpdateSliderMaybeLater() {
        if (isDelay()) {
            postUpdateSliderMaybeLater();
            return;
        }
        updateSlider();
    }

    private void postUpdateSliderMaybeLater() {
        if (mHandler == null) return;
        mHandler.removeMessages(MSG_UPDATE_SLIDER_MAYBE_LATER);
        mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_UPDATE_SLIDER_MAYBE_LATER),
                CHECK_UPDATE_SLIDER_LATER_MS);
    }

    // After stop volume it needs to add a small delay when playing volume or set stream.
    // It is because the call volume is from the earpiece and the alarm/ring/media
    // is from the speaker. If play the alarm volume or set alarm stream right after stop
@@ -422,7 +450,7 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba
        postStopSample();
        mContext.getContentResolver().unregisterContentObserver(mVolumeObserver);
        mReceiver.setListening(false);
        if (hasAudioProductStrategies()) {
        if (mDeviceHasProductStrategies) {
            unregisterVolumeGroupCb();
        }
        mSeekBar.setOnSeekBarChangeListener(null);
@@ -442,7 +470,7 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba
                System.getUriFor(System.VOLUME_SETTINGS_INT[mStreamType]),
                false, mVolumeObserver);
        mReceiver.setListening(true);
        if (hasAudioProductStrategies()) {
        if (mDeviceHasProductStrategies) {
            registerVolumeGroupCb();
        }
    }
@@ -466,6 +494,7 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba
        mLastProgress = progress;
        mHandler.removeMessages(MSG_SET_STREAM_VOLUME);
        mHandler.removeMessages(MSG_START_SAMPLE);
        mHandler.removeMessages(MSG_UPDATE_SLIDER_MAYBE_LATER);
        mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_SET_STREAM_VOLUME),
                isDelay() ? SET_STREAM_VOLUME_DELAY_MS : 0);
    }
@@ -609,7 +638,7 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba
            if (AudioManager.VOLUME_CHANGED_ACTION.equals(action)) {
                int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1);
                int streamValue = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, -1);
                if (hasAudioProductStrategies() && !isDelay()) {
                if (mDeviceHasProductStrategies && !isDelay()) {
                    updateVolumeSlider(streamType, streamValue);
                }
            } else if (AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION.equals(action)) {
@@ -621,9 +650,16 @@ public class SeekBarVolumizer implements OnSeekBarChangeListener, Handler.Callba
                }
            } else if (AudioManager.STREAM_DEVICES_CHANGED_ACTION.equals(action)) {
                int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1);
                if (hasAudioProductStrategies() && !isDelay()) {

                if (mDeviceHasProductStrategies) {
                    if (isDelay()) {
                        // not the right time to update the sliders, try again later
                        postUpdateSliderMaybeLater();
                    } else {
                        int streamVolume = mAudioManager.getStreamVolume(streamType);
                        updateVolumeSlider(streamType, streamVolume);
                    }

                } else {
                    int volumeGroup = getVolumeGroupIdForLegacyStreamType(streamType);
                    if (volumeGroup != AudioVolumeGroup.DEFAULT_VOLUME_GROUP