summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorDvTonder <david.vantonder@gmail.com>2013-02-03 14:28:03 -0500
committerDvTonder <david.vantonder@gmail.com>2013-02-06 20:05:18 -0500
commitc8ec72e30596cd15fe44f0010cf147422f5bdd42 (patch)
tree93aded274a085492de8a280ba82df3b7711ea69f /media
parentf97e4f341e9374f2c7023bd170dfea0bc11c87cd (diff)
downloadframeworks_base-c8ec72e30596cd15fe44f0010cf147422f5bdd42.zip
frameworks_base-c8ec72e30596cd15fe44f0010cf147422f5bdd42.tar.gz
frameworks_base-c8ec72e30596cd15fe44f0010cf147422f5bdd42.tar.bz2
Framework: Make Safe headset volume user configurable (1 of 2)
Patch set 1 : Initial commit Patch set 2 : Alternative approach using content observer to listen for settings changes and react dynamically Patch set 3 : Rebase Change-Id: I0bd57334ca1307786eaed6578b216323e442f00e
Diffstat (limited to 'media')
-rwxr-xr-xmedia/java/android/media/AudioService.java106
1 files changed, 67 insertions, 39 deletions
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index a7eb5fe..1b0675a 100755
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -46,6 +46,7 @@ import android.content.res.Resources;
import android.database.ContentObserver;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
+import android.net.Uri;
import android.os.Binder;
import android.os.Bundle;
import android.os.Environment;
@@ -681,6 +682,15 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
0);
}
+ private boolean safeVolumeEnabled(ContentResolver cr) {
+ boolean safeMediaVolumeEnabled = mContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_safe_media_volume_enabled);
+ boolean safeHeadsetVolumeEnabled = Settings.System.getIntForUser(cr,
+ Settings.System.SAFE_HEADSET_VOLUME, safeMediaVolumeEnabled ? 1 : 0,
+ UserHandle.USER_CURRENT_OR_SELF) != 0;
+ return safeHeadsetVolumeEnabled;
+ }
+
private void readPersistedSettings() {
final ContentResolver cr = mContentResolver;
@@ -746,6 +756,8 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
UserHandle.USER_CURRENT);
readDockAudioSettings(cr);
+
+ mSafeVolumeEnabled = new Boolean(safeVolumeEnabled(cr));
}
mLinkNotificationWithVolume = Settings.System.getIntForUser(cr,
@@ -1844,7 +1856,8 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
checkAllAliasStreamVolumes();
synchronized (mSafeMediaVolumeState) {
- if (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_ACTIVE) {
+ if (mSafeVolumeEnabled &&
+ mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_ACTIVE) {
enforceSafeMediaVolume();
}
}
@@ -2305,7 +2318,8 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
private void onCheckMusicActive() {
synchronized (mSafeMediaVolumeState) {
- if (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_INACTIVE) {
+ if (mSafeVolumeEnabled &&
+ mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_INACTIVE) {
int device = getDeviceForStream(AudioSystem.STREAM_MUSIC);
if ((device & mSafeMediaVolumeDevices) != 0) {
@@ -2339,9 +2353,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
if ((mMcc != mcc) || ((mMcc == 0) && force)) {
mSafeMediaVolumeIndex = mContext.getResources().getInteger(
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);
- if (safeMediaVolumeEnabled) {
+ if (mSafeVolumeEnabled) {
mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_ACTIVE;
enforceSafeMediaVolume();
} else {
@@ -3480,49 +3492,61 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
Settings.System.MODE_RINGER_STREAMS_AFFECTED), false, this);
mContentResolver.registerContentObserver(Settings.Global.getUriFor(
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.SAFE_HEADSET_VOLUME), false, this);
}
@Override
- public void onChange(boolean selfChange) {
- super.onChange(selfChange);
+ public void onChange(boolean selfChange, Uri uri) {
+ super.onChange(selfChange, uri);
// FIXME This synchronized is not necessary if mSettingsLock only protects mRingerMode.
// However there appear to be some missing locks around mRingerModeMutedStreams
// and mRingerModeAffectedStreams, so will leave this synchronized for now.
// mRingerModeMutedStreams and mMuteAffectedStreams are safe (only accessed once).
synchronized (mSettingsLock) {
- int ringerModeAffectedStreams = Settings.System.getIntForUser(mContentResolver,
- Settings.System.MODE_RINGER_STREAMS_AFFECTED,
- ((1 << AudioSystem.STREAM_RING)|(1 << AudioSystem.STREAM_NOTIFICATION)|
- (1 << AudioSystem.STREAM_SYSTEM)|(1 << AudioSystem.STREAM_SYSTEM_ENFORCED)),
- UserHandle.USER_CURRENT);
- if (mVoiceCapable) {
- ringerModeAffectedStreams &= ~(1 << AudioSystem.STREAM_MUSIC);
- } else {
- ringerModeAffectedStreams |= (1 << AudioSystem.STREAM_MUSIC);
- }
- synchronized (mCameraSoundForced) {
- if (mCameraSoundForced) {
- ringerModeAffectedStreams &= ~(1 << AudioSystem.STREAM_SYSTEM_ENFORCED);
+ if (uri.equals(Settings.System.getUriFor(Settings.System.MODE_RINGER_STREAMS_AFFECTED))) {
+ int ringerModeAffectedStreams = Settings.System.getIntForUser(mContentResolver,
+ Settings.System.MODE_RINGER_STREAMS_AFFECTED,
+ ((1 << AudioSystem.STREAM_RING)|(1 << AudioSystem.STREAM_NOTIFICATION)|
+ (1 << AudioSystem.STREAM_SYSTEM)|(1 << AudioSystem.STREAM_SYSTEM_ENFORCED)),
+ UserHandle.USER_CURRENT);
+ if (mVoiceCapable) {
+ ringerModeAffectedStreams &= ~(1 << AudioSystem.STREAM_MUSIC);
} else {
- ringerModeAffectedStreams |= (1 << AudioSystem.STREAM_SYSTEM_ENFORCED);
+ ringerModeAffectedStreams |= (1 << AudioSystem.STREAM_MUSIC);
+ }
+ synchronized (mCameraSoundForced) {
+ if (mCameraSoundForced) {
+ ringerModeAffectedStreams &= ~(1 << AudioSystem.STREAM_SYSTEM_ENFORCED);
+ } else {
+ ringerModeAffectedStreams |= (1 << AudioSystem.STREAM_SYSTEM_ENFORCED);
+ }
+ }
+ if (ringerModeAffectedStreams != mRingerModeAffectedStreams) {
+ /*
+ * Ensure all stream types that should be affected by ringer mode
+ * are in the proper state.
+ */
+ mRingerModeAffectedStreams = ringerModeAffectedStreams;
+ setRingerModeInt(getRingerMode(), false);
}
- }
- if (ringerModeAffectedStreams != mRingerModeAffectedStreams) {
- /*
- * Ensure all stream types that should be affected by ringer mode
- * are in the proper state.
- */
- mRingerModeAffectedStreams = ringerModeAffectedStreams;
- setRingerModeInt(getRingerMode(), false);
- }
- readDockAudioSettings(mContentResolver);
- mLinkNotificationWithVolume = Settings.System.getIntForUser(mContentResolver,
- Settings.System.VOLUME_LINK_NOTIFICATION, 1, UserHandle.USER_CURRENT) == 1;
- if (mLinkNotificationWithVolume) {
- mStreamVolumeAlias[AudioSystem.STREAM_NOTIFICATION] = AudioSystem.STREAM_RING;
- } else {
- mStreamVolumeAlias[AudioSystem.STREAM_NOTIFICATION] = AudioSystem.STREAM_NOTIFICATION;
+ } else if (uri.equals(Settings.Global.getUriFor(Settings.Global.DOCK_AUDIO_MEDIA_ENABLED))) {
+ readDockAudioSettings(mContentResolver);
+
+ } else if (uri.equals(Settings.System.getUriFor(Settings.System.VOLUME_LINK_NOTIFICATION))) {
+ mLinkNotificationWithVolume = Settings.System.getInt(mContentResolver,
+ Settings.System.VOLUME_LINK_NOTIFICATION, 1) == 1;
+ if (mLinkNotificationWithVolume) {
+ mStreamVolumeAlias[AudioSystem.STREAM_NOTIFICATION] = AudioSystem.STREAM_RING;
+ } else {
+ mStreamVolumeAlias[AudioSystem.STREAM_NOTIFICATION] = AudioSystem.STREAM_NOTIFICATION;
+ }
+
+ } else if (uri.equals(Settings.System.getUriFor(Settings.System.SAFE_HEADSET_VOLUME))) {
+ mSafeVolumeEnabled = safeVolumeEnabled(mContentResolver);
}
}
}
@@ -6057,6 +6081,8 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
private Integer mSafeMediaVolumeState;
private int mMcc = 0;
+ // mSafeVolumeEnabled indicates whether to check the volume of media play via headset
+ private boolean mSafeVolumeEnabled;
// mSafeMediaVolumeIndex is the cached value of config_safe_media_volume_index property
private int mSafeMediaVolumeIndex;
// mSafeMediaVolumeDevices lists the devices for which safe media volume is enforced,
@@ -6072,7 +6098,8 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
private void setSafeMediaVolumeEnabled(boolean on) {
synchronized (mSafeMediaVolumeState) {
- if ((mSafeMediaVolumeState != SAFE_MEDIA_VOLUME_NOT_CONFIGURED) &&
+ if (mSafeVolumeEnabled &&
+ (mSafeMediaVolumeState != SAFE_MEDIA_VOLUME_NOT_CONFIGURED) &&
(mSafeMediaVolumeState != SAFE_MEDIA_VOLUME_DISABLED)) {
if (on && (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_INACTIVE)) {
mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_ACTIVE;
@@ -6131,7 +6158,8 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
private boolean checkSafeMediaVolume(int streamType, int index, int device) {
synchronized (mSafeMediaVolumeState) {
- if ((mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_ACTIVE) &&
+ if (mSafeVolumeEnabled &&
+ (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_ACTIVE) &&
(mStreamVolumeAlias[streamType] == AudioSystem.STREAM_MUSIC) &&
((device & mSafeMediaVolumeDevices) != 0) &&
(index > mSafeMediaVolumeIndex)) {