Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge "Feat: Allow users to disable safe headset volume warning (1/2)…

…" into jb-mr1
  • Loading branch information...
commit 292313b061bbf8b89aa72d4c620169f08d4d8e77 2 parents ac38590 + 2e37f45
Gergely Szell (sethyx) authored Gerrit Code Review committed
View
6 core/java/android/provider/Settings.java
@@ -2434,6 +2434,12 @@ public static void setShowGTalkServiceStatusForUser(ContentResolver cr, boolean
public static final String VOLUME_MUSIC_CONTROLS = "volume_music_controls";
/**
+ * Whether to enable the built-in safe media volume for headsets
+ * @hide
+ */
+ public static final String MANUAL_SAFE_MEDIA_VOLUME = "manual_safe_media_volume";
+
+ /**
* whether to hide the Ram Usage Bar on recent switcher
*
* @hide
View
21 media/java/android/media/AudioService.java
@@ -482,6 +482,8 @@ public AudioService(Context context) {
null,
0);
+ mSafeMediaVolumeState = new Integer(SAFE_MEDIA_VOLUME_NOT_CONFIGURED);
+
readPersistedSettings();
mSettingsObserver = new SettingsObserver();
updateStreamVolumeAlias(false /*updateVolumes*/);
@@ -489,8 +491,6 @@ public AudioService(Context context) {
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;
@@ -730,6 +730,7 @@ private void readPersistedSettings() {
UserHandle.USER_CURRENT);
readDockAudioSettings(cr);
+ updateManualSafeMediaVolume();
}
boolean linkNotificationWithVolume = Settings.System.getInt(mContentResolver,
Settings.System.VOLUME_LINK_NOTIFICATION, 1) == 1;
@@ -3458,6 +3459,8 @@ public void handleMessage(Message msg) {
Settings.Global.DOCK_AUDIO_MEDIA_ENABLED), false, this);
mContentResolver.registerContentObserver(Settings.System.getUriFor(
Settings.System.VOLUME_LINK_NOTIFICATION), false, this);
+ mContentResolver.registerContentObserver(Settings.System.getUriFor(
+ Settings.System.MANUAL_SAFE_MEDIA_VOLUME), false, this);
}
@Override
@@ -3501,6 +3504,7 @@ public void onChange(boolean selfChange) {
STREAM_VOLUME_ALIAS[AudioSystem.STREAM_NOTIFICATION] = AudioSystem.STREAM_NOTIFICATION;
}
readDockAudioSettings(mContentResolver);
+ updateManualSafeMediaVolume();
}
}
}
@@ -5911,6 +5915,8 @@ public AudioRoutesInfo startWatchingRoutes(IAudioRoutesObserver observer) {
// mSafeMediaVolumeDevices lists the devices for which safe media volume is enforced,
private final int mSafeMediaVolumeDevices = AudioSystem.DEVICE_OUT_WIRED_HEADSET |
AudioSystem.DEVICE_OUT_WIRED_HEADPHONE;
+ // mManualSafeMediaVolume overrides the built-in safe media volume
+ boolean mManualSafeMediaVolume;
// mMusicActiveMs is the cumulative time of music activity since safe volume was disabled.
// When this time reaches UNSAFE_VOLUME_MUSIC_ACTIVE_MS_MAX, the safe media volume is re-enabled
// automatically. mMusicActiveMs is rounded to a multiple of MUSIC_ACTIVE_POLL_PERIOD_MS.
@@ -5942,6 +5948,9 @@ private void setSafeMediaVolumeEnabled(boolean on) {
}
private void enforceSafeMediaVolume() {
+ // return if safe volume has been manually turned off
+ if (!mManualSafeMediaVolume) return;
+
VolumeStreamState streamState = mStreamStates[AudioSystem.STREAM_MUSIC];
boolean lastAudible = (streamState.muteCount() != 0);
int devices = mSafeMediaVolumeDevices;
@@ -5983,7 +5992,7 @@ private boolean checkSafeMediaVolume(int streamType, int index, int device) {
if ((mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_ACTIVE) &&
(mStreamVolumeAlias[streamType] == AudioSystem.STREAM_MUSIC) &&
((device & mSafeMediaVolumeDevices) != 0) &&
- (index > mSafeMediaVolumeIndex)) {
+ (index > mSafeMediaVolumeIndex) && mManualSafeMediaVolume) {
mVolumePanel.postDisplaySafeVolumeWarning();
return false;
}
@@ -6043,4 +6052,10 @@ protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
pw.print(" mMainType=0x"); pw.println(Integer.toHexString(mCurAudioRoutes.mMainType));
pw.print(" mBluetoothName="); pw.println(mCurAudioRoutes.mBluetoothName);
}
+
+ protected void updateManualSafeMediaVolume() {
+ mManualSafeMediaVolume = Settings.System.getBoolean(mContext.getContentResolver(),
+ Settings.System.MANUAL_SAFE_MEDIA_VOLUME, true);
+ setSafeMediaVolumeEnabled(mManualSafeMediaVolume);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.