Loading android/app/aidl/android/bluetooth/IBluetooth.aidl +2 −2 Original line number Diff line number Diff line Loading @@ -227,8 +227,8 @@ interface IBluetooth @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})") oneway void startBrEdr(in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})") oneway void stopBle(in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)") oneway void bleOnToOff(in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED,android.Manifest.permission.MODIFY_PHONE_STATE})") int connectAllEnabledProfiles(in BluetoothDevice device, in AttributionSource attributionSource); Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +4 −5 Original line number Diff line number Diff line Loading @@ -3814,17 +3814,16 @@ public class AdapterService extends Service { } @Override public void stopBle(AttributionSource source) { public void bleOnToOff(AttributionSource source) { AdapterService service = getService(); if (service == null || !callerIsSystemOrActiveOrManagedUser(service, TAG, "stopBle") || !Utils.checkConnectPermissionForDataDelivery(service, source, TAG)) { || !callerIsSystemOrActiveOrManagedUser(service, TAG, "bleOnToOff")) { return; } service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null); service.stopBle(); service.bleOnToOff(); } @Override Loading Loading @@ -5767,7 +5766,7 @@ public class AdapterService extends Service { } @VisibleForTesting void stopBle() { void bleOnToOff() { mAdapterStateMachine.sendMessage(AdapterState.BLE_TURN_OFF); } Loading android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java +4 −4 Original line number Diff line number Diff line Loading @@ -540,7 +540,7 @@ public class AdapterServiceTest { onToBleOn(looper, adapter, ctx, callback, onlyGatt, services); adapter.stopBle(); adapter.bleOnToOff(); TestUtils.syncHandler(looper, AdapterState.BLE_TURN_OFF); verifyStateChange(callback, STATE_BLE_ON, STATE_BLE_TURNING_OFF); Loading Loading @@ -661,7 +661,7 @@ public class AdapterServiceTest { false, listOfMockServices()); mAdapterService.stopBle(); mAdapterService.bleOnToOff(); syncHandler(AdapterState.BLE_TURN_OFF); verifyStateChange(STATE_BLE_ON, STATE_BLE_TURNING_OFF, CONTEXT_SWITCH_MS); assertThat(mAdapterService.getBluetoothGatt()).isNull(); Loading Loading @@ -723,7 +723,7 @@ public class AdapterServiceTest { assertThat(mAdapterService.getBluetoothScan()).isNotNull(); assertThat(mAdapterService.getBluetoothGatt()).isNull(); mAdapterService.stopBle(); mAdapterService.bleOnToOff(); syncHandler(AdapterState.BLE_TURN_OFF); verifyStateChange(callback, STATE_BLE_ON, STATE_BLE_TURNING_OFF); Loading Loading @@ -910,7 +910,7 @@ public class AdapterServiceTest { false, listOfMockServices()); // Do not call stopBle(). The Adapter should turn itself off. // Do not call bleOnToOff(). The Adapter should turn itself off. syncHandler(AdapterState.BLE_TURN_OFF); verifyStateChange(STATE_BLE_ON, STATE_BLE_TURNING_OFF, CONTEXT_SWITCH_MS); Loading service/src/AdapterBinder.kt +2 −2 Original line number Diff line number Diff line Loading @@ -54,8 +54,8 @@ class AdapterBinder(rawBinder: IBinder) { } @Throws(RemoteException::class) fun stopBle(source: AttributionSource) { adapterBinder.stopBle(source) fun bleOnToOff(source: AttributionSource) { adapterBinder.bleOnToOff(source) } @Throws(RemoteException::class) Loading service/src/com/android/server/bluetooth/BluetoothManagerService.java +25 −23 Original line number Diff line number Diff line Loading @@ -269,15 +269,13 @@ class BluetoothManagerService { } if (state == STATE_BLE_ON) { ActiveLogs.add(ENABLE_DISABLE_REASON_FACTORY_RESET, false); mAdapter.stopBle(mContext.getAttributionSource()); bleOnToOff(); return true; } else if (state == STATE_ON) { ActiveLogs.add(ENABLE_DISABLE_REASON_FACTORY_RESET, false); onToBleOn(); return true; } } catch (RemoteException e) { Log.e(TAG, "Unable to shutdown Bluetooth", e); } finally { mAdapterLock.readLock().unlock(); } Loading Loading @@ -417,14 +415,13 @@ class BluetoothManagerService { // If currentState is BLE_ON make sure we trigger stopBle mAdapterLock.readLock().lock(); try { if (mAdapter != null) { if (mAdapter == null) { return; } mEnable = false; mEnableExternal = false; ActiveLogs.add(reason, false); mAdapter.stopBle(mContext.getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "Unable to call stopBle", e); bleOnToOff(); } finally { mAdapterLock.readLock().unlock(); } Loading Loading @@ -550,12 +547,10 @@ class BluetoothManagerService { return; } if (mState.oneOf(STATE_BLE_ON)) { mAdapter.stopBle(mContext.getAttributionSource()); bleOnToOff(); } else if (mState.oneOf(STATE_ON)) { onToBleOn(); } } catch (RemoteException e) { Log.e(TAG, "Unable to shutdown Bluetooth", e); } finally { mAdapterLock.readLock().unlock(); } Loading Loading @@ -667,11 +662,7 @@ class BluetoothManagerService { } if (mState.oneOf(STATE_BLE_ON)) { Log.i(TAG, "onBleScanDisabled: Shutting down BLE_ON mode"); try { mAdapter.stopBle(mContext.getAttributionSource()); } catch (RemoteException e) { Log.e(TAG, "onBleScanDisabled: stopBle failed", e); } bleOnToOff(); } else { Log.i(TAG, "onBleScanDisabled: Bluetooth is not in BLE_ON, staying on"); } Loading Loading @@ -914,10 +905,8 @@ class BluetoothManagerService { try { if (mAdapter != null) { ActiveLogs.add(ENABLE_DISABLE_REASON_APPLICATION_REQUEST, false); mAdapter.stopBle(mContext.getAttributionSource()); bleOnToOff(); } } catch (RemoteException e) { Log.e(TAG, "error when disabling bluetooth", e); } finally { mAdapterLock.readLock().unlock(); } Loading Loading @@ -1074,7 +1063,7 @@ class BluetoothManagerService { // enableBle & disableBle are executed on the handler Log.i(TAG, "continueFromBleOnState: Disabled while enabling BLE, disable BLE now"); mEnable = false; mAdapter.stopBle(mContext.getAttributionSource()); bleOnToOff(); return; } if (isBluetoothPersistedStateOnBluetooth() || !isBleAppPresent()) { Loading Loading @@ -1113,7 +1102,7 @@ class BluetoothManagerService { mAdapter.unregAllGattClient(mContext.getAttributionSource()); } else { Log.i(TAG, "sendBrEdrDownCallback: Stopping ble"); mAdapter.stopBle(mContext.getAttributionSource()); bleOnToOff(); } } catch (RemoteException e) { Log.e(TAG, "sendBrEdrDownCallback: Call to mAdapter failed.", e); Loading Loading @@ -2047,6 +2036,19 @@ class BluetoothManagerService { } } private void bleOnToOff() { if (!mState.oneOf(STATE_BLE_ON)) { Log.d(TAG, "bleOnToOff: Impossible transition from " + mState); return; } Log.d(TAG, "bleOnToOff: Sending request"); try { mAdapter.bleOnToOff(mContext.getAttributionSource()); } catch (RemoteException e) { Log.e(TAG, "Unable to call bleOnToOff()", e); } } private void broadcastIntentStateChange(String action, int prevState, int newState) { Log.d( TAG, Loading Loading
android/app/aidl/android/bluetooth/IBluetooth.aidl +2 −2 Original line number Diff line number Diff line Loading @@ -227,8 +227,8 @@ interface IBluetooth @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})") oneway void startBrEdr(in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})") oneway void stopBle(in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)") oneway void bleOnToOff(in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED,android.Manifest.permission.MODIFY_PHONE_STATE})") int connectAllEnabledProfiles(in BluetoothDevice device, in AttributionSource attributionSource); Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +4 −5 Original line number Diff line number Diff line Loading @@ -3814,17 +3814,16 @@ public class AdapterService extends Service { } @Override public void stopBle(AttributionSource source) { public void bleOnToOff(AttributionSource source) { AdapterService service = getService(); if (service == null || !callerIsSystemOrActiveOrManagedUser(service, TAG, "stopBle") || !Utils.checkConnectPermissionForDataDelivery(service, source, TAG)) { || !callerIsSystemOrActiveOrManagedUser(service, TAG, "bleOnToOff")) { return; } service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null); service.stopBle(); service.bleOnToOff(); } @Override Loading Loading @@ -5767,7 +5766,7 @@ public class AdapterService extends Service { } @VisibleForTesting void stopBle() { void bleOnToOff() { mAdapterStateMachine.sendMessage(AdapterState.BLE_TURN_OFF); } Loading
android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java +4 −4 Original line number Diff line number Diff line Loading @@ -540,7 +540,7 @@ public class AdapterServiceTest { onToBleOn(looper, adapter, ctx, callback, onlyGatt, services); adapter.stopBle(); adapter.bleOnToOff(); TestUtils.syncHandler(looper, AdapterState.BLE_TURN_OFF); verifyStateChange(callback, STATE_BLE_ON, STATE_BLE_TURNING_OFF); Loading Loading @@ -661,7 +661,7 @@ public class AdapterServiceTest { false, listOfMockServices()); mAdapterService.stopBle(); mAdapterService.bleOnToOff(); syncHandler(AdapterState.BLE_TURN_OFF); verifyStateChange(STATE_BLE_ON, STATE_BLE_TURNING_OFF, CONTEXT_SWITCH_MS); assertThat(mAdapterService.getBluetoothGatt()).isNull(); Loading Loading @@ -723,7 +723,7 @@ public class AdapterServiceTest { assertThat(mAdapterService.getBluetoothScan()).isNotNull(); assertThat(mAdapterService.getBluetoothGatt()).isNull(); mAdapterService.stopBle(); mAdapterService.bleOnToOff(); syncHandler(AdapterState.BLE_TURN_OFF); verifyStateChange(callback, STATE_BLE_ON, STATE_BLE_TURNING_OFF); Loading Loading @@ -910,7 +910,7 @@ public class AdapterServiceTest { false, listOfMockServices()); // Do not call stopBle(). The Adapter should turn itself off. // Do not call bleOnToOff(). The Adapter should turn itself off. syncHandler(AdapterState.BLE_TURN_OFF); verifyStateChange(STATE_BLE_ON, STATE_BLE_TURNING_OFF, CONTEXT_SWITCH_MS); Loading
service/src/AdapterBinder.kt +2 −2 Original line number Diff line number Diff line Loading @@ -54,8 +54,8 @@ class AdapterBinder(rawBinder: IBinder) { } @Throws(RemoteException::class) fun stopBle(source: AttributionSource) { adapterBinder.stopBle(source) fun bleOnToOff(source: AttributionSource) { adapterBinder.bleOnToOff(source) } @Throws(RemoteException::class) Loading
service/src/com/android/server/bluetooth/BluetoothManagerService.java +25 −23 Original line number Diff line number Diff line Loading @@ -269,15 +269,13 @@ class BluetoothManagerService { } if (state == STATE_BLE_ON) { ActiveLogs.add(ENABLE_DISABLE_REASON_FACTORY_RESET, false); mAdapter.stopBle(mContext.getAttributionSource()); bleOnToOff(); return true; } else if (state == STATE_ON) { ActiveLogs.add(ENABLE_DISABLE_REASON_FACTORY_RESET, false); onToBleOn(); return true; } } catch (RemoteException e) { Log.e(TAG, "Unable to shutdown Bluetooth", e); } finally { mAdapterLock.readLock().unlock(); } Loading Loading @@ -417,14 +415,13 @@ class BluetoothManagerService { // If currentState is BLE_ON make sure we trigger stopBle mAdapterLock.readLock().lock(); try { if (mAdapter != null) { if (mAdapter == null) { return; } mEnable = false; mEnableExternal = false; ActiveLogs.add(reason, false); mAdapter.stopBle(mContext.getAttributionSource()); } } catch (RemoteException e) { Log.e(TAG, "Unable to call stopBle", e); bleOnToOff(); } finally { mAdapterLock.readLock().unlock(); } Loading Loading @@ -550,12 +547,10 @@ class BluetoothManagerService { return; } if (mState.oneOf(STATE_BLE_ON)) { mAdapter.stopBle(mContext.getAttributionSource()); bleOnToOff(); } else if (mState.oneOf(STATE_ON)) { onToBleOn(); } } catch (RemoteException e) { Log.e(TAG, "Unable to shutdown Bluetooth", e); } finally { mAdapterLock.readLock().unlock(); } Loading Loading @@ -667,11 +662,7 @@ class BluetoothManagerService { } if (mState.oneOf(STATE_BLE_ON)) { Log.i(TAG, "onBleScanDisabled: Shutting down BLE_ON mode"); try { mAdapter.stopBle(mContext.getAttributionSource()); } catch (RemoteException e) { Log.e(TAG, "onBleScanDisabled: stopBle failed", e); } bleOnToOff(); } else { Log.i(TAG, "onBleScanDisabled: Bluetooth is not in BLE_ON, staying on"); } Loading Loading @@ -914,10 +905,8 @@ class BluetoothManagerService { try { if (mAdapter != null) { ActiveLogs.add(ENABLE_DISABLE_REASON_APPLICATION_REQUEST, false); mAdapter.stopBle(mContext.getAttributionSource()); bleOnToOff(); } } catch (RemoteException e) { Log.e(TAG, "error when disabling bluetooth", e); } finally { mAdapterLock.readLock().unlock(); } Loading Loading @@ -1074,7 +1063,7 @@ class BluetoothManagerService { // enableBle & disableBle are executed on the handler Log.i(TAG, "continueFromBleOnState: Disabled while enabling BLE, disable BLE now"); mEnable = false; mAdapter.stopBle(mContext.getAttributionSource()); bleOnToOff(); return; } if (isBluetoothPersistedStateOnBluetooth() || !isBleAppPresent()) { Loading Loading @@ -1113,7 +1102,7 @@ class BluetoothManagerService { mAdapter.unregAllGattClient(mContext.getAttributionSource()); } else { Log.i(TAG, "sendBrEdrDownCallback: Stopping ble"); mAdapter.stopBle(mContext.getAttributionSource()); bleOnToOff(); } } catch (RemoteException e) { Log.e(TAG, "sendBrEdrDownCallback: Call to mAdapter failed.", e); Loading Loading @@ -2047,6 +2036,19 @@ class BluetoothManagerService { } } private void bleOnToOff() { if (!mState.oneOf(STATE_BLE_ON)) { Log.d(TAG, "bleOnToOff: Impossible transition from " + mState); return; } Log.d(TAG, "bleOnToOff: Sending request"); try { mAdapter.bleOnToOff(mContext.getAttributionSource()); } catch (RemoteException e) { Log.e(TAG, "Unable to call bleOnToOff()", e); } } private void broadcastIntentStateChange(String action, int prevState, int newState) { Log.d( TAG, Loading