diff options
Diffstat (limited to 'core/java/android/server')
-rw-r--r-- | core/java/android/server/BluetoothA2dpService.java | 56 | ||||
-rw-r--r-- | core/java/android/server/BluetoothService.java | 9 |
2 files changed, 57 insertions, 8 deletions
diff --git a/core/java/android/server/BluetoothA2dpService.java b/core/java/android/server/BluetoothA2dpService.java index b73e53f..9a2d6d9 100644 --- a/core/java/android/server/BluetoothA2dpService.java +++ b/core/java/android/server/BluetoothA2dpService.java @@ -72,6 +72,8 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { private final AudioManager mAudioManager; private final BluetoothService mBluetoothService; private final BluetoothAdapter mAdapter; + private boolean mSuspending; + private boolean mResuming; private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override @@ -149,6 +151,8 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { if (mBluetoothService.isEnabled()) onBluetoothEnable(); + mSuspending = false; + mResuming = false; } @Override @@ -241,6 +245,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { } } mAudioManager.setParameters(BLUETOOTH_ENABLED+"=true"); + mAudioManager.setParameters("A2dpSuspended=false"); } private synchronized void onBluetoothDisable() { @@ -336,7 +341,10 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { public synchronized boolean suspendSink(BluetoothDevice device) { mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission"); - if (DBG) log("suspendSink(" + device + ")"); + if (DBG) log("suspendSink(" + device + "), mSuspending: "+mSuspending+", mResuming: "+mResuming); + if (mSuspending) { + return true; + } if (device == null || mAudioDevices == null) { return false; } @@ -347,9 +355,14 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { } switch (state.intValue()) { case BluetoothA2dp.STATE_CONNECTED: + if (mResuming) { + mSuspending = true; + } return true; case BluetoothA2dp.STATE_PLAYING: - return suspendSinkNative(path); + mAudioManager.setParameters("A2dpSuspended=true"); + mSuspending = suspendSinkNative(path); + return mSuspending; default: return false; } @@ -358,7 +371,10 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { public synchronized boolean resumeSink(BluetoothDevice device) { mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission"); - if (DBG) log("resumeSink(" + device + ")"); + if (DBG) log("resumeSink(" + device + "), mResuming: "+mResuming+", mSuspending: "+mSuspending); + if (mResuming) { + return true; + } if (device == null || mAudioDevices == null) { return false; } @@ -369,9 +385,14 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { } switch (state.intValue()) { case BluetoothA2dp.STATE_PLAYING: + if (mSuspending) { + mResuming = true; + } return true; case BluetoothA2dp.STATE_CONNECTED: - return resumeSinkNative(path); + mResuming = resumeSinkNative(path); + mAudioManager.setParameters("A2dpSuspended=false"); + return mResuming; default: return false; } @@ -437,6 +458,10 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { } private void handleSinkStateChange(BluetoothDevice device, int prevState, int state) { + if (state == BluetoothA2dp.STATE_DISCONNECTED) { + mSuspending = false; + mResuming = false; + } if (state != prevState) { if (state == BluetoothA2dp.STATE_DISCONNECTED || state == BluetoothA2dp.STATE_DISCONNECTING) { @@ -452,6 +477,29 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { } mAudioDevices.put(device, state); + if (state == BluetoothA2dp.STATE_CONNECTED && prevState == BluetoothA2dp.STATE_PLAYING) { + if (DBG) log("handleSinkStateChange() STATE_PLAYING -> STATE_CONNECTED: mSuspending: " + +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) { + mResuming = false; + if (mSuspending) { + mSuspending = false; + suspendSink(device); + } + } + } Intent intent = new Intent(BluetoothA2dp.ACTION_SINK_STATE_CHANGED); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.putExtra(BluetoothA2dp.EXTRA_PREVIOUS_SINK_STATE, prevState); diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java index 7ebd91d..5c8c7cc 100644 --- a/core/java/android/server/BluetoothService.java +++ b/core/java/android/server/BluetoothService.java @@ -61,7 +61,7 @@ import java.util.Map; public class BluetoothService extends IBluetooth.Stub { private static final String TAG = "BluetoothService"; - private static final boolean DBG = true; + private static final boolean DBG = false; private int mNativeData; private BluetoothEventLoop mEventLoop; @@ -191,10 +191,10 @@ public class BluetoothService extends IBluetooth.Stub { /** * Bring down bluetooth. Returns true on success. * - * @param saveSetting If true, disable BT in settings + * @param saveSetting If true, persist the new setting */ public synchronized boolean disable(boolean saveSetting) { - mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); + mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission"); switch (mBluetoothState) { case BluetoothAdapter.STATE_OFF: @@ -1013,7 +1013,8 @@ public class BluetoothService extends IBluetooth.Stub { */ public synchronized boolean setTrust(String address, boolean value) { if (!BluetoothAdapter.checkBluetoothAddress(address)) { - mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); + mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, + "Need BLUETOOTH_ADMIN permission"); return false; } |