Loading service/java/com/android/server/bluetooth/BluetoothManagerService.java +24 −21 Original line number Diff line number Diff line Loading @@ -225,9 +225,12 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { private final RemoteCallbackList<IBluetoothManagerCallback> mCallbacks; private final RemoteCallbackList<IBluetoothStateChangeCallback> mStateChangeCallbacks; private IBinder mBluetoothBinder; private final ReentrantReadWriteLock mBluetoothLock = new ReentrantReadWriteLock(); @GuardedBy("mBluetoothLock") private IBluetooth mBluetooth; private IBluetoothGatt mBluetoothGatt; private final ReentrantReadWriteLock mBluetoothLock = new ReentrantReadWriteLock(); private boolean mBinding; private boolean mUnbinding; private List<Integer> mSupportedProfileList = new ArrayList<>(); Loading Loading @@ -359,8 +362,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { // Clear registered LE apps to force shut-off Bluetooth clearBleApps(); state = getState(); try { mBluetoothLock.readLock().lock(); try { if (mBluetooth == null) { return false; } Loading Loading @@ -459,8 +462,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { // If state is BLE_ON make sure we trigger disableBLE if (st == BluetoothAdapter.STATE_BLE_ON) { try { mBluetoothLock.readLock().lock(); try { if (mBluetooth != null) { addActiveLog( BluetoothProtoEnums.ENABLE_DISABLE_REASON_AIRPLANE_MODE, Loading Loading @@ -1019,8 +1022,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { return BluetoothAdapter.STATE_OFF; } try { mBluetoothLock.readLock().lock(); try { if (mBluetooth != null) { return synchronousGetState(); } Loading Loading @@ -1118,8 +1121,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { // BLE scan is not available. disableBleScanMode(); clearBleApps(); try { mBluetoothLock.readLock().lock(); try { if (mBluetooth != null) { addActiveLog(BluetoothProtoEnums.ENABLE_DISABLE_REASON_APPLICATION_REQUEST, mContext.getPackageName(), false); Loading @@ -1139,8 +1142,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { // Disable ble scan only mode. private void disableBleScanMode() { try { mBluetoothLock.writeLock().lock(); try { if (mBluetooth != null && synchronousGetState() != BluetoothAdapter.STATE_ON) { if (DBG) { Log.d(TAG, "Resetting the mEnable flag for clean disable"); Loading Loading @@ -1301,8 +1304,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { if (DBG) { Log.d(TAG, "continueFromBleOnState()"); } try { mBluetoothLock.readLock().lock(); try { if (mBluetooth == null) { Log.e(TAG, "onBluetoothServiceUp: mBluetooth is null!"); return; Loading Loading @@ -1353,8 +1356,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { Log.e(TAG, "Unable to disconnect all apps.", e); } } else { try { mBluetoothLock.readLock().lock(); try { if (mBluetooth != null) { synchronousOnBrEdrDown(attributionSource); } Loading Loading @@ -1556,8 +1559,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { + " mUnbinding = " + mUnbinding); } try { mBluetoothLock.writeLock().lock(); try { if (mUnbinding) { return; } Loading Loading @@ -1967,8 +1970,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { return BluetoothAdapter.DEFAULT_MAC_ADDRESS; } try { mBluetoothLock.readLock().lock(); try { if (mBluetooth != null) { return synchronousGetAddress(attributionSource); } Loading Loading @@ -1996,8 +1999,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { return null; } try { mBluetoothLock.readLock().lock(); try { if (mBluetooth != null) { return synchronousGetName(attributionSource); } Loading Loading @@ -2069,8 +2072,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { if (DBG) { Log.d(TAG, "MESSAGE_GET_NAME_AND_ADDRESS"); } try { mBluetoothLock.writeLock().lock(); try { if ((mBluetooth == null) && (!mBinding)) { if (DBG) { Log.d(TAG, "Binding to service to get name and address"); Loading Loading @@ -2132,8 +2135,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { } // Use service interface to get the exact state try { mBluetoothLock.readLock().lock(); try { if (mBluetooth != null) { boolean isHandled = true; int state = synchronousGetState(); Loading Loading @@ -2352,8 +2355,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { } IBinder service = (IBinder) msg.obj; try { mBluetoothLock.writeLock().lock(); try { if (msg.arg1 == SERVICE_IBLUETOOTHGATT) { mBluetoothGatt = IBluetoothGatt.Stub.asInterface(service); continueFromBleOnState(); Loading Loading @@ -2466,8 +2469,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { } case MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED: { Log.e(TAG, "MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED(" + msg.arg1 + ")"); try { mBluetoothLock.writeLock().lock(); try { if (msg.arg1 == SERVICE_IBLUETOOTH) { // if service is unbinded already, do nothing and return if (mBluetooth == null) { Loading Loading @@ -2618,8 +2621,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { android.Manifest.permission.BLUETOOTH_PRIVILEGED }) private void restartForReason(int reason) { try { mBluetoothLock.readLock().lock(); try { if (mBluetooth != null) { synchronousUnregisterCallback(mBluetoothCallback, mContext.getAttributionSource()); Loading Loading @@ -2661,8 +2664,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { BluetoothAdapter.STATE_OFF); sendBluetoothServiceDownCallback(); try { mBluetoothLock.writeLock().lock(); try { if (mBluetooth != null) { mBluetooth = null; // Unbind Loading Loading @@ -2698,8 +2701,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { private void handleEnable(boolean quietMode) { mQuietEnable = quietMode; try { mBluetoothLock.writeLock().lock(); try { if ((mBluetooth == null) && (!mBinding)) { Log.d(TAG, "binding Bluetooth service"); //Start bind timeout and bind Loading Loading @@ -2739,8 +2742,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) private void handleDisable() { try { mBluetoothLock.readLock().lock(); try { if (mBluetooth != null) { if (DBG) { Log.d(TAG, "Sending off request."); Loading Loading @@ -3008,8 +3011,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { mHandler.removeCallbacks(mOnAirplaneModeChangedRunnable); repeatAirplaneRunnable = true; } try { mBluetoothLock.readLock().lock(); try { if (mBluetooth != null) { //Unregister callback object synchronousUnregisterCallback(mBluetoothCallback, mContext.getAttributionSource()); Loading @@ -3031,8 +3034,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { sendBluetoothServiceDownCallback(); try { mBluetoothLock.writeLock().lock(); try { if (mBluetooth != null) { mBluetooth = null; // Unbind Loading Loading
service/java/com/android/server/bluetooth/BluetoothManagerService.java +24 −21 Original line number Diff line number Diff line Loading @@ -225,9 +225,12 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { private final RemoteCallbackList<IBluetoothManagerCallback> mCallbacks; private final RemoteCallbackList<IBluetoothStateChangeCallback> mStateChangeCallbacks; private IBinder mBluetoothBinder; private final ReentrantReadWriteLock mBluetoothLock = new ReentrantReadWriteLock(); @GuardedBy("mBluetoothLock") private IBluetooth mBluetooth; private IBluetoothGatt mBluetoothGatt; private final ReentrantReadWriteLock mBluetoothLock = new ReentrantReadWriteLock(); private boolean mBinding; private boolean mUnbinding; private List<Integer> mSupportedProfileList = new ArrayList<>(); Loading Loading @@ -359,8 +362,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { // Clear registered LE apps to force shut-off Bluetooth clearBleApps(); state = getState(); try { mBluetoothLock.readLock().lock(); try { if (mBluetooth == null) { return false; } Loading Loading @@ -459,8 +462,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { // If state is BLE_ON make sure we trigger disableBLE if (st == BluetoothAdapter.STATE_BLE_ON) { try { mBluetoothLock.readLock().lock(); try { if (mBluetooth != null) { addActiveLog( BluetoothProtoEnums.ENABLE_DISABLE_REASON_AIRPLANE_MODE, Loading Loading @@ -1019,8 +1022,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { return BluetoothAdapter.STATE_OFF; } try { mBluetoothLock.readLock().lock(); try { if (mBluetooth != null) { return synchronousGetState(); } Loading Loading @@ -1118,8 +1121,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { // BLE scan is not available. disableBleScanMode(); clearBleApps(); try { mBluetoothLock.readLock().lock(); try { if (mBluetooth != null) { addActiveLog(BluetoothProtoEnums.ENABLE_DISABLE_REASON_APPLICATION_REQUEST, mContext.getPackageName(), false); Loading @@ -1139,8 +1142,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { // Disable ble scan only mode. private void disableBleScanMode() { try { mBluetoothLock.writeLock().lock(); try { if (mBluetooth != null && synchronousGetState() != BluetoothAdapter.STATE_ON) { if (DBG) { Log.d(TAG, "Resetting the mEnable flag for clean disable"); Loading Loading @@ -1301,8 +1304,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { if (DBG) { Log.d(TAG, "continueFromBleOnState()"); } try { mBluetoothLock.readLock().lock(); try { if (mBluetooth == null) { Log.e(TAG, "onBluetoothServiceUp: mBluetooth is null!"); return; Loading Loading @@ -1353,8 +1356,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { Log.e(TAG, "Unable to disconnect all apps.", e); } } else { try { mBluetoothLock.readLock().lock(); try { if (mBluetooth != null) { synchronousOnBrEdrDown(attributionSource); } Loading Loading @@ -1556,8 +1559,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { + " mUnbinding = " + mUnbinding); } try { mBluetoothLock.writeLock().lock(); try { if (mUnbinding) { return; } Loading Loading @@ -1967,8 +1970,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { return BluetoothAdapter.DEFAULT_MAC_ADDRESS; } try { mBluetoothLock.readLock().lock(); try { if (mBluetooth != null) { return synchronousGetAddress(attributionSource); } Loading Loading @@ -1996,8 +1999,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { return null; } try { mBluetoothLock.readLock().lock(); try { if (mBluetooth != null) { return synchronousGetName(attributionSource); } Loading Loading @@ -2069,8 +2072,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { if (DBG) { Log.d(TAG, "MESSAGE_GET_NAME_AND_ADDRESS"); } try { mBluetoothLock.writeLock().lock(); try { if ((mBluetooth == null) && (!mBinding)) { if (DBG) { Log.d(TAG, "Binding to service to get name and address"); Loading Loading @@ -2132,8 +2135,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { } // Use service interface to get the exact state try { mBluetoothLock.readLock().lock(); try { if (mBluetooth != null) { boolean isHandled = true; int state = synchronousGetState(); Loading Loading @@ -2352,8 +2355,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { } IBinder service = (IBinder) msg.obj; try { mBluetoothLock.writeLock().lock(); try { if (msg.arg1 == SERVICE_IBLUETOOTHGATT) { mBluetoothGatt = IBluetoothGatt.Stub.asInterface(service); continueFromBleOnState(); Loading Loading @@ -2466,8 +2469,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { } case MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED: { Log.e(TAG, "MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED(" + msg.arg1 + ")"); try { mBluetoothLock.writeLock().lock(); try { if (msg.arg1 == SERVICE_IBLUETOOTH) { // if service is unbinded already, do nothing and return if (mBluetooth == null) { Loading Loading @@ -2618,8 +2621,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { android.Manifest.permission.BLUETOOTH_PRIVILEGED }) private void restartForReason(int reason) { try { mBluetoothLock.readLock().lock(); try { if (mBluetooth != null) { synchronousUnregisterCallback(mBluetoothCallback, mContext.getAttributionSource()); Loading Loading @@ -2661,8 +2664,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { BluetoothAdapter.STATE_OFF); sendBluetoothServiceDownCallback(); try { mBluetoothLock.writeLock().lock(); try { if (mBluetooth != null) { mBluetooth = null; // Unbind Loading Loading @@ -2698,8 +2701,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { private void handleEnable(boolean quietMode) { mQuietEnable = quietMode; try { mBluetoothLock.writeLock().lock(); try { if ((mBluetooth == null) && (!mBinding)) { Log.d(TAG, "binding Bluetooth service"); //Start bind timeout and bind Loading Loading @@ -2739,8 +2742,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) private void handleDisable() { try { mBluetoothLock.readLock().lock(); try { if (mBluetooth != null) { if (DBG) { Log.d(TAG, "Sending off request."); Loading Loading @@ -3008,8 +3011,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { mHandler.removeCallbacks(mOnAirplaneModeChangedRunnable); repeatAirplaneRunnable = true; } try { mBluetoothLock.readLock().lock(); try { if (mBluetooth != null) { //Unregister callback object synchronousUnregisterCallback(mBluetoothCallback, mContext.getAttributionSource()); Loading @@ -3031,8 +3034,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { sendBluetoothServiceDownCallback(); try { mBluetoothLock.writeLock().lock(); try { if (mBluetooth != null) { mBluetooth = null; // Unbind Loading