Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +20 −16 Original line number Diff line number Diff line Loading @@ -4240,23 +4240,25 @@ public class AdapterService extends Service { } @Override public void onLeServiceUp(AttributionSource source, SynchronousResultReceiver receiver) { public void startBrEdr(AttributionSource source, SynchronousResultReceiver receiver) { try { onLeServiceUp(source); startBrEdr(source); receiver.send(null); } catch (RuntimeException e) { receiver.propagateException(e); } } @VisibleForTesting @RequiresPermission(allOf = { @RequiresPermission( allOf = { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, }) void onLeServiceUp(AttributionSource source) { void startBrEdr(AttributionSource source) { AdapterService service = getService(); if (service == null || !callerIsSystemOrActiveOrManagedUser(service, TAG, "onLeServiceUp") || !callerIsSystemOrActiveOrManagedUser(service, TAG, "startBrEdr") || !Utils.checkConnectPermissionForDataDelivery(service, source, TAG)) { return; } Loading @@ -4267,23 +4269,25 @@ public class AdapterService extends Service { } @Override public void onBrEdrDown(AttributionSource source, SynchronousResultReceiver receiver) { public void stopBle(AttributionSource source, SynchronousResultReceiver receiver) { try { onBrEdrDown(source); stopBle(source); receiver.send(null); } catch (RuntimeException e) { receiver.propagateException(e); } } @VisibleForTesting @RequiresPermission(allOf = { @RequiresPermission( allOf = { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, }) void onBrEdrDown(AttributionSource source) { void stopBle(AttributionSource source) { AdapterService service = getService(); if (service == null || !callerIsSystemOrActiveOrManagedUser(service, TAG, "onBrEdrDown") || !callerIsSystemOrActiveOrManagedUser(service, TAG, "stopBle") || !Utils.checkConnectPermissionForDataDelivery(service, source, TAG)) { return; } Loading android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceFactoryResetTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -374,7 +374,7 @@ public class AdapterServiceFactoryResetTest { verifyStateChange(BluetoothAdapter.STATE_BLE_TURNING_ON, BluetoothAdapter.STATE_BLE_ON, invocationNumber + 1, NATIVE_INIT_MS); mServiceBinder.onLeServiceUp(mAttributionSource); mServiceBinder.startBrEdr(mAttributionSource); verifyStateChange(BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_TURNING_ON, invocationNumber + 1, CONTEXT_SWITCH_MS); Loading android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java +9 −6 Original line number Diff line number Diff line Loading @@ -382,7 +382,7 @@ public class AdapterServiceTest { verifyStateChange(BluetoothAdapter.STATE_BLE_TURNING_ON, BluetoothAdapter.STATE_BLE_ON, invocationNumber + 1, NATIVE_INIT_MS); mServiceBinder.onLeServiceUp(mAttributionSource); mServiceBinder.startBrEdr(mAttributionSource); verifyStateChange(BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_TURNING_ON, invocationNumber + 1, CONTEXT_SWITCH_MS); Loading Loading @@ -435,7 +435,7 @@ public class AdapterServiceTest { verifyStateChange(BluetoothAdapter.STATE_TURNING_OFF, BluetoothAdapter.STATE_BLE_ON, invocationNumber + 1, PROFILE_SERVICE_TOGGLE_TIME_MS); mServiceBinder.onBrEdrDown(mAttributionSource); mServiceBinder.stopBle(mAttributionSource); verifyStateChange(BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_BLE_TURNING_OFF, invocationNumber + 1, CONTEXT_SWITCH_MS); Loading Loading @@ -560,7 +560,7 @@ public class AdapterServiceTest { verifyStateChange(BluetoothAdapter.STATE_TURNING_OFF, BluetoothAdapter.STATE_BLE_ON, 1, CONTEXT_SWITCH_MS); mServiceBinder.onBrEdrDown(mAttributionSource); mServiceBinder.stopBle(mAttributionSource); verifyStateChange(BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_BLE_TURNING_OFF, 1, CONTEXT_SWITCH_MS); Loading Loading @@ -595,7 +595,7 @@ public class AdapterServiceTest { verifyStateChange(BluetoothAdapter.STATE_BLE_TURNING_ON, BluetoothAdapter.STATE_BLE_ON, 1, NATIVE_INIT_MS); mServiceBinder.onLeServiceUp(mAttributionSource); mServiceBinder.startBrEdr(mAttributionSource); verifyStateChange(BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_TURNING_ON, 1, CONTEXT_SWITCH_MS); Loading Loading @@ -684,9 +684,12 @@ public class AdapterServiceTest { verifyStateChange(BluetoothAdapter.STATE_TURNING_OFF, BluetoothAdapter.STATE_BLE_ON, 1, CONTEXT_SWITCH_MS); // Don't call onBrEdrDown(). The Adapter should turn itself off. // Don't call stopBle(). The Adapter should turn itself off. verifyStateChange(BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_BLE_TURNING_OFF, 1, verifyStateChange( BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_BLE_TURNING_OFF, 1, CONTEXT_SWITCH_MS); // Stop GATT Loading service/src/com/android/server/bluetooth/AdapterBinder.kt +4 −4 Original line number Diff line number Diff line Loading @@ -64,16 +64,16 @@ class AdapterBinder(rawBinder: IBinder) { } @Throws(RemoteException::class, TimeoutException::class) fun onBrEdrDown(source: AttributionSource) { fun stopBle(source: AttributionSource) { val recv: SynchronousResultReceiver<Any> = SynchronousResultReceiver.get() adapterBinder.onBrEdrDown(source, recv) adapterBinder.stopBle(source, recv) recv.awaitResultNoInterrupt(SYNC_TIMEOUT).getValue(null) } @Throws(RemoteException::class, TimeoutException::class) fun onLeServiceUp(source: AttributionSource) { fun startBrEdr(source: AttributionSource) { val recv: SynchronousResultReceiver<Any> = SynchronousResultReceiver.get() adapterBinder.onLeServiceUp(source, recv) adapterBinder.startBrEdr(source, recv) recv.awaitResultNoInterrupt(SYNC_TIMEOUT).getValue(null) } Loading service/src/com/android/server/bluetooth/BluetoothManagerService.java +14 −14 Original line number Diff line number Diff line Loading @@ -354,7 +354,7 @@ class BluetoothManagerService { BluetoothProtoEnums.ENABLE_DISABLE_REASON_FACTORY_RESET, mContext.getPackageName(), false); mAdapter.onBrEdrDown(source); mAdapter.stopBle(source); return true; } else if (state == STATE_ON) { addActiveLog( Loading Loading @@ -503,7 +503,7 @@ class BluetoothManagerService { // Clear registered LE apps to force shut-off clearBleApps(); // If state is BLE_ON make sure we trigger disableBLE // If state is BLE_ON make sure we trigger stopBle if (st == STATE_BLE_ON) { mAdapterLock.readLock().lock(); try { Loading @@ -512,12 +512,12 @@ class BluetoothManagerService { BluetoothProtoEnums.ENABLE_DISABLE_REASON_AIRPLANE_MODE, mContext.getPackageName(), false); mAdapter.onBrEdrDown(mContext.getAttributionSource()); mAdapter.stopBle(mContext.getAttributionSource()); mEnable = false; mEnableExternal = false; } } catch (RemoteException | TimeoutException e) { Log.e(TAG, "Unable to call onBrEdrDown", e); Log.e(TAG, "Unable to call stopBle", e); } finally { mAdapterLock.readLock().unlock(); } Loading Loading @@ -638,7 +638,7 @@ class BluetoothManagerService { mEnable = false; mEnableExternal = false; if (mAdapter != null && mState.oneOf(STATE_BLE_ON)) { mAdapter.onBrEdrDown(mContext.getAttributionSource()); mAdapter.stopBle(mContext.getAttributionSource()); } else if (mAdapter != null && mState.oneOf(STATE_ON)) { mAdapter.disable(mContext.getAttributionSource()); } Loading Loading @@ -1056,7 +1056,7 @@ class BluetoothManagerService { .ENABLE_DISABLE_REASON_APPLICATION_REQUEST, mContext.getPackageName(), false); mAdapter.onBrEdrDown(mContext.getAttributionSource()); mAdapter.stopBle(mContext.getAttributionSource()); } } catch (RemoteException | TimeoutException e) { Log.e(TAG, "error when disabling bluetooth", e); Loading Loading @@ -1214,8 +1214,8 @@ class BluetoothManagerService { } /** * Call IBluetooth.onLeServiceUp() to continue if Bluetooth should be on, call * IBluetooth.onBrEdrDown() to disable if Bluetooth should be off. * Will call startBrEdr() if bluetooth classic should be on and will call stopBle if bluetooth * BLE should be off */ @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) private void continueFromBleOnState() { Loading @@ -1231,12 +1231,12 @@ class BluetoothManagerService { if (!mEnableExternal && !isBleAppPresent()) { Log.i(TAG, "Bluetooth was disabled while enabling BLE, disable BLE now"); mEnable = false; mAdapter.onBrEdrDown(mContext.getAttributionSource()); mAdapter.stopBle(mContext.getAttributionSource()); return; } if (isBluetoothPersistedStateOnBluetooth() || !isBleAppPresent()) { // This triggers transition to STATE_ON mAdapter.onLeServiceUp(mContext.getAttributionSource()); mAdapter.startBrEdr(mContext.getAttributionSource()); persistBluetoothSetting(BLUETOOTH_ON_BLUETOOTH); } } catch (RemoteException | TimeoutException e) { Loading Loading @@ -1278,10 +1278,10 @@ class BluetoothManagerService { mAdapterLock.readLock().lock(); try { if (mAdapter != null) { mAdapter.onBrEdrDown(source); mAdapter.stopBle(source); } } catch (RemoteException | TimeoutException e) { Log.e(TAG, "Call to onBrEdrDown() failed.", e); Log.e(TAG, "Call to stopBle() failed.", e); } finally { mAdapterLock.readLock().unlock(); } Loading Loading @@ -1978,7 +1978,7 @@ class BluetoothManagerService { Log.i(TAG, "Already at BLE_ON State"); } else { Log.w(TAG, "BT Enable in BLE_ON State, going to ON"); mAdapter.onLeServiceUp(mContext.getAttributionSource()); mAdapter.startBrEdr(mContext.getAttributionSource()); } break; case STATE_BLE_TURNING_ON: Loading Loading @@ -2495,7 +2495,7 @@ class BluetoothManagerService { mState.set(STATE_OFF); // enable addActiveLog(reason, mContext.getPackageName(), true); // mEnable flag could have been reset on disableBLE. Reenable it. // mEnable flag could have been reset on stopBle. Reenable it. mEnable = true; handleEnable(mQuietEnable); } Loading Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +20 −16 Original line number Diff line number Diff line Loading @@ -4240,23 +4240,25 @@ public class AdapterService extends Service { } @Override public void onLeServiceUp(AttributionSource source, SynchronousResultReceiver receiver) { public void startBrEdr(AttributionSource source, SynchronousResultReceiver receiver) { try { onLeServiceUp(source); startBrEdr(source); receiver.send(null); } catch (RuntimeException e) { receiver.propagateException(e); } } @VisibleForTesting @RequiresPermission(allOf = { @RequiresPermission( allOf = { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, }) void onLeServiceUp(AttributionSource source) { void startBrEdr(AttributionSource source) { AdapterService service = getService(); if (service == null || !callerIsSystemOrActiveOrManagedUser(service, TAG, "onLeServiceUp") || !callerIsSystemOrActiveOrManagedUser(service, TAG, "startBrEdr") || !Utils.checkConnectPermissionForDataDelivery(service, source, TAG)) { return; } Loading @@ -4267,23 +4269,25 @@ public class AdapterService extends Service { } @Override public void onBrEdrDown(AttributionSource source, SynchronousResultReceiver receiver) { public void stopBle(AttributionSource source, SynchronousResultReceiver receiver) { try { onBrEdrDown(source); stopBle(source); receiver.send(null); } catch (RuntimeException e) { receiver.propagateException(e); } } @VisibleForTesting @RequiresPermission(allOf = { @RequiresPermission( allOf = { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, }) void onBrEdrDown(AttributionSource source) { void stopBle(AttributionSource source) { AdapterService service = getService(); if (service == null || !callerIsSystemOrActiveOrManagedUser(service, TAG, "onBrEdrDown") || !callerIsSystemOrActiveOrManagedUser(service, TAG, "stopBle") || !Utils.checkConnectPermissionForDataDelivery(service, source, TAG)) { return; } Loading
android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceFactoryResetTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -374,7 +374,7 @@ public class AdapterServiceFactoryResetTest { verifyStateChange(BluetoothAdapter.STATE_BLE_TURNING_ON, BluetoothAdapter.STATE_BLE_ON, invocationNumber + 1, NATIVE_INIT_MS); mServiceBinder.onLeServiceUp(mAttributionSource); mServiceBinder.startBrEdr(mAttributionSource); verifyStateChange(BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_TURNING_ON, invocationNumber + 1, CONTEXT_SWITCH_MS); Loading
android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java +9 −6 Original line number Diff line number Diff line Loading @@ -382,7 +382,7 @@ public class AdapterServiceTest { verifyStateChange(BluetoothAdapter.STATE_BLE_TURNING_ON, BluetoothAdapter.STATE_BLE_ON, invocationNumber + 1, NATIVE_INIT_MS); mServiceBinder.onLeServiceUp(mAttributionSource); mServiceBinder.startBrEdr(mAttributionSource); verifyStateChange(BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_TURNING_ON, invocationNumber + 1, CONTEXT_SWITCH_MS); Loading Loading @@ -435,7 +435,7 @@ public class AdapterServiceTest { verifyStateChange(BluetoothAdapter.STATE_TURNING_OFF, BluetoothAdapter.STATE_BLE_ON, invocationNumber + 1, PROFILE_SERVICE_TOGGLE_TIME_MS); mServiceBinder.onBrEdrDown(mAttributionSource); mServiceBinder.stopBle(mAttributionSource); verifyStateChange(BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_BLE_TURNING_OFF, invocationNumber + 1, CONTEXT_SWITCH_MS); Loading Loading @@ -560,7 +560,7 @@ public class AdapterServiceTest { verifyStateChange(BluetoothAdapter.STATE_TURNING_OFF, BluetoothAdapter.STATE_BLE_ON, 1, CONTEXT_SWITCH_MS); mServiceBinder.onBrEdrDown(mAttributionSource); mServiceBinder.stopBle(mAttributionSource); verifyStateChange(BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_BLE_TURNING_OFF, 1, CONTEXT_SWITCH_MS); Loading Loading @@ -595,7 +595,7 @@ public class AdapterServiceTest { verifyStateChange(BluetoothAdapter.STATE_BLE_TURNING_ON, BluetoothAdapter.STATE_BLE_ON, 1, NATIVE_INIT_MS); mServiceBinder.onLeServiceUp(mAttributionSource); mServiceBinder.startBrEdr(mAttributionSource); verifyStateChange(BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_TURNING_ON, 1, CONTEXT_SWITCH_MS); Loading Loading @@ -684,9 +684,12 @@ public class AdapterServiceTest { verifyStateChange(BluetoothAdapter.STATE_TURNING_OFF, BluetoothAdapter.STATE_BLE_ON, 1, CONTEXT_SWITCH_MS); // Don't call onBrEdrDown(). The Adapter should turn itself off. // Don't call stopBle(). The Adapter should turn itself off. verifyStateChange(BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_BLE_TURNING_OFF, 1, verifyStateChange( BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_BLE_TURNING_OFF, 1, CONTEXT_SWITCH_MS); // Stop GATT Loading
service/src/com/android/server/bluetooth/AdapterBinder.kt +4 −4 Original line number Diff line number Diff line Loading @@ -64,16 +64,16 @@ class AdapterBinder(rawBinder: IBinder) { } @Throws(RemoteException::class, TimeoutException::class) fun onBrEdrDown(source: AttributionSource) { fun stopBle(source: AttributionSource) { val recv: SynchronousResultReceiver<Any> = SynchronousResultReceiver.get() adapterBinder.onBrEdrDown(source, recv) adapterBinder.stopBle(source, recv) recv.awaitResultNoInterrupt(SYNC_TIMEOUT).getValue(null) } @Throws(RemoteException::class, TimeoutException::class) fun onLeServiceUp(source: AttributionSource) { fun startBrEdr(source: AttributionSource) { val recv: SynchronousResultReceiver<Any> = SynchronousResultReceiver.get() adapterBinder.onLeServiceUp(source, recv) adapterBinder.startBrEdr(source, recv) recv.awaitResultNoInterrupt(SYNC_TIMEOUT).getValue(null) } Loading
service/src/com/android/server/bluetooth/BluetoothManagerService.java +14 −14 Original line number Diff line number Diff line Loading @@ -354,7 +354,7 @@ class BluetoothManagerService { BluetoothProtoEnums.ENABLE_DISABLE_REASON_FACTORY_RESET, mContext.getPackageName(), false); mAdapter.onBrEdrDown(source); mAdapter.stopBle(source); return true; } else if (state == STATE_ON) { addActiveLog( Loading Loading @@ -503,7 +503,7 @@ class BluetoothManagerService { // Clear registered LE apps to force shut-off clearBleApps(); // If state is BLE_ON make sure we trigger disableBLE // If state is BLE_ON make sure we trigger stopBle if (st == STATE_BLE_ON) { mAdapterLock.readLock().lock(); try { Loading @@ -512,12 +512,12 @@ class BluetoothManagerService { BluetoothProtoEnums.ENABLE_DISABLE_REASON_AIRPLANE_MODE, mContext.getPackageName(), false); mAdapter.onBrEdrDown(mContext.getAttributionSource()); mAdapter.stopBle(mContext.getAttributionSource()); mEnable = false; mEnableExternal = false; } } catch (RemoteException | TimeoutException e) { Log.e(TAG, "Unable to call onBrEdrDown", e); Log.e(TAG, "Unable to call stopBle", e); } finally { mAdapterLock.readLock().unlock(); } Loading Loading @@ -638,7 +638,7 @@ class BluetoothManagerService { mEnable = false; mEnableExternal = false; if (mAdapter != null && mState.oneOf(STATE_BLE_ON)) { mAdapter.onBrEdrDown(mContext.getAttributionSource()); mAdapter.stopBle(mContext.getAttributionSource()); } else if (mAdapter != null && mState.oneOf(STATE_ON)) { mAdapter.disable(mContext.getAttributionSource()); } Loading Loading @@ -1056,7 +1056,7 @@ class BluetoothManagerService { .ENABLE_DISABLE_REASON_APPLICATION_REQUEST, mContext.getPackageName(), false); mAdapter.onBrEdrDown(mContext.getAttributionSource()); mAdapter.stopBle(mContext.getAttributionSource()); } } catch (RemoteException | TimeoutException e) { Log.e(TAG, "error when disabling bluetooth", e); Loading Loading @@ -1214,8 +1214,8 @@ class BluetoothManagerService { } /** * Call IBluetooth.onLeServiceUp() to continue if Bluetooth should be on, call * IBluetooth.onBrEdrDown() to disable if Bluetooth should be off. * Will call startBrEdr() if bluetooth classic should be on and will call stopBle if bluetooth * BLE should be off */ @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) private void continueFromBleOnState() { Loading @@ -1231,12 +1231,12 @@ class BluetoothManagerService { if (!mEnableExternal && !isBleAppPresent()) { Log.i(TAG, "Bluetooth was disabled while enabling BLE, disable BLE now"); mEnable = false; mAdapter.onBrEdrDown(mContext.getAttributionSource()); mAdapter.stopBle(mContext.getAttributionSource()); return; } if (isBluetoothPersistedStateOnBluetooth() || !isBleAppPresent()) { // This triggers transition to STATE_ON mAdapter.onLeServiceUp(mContext.getAttributionSource()); mAdapter.startBrEdr(mContext.getAttributionSource()); persistBluetoothSetting(BLUETOOTH_ON_BLUETOOTH); } } catch (RemoteException | TimeoutException e) { Loading Loading @@ -1278,10 +1278,10 @@ class BluetoothManagerService { mAdapterLock.readLock().lock(); try { if (mAdapter != null) { mAdapter.onBrEdrDown(source); mAdapter.stopBle(source); } } catch (RemoteException | TimeoutException e) { Log.e(TAG, "Call to onBrEdrDown() failed.", e); Log.e(TAG, "Call to stopBle() failed.", e); } finally { mAdapterLock.readLock().unlock(); } Loading Loading @@ -1978,7 +1978,7 @@ class BluetoothManagerService { Log.i(TAG, "Already at BLE_ON State"); } else { Log.w(TAG, "BT Enable in BLE_ON State, going to ON"); mAdapter.onLeServiceUp(mContext.getAttributionSource()); mAdapter.startBrEdr(mContext.getAttributionSource()); } break; case STATE_BLE_TURNING_ON: Loading Loading @@ -2495,7 +2495,7 @@ class BluetoothManagerService { mState.set(STATE_OFF); // enable addActiveLog(reason, mContext.getPackageName(), true); // mEnable flag could have been reset on disableBLE. Reenable it. // mEnable flag could have been reset on stopBle. Reenable it. mEnable = true; handleEnable(mQuietEnable); } Loading