Loading android/app/aidl/android/bluetooth/IBluetooth.aidl +2 −2 Original line number Original line Diff line number Diff line Loading @@ -52,8 +52,8 @@ interface IBluetooth @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)") @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)") oneway void offToBleOn(boolean quietMode, in AttributionSource attributionSource); oneway void offToBleOn(boolean quietMode, in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)") @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)") oneway void disable(in AttributionSource attributionSource); oneway void onToBleOn(in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.LOCAL_MAC_ADDRESS})") @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.LOCAL_MAC_ADDRESS})") String getAddress(in AttributionSource attributionSource); String getAddress(in AttributionSource attributionSource); Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +7 −7 Original line number Original line Diff line number Diff line Loading @@ -2317,16 +2317,16 @@ public class AdapterService extends Service { } } @Override @Override public void disable(AttributionSource source) { public void onToBleOn(AttributionSource source) { AdapterService service = getService(); AdapterService service = getService(); if (service == null if (service == null || !callerIsSystemOrActiveOrManagedUser(service, TAG, "disable") || !callerIsSystemOrActiveOrManagedUser(service, TAG, "onToBleOn")) { || !Utils.checkConnectPermissionForDataDelivery( service, source, "AdapterService disable")) { return; return; } } service.disable(); service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null); service.onToBleOn(); } } @Override @Override Loading Loading @@ -4628,8 +4628,8 @@ public class AdapterService extends Service { mAdapterStateMachine.sendMessage(AdapterState.BLE_TURN_ON); mAdapterStateMachine.sendMessage(AdapterState.BLE_TURN_ON); } } void disable() { void onToBleOn() { Log.d(TAG, "disable() called with mRunningProfiles.size() = " + mRunningProfiles.size()); Log.d(TAG, "onToBleOn() called with mRunningProfiles.size() = " + mRunningProfiles.size()); mAdapterStateMachine.sendMessage(AdapterState.USER_TURN_OFF); mAdapterStateMachine.sendMessage(AdapterState.USER_TURN_OFF); } } Loading android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java +3 −3 Original line number Original line Diff line number Diff line Loading @@ -435,7 +435,7 @@ public class AdapterServiceTest { IBluetoothCallback callback, IBluetoothCallback callback, boolean onlyGatt, boolean onlyGatt, List<ProfileService> services) { List<ProfileService> services) { adapter.disable(); adapter.onToBleOn(); TestUtils.syncHandler(looper, AdapterState.USER_TURN_OFF); TestUtils.syncHandler(looper, AdapterState.USER_TURN_OFF); verifyStateChange(callback, STATE_ON, STATE_TURNING_OFF); verifyStateChange(callback, STATE_ON, STATE_TURNING_OFF); Loading Loading @@ -789,7 +789,7 @@ public class AdapterServiceTest { assertThat(mAdapterService.getState()).isEqualTo(STATE_ON); assertThat(mAdapterService.getState()).isEqualTo(STATE_ON); mAdapterService.disable(); mAdapterService.onToBleOn(); TestUtils.syncHandler(mLooper, AdapterState.USER_TURN_OFF); TestUtils.syncHandler(mLooper, AdapterState.USER_TURN_OFF); verifyStateChange(callback, STATE_ON, STATE_TURNING_OFF); verifyStateChange(callback, STATE_ON, STATE_TURNING_OFF); Loading Loading @@ -858,7 +858,7 @@ public class AdapterServiceTest { public void testProfileStopTimeout() { public void testProfileStopTimeout() { doEnable(false); doEnable(false); mAdapterService.disable(); mAdapterService.onToBleOn(); syncHandler(AdapterState.USER_TURN_OFF); syncHandler(AdapterState.USER_TURN_OFF); verifyStateChange(STATE_ON, STATE_TURNING_OFF); verifyStateChange(STATE_ON, STATE_TURNING_OFF); assertThat(mAdapterService.mSetProfileServiceStateCounter).isEqualTo(4); assertThat(mAdapterService.mSetProfileServiceStateCounter).isEqualTo(4); Loading service/src/AdapterBinder.kt +2 −2 Original line number Original line Diff line number Diff line Loading @@ -34,8 +34,8 @@ class AdapterBinder(rawBinder: IBinder) { "]" "]" @Throws(RemoteException::class) @Throws(RemoteException::class) fun disable(source: AttributionSource) { fun onToBleOn(source: AttributionSource) { adapterBinder.disable(source) adapterBinder.onToBleOn(source) } } @Throws(RemoteException::class) @Throws(RemoteException::class) Loading service/src/com/android/server/bluetooth/BluetoothManagerService.java +25 −24 Original line number Original line Diff line number Diff line Loading @@ -273,7 +273,7 @@ class BluetoothManagerService { return true; return true; } else if (state == STATE_ON) { } else if (state == STATE_ON) { ActiveLogs.add(ENABLE_DISABLE_REASON_FACTORY_RESET, false); ActiveLogs.add(ENABLE_DISABLE_REASON_FACTORY_RESET, false); mAdapter.disable(mContext.getAttributionSource()); onToBleOn(); return true; return true; } } } catch (RemoteException e) { } catch (RemoteException e) { Loading Loading @@ -404,13 +404,12 @@ class BluetoothManagerService { if (currentState == STATE_ON) { if (currentState == STATE_ON) { mAdapterLock.readLock().lock(); mAdapterLock.readLock().lock(); try { try { if (mAdapter != null) { if (mAdapter == null) { return; } mEnable = false; mEnable = false; ActiveLogs.add(reason, false); ActiveLogs.add(reason, false); mAdapter.disable(mContext.getAttributionSource()); onToBleOn(); } } catch (RemoteException e) { Log.e(TAG, "Unable to call disable", e); } finally { } finally { mAdapterLock.readLock().unlock(); mAdapterLock.readLock().unlock(); } } Loading Loading @@ -547,10 +546,13 @@ class BluetoothManagerService { try { try { mEnable = false; mEnable = false; mEnableExternal = false; mEnableExternal = false; if (mAdapter != null && mState.oneOf(STATE_BLE_ON)) { if (mAdapter == null) { return; } if (mState.oneOf(STATE_BLE_ON)) { mAdapter.stopBle(mContext.getAttributionSource()); mAdapter.stopBle(mContext.getAttributionSource()); } else if (mAdapter != null && mState.oneOf(STATE_ON)) { } else if (mState.oneOf(STATE_ON)) { mAdapter.disable(mContext.getAttributionSource()); onToBleOn(); } } } catch (RemoteException e) { } catch (RemoteException e) { Log.e(TAG, "Unable to shutdown Bluetooth", e); Log.e(TAG, "Unable to shutdown Bluetooth", e); Loading Loading @@ -1580,7 +1582,7 @@ class BluetoothManagerService { // should move forward to the next step. // should move forward to the next step. mWaitForDisableRetry = 0; mWaitForDisableRetry = 0; mEnable = false; mEnable = false; handleDisable(); onToBleOn(); // Wait for state exiting STATE_ON // Wait for state exiting STATE_ON Message disableDelayedMsg = Message disableDelayedMsg = mHandler.obtainMessage(MESSAGE_HANDLE_DISABLE_DELAYED, 1, 0); mHandler.obtainMessage(MESSAGE_HANDLE_DISABLE_DELAYED, 1, 0); Loading Loading @@ -1670,7 +1672,7 @@ class BluetoothManagerService { if (!mEnable) { if (!mEnable) { waitForState(STATE_ON); waitForState(STATE_ON); handleDisable(); onToBleOn(); waitForState( waitForState( STATE_OFF, STATE_OFF, STATE_TURNING_ON, STATE_TURNING_ON, Loading Loading @@ -1851,7 +1853,7 @@ class BluetoothManagerService { // disable // disable ActiveLogs.add(ENABLE_DISABLE_REASON_USER_SWITCH, false); ActiveLogs.add(ENABLE_DISABLE_REASON_USER_SWITCH, false); handleDisable(); onToBleOn(); // Pbap service need receive STATE_TURNING_OFF intent to close // Pbap service need receive STATE_TURNING_OFF intent to close bluetoothStateChangeHandler(STATE_ON, STATE_TURNING_OFF); bluetoothStateChangeHandler(STATE_ON, STATE_TURNING_OFF); Loading Loading @@ -1979,7 +1981,7 @@ class BluetoothManagerService { MESSAGE_HANDLE_DISABLE_DELAYED, ENABLE_DISABLE_DELAY_MS); MESSAGE_HANDLE_DISABLE_DELAYED, ENABLE_DISABLE_DELAY_MS); } else { } else { mEnable = false; mEnable = false; handleDisable(); onToBleOn(); } } } } Loading Loading @@ -2032,17 +2034,16 @@ class BluetoothManagerService { } } } } private void handleDisable() { private void onToBleOn() { mAdapterLock.readLock().lock(); if (!mState.oneOf(STATE_ON)) { try { Log.d(TAG, "onToBleOn: Impossible transition from " + mState); if (mAdapter != null) { return; Log.d(TAG, "handleDisable: Sending off request."); mAdapter.disable(mContext.getAttributionSource()); } } Log.d(TAG, "onToBleOn: Sending request"); try { mAdapter.onToBleOn(mContext.getAttributionSource()); } catch (RemoteException e) { } catch (RemoteException e) { Log.e(TAG, "Unable to call disable()", e); Log.e(TAG, "Unable to call onToBleOn()", e); } finally { mAdapterLock.readLock().unlock(); } } } } Loading Loading @@ -2180,7 +2181,7 @@ class BluetoothManagerService { // disable // disable ActiveLogs.add(ENABLE_DISABLE_REASON_START_ERROR, false); ActiveLogs.add(ENABLE_DISABLE_REASON_START_ERROR, false); handleDisable(); onToBleOn(); waitForState(STATE_OFF); waitForState(STATE_OFF); Loading Loading
android/app/aidl/android/bluetooth/IBluetooth.aidl +2 −2 Original line number Original line Diff line number Diff line Loading @@ -52,8 +52,8 @@ interface IBluetooth @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)") @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)") oneway void offToBleOn(boolean quietMode, in AttributionSource attributionSource); oneway void offToBleOn(boolean quietMode, in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)") @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)") oneway void disable(in AttributionSource attributionSource); oneway void onToBleOn(in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.LOCAL_MAC_ADDRESS})") @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.LOCAL_MAC_ADDRESS})") String getAddress(in AttributionSource attributionSource); String getAddress(in AttributionSource attributionSource); Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +7 −7 Original line number Original line Diff line number Diff line Loading @@ -2317,16 +2317,16 @@ public class AdapterService extends Service { } } @Override @Override public void disable(AttributionSource source) { public void onToBleOn(AttributionSource source) { AdapterService service = getService(); AdapterService service = getService(); if (service == null if (service == null || !callerIsSystemOrActiveOrManagedUser(service, TAG, "disable") || !callerIsSystemOrActiveOrManagedUser(service, TAG, "onToBleOn")) { || !Utils.checkConnectPermissionForDataDelivery( service, source, "AdapterService disable")) { return; return; } } service.disable(); service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null); service.onToBleOn(); } } @Override @Override Loading Loading @@ -4628,8 +4628,8 @@ public class AdapterService extends Service { mAdapterStateMachine.sendMessage(AdapterState.BLE_TURN_ON); mAdapterStateMachine.sendMessage(AdapterState.BLE_TURN_ON); } } void disable() { void onToBleOn() { Log.d(TAG, "disable() called with mRunningProfiles.size() = " + mRunningProfiles.size()); Log.d(TAG, "onToBleOn() called with mRunningProfiles.size() = " + mRunningProfiles.size()); mAdapterStateMachine.sendMessage(AdapterState.USER_TURN_OFF); mAdapterStateMachine.sendMessage(AdapterState.USER_TURN_OFF); } } Loading
android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java +3 −3 Original line number Original line Diff line number Diff line Loading @@ -435,7 +435,7 @@ public class AdapterServiceTest { IBluetoothCallback callback, IBluetoothCallback callback, boolean onlyGatt, boolean onlyGatt, List<ProfileService> services) { List<ProfileService> services) { adapter.disable(); adapter.onToBleOn(); TestUtils.syncHandler(looper, AdapterState.USER_TURN_OFF); TestUtils.syncHandler(looper, AdapterState.USER_TURN_OFF); verifyStateChange(callback, STATE_ON, STATE_TURNING_OFF); verifyStateChange(callback, STATE_ON, STATE_TURNING_OFF); Loading Loading @@ -789,7 +789,7 @@ public class AdapterServiceTest { assertThat(mAdapterService.getState()).isEqualTo(STATE_ON); assertThat(mAdapterService.getState()).isEqualTo(STATE_ON); mAdapterService.disable(); mAdapterService.onToBleOn(); TestUtils.syncHandler(mLooper, AdapterState.USER_TURN_OFF); TestUtils.syncHandler(mLooper, AdapterState.USER_TURN_OFF); verifyStateChange(callback, STATE_ON, STATE_TURNING_OFF); verifyStateChange(callback, STATE_ON, STATE_TURNING_OFF); Loading Loading @@ -858,7 +858,7 @@ public class AdapterServiceTest { public void testProfileStopTimeout() { public void testProfileStopTimeout() { doEnable(false); doEnable(false); mAdapterService.disable(); mAdapterService.onToBleOn(); syncHandler(AdapterState.USER_TURN_OFF); syncHandler(AdapterState.USER_TURN_OFF); verifyStateChange(STATE_ON, STATE_TURNING_OFF); verifyStateChange(STATE_ON, STATE_TURNING_OFF); assertThat(mAdapterService.mSetProfileServiceStateCounter).isEqualTo(4); assertThat(mAdapterService.mSetProfileServiceStateCounter).isEqualTo(4); Loading
service/src/AdapterBinder.kt +2 −2 Original line number Original line Diff line number Diff line Loading @@ -34,8 +34,8 @@ class AdapterBinder(rawBinder: IBinder) { "]" "]" @Throws(RemoteException::class) @Throws(RemoteException::class) fun disable(source: AttributionSource) { fun onToBleOn(source: AttributionSource) { adapterBinder.disable(source) adapterBinder.onToBleOn(source) } } @Throws(RemoteException::class) @Throws(RemoteException::class) Loading
service/src/com/android/server/bluetooth/BluetoothManagerService.java +25 −24 Original line number Original line Diff line number Diff line Loading @@ -273,7 +273,7 @@ class BluetoothManagerService { return true; return true; } else if (state == STATE_ON) { } else if (state == STATE_ON) { ActiveLogs.add(ENABLE_DISABLE_REASON_FACTORY_RESET, false); ActiveLogs.add(ENABLE_DISABLE_REASON_FACTORY_RESET, false); mAdapter.disable(mContext.getAttributionSource()); onToBleOn(); return true; return true; } } } catch (RemoteException e) { } catch (RemoteException e) { Loading Loading @@ -404,13 +404,12 @@ class BluetoothManagerService { if (currentState == STATE_ON) { if (currentState == STATE_ON) { mAdapterLock.readLock().lock(); mAdapterLock.readLock().lock(); try { try { if (mAdapter != null) { if (mAdapter == null) { return; } mEnable = false; mEnable = false; ActiveLogs.add(reason, false); ActiveLogs.add(reason, false); mAdapter.disable(mContext.getAttributionSource()); onToBleOn(); } } catch (RemoteException e) { Log.e(TAG, "Unable to call disable", e); } finally { } finally { mAdapterLock.readLock().unlock(); mAdapterLock.readLock().unlock(); } } Loading Loading @@ -547,10 +546,13 @@ class BluetoothManagerService { try { try { mEnable = false; mEnable = false; mEnableExternal = false; mEnableExternal = false; if (mAdapter != null && mState.oneOf(STATE_BLE_ON)) { if (mAdapter == null) { return; } if (mState.oneOf(STATE_BLE_ON)) { mAdapter.stopBle(mContext.getAttributionSource()); mAdapter.stopBle(mContext.getAttributionSource()); } else if (mAdapter != null && mState.oneOf(STATE_ON)) { } else if (mState.oneOf(STATE_ON)) { mAdapter.disable(mContext.getAttributionSource()); onToBleOn(); } } } catch (RemoteException e) { } catch (RemoteException e) { Log.e(TAG, "Unable to shutdown Bluetooth", e); Log.e(TAG, "Unable to shutdown Bluetooth", e); Loading Loading @@ -1580,7 +1582,7 @@ class BluetoothManagerService { // should move forward to the next step. // should move forward to the next step. mWaitForDisableRetry = 0; mWaitForDisableRetry = 0; mEnable = false; mEnable = false; handleDisable(); onToBleOn(); // Wait for state exiting STATE_ON // Wait for state exiting STATE_ON Message disableDelayedMsg = Message disableDelayedMsg = mHandler.obtainMessage(MESSAGE_HANDLE_DISABLE_DELAYED, 1, 0); mHandler.obtainMessage(MESSAGE_HANDLE_DISABLE_DELAYED, 1, 0); Loading Loading @@ -1670,7 +1672,7 @@ class BluetoothManagerService { if (!mEnable) { if (!mEnable) { waitForState(STATE_ON); waitForState(STATE_ON); handleDisable(); onToBleOn(); waitForState( waitForState( STATE_OFF, STATE_OFF, STATE_TURNING_ON, STATE_TURNING_ON, Loading Loading @@ -1851,7 +1853,7 @@ class BluetoothManagerService { // disable // disable ActiveLogs.add(ENABLE_DISABLE_REASON_USER_SWITCH, false); ActiveLogs.add(ENABLE_DISABLE_REASON_USER_SWITCH, false); handleDisable(); onToBleOn(); // Pbap service need receive STATE_TURNING_OFF intent to close // Pbap service need receive STATE_TURNING_OFF intent to close bluetoothStateChangeHandler(STATE_ON, STATE_TURNING_OFF); bluetoothStateChangeHandler(STATE_ON, STATE_TURNING_OFF); Loading Loading @@ -1979,7 +1981,7 @@ class BluetoothManagerService { MESSAGE_HANDLE_DISABLE_DELAYED, ENABLE_DISABLE_DELAY_MS); MESSAGE_HANDLE_DISABLE_DELAYED, ENABLE_DISABLE_DELAY_MS); } else { } else { mEnable = false; mEnable = false; handleDisable(); onToBleOn(); } } } } Loading Loading @@ -2032,17 +2034,16 @@ class BluetoothManagerService { } } } } private void handleDisable() { private void onToBleOn() { mAdapterLock.readLock().lock(); if (!mState.oneOf(STATE_ON)) { try { Log.d(TAG, "onToBleOn: Impossible transition from " + mState); if (mAdapter != null) { return; Log.d(TAG, "handleDisable: Sending off request."); mAdapter.disable(mContext.getAttributionSource()); } } Log.d(TAG, "onToBleOn: Sending request"); try { mAdapter.onToBleOn(mContext.getAttributionSource()); } catch (RemoteException e) { } catch (RemoteException e) { Log.e(TAG, "Unable to call disable()", e); Log.e(TAG, "Unable to call onToBleOn()", e); } finally { mAdapterLock.readLock().unlock(); } } } } Loading Loading @@ -2180,7 +2181,7 @@ class BluetoothManagerService { // disable // disable ActiveLogs.add(ENABLE_DISABLE_REASON_START_ERROR, false); ActiveLogs.add(ENABLE_DISABLE_REASON_START_ERROR, false); handleDisable(); onToBleOn(); waitForState(STATE_OFF); waitForState(STATE_OFF); Loading