Skip to content

Commit 7ee1e4f

Browse files
author
Eric Laurent
committed
add settings for dock audio enabled
Add settings dock_audio_media_enabled indicating if dock audio is enabled for media for docks that do not implement jack detection. Bug 7302106. Change-Id: I75766b606ceb870b3f89979c4e3cca88ed197aaf
1 parent 799916e commit 7ee1e4f

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

core/java/android/provider/Settings.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5299,6 +5299,14 @@ public static final String getBluetoothInputDevicePriorityKey(String address) {
52995299
public static final String ALWAYS_FINISH_ACTIVITIES =
53005300
"always_finish_activities";
53015301

5302+
/**
5303+
* Use Dock audio output for media:
5304+
* 0 = disabled
5305+
* 1 = enabled
5306+
* @hide
5307+
*/
5308+
public static final String DOCK_AUDIO_MEDIA_ENABLED = "dock_audio_media_enabled";
5309+
53025310
/**
53035311
* Settings to backup. This is here so that it's in the same place as the settings
53045312
* keys and easy to update.
@@ -5330,6 +5338,7 @@ public static final String getBluetoothInputDevicePriorityKey(String address) {
53305338
WIFI_NUM_OPEN_NETWORKS_KEPT,
53315339
EMERGENCY_TONE,
53325340
CALL_AUTO_RETRY,
5341+
DOCK_AUDIO_MEDIA_ENABLED
53335342
};
53345343

53355344
// Populated lazily, guarded by class object:

media/java/android/media/AudioService.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,13 @@ public void onError(int error) {
429429
// Devices for which the volume is fixed and VolumePanel slider should be disabled
430430
final int mFixedVolumeDevices = AudioSystem.DEVICE_OUT_AUX_DIGITAL |
431431
AudioSystem.DEVICE_OUT_DGTL_DOCK_HEADSET |
432+
AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET |
432433
AudioSystem.DEVICE_OUT_ALL_USB;
433434

434435
private final boolean mMonitorOrientation;
435436

437+
private boolean mDockAudioMediaEnabled = true;
438+
436439
///////////////////////////////////////////////////////////////////////////
437440
// Construction
438441
///////////////////////////////////////////////////////////////////////////
@@ -630,6 +633,27 @@ private void updateStreamVolumeAlias(boolean updateVolumes) {
630633
}
631634
}
632635

636+
private void readDockAudioSettings(ContentResolver cr)
637+
{
638+
mDockAudioMediaEnabled = Settings.Global.getInt(
639+
cr, Settings.Global.DOCK_AUDIO_MEDIA_ENABLED, 1) == 1;
640+
641+
if (mDockAudioMediaEnabled) {
642+
mBecomingNoisyIntentDevices |= AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET;
643+
} else {
644+
mBecomingNoisyIntentDevices &= ~AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET;
645+
}
646+
647+
sendMsg(mAudioHandler,
648+
MSG_SET_FORCE_USE,
649+
SENDMSG_QUEUE,
650+
AudioSystem.FOR_DOCK,
651+
mDockAudioMediaEnabled ?
652+
AudioSystem.FORCE_ANALOG_DOCK : AudioSystem.FORCE_NONE,
653+
null,
654+
0);
655+
}
656+
633657
private void readPersistedSettings() {
634658
final ContentResolver cr = mContentResolver;
635659

@@ -693,6 +717,8 @@ private void readPersistedSettings() {
693717
Settings.System.MODE_RINGER_STREAMS_AFFECTED,
694718
mRingerModeAffectedStreams,
695719
UserHandle.USER_CURRENT);
720+
721+
readDockAudioSettings(cr);
696722
}
697723

698724
mMuteAffectedStreams = System.getIntForUser(cr,
@@ -3408,6 +3434,8 @@ private class SettingsObserver extends ContentObserver {
34083434
super(new Handler());
34093435
mContentResolver.registerContentObserver(Settings.System.getUriFor(
34103436
Settings.System.MODE_RINGER_STREAMS_AFFECTED), false, this);
3437+
mContentResolver.registerContentObserver(Settings.Global.getUriFor(
3438+
Settings.Global.DOCK_AUDIO_MEDIA_ENABLED), false, this);
34113439
}
34123440

34133441
@Override
@@ -3443,6 +3471,7 @@ public void onChange(boolean selfChange) {
34433471
mRingerModeAffectedStreams = ringerModeAffectedStreams;
34443472
setRingerModeInt(getRingerMode(), false);
34453473
}
3474+
readDockAudioSettings(mContentResolver);
34463475
}
34473476
}
34483477
}
@@ -3722,7 +3751,13 @@ public void onReceive(Context context, Intent intent) {
37223751
config = AudioSystem.FORCE_BT_CAR_DOCK;
37233752
break;
37243753
case Intent.EXTRA_DOCK_STATE_LE_DESK:
3725-
config = AudioSystem.FORCE_ANALOG_DOCK;
3754+
synchronized (mSettingsLock) {
3755+
if (mDockAudioMediaEnabled) {
3756+
config = AudioSystem.FORCE_ANALOG_DOCK;
3757+
} else {
3758+
config = AudioSystem.FORCE_NONE;
3759+
}
3760+
}
37263761
break;
37273762
case Intent.EXTRA_DOCK_STATE_HE_DESK:
37283763
config = AudioSystem.FORCE_DIGITAL_DOCK;
@@ -3731,6 +3766,7 @@ public void onReceive(Context context, Intent intent) {
37313766
default:
37323767
config = AudioSystem.FORCE_NONE;
37333768
}
3769+
37343770
AudioSystem.setForceUse(AudioSystem.FOR_DOCK, config);
37353771
} else if (action.equals(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED)) {
37363772
state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE,

0 commit comments

Comments
 (0)