SystemServer: Uniformize binder
Between the SystemServer and the Bluetooth app, we don't need to use an
attribution source, and we also don't need to enforce connect on top of
BLUETOOTH_PRIVILEGED
Bug: 416075285
Test: m .
Flag: EXEMPT refactor
Change-Id: Ic1562411dbfc6db6af6adde69f209546be09b0f7
diff --git a/android/app/aidl/android/bluetooth/IAdapter.aidl b/android/app/aidl/android/bluetooth/IAdapter.aidl
index c936e26..22f7321 100644
--- a/android/app/aidl/android/bluetooth/IAdapter.aidl
+++ b/android/app/aidl/android/bluetooth/IAdapter.aidl
@@ -24,30 +24,30 @@
interface IAdapter
{
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
- oneway void offToBleOn(boolean quietMode, in String hciInstanceName, in AttributionSource attributionSource);
+ oneway void offToBleOn(boolean quietMode, in String hciInstanceName);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
- oneway void onToBleOn(in AttributionSource attributionSource);
+ oneway void onToBleOn();
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
- oneway void bleOnToOn(in AttributionSource attributionSource);
+ oneway void bleOnToOn();
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
- oneway void bleOnToOff(in AttributionSource attributionSource);
+ oneway void bleOnToOff();
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- oneway void registerCallback(in IBluetoothCallback callback, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- oneway void unregisterCallback(in IBluetoothCallback callback, in AttributionSource attributionSource);
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
+ oneway void registerCallback(in IBluetoothCallback callback);
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
+ oneway void unregisterCallback(in IBluetoothCallback callback);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- oneway void setForegroundUserId(in int userId, in AttributionSource attributionSource);
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
+ oneway void setForegroundUserId(in int userId);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
oneway void onewayFactoryReset();
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- boolean isMediaProfileConnected(in AttributionSource attributionSource);
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
+ boolean isMediaProfileConnected();
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
- oneway void unregAllGattClient(in AttributionSource attributionSource);
+ oneway void unregAllGattClient();
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
oneway void killBluetoothProcess();
diff --git a/android/app/src/com/android/bluetooth/btservice/AdapterBinder.java b/android/app/src/com/android/bluetooth/btservice/AdapterBinder.java
index 5d933b2..c1eaedd 100644
--- a/android/app/src/com/android/bluetooth/btservice/AdapterBinder.java
+++ b/android/app/src/com/android/bluetooth/btservice/AdapterBinder.java
@@ -20,11 +20,9 @@
import static android.Manifest.permission.DUMP;
import static com.android.bluetooth.Utils.callerIsSystemOrActiveOrManagedUser;
-import static com.android.bluetooth.Utils.checkConnectPermissionForDataDelivery;
import android.bluetooth.IAdapter;
import android.bluetooth.IBluetoothCallback;
-import android.content.AttributionSource;
import android.os.Process;
import android.util.Log;
@@ -86,7 +84,7 @@
}
@Override
- public void offToBleOn(boolean quietMode, String hciInstanceName, AttributionSource source) {
+ public void offToBleOn(boolean quietMode, String hciInstanceName) {
AdapterService service = getService();
if (service == null || !callerIsSystemOrActiveOrManagedUser(service, TAG, "offToBleOn")) {
return;
@@ -97,7 +95,7 @@
}
@Override
- public void onToBleOn(AttributionSource source) {
+ public void onToBleOn() {
AdapterService service = getService();
if (service == null || !callerIsSystemOrActiveOrManagedUser(service, TAG, "onToBleOn")) {
return;
@@ -119,12 +117,10 @@
}
@Override
- public void registerCallback(IBluetoothCallback callback, AttributionSource source) {
+ public void registerCallback(IBluetoothCallback callback) {
AdapterService service = getService();
if (service == null
- || !callerIsSystemOrActiveOrManagedUser(service, TAG, "registerCallback")
- || !checkConnectPermissionForDataDelivery(
- service, source, TAG, "registerCallback")) {
+ || !callerIsSystemOrActiveOrManagedUser(service, TAG, "registerCallback")) {
return;
}
@@ -133,12 +129,10 @@
}
@Override
- public void unregisterCallback(IBluetoothCallback callback, AttributionSource source) {
+ public void unregisterCallback(IBluetoothCallback callback) {
AdapterService service = getService();
if (service == null
- || !callerIsSystemOrActiveOrManagedUser(service, TAG, "unregisterCallback")
- || !checkConnectPermissionForDataDelivery(
- service, source, TAG, "unregisterCallback")) {
+ || !callerIsSystemOrActiveOrManagedUser(service, TAG, "unregisterCallback")) {
return;
}
@@ -147,7 +141,7 @@
}
@Override
- public void bleOnToOn(AttributionSource source) {
+ public void bleOnToOn() {
AdapterService service = getService();
if (service == null || !callerIsSystemOrActiveOrManagedUser(service, TAG, "bleOnToOn")) {
return;
@@ -158,7 +152,7 @@
}
@Override
- public void bleOnToOff(AttributionSource source) {
+ public void bleOnToOff() {
AdapterService service = getService();
if (service == null || !callerIsSystemOrActiveOrManagedUser(service, TAG, "bleOnToOff")) {
return;
@@ -182,11 +176,9 @@
}
@Override
- public boolean isMediaProfileConnected(AttributionSource source) {
+ public boolean isMediaProfileConnected() {
AdapterService service = getService();
- if (service == null
- || !checkConnectPermissionForDataDelivery(
- service, source, TAG, "isMediaProfileConnected")) {
+ if (service == null) {
return false;
}
@@ -195,14 +187,9 @@
}
@Override
- public void setForegroundUserId(int userId, AttributionSource source) {
+ public void setForegroundUserId(int userId) {
AdapterService service = getService();
- if (service == null
- || !checkConnectPermissionForDataDelivery(
- service,
- Utils.getCallingAttributionSource(mService),
- TAG,
- "setForegroundUserId")) {
+ if (service == null) {
return;
}
@@ -211,12 +198,12 @@
}
@Override
- public void unregAllGattClient(AttributionSource source) {
+ public void unregAllGattClient() {
AdapterService service = getService();
if (service == null) {
return;
}
service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);
- service.unregAllGattClient(source);
+ service.unregAllGattClient();
}
}
diff --git a/android/app/src/com/android/bluetooth/btservice/AdapterService.java b/android/app/src/com/android/bluetooth/btservice/AdapterService.java
index 7178782..a41434b 100644
--- a/android/app/src/com/android/bluetooth/btservice/AdapterService.java
+++ b/android/app/src/com/android/bluetooth/btservice/AdapterService.java
@@ -4177,9 +4177,9 @@
return mGattService == null ? null : mGattService.getDistanceMeasurement();
}
- void unregAllGattClient(AttributionSource source) {
+ void unregAllGattClient() {
if (mGattService != null) {
- mGattService.unregAll(source);
+ mGattService.unregAll();
}
}
diff --git a/android/app/src/com/android/bluetooth/gatt/GattService.java b/android/app/src/com/android/bluetooth/gatt/GattService.java
index 89a6ab3..9efab0a 100644
--- a/android/app/src/com/android/bluetooth/gatt/GattService.java
+++ b/android/app/src/com/android/bluetooth/gatt/GattService.java
@@ -823,10 +823,11 @@
}
}
- public void unregAll(AttributionSource source) {
+ public void unregAll() {
for (IBluetoothGattCallback appId : mClientMap.getAllAppsCallbackId()) {
Log.d(TAG, "unreg:" + appId);
- unregisterClient(appId, source, ContextMap.RemoveReason.REASON_UNREGISTER_ALL);
+ unregisterClient(
+ appId, getAttributionSource(), ContextMap.RemoveReason.REASON_UNREGISTER_ALL);
}
for (IBluetoothGattServerCallback appId : mServerMap.getAllAppsCallbackId()) {
Log.d(TAG, "unreg:" + appId);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/gatt/GattServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/gatt/GattServiceTest.java
index 70c83de..cf1c877 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/gatt/GattServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/gatt/GattServiceTest.java
@@ -665,7 +665,7 @@
callbacks.add(callback);
doReturn(callbacks).when(mClientMap).getAllAppsCallbackId();
- mService.unregAll(mAttributionSource);
+ mService.unregAll();
verify(mClientMap).remove(appId, ContextMap.RemoveReason.REASON_UNREGISTER_ALL);
verify(mNativeInterface).gattClientUnregisterApp(appId);
}
diff --git a/service/src/AdapterBinder.kt b/service/src/AdapterBinder.kt
index 8557f79..f46bd5d 100644
--- a/service/src/AdapterBinder.kt
+++ b/service/src/AdapterBinder.kt
@@ -18,7 +18,6 @@
import android.bluetooth.IAdapter
import android.bluetooth.IBluetoothCallback
-import android.content.AttributionSource
import android.os.IBinder
import android.os.RemoteException
@@ -36,43 +35,43 @@
"]"
@Throws(RemoteException::class)
- fun onToBleOn(source: AttributionSource) {
- adapterBinder.onToBleOn(source)
+ fun onToBleOn() {
+ adapterBinder.onToBleOn()
}
@Throws(RemoteException::class)
- fun offToBleOn(quietMode: Boolean, hciInstanceName: String, source: AttributionSource) {
- adapterBinder.offToBleOn(quietMode, hciInstanceName, source)
+ fun offToBleOn(quietMode: Boolean, hciInstanceName: String) {
+ adapterBinder.offToBleOn(quietMode, hciInstanceName)
}
@Throws(RemoteException::class)
- fun bleOnToOff(source: AttributionSource) {
- adapterBinder.bleOnToOff(source)
+ fun bleOnToOff() {
+ adapterBinder.bleOnToOff()
}
@Throws(RemoteException::class)
- fun bleOnToOn(source: AttributionSource) {
- adapterBinder.bleOnToOn(source)
+ fun bleOnToOn() {
+ adapterBinder.bleOnToOn()
}
@Throws(RemoteException::class)
- fun registerCallback(callback: IBluetoothCallback, source: AttributionSource) {
- adapterBinder.registerCallback(callback, source)
+ fun registerCallback(callback: IBluetoothCallback) {
+ adapterBinder.registerCallback(callback)
}
@Throws(RemoteException::class)
- fun unregisterCallback(callback: IBluetoothCallback, source: AttributionSource) {
- adapterBinder.unregisterCallback(callback, source)
+ fun unregisterCallback(callback: IBluetoothCallback) {
+ adapterBinder.unregisterCallback(callback)
}
@Throws(RemoteException::class)
- fun setForegroundUserId(userId: Int, source: AttributionSource) {
- adapterBinder.setForegroundUserId(userId, source)
+ fun setForegroundUserId(userId: Int) {
+ adapterBinder.setForegroundUserId(userId)
}
@Throws(RemoteException::class)
- fun unregAllGattClient(source: AttributionSource) {
- adapterBinder.unregAllGattClient(source)
+ fun unregAllGattClient() {
+ adapterBinder.unregAllGattClient()
}
@Throws(RemoteException::class)
@@ -80,9 +79,9 @@
adapterBinder.onewayFactoryReset()
}
- fun isMediaProfileConnected(source: AttributionSource): Boolean {
+ fun isMediaProfileConnected(): Boolean {
try {
- return adapterBinder.isMediaProfileConnected(source)
+ return adapterBinder.isMediaProfileConnected()
} catch (ex: RemoteException) {
Log.e(TAG, "Error when calling isMediaProfileConnected", ex)
}
diff --git a/service/src/com/android/server/bluetooth/BluetoothManagerService.java b/service/src/com/android/server/bluetooth/BluetoothManagerService.java
index ac7ccd1..8461109 100644
--- a/service/src/com/android/server/bluetooth/BluetoothManagerService.java
+++ b/service/src/com/android/server/bluetooth/BluetoothManagerService.java
@@ -807,7 +807,7 @@
return;
}
try {
- mAdapter.setForegroundUserId(userId, mContext.getAttributionSource());
+ mAdapter.setForegroundUserId(userId);
} catch (RemoteException e) {
Log.e(TAG, "Unable to set foreground user id", e);
}
@@ -883,7 +883,7 @@
if (!mState.oneOf(STATE_ON)) {
return false;
}
- return mAdapter.isMediaProfileConnected(mContext.getAttributionSource());
+ return mAdapter.isMediaProfileConnected();
}
// Disable ble scan only mode.
@@ -1085,7 +1085,7 @@
// Need to stay at BLE ON. Disconnect all Gatt connections
Log.i(TAG, "sendBrEdrDownCallback: Staying in BLE_ON");
try {
- mAdapter.unregAllGattClient(mContext.getAttributionSource());
+ mAdapter.unregAllGattClient();
} catch (RemoteException e) {
Log.e(TAG, "sendBrEdrDownCallback: failed to call unregAllGattClient()", e);
}
@@ -1220,7 +1220,7 @@
long currentTimeMs = System.currentTimeMillis();
try {
- mAdapter.unregisterCallback(mBluetoothCallback, mContext.getAttributionSource());
+ mAdapter.unregisterCallback(mBluetoothCallback);
} catch (RemoteException e) {
Log.e(TAG, "unbindAndFinish(): Unable to unregister BluetoothCallback", e);
}
@@ -1477,8 +1477,7 @@
propagateForegroundUserId(ActivityManager.getCurrentUser());
try {
- mAdapter.registerCallback(
- mBluetoothCallback, mContext.getAttributionSource());
+ mAdapter.registerCallback(mBluetoothCallback);
} catch (RemoteException e) {
Log.e(TAG, "Unable to register BluetoothCallback", e);
}
@@ -1649,7 +1648,7 @@
private void restartForNewUser(UserHandle unusedNewUser) {
try {
- mAdapter.unregisterCallback(mBluetoothCallback, mContext.getAttributionSource());
+ mAdapter.unregisterCallback(mBluetoothCallback);
} catch (RemoteException e) {
Log.e(TAG, "Unable to unregister", e);
}
@@ -1928,7 +1927,7 @@
}
Log.d(TAG, "offToBleOn: Sending request hciInstanceName " + hciInstanceName);
try {
- mAdapter.offToBleOn(mQuietEnable, hciInstanceName, mContext.getAttributionSource());
+ mAdapter.offToBleOn(mQuietEnable, hciInstanceName);
} catch (RemoteException e) {
Log.e(TAG, "Unable to call offToBleOn()", e);
}
@@ -1942,7 +1941,7 @@
}
Log.d(TAG, "onToBleOn: Sending request");
try {
- mAdapter.onToBleOn(mContext.getAttributionSource());
+ mAdapter.onToBleOn();
} catch (RemoteException e) {
Log.e(TAG, "Unable to call onToBleOn()", e);
}
@@ -1956,7 +1955,7 @@
}
Log.d(TAG, "bleOnToOn: sending request");
try {
- mAdapter.bleOnToOn(mContext.getAttributionSource());
+ mAdapter.bleOnToOn();
} catch (RemoteException e) {
Log.e(TAG, "Unable to call bleOnToOn()", e);
}
@@ -1970,7 +1969,7 @@
}
Log.d(TAG, "bleOnToOff: Sending request");
try {
- mAdapter.bleOnToOff(mContext.getAttributionSource());
+ mAdapter.bleOnToOff();
} catch (RemoteException e) {
Log.e(TAG, "Unable to call bleOnToOff()", e);
}
@@ -2113,7 +2112,7 @@
if (mAdapter != null) {
try {
- mAdapter.unregisterCallback(mBluetoothCallback, mContext.getAttributionSource());
+ mAdapter.unregisterCallback(mBluetoothCallback);
} catch (RemoteException e) {
Log.e(TAG, "Unable to unregister", e);
}
diff --git a/service/tests/src/com/android/server/bluetooth/BluetoothManagerServiceTest.java b/service/tests/src/com/android/server/bluetooth/BluetoothManagerServiceTest.java
index 076ce25..8241eaa 100644
--- a/service/tests/src/com/android/server/bluetooth/BluetoothManagerServiceTest.java
+++ b/service/tests/src/com/android/server/bluetooth/BluetoothManagerServiceTest.java
@@ -412,7 +412,7 @@
private IBluetoothCallback captureBluetoothCallback() throws Exception {
ArgumentCaptor<IBluetoothCallback> captor =
ArgumentCaptor.forClass(IBluetoothCallback.class);
- mInOrder.verify(mAdapterBinder).registerCallback(captor.capture(), any());
+ mInOrder.verify(mAdapterBinder).registerCallback(captor.capture());
assertThat(captor.getAllValues()).hasSize(1);
return captor.getValue();
}
@@ -422,7 +422,7 @@
acceptBluetoothBinding();
IBluetoothCallback btCallback = captureBluetoothCallback();
- mInOrder.verify(mAdapterBinder).offToBleOn(anyBoolean(), anyString(), any());
+ mInOrder.verify(mAdapterBinder).offToBleOn(anyBoolean(), anyString());
verifyBleStateIntentSent(STATE_OFF, STATE_BLE_TURNING_ON);
btCallback.setAdapterServiceBinder(mBinder);
syncHandler(0); // To post setAdapterServiceBinder
@@ -440,7 +440,7 @@
private IBluetoothCallback transition_offToOn() throws Exception {
IBluetoothCallback btCallback = transition_offToBleOn();
- mInOrder.verify(mAdapterBinder).bleOnToOn(any());
+ mInOrder.verify(mAdapterBinder).bleOnToOn();
// AdapterService go to turning_on and start all profile on its own
btCallback.onBluetoothStateChange(STATE_BLE_ON, STATE_TURNING_ON);
@@ -457,7 +457,7 @@
}
private void transition_onToBleOn(IBluetoothCallback btCallback) throws Exception {
- mInOrder.verify(mAdapterBinder).onToBleOn(any());
+ mInOrder.verify(mAdapterBinder).onToBleOn();
btCallback.onBluetoothStateChange(STATE_TURNING_OFF, STATE_BLE_ON);
syncHandler(MESSAGE_BLUETOOTH_STATE_CHANGE);
@@ -465,7 +465,7 @@
private void transition_onToOff(IBluetoothCallback btCallback) throws Exception {
transition_onToBleOn(btCallback);
- mInOrder.verify(mAdapterBinder).bleOnToOff(any());
+ mInOrder.verify(mAdapterBinder).bleOnToOff();
// When all the profile are started, adapterService consider it is ON
btCallback.onBluetoothStateChange(STATE_BLE_TURNING_OFF, STATE_OFF);
@@ -492,7 +492,7 @@
btCallback.onBluetoothStateChange(STATE_BLE_TURNING_ON, STATE_BLE_ON);
syncHandler(MESSAGE_BLUETOOTH_STATE_CHANGE);
- mInOrder.verify(mAdapterBinder).bleOnToOn(any());
+ mInOrder.verify(mAdapterBinder).bleOnToOn();
endTest();
}
@@ -518,7 +518,7 @@
btCallback.onBluetoothStateChange(STATE_BLE_TURNING_ON, STATE_BLE_ON);
syncHandler(MESSAGE_BLUETOOTH_STATE_CHANGE);
- mInOrder.verify(mAdapterBinder).bleOnToOn(any());
+ mInOrder.verify(mAdapterBinder).bleOnToOn();
endTest();
}
@@ -533,7 +533,7 @@
transition_offToBleOn();
// Check that there was no transition to STATE_ON
- mInOrder.verify(mAdapterBinder, never()).bleOnToOn(any());
+ mInOrder.verify(mAdapterBinder, never()).bleOnToOn();
assertThat(mManagerService.getState()).isEqualTo(STATE_BLE_ON);
endTest();
@@ -564,7 +564,7 @@
acceptBluetoothBinding();
IBluetoothCallback btCallback = captureBluetoothCallback();
- mInOrder.verify(mAdapterBinder).offToBleOn(anyBoolean(), anyString(), any());
+ mInOrder.verify(mAdapterBinder).offToBleOn(anyBoolean(), anyString());
btCallback.onBluetoothStateChange(STATE_OFF, STATE_BLE_TURNING_ON);
syncHandler(MESSAGE_BLUETOOTH_STATE_CHANGE);
assertThat(mManagerService.getState()).isEqualTo(STATE_BLE_TURNING_ON);
@@ -697,7 +697,7 @@
mManagerService.onAirplaneModeChanged(false);
transition_onToBleOn(btCallback);
- mInOrder.verify(mAdapterBinder).bleOnToOff(any());
+ mInOrder.verify(mAdapterBinder).bleOnToOff();
assertThat(mManagerService.getState()).isEqualTo(STATE_BLE_TURNING_OFF);
// As soon as we left BLE_ON, generate a call from 3p app that request to turn on Bluetooth