summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author William Escande <wescande@google.com> 2024-08-15 02:09:28 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2024-08-15 02:09:28 +0000
commit8ba42e6bbb0fa94edab18e61c0ecbd7e7a54c7d7 (patch)
tree942e4b174e0c8fcd0ef3adff9c1222b8c37efe52
parentffb2cac39600d3604f703b77c0e84b8b69c91c5a (diff)
parentde91e69b8f869f1eee62644679b805399127b9ab (diff)
Merge "SystemServer: One unique method to call StopBle" into main
-rw-r--r--android/app/aidl/android/bluetooth/IBluetooth.aidl4
-rw-r--r--android/app/src/com/android/bluetooth/btservice/AdapterService.java9
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java8
-rw-r--r--service/src/AdapterBinder.kt4
-rw-r--r--service/src/com/android/server/bluetooth/BluetoothManagerService.java48
5 files changed, 37 insertions, 36 deletions
diff --git a/android/app/aidl/android/bluetooth/IBluetooth.aidl b/android/app/aidl/android/bluetooth/IBluetooth.aidl
index c8e613063b..c950d1dbbe 100644
--- a/android/app/aidl/android/bluetooth/IBluetooth.aidl
+++ b/android/app/aidl/android/bluetooth/IBluetooth.aidl
@@ -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);
diff --git a/android/app/src/com/android/bluetooth/btservice/AdapterService.java b/android/app/src/com/android/bluetooth/btservice/AdapterService.java
index 2e2be81f77..95c02297b9 100644
--- a/android/app/src/com/android/bluetooth/btservice/AdapterService.java
+++ b/android/app/src/com/android/bluetooth/btservice/AdapterService.java
@@ -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
@@ -5767,7 +5766,7 @@ public class AdapterService extends Service {
}
@VisibleForTesting
- void stopBle() {
+ void bleOnToOff() {
mAdapterStateMachine.sendMessage(AdapterState.BLE_TURN_OFF);
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java
index fe2b47d932..9e76b9daea 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java
@@ -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);
@@ -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();
@@ -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);
@@ -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);
diff --git a/service/src/AdapterBinder.kt b/service/src/AdapterBinder.kt
index 565281f79c..403cce039d 100644
--- a/service/src/AdapterBinder.kt
+++ b/service/src/AdapterBinder.kt
@@ -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)
diff --git a/service/src/com/android/server/bluetooth/BluetoothManagerService.java b/service/src/com/android/server/bluetooth/BluetoothManagerService.java
index b8bcd17270..b76a5c983a 100644
--- a/service/src/com/android/server/bluetooth/BluetoothManagerService.java
+++ b/service/src/com/android/server/bluetooth/BluetoothManagerService.java
@@ -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();
}
@@ -417,14 +415,13 @@ class BluetoothManagerService {
// If currentState is BLE_ON make sure we trigger stopBle
mAdapterLock.readLock().lock();
try {
- if (mAdapter != null) {
- mEnable = false;
- mEnableExternal = false;
- ActiveLogs.add(reason, false);
- mAdapter.stopBle(mContext.getAttributionSource());
+ if (mAdapter == null) {
+ return;
}
- } catch (RemoteException e) {
- Log.e(TAG, "Unable to call stopBle", e);
+ mEnable = false;
+ mEnableExternal = false;
+ ActiveLogs.add(reason, false);
+ bleOnToOff();
} finally {
mAdapterLock.readLock().unlock();
}
@@ -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();
}
@@ -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");
}
@@ -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();
}
@@ -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()) {
@@ -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);
@@ -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,