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

Commit afababd4 authored by Ivan Podogov's avatar Ivan Podogov
Browse files

In permission review mode, always request user's consent to toggle BT.

Bug: 33155221
Test: Manual: flash the watch, check that the consent UI was
      displayed in both apps (the one with CompileSDK=21 and
      TargetSDK=21, and the one with CompileSDK=25 and
      TargetSDK=25).
Change-Id: Ic1ed987bbaf282892a2aef354a8ca0add2c829ba
parent 1471ad3e
Loading
Loading
Loading
Loading
+9 −15
Original line number Original line Diff line number Diff line
@@ -717,9 +717,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
            mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
            mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                    "Need BLUETOOTH ADMIN permission");
                    "Need BLUETOOTH ADMIN permission");


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


            if (isEnabled() && mPermissionReviewRequired
            if (isEnabled() && mPermissionReviewRequired) {
                    && startConsentUiIfNeeded(packageName, callingUid,
                startConsentUi(packageName, callingUid, BluetoothAdapter.ACTION_REQUEST_DISABLE);
                            BluetoothAdapter.ACTION_REQUEST_DISABLE)) {
                return false;
                return false;
            }
            }
        }
        }
@@ -775,8 +773,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
        return true;
        return true;
    }
    }


    private boolean startConsentUiIfNeeded(String packageName,
    private void startConsentUi(String packageName, int callingUid, String intentAction)
            int callingUid, String intentAction) throws RemoteException {
            throws RemoteException {
        try {
        try {
            // Validate the package only if we are going to use it
            // Validate the package only if we are going to use it
            ApplicationInfo applicationInfo = mContext.getPackageManager()
            ApplicationInfo applicationInfo = mContext.getPackageManager()
@@ -788,16 +786,12 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                        + " not in uid " + callingUid);
                        + " not in uid " + callingUid);
            }
            }


            // Legacy apps in permission review mode trigger a user prompt
            // Permission review mode, trigger a user prompt
            if (applicationInfo.targetSdkVersion < Build.VERSION_CODES.M) {
            Intent intent = new Intent(intentAction);
            Intent intent = new Intent(intentAction);
            mContext.startActivity(intent);
            mContext.startActivity(intent);
                return true;
            }
        } catch (PackageManager.NameNotFoundException e) {
        } catch (PackageManager.NameNotFoundException e) {
            throw new RemoteException(e.getMessage());
            throw new RemoteException(e.getMessage());
        }
        }
        return false;
    }
    }


    public void unbindAndFinish() {
    public void unbindAndFinish() {