Skip to content

Commit b40c0b5

Browse files
jmtriviAndroid (Google) Code Review
authored andcommitted
Merge "Handle wakelocks for device connection intents from AudioService" into jb-dev
2 parents 1c094d3 + 2d8dab5 commit b40c0b5

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

media/java/android/media/AudioService.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
135135
private static final int MSG_RCDISPLAY_UPDATE = 13;
136136
private static final int MSG_SET_ALL_VOLUMES = 14;
137137
private static final int MSG_PERSIST_MASTER_VOLUME_MUTE = 15;
138-
private static final int MSG_SET_WIRED_DEVICE_CONNECTION_STATE = 16;
139-
private static final int MSG_SET_A2DP_CONNECTION_STATE = 17;
138+
private static final int MSG_SET_WIRED_DEVICE_CONNECTION_STATE = 16;//handled under wakelock
139+
private static final int MSG_SET_A2DP_CONNECTION_STATE = 17; //handled under wakelock
140140

141141

142142
// flags for MSG_PERSIST_VOLUME indicating if current and/or last audible volume should be
@@ -410,7 +410,7 @@ public AudioService(Context context) {
410410
com.android.internal.R.bool.config_voice_capable);
411411

412412
PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
413-
mMediaEventWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "mediaKeyEvent");
413+
mMediaEventWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "handleMediaEvent");
414414

415415
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
416416
mHasVibrator = vibrator == null ? false : vibrator.hasVibrator();
@@ -2228,6 +2228,15 @@ private void broadcastVibrateSetting(int vibrateType) {
22282228
}
22292229

22302230
// Message helper methods
2231+
/**
2232+
* Queue a message on the given handler's message queue, after acquiring the service wake lock.
2233+
* Note that the wake lock needs to be released after the message has been handled.
2234+
*/
2235+
private void queueMsgUnderWakeLock(Handler handler, int msg,
2236+
int arg1, int arg2, Object obj, int delay) {
2237+
mMediaEventWakeLock.acquire();
2238+
sendMsg(handler, msg, SENDMSG_QUEUE, arg1, arg2, obj, delay);
2239+
}
22312240

22322241
private static void sendMsg(Handler handler, int msg,
22332242
int existingMsgPolicy, int arg1, int arg2, Object obj, int delay) {
@@ -2273,9 +2282,8 @@ private int getDeviceForStream(int stream) {
22732282
public void setWiredDeviceConnectionState(int device, int state, String name) {
22742283
synchronized (mConnectedDevices) {
22752284
int delay = checkSendBecomingNoisyIntent(device, state);
2276-
sendMsg(mAudioHandler,
2285+
queueMsgUnderWakeLock(mAudioHandler,
22772286
MSG_SET_WIRED_DEVICE_CONNECTION_STATE,
2278-
SENDMSG_QUEUE,
22792287
device,
22802288
state,
22812289
name,
@@ -2289,9 +2297,8 @@ public int setBluetoothA2dpDeviceConnectionState(BluetoothDevice device, int sta
22892297
synchronized (mConnectedDevices) {
22902298
delay = checkSendBecomingNoisyIntent(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,
22912299
(state == BluetoothA2dp.STATE_CONNECTED) ? 1 : 0);
2292-
sendMsg(mAudioHandler,
2300+
queueMsgUnderWakeLock(mAudioHandler,
22932301
MSG_SET_A2DP_CONNECTION_STATE,
2294-
SENDMSG_QUEUE,
22952302
state,
22962303
0,
22972304
device,
@@ -3000,10 +3007,12 @@ public void handleMessage(Message msg) {
30003007

30013008
case MSG_SET_WIRED_DEVICE_CONNECTION_STATE:
30023009
onSetWiredDeviceConnectionState(msg.arg1, msg.arg2, (String)msg.obj);
3010+
mMediaEventWakeLock.release();
30033011
break;
30043012

30053013
case MSG_SET_A2DP_CONNECTION_STATE:
30063014
onSetA2dpConnectionState((BluetoothDevice)msg.obj, msg.arg1);
3015+
mMediaEventWakeLock.release();
30073016
break;
30083017
}
30093018
}

0 commit comments

Comments
 (0)