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

Commit b686ecea authored by Eric Laurent's avatar Eric Laurent Committed by Android Git Automerger
Browse files

am b46857d2: am b1f45c4a: am c3eb57b2: Merge "AudioService: improve initial...

am b46857d2: am b1f45c4a: am c3eb57b2: Merge "AudioService: improve initial safe volume delay" into jb-mr1.1-dev

* commit 'b46857d2':
  AudioService: improve initial safe volume delay
parents 9e3efb91 b46857d2
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -5314,6 +5314,12 @@ public final class Settings {
         */
        public static final String DOCK_AUDIO_MEDIA_ENABLED = "dock_audio_media_enabled";

        /**
         * Persisted safe headphone volume management state by AudioService
         * @hide
         */
        public static final String AUDIO_SAFE_VOLUME_STATE = "audio_safe_volume_state";

        /**
         * Settings to backup. This is here so that it's in the same place as the settings
         * keys and easy to update.
+97 −61
Original line number Diff line number Diff line
@@ -157,6 +157,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
    private static final int MSG_BROADCAST_AUDIO_BECOMING_NOISY = 25;
    private static final int MSG_CONFIGURE_SAFE_MEDIA_VOLUME = 26;
    private static final int MSG_CONFIGURE_SAFE_MEDIA_VOLUME_FORCED = 27;
    private static final int MSG_PERSIST_SAFE_VOLUME_STATE = 28;

    // flags for MSG_PERSIST_VOLUME indicating if current and/or last audible volume should be
    // persisted
@@ -481,6 +482,14 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                null,
                0);

        mSafeMediaVolumeState = new Integer(Settings.Global.getInt(mContentResolver,
                                                        Settings.Global.AUDIO_SAFE_VOLUME_STATE,
                                                        SAFE_MEDIA_VOLUME_NOT_CONFIGURED));
        // The default safe volume index read here will be replaced by the actual value when
        // the mcc is read by onConfigureSafeVolume()
        mSafeMediaVolumeIndex = mContext.getResources().getInteger(
                com.android.internal.R.integer.config_safe_media_volume_index) * 10;

        readPersistedSettings();
        mSettingsObserver = new SettingsObserver();
        updateStreamVolumeAlias(false /*updateVolumes*/);
@@ -488,8 +497,6 @@ public class AudioService extends IAudioService.Stub implements OnFinished {

        mMediaServerOk = true;

        mSafeMediaVolumeState = new Integer(SAFE_MEDIA_VOLUME_NOT_CONFIGURED);

        // Call setRingerModeInt() to apply correct mute
        // state on streams affected by ringer mode.
        mRingerModeMutedStreams = 0;
@@ -822,14 +829,15 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
        // convert one UI step (+/-1) into a number of internal units on the stream alias
        int step = rescaleIndex(10, streamType, streamTypeAlias);

        if ((direction == AudioManager.ADJUST_RAISE) &&
                !checkSafeMediaVolume(streamTypeAlias, aliasIndex + step, device)) {
            return;
        }

        int index;
        int oldIndex;

        if ((direction == AudioManager.ADJUST_RAISE) &&
                !checkSafeMediaVolume(streamTypeAlias, aliasIndex + step, device)) {
            index = mStreamStates[streamType].getIndex(device,
                                                 (streamState.muteCount() != 0)  /* lastAudible */);
            oldIndex = index;
        } else {
            flags &= ~AudioManager.FLAG_FIXED_VOLUME;
            if ((streamTypeAlias == AudioSystem.STREAM_MUSIC) &&
                   ((device & mFixedVolumeDevices) != 0)) {
@@ -888,6 +896,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                    index = mStreamStates[streamType].getIndex(device, false  /* lastAudible */);
                }
            }
        }
        sendVolumeUpdate(streamType, oldIndex, index, flags);
    }

@@ -2306,13 +2315,31 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                        com.android.internal.R.integer.config_safe_media_volume_index) * 10;
                boolean safeMediaVolumeEnabled = mContext.getResources().getBoolean(
                        com.android.internal.R.bool.config_safe_media_volume_enabled);

                // The persisted state is either "disabled" or "active": this is the state applied
                // next time we boot and cannot be "inactive"
                int persistedState;
                if (safeMediaVolumeEnabled) {
                    persistedState = SAFE_MEDIA_VOLUME_ACTIVE;
                    // The state can already be "inactive" here if the user has forced it before
                    // the 30 seconds timeout for forced configuration. In this case we don't reset
                    // it to "active".
                    if (mSafeMediaVolumeState != SAFE_MEDIA_VOLUME_INACTIVE) {
                        mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_ACTIVE;
                        enforceSafeMediaVolume();
                    }
                } else {
                    persistedState = SAFE_MEDIA_VOLUME_DISABLED;
                    mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_DISABLED;
                }
                mMcc = mcc;
                sendMsg(mAudioHandler,
                        MSG_PERSIST_SAFE_VOLUME_STATE,
                        SENDMSG_QUEUE,
                        persistedState,
                        0,
                        null,
                        0);
            }
        }
    }
@@ -3224,6 +3251,12 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
            AudioSystem.setForceUse(usage, config);
        }

        private void onPersistSafeVolumeState(int state) {
            Settings.Global.putInt(mContentResolver,
                    Settings.Global.AUDIO_SAFE_VOLUME_STATE,
                    state);
        }

        @Override
        public void handleMessage(Message msg) {

@@ -3433,6 +3466,9 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                case MSG_CONFIGURE_SAFE_MEDIA_VOLUME:
                    onConfigureSafeVolume((msg.what == MSG_CONFIGURE_SAFE_MEDIA_VOLUME_FORCED));
                    break;
                case MSG_PERSIST_SAFE_VOLUME_STATE:
                    onPersistSafeVolumeState(msg.arg1);
                    break;
            }
        }
    }