summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/java/android/bluetooth/BluetoothAdapter.java4
-rw-r--r--core/java/android/bluetooth/BluetoothDevice.java6
-rw-r--r--core/java/android/net/MobileDataStateTracker.java3
-rw-r--r--core/java/android/server/BluetoothA2dpService.java56
-rw-r--r--core/java/android/server/BluetoothService.java9
5 files changed, 69 insertions, 9 deletions
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java
index cc35b7d..ff48583 100644
--- a/core/java/android/bluetooth/BluetoothAdapter.java
+++ b/core/java/android/bluetooth/BluetoothAdapter.java
@@ -46,7 +46,7 @@ import java.util.UUID;
*/
public final class BluetoothAdapter {
private static final String TAG = "BluetoothAdapter";
- private static final boolean DBG = true; //STOPSHIP: Remove excess logging
+ private static final boolean DBG = false;
/**
* Sentinel error value for this class. Guaranteed to not equal any other
@@ -569,6 +569,7 @@ public final class BluetoothAdapter {
* <p>Applications can also register for {@link #ACTION_DISCOVERY_STARTED}
* or {@link #ACTION_DISCOVERY_FINISHED} to be notified when discovery
* starts or completes.
+ * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
*
* @return true if discovering
*/
@@ -582,6 +583,7 @@ public final class BluetoothAdapter {
/**
* Return the set of {@link BluetoothDevice} objects that are bonded
* (paired) to the local adapter.
+ * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
*
* @return unmodifiable set of {@link BluetoothDevice}, or null on error
*/
diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java
index 39a74ac..849e6c7 100644
--- a/core/java/android/bluetooth/BluetoothDevice.java
+++ b/core/java/android/bluetooth/BluetoothDevice.java
@@ -513,6 +513,7 @@ public final class BluetoothDevice implements Parcelable {
/**
* Get trust state of a remote device.
+ * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
* @hide
*/
public boolean getTrustState() {
@@ -526,6 +527,7 @@ public final class BluetoothDevice implements Parcelable {
/**
* Set trust state for a remote device.
+ * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
* @param value the trust state value (true or false)
* @hide
*/
@@ -657,6 +659,8 @@ public final class BluetoothDevice implements Parcelable {
* Call #connect on the returned #BluetoothSocket to begin the connection.
* The remote device will not be authenticated and communication on this
* socket will not be encrypted.
+ * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
+ *
* @param port remote port
* @return An RFCOMM BluetoothSocket
* @throws IOException On error, for example Bluetooth not available, or
@@ -671,6 +675,8 @@ public final class BluetoothDevice implements Parcelable {
/**
* Construct a SCO socket ready to start an outgoing connection.
* Call #connect on the returned #BluetoothSocket to begin the connection.
+ * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
+ *
* @return a SCO BluetoothSocket
* @throws IOException on error, for example Bluetooth not available, or
* insufficient permissions.
diff --git a/core/java/android/net/MobileDataStateTracker.java b/core/java/android/net/MobileDataStateTracker.java
index e5e6db9..538e51a 100644
--- a/core/java/android/net/MobileDataStateTracker.java
+++ b/core/java/android/net/MobileDataStateTracker.java
@@ -48,6 +48,7 @@ public class MobileDataStateTracker extends NetworkStateTracker {
private ITelephony mPhoneService;
private String mApnType;
+ private String mApnName;
private boolean mEnabled;
private BroadcastReceiver mStateReceiver;
@@ -139,6 +140,7 @@ public class MobileDataStateTracker extends NetworkStateTracker {
String reason = intent.getStringExtra(Phone.STATE_CHANGE_REASON_KEY);
String apnName = intent.getStringExtra(Phone.DATA_APN_KEY);
String apnTypeList = intent.getStringExtra(Phone.DATA_APN_TYPES_KEY);
+ mApnName = apnName;
boolean unavailable = intent.getBooleanExtra(Phone.NETWORK_UNAVAILABLE_KEY,
false);
@@ -339,6 +341,7 @@ public class MobileDataStateTracker extends NetworkStateTracker {
intent.putExtra(Phone.STATE_KEY, Phone.DataState.CONNECTED.toString());
intent.putExtra(Phone.STATE_CHANGE_REASON_KEY, Phone.REASON_APN_CHANGED);
intent.putExtra(Phone.DATA_APN_TYPES_KEY, mApnType);
+ intent.putExtra(Phone.DATA_APN_KEY, mApnName);
intent.putExtra(Phone.DATA_IFACE_NAME_KEY, mInterfaceName);
intent.putExtra(Phone.NETWORK_UNAVAILABLE_KEY, false);
if (mStateReceiver != null) mStateReceiver.onReceive(mContext, intent);
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;
}