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

Commit 12641eeb authored by Wonil Kim's avatar Wonil Kim Committed by Android (Google) Code Review
Browse files

Merge "Persist music stream volume per user for Automotive" into main

parents 78702edc 534e5135
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -8571,6 +8571,12 @@ public class AudioService extends IAudioService.Stub
        return true;
    }
    private boolean shouldPreserveVolume(boolean userSwitch, VolumeGroupState vgs) {
        // as for STREAM_MUSIC, preserve volume from one user to the next except
        // Android Automotive platform
        return (userSwitch && vgs.isMusic()) && !isPlatformAutomotive();
    }
    private void readVolumeGroupsSettings(boolean userSwitch) {
        synchronized (mSettingsLock) {
            synchronized (VolumeStreamState.class) {
@@ -8579,8 +8585,7 @@ public class AudioService extends IAudioService.Stub
                }
                for (int i = 0; i < sVolumeGroupStates.size(); i++) {
                    VolumeGroupState vgs = sVolumeGroupStates.valueAt(i);
                    // as for STREAM_MUSIC, preserve volume from one user to the next.
                    if (!(userSwitch && vgs.isMusic())) {
                    if (!shouldPreserveVolume(userSwitch, vgs)) {
                        vgs.clearIndexCache();
                        vgs.readSettings();
                    }
@@ -9019,6 +9024,11 @@ public class AudioService extends IAudioService.Stub
            mIndexMap.clear();
        }
        private @UserIdInt int getVolumePersistenceUserId() {
            return isMusic() && !isPlatformAutomotive()
                    ? UserHandle.USER_SYSTEM : UserHandle.USER_CURRENT;
        }
        private void persistVolumeGroup(int device) {
            // No need to persist the index if the volume group is backed up
            // by a public stream type as this is redundant
@@ -9036,7 +9046,7 @@ public class AudioService extends IAudioService.Stub
            boolean success = mSettings.putSystemIntForUser(mContentResolver,
                    getSettingNameForDevice(device),
                    getIndex(device),
                    isMusic() ? UserHandle.USER_SYSTEM : UserHandle.USER_CURRENT);
                    getVolumePersistenceUserId());
            if (!success) {
                Log.e(TAG, "persistVolumeGroup failed for group " +  mAudioVolumeGroup.name());
            }
@@ -9059,7 +9069,7 @@ public class AudioService extends IAudioService.Stub
                    String name = getSettingNameForDevice(device);
                    index = mSettings.getSystemIntForUser(
                            mContentResolver, name, defaultIndex,
                            isMusic() ? UserHandle.USER_SYSTEM : UserHandle.USER_CURRENT);
                            getVolumePersistenceUserId());
                    if (index == -1) {
                        continue;
                    }