Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c2342ac2 authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Always review permissions before <M app is started the first time

This splits the
- review permissions
- individually control permissions
- consent to manage wireleess (wifi + bluetooth)
properties.

Almost all code cares only for the first and it is now always true.
Hence a lot of code can be simplified.

Bug: 110431654
Test: atest PermissionsHostTest
      started pre-M app
Change-Id: I733cd476ccd0bf5eaa59e9a9506db34f57c6baee
parent 15e33418
Loading
Loading
Loading
Loading
+10 −13
Original line number Diff line number Diff line
@@ -211,7 +211,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
    // bluetooth profile services
    private final Map<Integer, ProfileServiceConnections> mProfileServices = new HashMap<>();

    private final boolean mPermissionReviewRequired;
    private final boolean mWirelessConsentRequired;

    private final IBluetoothCallback mBluetoothCallback = new IBluetoothCallback.Stub() {
        @Override
@@ -368,8 +368,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {

        mContext = context;

        mPermissionReviewRequired = context.getResources()
                .getBoolean(com.android.internal.R.bool.config_permissionReviewRequired);
        mWirelessConsentRequired = context.getResources()
                .getBoolean(com.android.internal.R.bool.config_wirelessConsentRequired);

        mCrashes = 0;
        mBluetooth = null;
@@ -885,7 +885,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
            mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                    "Need BLUETOOTH ADMIN permission");

            if (!isEnabled() && mPermissionReviewRequired && startConsentUiIfNeeded(packageName,
            if (!isEnabled() && mWirelessConsentRequired && startConsentUiIfNeeded(packageName,
                    callingUid, BluetoothAdapter.ACTION_REQUEST_ENABLE)) {
                return false;
            }
@@ -922,7 +922,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
            mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                    "Need BLUETOOTH ADMIN permission");

            if (isEnabled() && mPermissionReviewRequired && startConsentUiIfNeeded(packageName,
            if (isEnabled() && mWirelessConsentRequired && startConsentUiIfNeeded(packageName,
                    callingUid, BluetoothAdapter.ACTION_REQUEST_DISABLE)) {
                return false;
            }
@@ -945,7 +945,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {

    private boolean startConsentUiIfNeeded(String packageName,
            int callingUid, String intentAction) throws RemoteException {
        if (checkBluetoothPermissionWhenPermissionReviewRequired()) {
        if (checkBluetoothPermissionWhenWirelessConsentRequired()) {
            return false;
        }
        try {
@@ -978,21 +978,18 @@ class BluetoothManagerService extends IBluetoothManager.Stub {

    /**
     * Check if the caller must still pass permission check or if the caller is exempted
     * from the consent UI via the MANAGE_BLUETOOTH_WHEN_PERMISSION_REVIEW_REQUIRED check.
     * from the consent UI via the MANAGE_BLUETOOTH_WHEN_WIRELESS_CONSENT_REQUIRED check.
     *
     * Commands from some callers may be exempted from triggering the consent UI when
     * enabling bluetooth. This exemption is checked via the
     * MANAGE_BLUETOOTH_WHEN_PERMISSION_REVIEW_REQUIRED and allows calls to skip
     * MANAGE_BLUETOOTH_WHEN_WIRELESS_CONSENT_REQUIRED and allows calls to skip
     * the consent UI where it may otherwise be required.
     *
     * @hide
     */
    private boolean checkBluetoothPermissionWhenPermissionReviewRequired() {
        if (!mPermissionReviewRequired) {
            return false;
        }
    private boolean checkBluetoothPermissionWhenWirelessConsentRequired() {
        int result = mContext.checkCallingPermission(
                android.Manifest.permission.MANAGE_BLUETOOTH_WHEN_PERMISSION_REVIEW_REQUIRED);
                android.Manifest.permission.MANAGE_BLUETOOTH_WHEN_WIRELESS_CONSENT_REQUIRED);
        return result == PackageManager.PERMISSION_GRANTED;
    }