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

Commit 2e05346f authored by Shijian Li's avatar Shijian Li
Browse files

Sync the startConsentUiIfNeeded logics to master. We are missing the package

name when starting the activity now.

Bug: 34216066
Change-Id: Ic8c8576ce2c65bc554bbf4794e169838c2ccbbe1
parent fbccc787
Loading
Loading
Loading
Loading
+20 −8
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@ import android.bluetooth.IBluetoothManager;
import android.bluetooth.IBluetoothManagerCallback;
import android.bluetooth.IBluetoothManagerCallback;
import android.bluetooth.IBluetoothProfileServiceConnection;
import android.bluetooth.IBluetoothProfileServiceConnection;
import android.bluetooth.IBluetoothStateChangeCallback;
import android.bluetooth.IBluetoothStateChangeCallback;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContentResolver;
@@ -676,8 +677,9 @@ 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
                startConsentUi(packageName, callingUid, BluetoothAdapter.ACTION_REQUEST_ENABLE);
                    && startConsentUiIfNeeded(packageName, callingUid,
                            BluetoothAdapter.ACTION_REQUEST_ENABLE)) {
                return false;
                return false;
            }
            }
        }
        }
@@ -710,8 +712,9 @@ 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
                startConsentUi(packageName, callingUid, BluetoothAdapter.ACTION_REQUEST_DISABLE);
                    && startConsentUiIfNeeded(packageName, callingUid,
                            BluetoothAdapter.ACTION_REQUEST_DISABLE)) {
                return false;
                return false;
            }
            }
        }
        }
@@ -734,8 +737,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
        return true;
        return true;
    }
    }


    private void startConsentUi(String packageName, int callingUid, String intentAction)
    private boolean startConsentUiIfNeeded(String packageName,
            throws RemoteException {
            int callingUid, String intentAction) 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()
@@ -747,9 +750,18 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                        + " not in uid " + callingUid);
                        + " not in uid " + callingUid);
            }
            }


            // Permission review mode, trigger a user prompt
            Intent intent = new Intent(intentAction);
            Intent intent = new Intent(intentAction);
            intent.putExtra(Intent.EXTRA_PACKAGE_NAME, packageName);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                    | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            try {
                mContext.startActivity(intent);
                mContext.startActivity(intent);
            } catch (ActivityNotFoundException e) {
                // Shouldn't happen
                Slog.e(TAG, "Intent to handle action " + intentAction + " missing");
                return false;
            }
            return true;
        } catch (PackageManager.NameNotFoundException e) {
        } catch (PackageManager.NameNotFoundException e) {
            throw new RemoteException(e.getMessage());
            throw new RemoteException(e.getMessage());
        }
        }