diff options
author | Steve Kondik <steve@cyngn.com> | 2016-01-08 21:08:12 -0800 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2016-01-08 21:08:12 -0800 |
commit | b9398e5a366d0663d4a92e1642948d1f69c81913 (patch) | |
tree | ca48cfabd4b75c3097d0a53125464e1fc8ecbefb | |
parent | 63088a98979893cb282576db14cd48a503fe1ffc (diff) | |
parent | aefbc8ce31a4da1dd6b0ebcd322ddcdf031093e6 (diff) | |
download | android_packages_apps_Bluetooth-b9398e5a366d0663d4a92e1642948d1f69c81913.tar.gz android_packages_apps_Bluetooth-b9398e5a366d0663d4a92e1642948d1f69c81913.tar.bz2 android_packages_apps_Bluetooth-b9398e5a366d0663d4a92e1642948d1f69c81913.zip |
Merge branch 'LA.BF.1.1.3_rb1.7' of git://codeaurora.org/platform/packages/apps/Bluetooth into cm-13.0
Change-Id: I33c3d3cc73cdbae8f971d727565da1dad12fe94f
14 files changed, 85 insertions, 46 deletions
diff --git a/jni/com_android_bluetooth_a2dp.cpp b/jni/com_android_bluetooth_a2dp.cpp index 13f889464..df8fe9837 100644 --- a/jni/com_android_bluetooth_a2dp.cpp +++ b/jni/com_android_bluetooth_a2dp.cpp @@ -58,10 +58,15 @@ static void bta2dp_connection_state_callback(btav_connection_state_t state, bt_b ALOGI("%s", __FUNCTION__); + if (mCallbacksObj == NULL) { + ALOGE("Callbacks Obj is no more valid: '%s", __FUNCTION__); + return; + } if (!checkCallbackThread()) { \ ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__); \ return; \ } + addr = sCallbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); if (!addr) { ALOGE("Fail to new jbyteArray bd addr for connection state"); @@ -81,6 +86,10 @@ static void bta2dp_audio_state_callback(btav_audio_state_t state, bt_bdaddr_t* b ALOGI("%s", __FUNCTION__); + if (mCallbacksObj == NULL) { + ALOGE("Callbacks Obj is no more valid: '%s", __FUNCTION__); + return; + } if (!checkCallbackThread()) { \ ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__); \ return; \ @@ -104,6 +113,10 @@ static void bta2dp_connection_priority_callback(bt_bdaddr_t* bd_addr) { ALOGI("%s", __FUNCTION__); + if (mCallbacksObj == NULL) { + ALOGE("Callbacks Obj is no more valid: '%s", __FUNCTION__); + return; + } if (!checkCallbackThread()) { \ ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__); \ return; \ @@ -125,6 +138,10 @@ static void bta2dp_multicast_enabled_callback(int state) { ALOGI("%s", __FUNCTION__); + if (mCallbacksObj == NULL) { + ALOGE("Callbacks Obj is no more valid: '%s", __FUNCTION__); + return; + } if (!checkCallbackThread()) { \ ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__); \ return; \ @@ -213,14 +230,20 @@ static void initNative(JNIEnv *env, jobject object, jint maxA2dpConnections, return; } + mCallbacksObj = env->NewGlobalRef(object); + if ( (status = sBluetoothA2dpInterface->init(&sBluetoothA2dpCallbacks, maxA2dpConnections, multiCastState)) != BT_STATUS_SUCCESS) { ALOGE("Failed to initialize Bluetooth A2DP, status: %d", status); sBluetoothA2dpInterface = NULL; + if (mCallbacksObj != NULL) { + ALOGW("Clean up A2DP callback object"); + env->DeleteGlobalRef(mCallbacksObj); + mCallbacksObj = NULL; + } return; } - mCallbacksObj = env->NewGlobalRef(object); } static void cleanupNative(JNIEnv *env, jobject object) { diff --git a/src/com/android/bluetooth/a2dp/A2dpSinkStateMachine.java b/src/com/android/bluetooth/a2dp/A2dpSinkStateMachine.java index 321713e3c..2aa61a301 100644 --- a/src/com/android/bluetooth/a2dp/A2dpSinkStateMachine.java +++ b/src/com/android/bluetooth/a2dp/A2dpSinkStateMachine.java @@ -1103,9 +1103,6 @@ final class A2dpSinkStateMachine extends StateMachine { AvrcpControllerService avrcpCtrlService = AvrcpControllerService.getAvrcpControllerService(); if ((avrcpCtrlService != null) && (mDevice != null) && (avrcpCtrlService.getConnectedDevices().contains(mDevice))){ - if (mPlayingDevice == null){ - return true; // don't send Pause if we are not playing already. - } avrcpCtrlService.sendPassThroughCmd(mDevice, AVRC_ID_PAUSE, KEY_STATE_PRESSED); avrcpCtrlService.sendPassThroughCmd(mDevice, AVRC_ID_PAUSE, KEY_STATE_RELEASED); log(" SendPassThruPause command sent - "); diff --git a/src/com/android/bluetooth/avrcp/Avrcp.java b/src/com/android/bluetooth/avrcp/Avrcp.java index c7272cb0b..2195559c0 100644 --- a/src/com/android/bluetooth/avrcp/Avrcp.java +++ b/src/com/android/bluetooth/avrcp/Avrcp.java @@ -2418,28 +2418,33 @@ public final class Avrcp { case FOLDER_DOWN: if (deviceFeatures[deviceIndex].mCurrentPathUid == null) { Cursor cursor = null; + String[] playlistMemberCols = new String[] { + MediaStore.Audio.Playlists.Members._ID, + MediaStore.Audio.Media.TITLE, + MediaStore.Audio.Media.DATA, + MediaStore.Audio.Media.ALBUM, + MediaStore.Audio.Media.ARTIST, + MediaStore.Audio.Media.DURATION, + MediaStore.Audio.Playlists.Members.PLAY_ORDER, + MediaStore.Audio.Playlists.Members.AUDIO_ID, + MediaStore.Audio.Media.IS_MUSIC + }; try { - String[] cols = new String[] { - MediaStore.Audio.Playlists._ID, - MediaStore.Audio.Playlists.NAME - }; - + Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", + folderUid); StringBuilder where = new StringBuilder(); - where.append(MediaStore.Audio.Playlists.NAME + " != ''"); - - cursor = mContext.getContentResolver().query( - MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, - cols, MediaStore.Audio.Playlists._ID + "=" + folderUid, - null, null); - - if ((cursor == null) || (cursor.getCount() == 0)) { - status = DOES_NOT_EXIST; - } else{ - numberOfItems = cursor.getCount(); + where.append(MediaStore.Audio.Media.TITLE + " != ''"); + cursor = mContext.getContentResolver().query(uri, playlistMemberCols, + where.toString(), null, + MediaStore.Audio.Playlists.Members.DEFAULT_SORT_ORDER); + if (cursor != null) { + numberOfItems = cursor.getCount(); deviceFeatures[deviceIndex].mCurrentPathUid = String.valueOf(folderUid); deviceFeatures[deviceIndex].mCurrentPath = PATH_PLAYLISTS; + } else { + status = DOES_NOT_EXIST; } } catch (Exception e) { Log.e(TAG, "Exception " + e); diff --git a/src/com/android/bluetooth/avrcp/AvrcpControllerService.java b/src/com/android/bluetooth/avrcp/AvrcpControllerService.java index 90245e058..bab1cf277 100644 --- a/src/com/android/bluetooth/avrcp/AvrcpControllerService.java +++ b/src/com/android/bluetooth/avrcp/AvrcpControllerService.java @@ -308,7 +308,8 @@ public class AvrcpControllerService extends ProfileService { public String toString() { return "Metadata [artist=" + artist + " trackTitle= " + trackTitle + " albumTitle= " + albumTitle + " genre= " +genre+" trackNum= "+Long.toString(trackNum) + " cur_time: "+ - Long.toString(playTime) + " total_time = "+ Long.toString(totalTrackLen) + "]"; + Long.toString(playTime) + " total_time = "+ Long.toString(totalTrackLen) + + "playStatus=" + playStatus + "]"; } }; diff --git a/src/com/android/bluetooth/btservice/AdapterService.java b/src/com/android/bluetooth/btservice/AdapterService.java index 57c724dda..8eb6d8e23 100644 --- a/src/com/android/bluetooth/btservice/AdapterService.java +++ b/src/com/android/bluetooth/btservice/AdapterService.java @@ -1804,6 +1804,7 @@ public class AdapterService extends Service { // check for MTP now if((hfConnDevList.isEmpty() || !(hfConnDevList.contains(device))) && + (hsService != null) && (hsService.getPriority(device) >= BluetoothProfile.PRIORITY_ON) && (a2dpConnected || (a2dpService.getPriority(device) == BluetoothProfile.PRIORITY_OFF))) { int maxHfpConnectionSysProp = @@ -1824,6 +1825,7 @@ public class AdapterService extends Service { } } else if((a2dpConnDevList.isEmpty() || !(a2dpConnDevList.contains(device))) && + (a2dpService != null) && (a2dpService.getPriority(device) >= BluetoothProfile.PRIORITY_ON) && (hsConnected || (hsService.getPriority(device) == BluetoothProfile.PRIORITY_OFF))) { int maxA2dpConnectionSysProp = diff --git a/src/com/android/bluetooth/btservice/AdapterState.java b/src/com/android/bluetooth/btservice/AdapterState.java index b2d96899f..54ecbe2c7 100644 --- a/src/com/android/bluetooth/btservice/AdapterState.java +++ b/src/com/android/bluetooth/btservice/AdapterState.java @@ -453,6 +453,8 @@ final class AdapterState extends StateMachine { mPendingCommandState.setTurningOff(false); transitionTo(mBleOnState); notifyAdapterStateChange(BluetoothAdapter.STATE_BLE_ON); + errorLog("BREDR_STOP_TIMEOUT:Killing the process to force a restart as part cleanup"); + android.os.Process.killProcess(android.os.Process.myPid()); break; case BLE_STOP_TIMEOUT: diff --git a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java index e315a725c..a163dc055 100644 --- a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java +++ b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java @@ -830,6 +830,11 @@ final class HeadsetStateMachine extends StateMachine { private class Connected extends State { @Override public void enter() { + // Remove pending connection attempts that were deferred during the pending + // state. This is to prevent auto connect attempts from disconnecting + // devices that previously successfully connected. + // TODO: This needs to check for multiple HFP connections, once supported... + removeDeferredMessages(CONNECT); Log.d(TAG, "Enter Connected: " + getCurrentMessage().what + ", size: " + mConnectedDevicesList.size()); // start phone state listener here so that the CIND response as part of SLC can be @@ -3114,6 +3119,11 @@ final class HeadsetStateMachine extends StateMachine { } atResponseCodeNative(HeadsetHalConstants.AT_RESPONSE_OK, 0, getByteAddress(device)); + removeMessages(DIALING_OUT_TIMEOUT); + } else if (callState.mCallState == + HeadsetHalConstants.CALL_STATE_ACTIVE || callState.mCallState + == HeadsetHalConstants.CALL_STATE_IDLE) { + mDialingOut = false; } /* Set ActiveScoDevice to null when call ends */ diff --git a/src/com/android/bluetooth/opp/BluetoothOppL2capListener.java b/src/com/android/bluetooth/opp/BluetoothOppL2capListener.java index 8356dc3db..855851272 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppL2capListener.java +++ b/src/com/android/bluetooth/opp/BluetoothOppL2capListener.java @@ -138,7 +138,10 @@ public class BluetoothOppL2capListener { Log.e(TAG, "Error accept connection " + e); try { Thread.sleep(500); - } catch (InterruptedException ie) {} + } catch (InterruptedException ie) { + Log.e(TAG, "mSocketAcceptThread was interrupted " + ie); + mInterrupted = true; + } } } Log.i(TAG, "BluetoothSocket listen thread finished"); @@ -180,17 +183,12 @@ public class BluetoothOppL2capListener { } } } - try { + if (mSocketAcceptThread != null) { + if (V) Log.v(TAG, "Interrupting mSocketAcceptThread :" + mSocketAcceptThread); mSocketAcceptThread.interrupt(); - if (V) Log.v(TAG, "waiting for thread to terminate"); - //mSocketAcceptThread.join(JOIN_TIMEOUT_MS); - mSocketAcceptThread.join(); - if (V) Log.v(TAG, "done waiting for thread to terminate"); - mSocketAcceptThread = null; - mCallback = null; - } catch (InterruptedException e) { - if (V) Log.v(TAG, "Interrupted waiting for Accept Thread to join"); } + mSocketAcceptThread = null; + mCallback = null; } } diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java index 37aeeb1f0..d3b0c28de 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java +++ b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java @@ -149,7 +149,6 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { updateValues.put(BluetoothShare.CURRENT_BYTES, position); mContext1.getContentResolver().update(contentUri, updateValues, null, null); - try { Thread.sleep(sSleepTime); } catch (InterruptedException e1) { @@ -521,7 +520,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { if (uiUpdateThread == null) { uiUpdateThread = new ContentResolverUpdateThread (mContext1, - contentUri); + contentUri); if (V) Log.v(TAG, "Worker for Updation : Created"); uiUpdateThread.start ( ); } diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java index ac555b8cc..39355eb40 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java +++ b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java @@ -178,6 +178,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen private Uri contentUri; private Context mContext1; private volatile boolean interrupted = false; + public ContentResolverUpdateThread(Context context, Uri cntUri) { super("BtOpp Server ContentResolverUpdateThread"); mContext1 = context; diff --git a/src/com/android/bluetooth/opp/BluetoothOppReceiver.java b/src/com/android/bluetooth/opp/BluetoothOppReceiver.java index a6770aba7..1479646eb 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppReceiver.java +++ b/src/com/android/bluetooth/opp/BluetoothOppReceiver.java @@ -63,10 +63,12 @@ public class BluetoothOppReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); - if (!Utils.checkCaller()) { + /* Ignore if Broadcast action is not transfer complete and Invalid user */ + if (!Utils.checkCaller() && !action.equals(BluetoothShare.TRANSFER_COMPLETED_ACTION)) { Log.w(TAG, action + " received for non-active user, ignoring!!"); return; } + if (V) Log.v(TAG, action + " Intent received for active user"); if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { if (BluetoothAdapter.STATE_ON == intent.getIntExtra( diff --git a/src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java b/src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java index 941878a85..5f7434d0c 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java +++ b/src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java @@ -135,7 +135,10 @@ public class BluetoothOppRfcommListener { Log.e(TAG, "Error accept connection " + e); try { Thread.sleep(500); - } catch (InterruptedException ie) {} + } catch (InterruptedException ie) { + Log.e(TAG, "mSocketAcceptThread was interrupted " + ie); + mInterrupted = true; + } } } Log.i(TAG, "BluetoothSocket listen thread finished"); @@ -177,17 +180,12 @@ public class BluetoothOppRfcommListener { } } } - try { + if (mSocketAcceptThread != null) { + if (V) Log.v(TAG, "Interrupting mSocketAcceptThread :" + mSocketAcceptThread); mSocketAcceptThread.interrupt(); - if (V) Log.v(TAG, "waiting for thread to terminate"); - //mSocketAcceptThread.join(JOIN_TIMEOUT_MS); - mSocketAcceptThread.join(); - if (V) Log.v(TAG, "done waiting for thread to terminate"); - mSocketAcceptThread = null; - mCallback = null; - } catch (InterruptedException e) { - if (V) Log.v(TAG, "Interrupted waiting for Accept Thread to join"); } + mSocketAcceptThread = null; + mCallback = null; } } diff --git a/src/com/android/bluetooth/opp/BluetoothOppService.java b/src/com/android/bluetooth/opp/BluetoothOppService.java index 080b220b6..aa6b051a2 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppService.java +++ b/src/com/android/bluetooth/opp/BluetoothOppService.java @@ -259,6 +259,8 @@ public class BluetoothOppService extends Service { stopSelf(); } } + // Update Notification + mNotifier.updateNotifier(); break; case START_LISTENER: if (mAdapter.isEnabled()) { @@ -407,8 +409,6 @@ public class BluetoothOppService extends Service { break; case BluetoothAdapter.STATE_TURNING_OFF: if (V) Log.v(TAG, "Receiver DISABLED_ACTION "); - mNotifier.updateNotifier(); - //FIX: Don't block main thread /* mSocketListener.stop(); diff --git a/src/com/android/bluetooth/sap/SapMessage.java b/src/com/android/bluetooth/sap/SapMessage.java index 2bcee607e..451d9280c 100644 --- a/src/com/android/bluetooth/sap/SapMessage.java +++ b/src/com/android/bluetooth/sap/SapMessage.java @@ -28,6 +28,7 @@ public class SapMessage { public static final String TAG = "SapMessage"; public static final boolean DEBUG = Log.isLoggable(SapService.LOG_TAG, Log.DEBUG); public static final boolean VERBOSE = Log.isLoggable(SapService.LOG_TAG, Log.VERBOSE); + public static final boolean TEST = false; /* Message IDs - SAP specification */ public static final int ID_CONNECT_REQ = 0x00; |