am 52f545c7: Merge change Ibe55f880 into eclair-mr2
Merge commit '52f545c7fd427610cf06d8215fde434cbbf55d81' into eclair-mr2-plus-aosp * commit '52f545c7fd427610cf06d8215fde434cbbf55d81': Bluetooth A2DP suspend-resume improvements.
This commit is contained in:
@@ -72,8 +72,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
|
|||||||
private final AudioManager mAudioManager;
|
private final AudioManager mAudioManager;
|
||||||
private final BluetoothService mBluetoothService;
|
private final BluetoothService mBluetoothService;
|
||||||
private final BluetoothAdapter mAdapter;
|
private final BluetoothAdapter mAdapter;
|
||||||
private boolean mSuspending;
|
private int mTargetA2dpState;
|
||||||
private boolean mResuming;
|
|
||||||
|
|
||||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
@@ -151,8 +150,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
|
|||||||
|
|
||||||
if (mBluetoothService.isEnabled())
|
if (mBluetoothService.isEnabled())
|
||||||
onBluetoothEnable();
|
onBluetoothEnable();
|
||||||
mSuspending = false;
|
mTargetA2dpState = -1;
|
||||||
mResuming = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -341,10 +339,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
|
|||||||
public synchronized boolean suspendSink(BluetoothDevice device) {
|
public synchronized boolean suspendSink(BluetoothDevice device) {
|
||||||
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
|
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
|
||||||
"Need BLUETOOTH_ADMIN permission");
|
"Need BLUETOOTH_ADMIN permission");
|
||||||
if (DBG) log("suspendSink(" + device + "), mSuspending: "+mSuspending+", mResuming: "+mResuming);
|
if (DBG) log("suspendSink(" + device + "), mTargetA2dpState: "+mTargetA2dpState);
|
||||||
if (mSuspending) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (device == null || mAudioDevices == null) {
|
if (device == null || mAudioDevices == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -353,28 +348,15 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
|
|||||||
if (path == null || state == null) {
|
if (path == null || state == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
switch (state.intValue()) {
|
|
||||||
case BluetoothA2dp.STATE_CONNECTED:
|
mTargetA2dpState = BluetoothA2dp.STATE_CONNECTED;
|
||||||
if (mResuming) {
|
return checkSinkSuspendState(state.intValue());
|
||||||
mSuspending = true;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case BluetoothA2dp.STATE_PLAYING:
|
|
||||||
mAudioManager.setParameters("A2dpSuspended=true");
|
|
||||||
mSuspending = suspendSinkNative(path);
|
|
||||||
return mSuspending;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean resumeSink(BluetoothDevice device) {
|
public synchronized boolean resumeSink(BluetoothDevice device) {
|
||||||
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
|
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
|
||||||
"Need BLUETOOTH_ADMIN permission");
|
"Need BLUETOOTH_ADMIN permission");
|
||||||
if (DBG) log("resumeSink(" + device + "), mResuming: "+mResuming+", mSuspending: "+mSuspending);
|
if (DBG) log("resumeSink(" + device + "), mTargetA2dpState: "+mTargetA2dpState);
|
||||||
if (mResuming) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (device == null || mAudioDevices == null) {
|
if (device == null || mAudioDevices == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -383,19 +365,8 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
|
|||||||
if (path == null || state == null) {
|
if (path == null || state == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
switch (state.intValue()) {
|
mTargetA2dpState = BluetoothA2dp.STATE_PLAYING;
|
||||||
case BluetoothA2dp.STATE_PLAYING:
|
return checkSinkSuspendState(state.intValue());
|
||||||
if (mSuspending) {
|
|
||||||
mResuming = true;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case BluetoothA2dp.STATE_CONNECTED:
|
|
||||||
mResuming = resumeSinkNative(path);
|
|
||||||
mAudioManager.setParameters("A2dpSuspended=false");
|
|
||||||
return mResuming;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized BluetoothDevice[] getConnectedSinks() {
|
public synchronized BluetoothDevice[] getConnectedSinks() {
|
||||||
@@ -458,10 +429,6 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleSinkStateChange(BluetoothDevice device, int prevState, int state) {
|
private void handleSinkStateChange(BluetoothDevice device, int prevState, int state) {
|
||||||
if (state == BluetoothA2dp.STATE_DISCONNECTED) {
|
|
||||||
mSuspending = false;
|
|
||||||
mResuming = false;
|
|
||||||
}
|
|
||||||
if (state != prevState) {
|
if (state != prevState) {
|
||||||
if (state == BluetoothA2dp.STATE_DISCONNECTED ||
|
if (state == BluetoothA2dp.STATE_DISCONNECTED ||
|
||||||
state == BluetoothA2dp.STATE_DISCONNECTING) {
|
state == BluetoothA2dp.STATE_DISCONNECTING) {
|
||||||
@@ -477,28 +444,11 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
|
|||||||
}
|
}
|
||||||
mAudioDevices.put(device, state);
|
mAudioDevices.put(device, state);
|
||||||
|
|
||||||
if (state == BluetoothA2dp.STATE_CONNECTED && prevState == BluetoothA2dp.STATE_PLAYING) {
|
checkSinkSuspendState(state);
|
||||||
if (DBG) log("handleSinkStateChange() STATE_PLAYING -> STATE_CONNECTED: mSuspending: "
|
mTargetA2dpState = -1;
|
||||||
+mSuspending+", mResuming: "+mResuming);
|
|
||||||
if (mSuspending) {
|
|
||||||
mSuspending = false;
|
|
||||||
if (mResuming) {
|
|
||||||
mResuming = false;
|
|
||||||
resumeSink(device);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (state == BluetoothA2dp.STATE_PLAYING && prevState == BluetoothA2dp.STATE_CONNECTED) {
|
|
||||||
if (DBG) log("handleSinkStateChange() STATE_CONNECTED -> STATE_PLAYING: mSuspending: "
|
|
||||||
+mSuspending+", mResuming: "+mResuming);
|
|
||||||
|
|
||||||
if (mResuming) {
|
if (state == BluetoothA2dp.STATE_CONNECTING) {
|
||||||
mResuming = false;
|
mAudioManager.setParameters("A2dpSuspended=false");
|
||||||
if (mSuspending) {
|
|
||||||
mSuspending = false;
|
|
||||||
suspendSink(device);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Intent intent = new Intent(BluetoothA2dp.ACTION_SINK_STATE_CHANGED);
|
Intent intent = new Intent(BluetoothA2dp.ACTION_SINK_STATE_CHANGED);
|
||||||
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
|
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
|
||||||
@@ -527,6 +477,23 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
|
|||||||
return sinks;
|
return sinks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean checkSinkSuspendState(int state) {
|
||||||
|
boolean result = true;
|
||||||
|
|
||||||
|
if (state != mTargetA2dpState) {
|
||||||
|
if (state == BluetoothA2dp.STATE_PLAYING &&
|
||||||
|
mTargetA2dpState == BluetoothA2dp.STATE_CONNECTED) {
|
||||||
|
mAudioManager.setParameters("A2dpSuspended=true");
|
||||||
|
} else if (state == BluetoothA2dp.STATE_CONNECTED &&
|
||||||
|
mTargetA2dpState == BluetoothA2dp.STATE_PLAYING) {
|
||||||
|
mAudioManager.setParameters("A2dpSuspended=false");
|
||||||
|
} else {
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected synchronized void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
protected synchronized void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||||
if (mAudioDevices.isEmpty()) return;
|
if (mAudioDevices.isEmpty()) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user