diff options
author | Ajay Kumar <ajayku@codeaurora.org> | 2014-03-21 15:17:23 +0530 |
---|---|---|
committer | Linux Build Service Account <lnxbuild@localhost> | 2014-11-04 08:25:06 -0700 |
commit | e2eae48e90d44a919ff83c9336b5f39b77fa88a4 (patch) | |
tree | 075844a3c20e1bcf06108b4365c76c6388752715 | |
parent | dbfc61c66c1fe93db4490f83d106235209e6006a (diff) | |
download | android_packages_apps_Bluetooth-e2eae48e90d44a919ff83c9336b5f39b77fa88a4.tar.gz android_packages_apps_Bluetooth-e2eae48e90d44a919ff83c9336b5f39b77fa88a4.tar.bz2 android_packages_apps_Bluetooth-e2eae48e90d44a919ff83c9336b5f39b77fa88a4.zip |
Fix to avoid the case when interface is already enabled.
Added BT_STATUS_DONE check in JNI interface loading.
Change-id: Iccfbe510a91bd94de258bcbe61b4fd6fa9044441
CRs-Fixed: 636497
Bluetooth :Fix to avoid the access of JNI gloabal reference object
This is a conrner case where bindandfinish gets called anytime
where adapter state!= STOPPED and calls cleanupNative. Further
while cleanup at lower layer will try to access JNI reference
which is already deleted.
Change-id: I579bc4015b61ad653f18a5f4a3d26a2508236ff5
CRs-Fixed: 642466
Bluetooth: Adapterservice Cleanup and unbind
AdapterService cleanup and unbind happens only when the
BT state is off.
CRs-fixed: 556716,562137
Change-id: Ida3b3c12a97604919fbab6d7f4f34b9daa93d85a
Bluetooth: GAP: Transition to stable state based on device
This patch adds check in BluetoothBondStateMachine to transition to
stable state on reception of BOND_STATE_NONE only for device that
are in pairing state and not for all devices. Without this patch it
was observed that state was transitioning to stable state for all
devices resulting in discarding of BOND_STATE_NONE from device that
was actually in pairing mode resulting in UI stuck in pairing forever.
Change-id: Ia860d26a5f036c13d649434246ba6dea7b9807f2
CRs-Fixed: 584102
Bluetooth: GAP: Update bondstatemachine to handle pairing scenarios
This patch updates BluetoothBondStateMachine to properly handle concurrency
scenarios of pairing while pairing is ongoing with some remote device.
Without this patch it was observed that DUT was getting stuck in pairing
when unpairing was done for some paired devices and pairing timed out with
device for which pairing was being initiated.
Change-id: I07d2bc323aebbeada9c930eb36c9855da59dd677
CRs-Fixed: 586935
Bluetooth: Null check added before accessing the Adapter service
Change-id: I22acb495f8aa76683dae4bc68376443a67f45b0a
Null check is being added before accesing the Adapter service's
APIs like createBondNative, cancelBondNative.
CRs-Fixed: 552616
Change-Id: Ib9014f653e829a5e4518a558ff39d5e89dafa0f3
Conflicts:
src/com/android/bluetooth/btservice/BondStateMachine.java
Change-Id: I93c377d8a55b5a23ea9e12c453aaa145b2a71961
3 files changed, 31 insertions, 10 deletions
diff --git a/jni/com_android_bluetooth_btservice_AdapterService.cpp b/jni/com_android_bluetooth_btservice_AdapterService.cpp index dcfd0beb1..8508a6f29 100644 --- a/jni/com_android_bluetooth_btservice_AdapterService.cpp +++ b/jni/com_android_bluetooth_btservice_AdapterService.cpp @@ -54,7 +54,7 @@ static const btmce_interface_t *sBluetoothMceInterface = NULL; static JNIEnv *callbackEnv = NULL; static jobject sJniAdapterServiceObj; -static jobject sJniCallbacksObj; +static jobject sJniCallbacksObj = NULL; static jfieldID sJniCallbacksField; @@ -90,9 +90,11 @@ static void adapter_state_change_callback(bt_state_t status) { return; } ALOGV("%s: Status is: %d", __FUNCTION__, status); - - callbackEnv->CallVoidMethod(sJniCallbacksObj, method_stateChangeCallback, (jint)status); - + if(sJniCallbacksObj) { + callbackEnv->CallVoidMethod(sJniCallbacksObj, method_stateChangeCallback, (jint)status); + } else { + ALOGE("JNI ERROR : JNI reference already cleaned : adapter_state_change_callback", __FUNCTION__); + } checkAndClearExceptionFromCallback(callbackEnv, __FUNCTION__); } @@ -744,7 +746,7 @@ static bool initNative(JNIEnv* env, jobject obj) { if (sBluetoothInterface) { int ret = sBluetoothInterface->init(&sBluetoothCallbacks); - if (ret != BT_STATUS_SUCCESS) { + if (ret != BT_STATUS_SUCCESS && ret != BT_STATUS_DONE) { ALOGE("Error while setting the callbacks: %d\n", ret); sBluetoothInterface = NULL; return JNI_FALSE; @@ -788,6 +790,7 @@ static bool cleanupNative(JNIEnv *env, jobject obj) { env->DeleteGlobalRef(sJniCallbacksObj); env->DeleteGlobalRef(sJniAdapterServiceObj); + sJniCallbacksObj = NULL; return JNI_TRUE; } diff --git a/src/com/android/bluetooth/btservice/AdapterService.java b/src/com/android/bluetooth/btservice/AdapterService.java index 9ee0a2fdf..b699b7b91 100644 --- a/src/com/android/bluetooth/btservice/AdapterService.java +++ b/src/com/android/bluetooth/btservice/AdapterService.java @@ -352,9 +352,12 @@ public class AdapterService extends Service { return mBinder; } public boolean onUnbind(Intent intent) { - debugLog("onUnbind() - calling cleanup"); - cleanup(); - return super.onUnbind(intent); + if (getState() == BluetoothAdapter.STATE_OFF) { + if (DBG) debugLog("onUnbind, calling cleanup"); + cleanup(); + return super.onUnbind(intent); + } + return false; } public void onDestroy() { diff --git a/src/com/android/bluetooth/btservice/BondStateMachine.java b/src/com/android/bluetooth/btservice/BondStateMachine.java index e4d23497b..58635e917 100644 --- a/src/com/android/bluetooth/btservice/BondStateMachine.java +++ b/src/com/android/bluetooth/btservice/BondStateMachine.java @@ -66,6 +66,9 @@ final class BondStateMachine extends StateMachine { private PendingCommandState mPendingCommandState = new PendingCommandState(); private StableState mStableState = new StableState(); + private final ArrayList<BluetoothDevice> mDevices = + new ArrayList<BluetoothDevice>(); + private BondStateMachine(AdapterService service, AdapterProperties prop, RemoteDevices remoteDevices) { super("BondStateMachine:"); @@ -120,6 +123,9 @@ final class BondStateMachine extends StateMachine { /* if incoming pairing, transition to pending state */ if (newState == BluetoothDevice.BOND_BONDING) { + if(!mDevices.contains(dev)) { + mDevices.add(dev); + } sendIntent(dev, newState, 0); transitionTo(mPendingCommandState); } @@ -140,8 +146,6 @@ final class BondStateMachine extends StateMachine { private class PendingCommandState extends State { - private final ArrayList<BluetoothDevice> mDevices = - new ArrayList<BluetoothDevice>(); @Override public void enter() { @@ -180,6 +184,14 @@ final class BondStateMachine extends StateMachine { sendIntent(dev, newState, reason); if(newState != BluetoothDevice.BOND_BONDING ) { + // check if bond none is received from device which + // was in pairing state otherwise don't transition to + // stable state. + if (newState == BluetoothDevice.BOND_NONE && + !mDevices.contains(dev) && mDevices.size() != 0) { + infoLog("not transitioning to stable state"); + break; + } /* this is either none/bonded, remove and transition */ result = !mDevices.remove(dev); if (mDevices.isEmpty()) { @@ -250,6 +262,7 @@ final class BondStateMachine extends StateMachine { } private boolean cancelBond(BluetoothDevice dev) { + if(mAdapterService == null) return false; if (dev.getBondState() == BluetoothDevice.BOND_BONDING) { byte[] addr = Utils.getBytesFromAddress(dev.getAddress()); if (!mAdapterService.cancelBondNative(addr)) { @@ -262,6 +275,7 @@ final class BondStateMachine extends StateMachine { } private boolean removeBond(BluetoothDevice dev, boolean transition) { + if(mAdapterService == null) return false; if (dev.getBondState() == BluetoothDevice.BOND_BONDED) { byte[] addr = Utils.getBytesFromAddress(dev.getAddress()); if (!mAdapterService.removeBondNative(addr)) { @@ -276,6 +290,7 @@ final class BondStateMachine extends StateMachine { } private boolean createBond(BluetoothDevice dev, int transport, boolean transition) { + if(mAdapterService == null) return false; if (dev.getBondState() == BluetoothDevice.BOND_NONE) { infoLog("Bond address is:" + dev); byte[] addr = Utils.getBytesFromAddress(dev.getAddress()); |