Merge "Ensure privileged APIs require runtime permission." into sc-dev

This commit is contained in:
Jeff Sharkey
2021-04-29 22:22:25 +00:00
committed by Android (Google) Code Review
6 changed files with 165 additions and 88 deletions

View File

@@ -9035,7 +9035,7 @@ package android.bluetooth {
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public int getType();
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public android.os.ParcelUuid[] getUuids();
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean setAlias(@NonNull String);
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean setPairingConfirmation(boolean);
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean setPairingConfirmation(boolean);
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean setPin(byte[]);
method public void writeToParcel(android.os.Parcel, int);
field @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public static final String ACTION_ACL_CONNECTED = "android.bluetooth.device.action.ACL_CONNECTED";

View File

@@ -1930,16 +1930,16 @@ package android.bluetooth {
}
public final class BluetoothAdapter {
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean addOnMetadataChangedListener(@NonNull android.bluetooth.BluetoothDevice, @NonNull java.util.concurrent.Executor, @NonNull android.bluetooth.BluetoothAdapter.OnMetadataChangedListener);
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean addOnMetadataChangedListener(@NonNull android.bluetooth.BluetoothDevice, @NonNull java.util.concurrent.Executor, @NonNull android.bluetooth.BluetoothAdapter.OnMetadataChangedListener);
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean disableBLE();
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean enableBLE();
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean enableNoAutoConnect();
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public void generateLocalOobData(int, @NonNull java.util.concurrent.Executor, @NonNull android.bluetooth.BluetoothAdapter.OobDataCallback);
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public long getDiscoveryEndMillis();
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void generateLocalOobData(int, @NonNull java.util.concurrent.Executor, @NonNull android.bluetooth.BluetoothAdapter.OobDataCallback);
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public long getDiscoveryEndMillis();
method public boolean isBleScanAlwaysAvailable();
method public boolean isLeEnabled();
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, android.Manifest.permission.MODIFY_PHONE_STATE}) public boolean removeActiveDevice(int);
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean removeOnMetadataChangedListener(@NonNull android.bluetooth.BluetoothDevice, @NonNull android.bluetooth.BluetoothAdapter.OnMetadataChangedListener);
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean removeOnMetadataChangedListener(@NonNull android.bluetooth.BluetoothDevice, @NonNull android.bluetooth.BluetoothAdapter.OnMetadataChangedListener);
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, android.Manifest.permission.MODIFY_PHONE_STATE}) public boolean setActiveDevice(@NonNull android.bluetooth.BluetoothDevice, int);
field public static final String ACTION_BLE_STATE_CHANGED = "android.bluetooth.adapter.action.BLE_STATE_CHANGED";
field public static final String ACTION_REQUEST_BLE_SCAN_ALWAYS_AVAILABLE = "android.bluetooth.adapter.action.REQUEST_BLE_SCAN_ALWAYS_AVAILABLE";
@@ -1961,20 +1961,20 @@ package android.bluetooth {
}
public final class BluetoothDevice implements android.os.Parcelable {
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean canBondWithoutDialog();
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean canBondWithoutDialog();
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean cancelBondProcess();
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean createBondOutOfBand(int, @Nullable android.bluetooth.OobData, @Nullable android.bluetooth.OobData);
method @Nullable @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public byte[] getMetadata(int);
method @Nullable @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public byte[] getMetadata(int);
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public int getSimAccessPermission();
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean isConnected();
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean isEncrypted();
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean isInSilenceMode();
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean isInSilenceMode();
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean removeBond();
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean setMessageAccessPermission(int);
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean setMetadata(int, @NonNull byte[]);
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean setPhonebookAccessPermission(int);
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean setSilenceMode(boolean);
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean setSimAccessPermission(int);
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean setMessageAccessPermission(int);
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean setMetadata(int, @NonNull byte[]);
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean setPhonebookAccessPermission(int);
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean setSilenceMode(boolean);
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean setSimAccessPermission(int);
field public static final int ACCESS_ALLOWED = 1; // 0x1
field public static final int ACCESS_REJECTED = 2; // 0x2
field public static final int ACCESS_UNKNOWN = 0; // 0x0

View File

@@ -1311,11 +1311,15 @@ public final class BluetoothAdapter {
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresBluetoothConnectPermission
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public boolean factoryReset() {
try {
mServiceLock.readLock().lock();
if (mService != null && mService.factoryReset()
if (mService != null && mService.factoryReset(mAttributionSource)
&& mManagerService != null
&& mManagerService.onFactoryReset(mAttributionSource)) {
return true;
@@ -1430,7 +1434,11 @@ public final class BluetoothAdapter {
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresBluetoothConnectPermission
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public boolean setBluetoothClass(BluetoothClass bluetoothClass) {
if (getState() != STATE_ON) {
return false;
@@ -1438,7 +1446,7 @@ public final class BluetoothAdapter {
try {
mServiceLock.readLock().lock();
if (mService != null) {
return mService.setBluetoothClass(bluetoothClass);
return mService.setBluetoothClass(bluetoothClass, mAttributionSource);
}
} catch (RemoteException e) {
Log.e(TAG, "", e);
@@ -1487,12 +1495,16 @@ public final class BluetoothAdapter {
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresBluetoothConnectPermission
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public boolean setIoCapability(@IoCapability int capability) {
if (getState() != STATE_ON) return false;
try {
mServiceLock.readLock().lock();
if (mService != null) return mService.setIoCapability(capability);
if (mService != null) return mService.setIoCapability(capability, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, e.getMessage(), e);
} finally {
@@ -1540,12 +1552,16 @@ public final class BluetoothAdapter {
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresBluetoothConnectPermission
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public boolean setLeIoCapability(@IoCapability int capability) {
if (getState() != STATE_ON) return false;
try {
mServiceLock.readLock().lock();
if (mService != null) return mService.setLeIoCapability(capability);
if (mService != null) return mService.setLeIoCapability(capability, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, e.getMessage(), e);
} finally {
@@ -1739,12 +1755,16 @@ public final class BluetoothAdapter {
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresBluetoothConnectPermission
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public long getDiscoveryEndMillis() {
try {
mServiceLock.readLock().lock();
if (mService != null) {
return mService.getDiscoveryEndMillis();
return mService.getDiscoveryEndMillis(mAttributionSource);
}
} catch (RemoteException e) {
Log.e(TAG, "", e);
@@ -2353,7 +2373,11 @@ public final class BluetoothAdapter {
* instead.
*/
@Deprecated
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresBluetoothConnectPermission
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public BluetoothActivityEnergyInfo getControllerActivityEnergyInfo(int updateType) {
SynchronousResultReceiver receiver = new SynchronousResultReceiver();
requestControllerActivityEnergyInfo(receiver);
@@ -2379,12 +2403,16 @@ public final class BluetoothAdapter {
* @param result The callback to which to send the activity info.
* @hide
*/
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresBluetoothConnectPermission
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public void requestControllerActivityEnergyInfo(ResultReceiver result) {
try {
mServiceLock.readLock().lock();
if (mService != null) {
mService.requestActivityInfo(result);
mService.requestActivityInfo(result, mAttributionSource);
result = null;
}
} catch (RemoteException e) {
@@ -3141,7 +3169,7 @@ public final class BluetoothAdapter {
sMetadataListeners.forEach((device, pair) -> {
try {
mService.registerMetadataListener(sBluetoothMetadataListener,
device);
device, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "Failed to register metadata listener", e);
}
@@ -3150,7 +3178,8 @@ public final class BluetoothAdapter {
synchronized (mBluetoothConnectionCallbackExecutorMap) {
if (!mBluetoothConnectionCallbackExecutorMap.isEmpty()) {
try {
mService.registerBluetoothConnectionCallback(mConnectionCallback);
mService.registerBluetoothConnectionCallback(mConnectionCallback,
mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "onBluetoothServiceUp: Failed to register bluetooth"
+ "connection callback", e);
@@ -3364,7 +3393,11 @@ public final class BluetoothAdapter {
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresBluetoothConnectPermission
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public void generateLocalOobData(@Transport int transport,
@NonNull @CallbackExecutor Executor executor, @NonNull OobDataCallback callback) {
if (transport != BluetoothDevice.TRANSPORT_BREDR && transport
@@ -3378,7 +3411,7 @@ public final class BluetoothAdapter {
} else {
try {
mService.generateLocalOobData(transport, new WrappedOobDataCallback(callback,
executor));
executor), mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -3515,11 +3548,13 @@ public final class BluetoothAdapter {
/** {@hide} */
@UnsupportedAppUsage
@RequiresNoPermission
public IBluetoothManager getBluetoothManager() {
return mManagerService;
}
/** {@hide} */
@RequiresNoPermission
public AttributionSource getAttributionSource() {
return mAttributionSource;
}
@@ -3892,7 +3927,11 @@ public final class BluetoothAdapter {
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresBluetoothConnectPermission
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public boolean addOnMetadataChangedListener(@NonNull BluetoothDevice device,
@NonNull Executor executor, @NonNull OnMetadataChangedListener listener) {
if (DBG) Log.d(TAG, "addOnMetadataChangedListener()");
@@ -3932,7 +3971,8 @@ public final class BluetoothAdapter {
boolean ret = false;
try {
ret = service.registerMetadataListener(sBluetoothMetadataListener, device);
ret = service.registerMetadataListener(sBluetoothMetadataListener, device,
mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "registerMetadataListener fail", e);
} finally {
@@ -3965,7 +4005,11 @@ public final class BluetoothAdapter {
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresBluetoothConnectPermission
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public boolean removeOnMetadataChangedListener(@NonNull BluetoothDevice device,
@NonNull OnMetadataChangedListener listener) {
if (DBG) Log.d(TAG, "removeOnMetadataChangedListener()");
@@ -3993,7 +4037,7 @@ public final class BluetoothAdapter {
return true;
}
try {
return service.unregisterMetadataListener(device);
return service.unregisterMetadataListener(device, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "unregisterMetadataListener fail", e);
return false;
@@ -4055,7 +4099,11 @@ public final class BluetoothAdapter {
* @throws IllegalArgumentException if the callback is already registered
* @hide
*/
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresBluetoothConnectPermission
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public boolean registerBluetoothConnectionCallback(@NonNull @CallbackExecutor Executor executor,
@NonNull BluetoothConnectionCallback callback) {
if (DBG) Log.d(TAG, "registerBluetoothConnectionCallback()");
@@ -4069,7 +4117,8 @@ public final class BluetoothAdapter {
try {
mServiceLock.readLock().lock();
if (mService != null) {
if (!mService.registerBluetoothConnectionCallback(mConnectionCallback)) {
if (!mService.registerBluetoothConnectionCallback(mConnectionCallback,
mAttributionSource)) {
return false;
}
}
@@ -4098,7 +4147,11 @@ public final class BluetoothAdapter {
* @return true if the callback was unregistered successfully, false otherwise
* @hide
*/
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresBluetoothConnectPermission
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public boolean unregisterBluetoothConnectionCallback(
@NonNull BluetoothConnectionCallback callback) {
if (DBG) Log.d(TAG, "unregisterBluetoothConnectionCallback()");
@@ -4120,7 +4173,8 @@ public final class BluetoothAdapter {
try {
mServiceLock.readLock().lock();
if (mService != null) {
return mService.unregisterBluetoothConnectionCallback(mConnectionCallback);
return mService.unregisterBluetoothConnectionCallback(mConnectionCallback,
mAttributionSource);
}
} catch (RemoteException e) {
Log.e(TAG, "", e);

View File

@@ -1644,7 +1644,10 @@ public final class BluetoothDevice implements Parcelable {
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public boolean canBondWithoutDialog() {
final IBluetooth service = sService;
if (service == null) {
@@ -1653,7 +1656,7 @@ public final class BluetoothDevice implements Parcelable {
}
try {
if (DBG) Log.d(TAG, "canBondWithoutDialog, device: " + this);
return service.canBondWithoutDialog(this);
return service.canBondWithoutDialog(this, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -1874,7 +1877,10 @@ public final class BluetoothDevice implements Parcelable {
*
* @return true confirmation has been sent out false for error
*/
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public boolean setPairingConfirmation(boolean confirm) {
final IBluetooth service = sService;
if (service == null) {
@@ -1882,7 +1888,7 @@ public final class BluetoothDevice implements Parcelable {
return false;
}
try {
return service.setPairingConfirmation(this, confirm);
return service.setPairingConfirmation(this, confirm, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -1971,14 +1977,17 @@ public final class BluetoothDevice implements Parcelable {
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public boolean setSilenceMode(boolean silence) {
final IBluetooth service = sService;
if (service == null) {
throw new IllegalStateException("Bluetooth is not turned ON");
}
try {
return service.setSilenceMode(this, silence);
return service.setSilenceMode(this, silence, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "setSilenceMode fail", e);
return false;
@@ -1993,14 +2002,17 @@ public final class BluetoothDevice implements Parcelable {
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public boolean isInSilenceMode() {
final IBluetooth service = sService;
if (service == null) {
throw new IllegalStateException("Bluetooth is not turned ON");
}
try {
return service.getSilenceMode(this);
return service.getSilenceMode(this, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "isInSilenceMode fail", e);
return false;
@@ -2016,14 +2028,17 @@ public final class BluetoothDevice implements Parcelable {
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public boolean setPhonebookAccessPermission(@AccessPermission int value) {
final IBluetooth service = sService;
if (service == null) {
return false;
}
try {
return service.setPhonebookAccessPermission(this, value);
return service.setPhonebookAccessPermission(this, value, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -2063,7 +2078,10 @@ public final class BluetoothDevice implements Parcelable {
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public boolean setMessageAccessPermission(@AccessPermission int value) {
// Validates param value is one of the accepted constants
if (value != ACCESS_ALLOWED && value != ACCESS_REJECTED && value != ACCESS_UNKNOWN) {
@@ -2074,7 +2092,7 @@ public final class BluetoothDevice implements Parcelable {
return false;
}
try {
return service.setMessageAccessPermission(this, value);
return service.setMessageAccessPermission(this, value, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -2114,14 +2132,17 @@ public final class BluetoothDevice implements Parcelable {
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public boolean setSimAccessPermission(int value) {
final IBluetooth service = sService;
if (service == null) {
return false;
}
try {
return service.setSimAccessPermission(this, value);
return service.setSimAccessPermission(this, value, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
@@ -2616,7 +2637,10 @@ public final class BluetoothDevice implements Parcelable {
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public boolean setMetadata(@MetadataKey int key, @NonNull byte[] value) {
final IBluetooth service = sService;
if (service == null) {
@@ -2628,7 +2652,7 @@ public final class BluetoothDevice implements Parcelable {
+ ", should not over " + METADATA_MAX_LENGTH);
}
try {
return service.setMetadata(this, key, value);
return service.setMetadata(this, key, value, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "setMetadata fail", e);
return false;
@@ -2644,7 +2668,10 @@ public final class BluetoothDevice implements Parcelable {
*/
@SystemApi
@Nullable
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public byte[] getMetadata(@MetadataKey int key) {
final IBluetooth service = sService;
if (service == null) {
@@ -2652,7 +2679,7 @@ public final class BluetoothDevice implements Parcelable {
return null;
}
try {
return service.getMetadata(this, key);
return service.getMetadata(this, key, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "getMetadata fail", e);
return null;

View File

@@ -205,10 +205,14 @@ public final class AdvertisingSet {
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
@RequiresBluetoothAdvertisePermission
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_ADVERTISE,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
public void getOwnAddress() {
try {
mGatt.getOwnAddress(mAdvertiserId);
mGatt.getOwnAddress(mAdvertiserId, mAttributionSource);
} catch (RemoteException e) {
Log.e(TAG, "remote exception - ", e);
}

View File

@@ -312,19 +312,6 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
"Need BLUETOOTH_PRIVILEGED permission");
final long token = Binder.clearCallingIdentity();
try {
return onFactoryResetInternal(attributionSource);
} finally {
Binder.restoreCallingIdentity(token);
}
}
@RequiresPermission(allOf = {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
private boolean onFactoryResetInternal(AttributionSource attributionSource) {
// Wait for stable state if bluetooth is temporary state.
int state = getState();
if (state == BluetoothAdapter.STATE_BLE_TURNING_ON
@@ -347,7 +334,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
addActiveLog(
BluetoothProtoEnums.ENABLE_DISABLE_REASON_FACTORY_RESET,
mContext.getPackageName(), false);
mBluetooth.onBrEdrDown();
mBluetooth.onBrEdrDown(attributionSource);
return true;
} else if (state == BluetoothAdapter.STATE_ON) {
addActiveLog(
@@ -404,7 +391,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
addActiveLog(
BluetoothProtoEnums.ENABLE_DISABLE_REASON_AIRPLANE_MODE,
mContext.getPackageName(), false);
mBluetooth.onBrEdrDown();
mBluetooth.onBrEdrDown(mContext.getAttributionSource());
mEnable = false;
mEnableExternal = false;
}
@@ -888,7 +875,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
if (mBluetooth != null) {
addActiveLog(BluetoothProtoEnums.ENABLE_DISABLE_REASON_APPLICATION_REQUEST,
mContext.getPackageName(), false);
mBluetooth.onBrEdrDown();
mBluetooth.onBrEdrDown(mContext.getAttributionSource());
}
} catch (RemoteException e) {
Slog.e(TAG, "error when disabling bluetooth", e);
@@ -1037,7 +1024,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
if (!mEnableExternal) {
addActiveLog(BluetoothProtoEnums.ENABLE_DISABLE_REASON_APPLICATION_REQUEST,
packageName, false);
sendBrEdrDownCallback();
sendBrEdrDownCallback(attributionSource);
}
}
return true;
@@ -1074,12 +1061,12 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
if (!mEnableExternal && !isBleAppPresent()) {
Slog.i(TAG, "Bluetooth was disabled while enabling BLE, disable BLE now");
mEnable = false;
mBluetooth.onBrEdrDown();
mBluetooth.onBrEdrDown(mContext.getAttributionSource());
return;
}
if (isBluetoothPersistedStateOnBluetooth() || !isBleAppPresent()) {
// This triggers transition to STATE_ON
mBluetooth.onLeServiceUp();
mBluetooth.onLeServiceUp(mContext.getAttributionSource());
persistBluetoothSetting(BLUETOOTH_ON_BLUETOOTH);
}
} catch (RemoteException e) {
@@ -1097,7 +1084,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
android.Manifest.permission.BLUETOOTH_CONNECT,
android.Manifest.permission.BLUETOOTH_PRIVILEGED,
})
private void sendBrEdrDownCallback() {
private void sendBrEdrDownCallback(AttributionSource attributionSource) {
if (DBG) {
Slog.d(TAG, "Calling sendBrEdrDownCallback callbacks");
}
@@ -1110,7 +1097,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
if (isBleAppPresent()) {
// Need to stay at BLE ON. Disconnect all Gatt connections
try {
mBluetoothGatt.unregAll(mContext.getAttributionSource());
mBluetoothGatt.unregAll(attributionSource);
} catch (RemoteException e) {
Slog.e(TAG, "Unable to disconnect all apps.", e);
}
@@ -1118,7 +1105,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
try {
mBluetoothLock.readLock().lock();
if (mBluetooth != null) {
mBluetooth.onBrEdrDown();
mBluetooth.onBrEdrDown(attributionSource);
}
} catch (RemoteException e) {
Slog.e(TAG, "Call to onBrEdrDown() failed.", e);
@@ -1319,7 +1306,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
if (mBluetooth != null) {
//Unregister callback object
try {
mBluetooth.unregisterCallback(mBluetoothCallback);
mBluetooth.unregisterCallback(mBluetoothCallback,
mContext.getAttributionSource());
} catch (RemoteException re) {
Slog.e(TAG, "Unable to unregister BluetoothCallback", re);
}
@@ -1729,7 +1717,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
try {
mBluetoothLock.readLock().lock();
if (mBluetooth != null) {
return mBluetooth.getAddressWithAttribution(mContext.getAttributionSource());
return mBluetooth.getAddressWithAttribution(attributionSource);
}
} catch (RemoteException e) {
Slog.e(TAG,
@@ -1758,7 +1746,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
try {
mBluetoothLock.readLock().lock();
if (mBluetooth != null) {
return mBluetooth.getName(mContext.getAttributionSource());
return mBluetooth.getName(attributionSource);
}
} catch (RemoteException e) {
Slog.e(TAG, "getName(): Unable to retrieve name remotely. Returning cached name", e);
@@ -1886,7 +1874,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
int state = mBluetooth.getState();
if (state == BluetoothAdapter.STATE_BLE_ON) {
Slog.w(TAG, "BT Enable in BLE_ON State, going to ON");
mBluetooth.onLeServiceUp();
mBluetooth.onLeServiceUp(mContext.getAttributionSource());
persistBluetoothSetting(BLUETOOTH_ON_BLUETOOTH);
break;
}
@@ -2105,7 +2093,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
//Register callback object
try {
mBluetooth.registerCallback(mBluetoothCallback);
mBluetooth.registerCallback(mBluetoothCallback,
mContext.getAttributionSource());
} catch (RemoteException re) {
Slog.e(TAG, "Unable to register BluetoothCallback", re);
}
@@ -2342,7 +2331,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
try {
mBluetoothLock.readLock().lock();
if (mBluetooth != null) {
mBluetooth.unregisterCallback(mBluetoothCallback);
mBluetooth.unregisterCallback(mBluetoothCallback,
mContext.getAttributionSource());
}
} catch (RemoteException re) {
Slog.e(TAG, "Unable to unregister", re);
@@ -2569,7 +2559,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
sendBluetoothStateCallback(false); // BT is OFF for general users
// Broadcast as STATE_OFF
newState = BluetoothAdapter.STATE_OFF;
sendBrEdrDownCallback();
sendBrEdrDownCallback(mContext.getAttributionSource());
}
} else if (newState == BluetoothAdapter.STATE_ON) {
boolean isUp = (newState == BluetoothAdapter.STATE_ON);
@@ -2670,7 +2660,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
mBluetoothLock.readLock().lock();
if (mBluetooth != null) {
//Unregister callback object
mBluetooth.unregisterCallback(mBluetoothCallback);
mBluetooth.unregisterCallback(mBluetoothCallback, mContext.getAttributionSource());
}
} catch (RemoteException re) {
Slog.e(TAG, "Unable to unregister", re);
@@ -2890,6 +2880,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
}
}
@SuppressLint("AndroidFrameworkRequiresPermission")
private static boolean checkPermissionForDataDelivery(Context context, String permission,
AttributionSource attributionSource, String message) {
final int result = PermissionChecker.checkPermissionForDataDeliveryFromDataSource(
@@ -2916,6 +2907,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
*
* <p>Should be used in situations where the app op should not be noted.
*/
@SuppressLint("AndroidFrameworkRequiresPermission")
@RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
public static boolean checkConnectPermissionForDataDelivery(
Context context, AttributionSource attributionSource, String message) {