summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinux Build Service Account <lnxbuild@localhost>2014-03-19 02:58:09 -0600
committerLinux Build Service Account <lnxbuild@localhost>2014-03-19 02:58:09 -0600
commit933fef161e095a318e94e21b66ddeaa74921f705 (patch)
tree8eb1ad27cf78fe199203756e66064da2c158af15
parent4940e6a5b51f4230418a8b049dbe59638f094ff4 (diff)
parentbf25235573c5da7c7d43f7ebb10e875fb509fdeb (diff)
downloadandroid_packages_apps_Bluetooth-933fef161e095a318e94e21b66ddeaa74921f705.tar.gz
android_packages_apps_Bluetooth-933fef161e095a318e94e21b66ddeaa74921f705.tar.bz2
android_packages_apps_Bluetooth-933fef161e095a318e94e21b66ddeaa74921f705.zip
Merge bf25235573c5da7c7d43f7ebb10e875fb509fdeb on remote branch
Change-Id: I091020a62d838bfe7f75cc40410213eca4cc7859
-rw-r--r--jni/com_android_bluetooth_a2dp.cpp6
-rw-r--r--src/com/android/bluetooth/a2dp/A2dpService.java22
-rw-r--r--src/com/android/bluetooth/a2dp/A2dpStateMachine.java49
-rw-r--r--src/com/android/bluetooth/btservice/AdapterService.java1
4 files changed, 65 insertions, 13 deletions
diff --git a/jni/com_android_bluetooth_a2dp.cpp b/jni/com_android_bluetooth_a2dp.cpp
index 76f90d6a4..babdf9864 100644
--- a/jni/com_android_bluetooth_a2dp.cpp
+++ b/jni/com_android_bluetooth_a2dp.cpp
@@ -305,7 +305,7 @@ static void informAudioFocusStateNative(JNIEnv *env, jobject object, int state)
}
-static jboolean isSrcNative(JNIEnv *env, jobject object, jbyteArray address) {
+static jint isSrcNative(JNIEnv *env, jobject object, jbyteArray address) {
jbyte *addr;
bt_status_t status;
@@ -321,7 +321,7 @@ static jboolean isSrcNative(JNIEnv *env, jobject object, jbyteArray address) {
ALOGE("Failed HF disconnection, status: %d", status);
}
env->ReleaseByteArrayElements(address, addr, 0);
- return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
+ return status;
}
static void suspendA2dpNative(JNIEnv *env, jobject object) {
@@ -352,7 +352,7 @@ static JNINativeMethod sMethods[] = {
{"connectA2dpNative", "([B)Z", (void *) connectA2dpNative},
{"disconnectA2dpNative", "([B)Z", (void *) disconnectA2dpNative},
{"allowConnectionNative", "(I)V", (void *) allowConnectionNative},
- {"isSrcNative", "([B)Z", (void *) isSrcNative},
+ {"isSrcNative", "([B)I", (void *) isSrcNative},
{"suspendA2dpNative", "()V", (void *) suspendA2dpNative},
{"resumeA2dpNative", "()V", (void *) resumeA2dpNative},
{"informAudioFocusStateNative", "(I)V", (void *) informAudioFocusStateNative},
diff --git a/src/com/android/bluetooth/a2dp/A2dpService.java b/src/com/android/bluetooth/a2dp/A2dpService.java
index 902b6849c..22c6081b9 100644
--- a/src/com/android/bluetooth/a2dp/A2dpService.java
+++ b/src/com/android/bluetooth/a2dp/A2dpService.java
@@ -201,6 +201,28 @@ public class A2dpService extends ProfileService {
return priority;
}
+ public boolean setLastConnectedA2dpSepType(BluetoothDevice device, int sepType) {
+ enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
+ "Need BLUETOOTH_ADMIN permission");
+
+ Log.d(TAG,"setLastConnectedA2dpSepType: " + sepType);
+
+ Settings.Global.putInt(getContentResolver(),
+ Settings.Global.getBluetoothLastConnectedA2dpSepTypeKey(device.getAddress()),
+ sepType);
+ return true;
+ }
+
+ public int getLastConnectedA2dpSepType(BluetoothDevice device) {
+ enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
+ "Need BLUETOOTH_ADMIN permission");
+ int sepType = Settings.Global.getInt(getContentResolver(),
+ Settings.Global.getBluetoothLastConnectedA2dpSepTypeKey(device.getAddress()),
+ BluetoothProfile.PROFILE_A2DP_UNDEFINED);
+ return sepType;
+ }
+
+
/* Absolute volume implementation */
public boolean isAvrcpAbsoluteVolumeSupported() {
return mAvrcp.isAbsoluteVolumeSupported();
diff --git a/src/com/android/bluetooth/a2dp/A2dpStateMachine.java b/src/com/android/bluetooth/a2dp/A2dpStateMachine.java
index 642a0a228..fc1f3ec02 100644
--- a/src/com/android/bluetooth/a2dp/A2dpStateMachine.java
+++ b/src/com/android/bluetooth/a2dp/A2dpStateMachine.java
@@ -52,6 +52,7 @@ import android.os.ParcelUuid;
import android.util.Log;
import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.AdapterService;
+import com.android.bluetooth.btservice.AbstractionLayer;
import com.android.bluetooth.btservice.ProfileService;
import com.android.internal.util.IState;
import com.android.internal.util.State;
@@ -560,6 +561,11 @@ final class A2dpStateMachine extends StateMachine {
BluetoothProfile.STATE_DISCONNECTING);
break;
}
+ if (mPlayingA2dpDevice != null) {
+ broadcastAudioState(mPlayingA2dpDevice, BluetoothA2dp.STATE_NOT_PLAYING,
+ BluetoothA2dp.STATE_PLAYING);
+ mPlayingA2dpDevice = null;
+ }
transitionTo(mPending);
}
break;
@@ -609,7 +615,8 @@ final class A2dpStateMachine extends StateMachine {
loge("Disconnected from unknown device: " + device);
}
- if (isSrcNative(getByteAddress(device))) {
+ if (isSrcNative(getByteAddress(device))
+ == AbstractionLayer.BT_STATUS_SUCCESS) {
// in case PEER DEVICE is A2DP SRC we need to manager audio focus
int status = mAudioManager.abandonAudioFocus(mAudioFocusListener);
log("Status loss returned " + status);
@@ -625,7 +632,8 @@ final class A2dpStateMachine extends StateMachine {
private void processAudioFocusRequestEvent(int enable, BluetoothDevice device) {
if (mPlayingA2dpDevice != null) {
- if ((isSrcNative(getByteAddress(device))) && (enable == 1)){
+ if ((isSrcNative(getByteAddress(device))
+ == AbstractionLayer.BT_STATUS_SUCCESS) && (enable == 1)){
// in case PEER DEVICE is A2DP SRC we need to manager audio focus
int status = mAudioManager.requestAudioFocus(mAudioFocusListener,
AudioManager.STREAM_MUSIC,AudioManager.AUDIOFOCUS_GAIN);
@@ -667,9 +675,14 @@ final class A2dpStateMachine extends StateMachine {
}
}
+ // true if peer device is source
boolean isConnectedSrc(BluetoothDevice device)
{
- return isSrcNative(getByteAddress(device));
+ if (isSrcNative(getByteAddress(device))
+ == AbstractionLayer.BT_STATUS_SUCCESS)
+ return true;
+ else
+ return false;
}
int getConnectionState(BluetoothDevice device) {
@@ -768,17 +781,31 @@ final class A2dpStateMachine extends StateMachine {
// This method does not check for error conditon (newState == prevState)
private void broadcastConnectionState(BluetoothDevice device, int newState, int prevState) {
- int delay;
- // in case PEER DEVICE is A2DP SRC we don't need to tell AUDIO
- if (!isSrcNative(getByteAddress(device))) {
+ int delay = 0;
+ // in case PEER DEVICE is A2DP SNK we need to tell AUDIO
+ if (isSrcNative(getByteAddress(device))
+ == AbstractionLayer.BT_STATUS_FAIL) {
+ // do not update delay for disconecting as by time disconnect comes
+ // Sep end point is cleared
delay = mAudioManager.setBluetoothA2dpDeviceConnectionState(device, newState);
+ if (newState == BluetoothProfile.STATE_DISCONNECTING)
+ delay = 0;
log("Peer Device is SNK");
+ if (newState == BluetoothProfile.STATE_CONNECTED) {
+ mService.setLastConnectedA2dpSepType (device,
+ BluetoothProfile.PROFILE_A2DP_SNK);
+ }
}
else {
- delay = 0;
log("Peer Device is SRC");
+ if (newState == BluetoothProfile.STATE_CONNECTED) {
+ mService.setLastConnectedA2dpSepType (device,
+ BluetoothProfile.PROFILE_A2DP_SRC);
+ }
+ log("Peer Device is SRC/Not ready yet");
}
mWakeLock.acquire();
+ log("delay is " + delay + "for device " + device);
mIntentBroadcastHandler.sendMessageDelayed(mIntentBroadcastHandler.obtainMessage(
MSG_CONNECTION_STATE_CHANGED,
prevState,
@@ -888,7 +915,8 @@ final class A2dpStateMachine extends StateMachine {
log("Command Received " + cmd);
if (cmd.equals("pause")) {
if (mCurrentDevice != null) {
- if (isSrcNative(getByteAddress(mCurrentDevice))) {
+ if (isSrcNative(getByteAddress(mCurrentDevice))
+ == AbstractionLayer.BT_STATUS_SUCCESS) {
//Camera Pauses the Playback before starting the Video recording
//But it doesn't start the playback once recording is completed.
//Disconnecting the A2dp to move the A2dpSink to proper state.
@@ -912,7 +940,8 @@ final class A2dpStateMachine extends StateMachine {
switch(focusChange){
case AudioManager.AUDIOFOCUS_LOSS:
if (mCurrentDevice != null) {
- if (isSrcNative(getByteAddress(mCurrentDevice))) {
+ if (isSrcNative(getByteAddress(mCurrentDevice))
+ == AbstractionLayer.BT_STATUS_SUCCESS) {
// in case of perm loss, disconnect the link
disconnectA2dpNative(getByteAddress(mCurrentDevice));
// in case PEER DEVICE is A2DP SRC we need to manage audio focus
@@ -973,7 +1002,7 @@ final class A2dpStateMachine extends StateMachine {
private native boolean connectA2dpNative(byte[] address);
private native boolean disconnectA2dpNative(byte[] address);
private native void allowConnectionNative(int isValid);
- private native boolean isSrcNative(byte[] address);
+ private native int isSrcNative(byte[] address);
private native void suspendA2dpNative();
private native void resumeA2dpNative();
private native void informAudioFocusStateNative(int state);
diff --git a/src/com/android/bluetooth/btservice/AdapterService.java b/src/com/android/bluetooth/btservice/AdapterService.java
index 88066c5e8..a62a20729 100644
--- a/src/com/android/bluetooth/btservice/AdapterService.java
+++ b/src/com/android/bluetooth/btservice/AdapterService.java
@@ -1279,6 +1279,7 @@ public class AdapterService extends Service {
}
else if((a2dpConnDevList.isEmpty()) &&
(a2dpService.getPriority(device) >= BluetoothProfile.PRIORITY_ON) &&
+ (a2dpService.getLastConnectedA2dpSepType(device) == BluetoothProfile.PROFILE_A2DP_SNK)&&
(hsConnected || (hsService.getPriority(device) == BluetoothProfile.PRIORITY_OFF))) {
a2dpService.connect(device);
}