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

Commit abb39b5d authored by William Escande's avatar William Escande
Browse files

Intents: assure proper permission are set

When sending an intent that is documented with a permission, we need to
make sure the receiver has the appropriate permissions.

The linter was previously broken, but it is fixed with aosp/3169496

This CL fix all the error reported by it

Bug: 349682934
Test: m Bluetooth
Flag: Exempt permission enforcement
Change-Id: I26716b7e611bef902ec16947245bd027a83fddde
parent 60ee4e76
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.bluetooth;

import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
@@ -186,7 +185,8 @@ public class BluetoothMethodProxy {
    }

    /** Proxies {@link Context#sendBroadcast(Intent)}. */
    public void contextSendBroadcast(Context context, @RequiresPermission Intent intent) {
    @SuppressLint("AndroidFrameworkRequiresPermission") // only intent is ACTION_OPEN
    public void contextSendBroadcast(Context context, Intent intent) {
        context.sendBroadcast(intent);
    }

+5 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.bluetooth.bass_client;

import static android.Manifest.permission.BLUETOOTH_CONNECT;
import static android.Manifest.permission.BLUETOOTH_PRIVILEGED;

import android.annotation.Nullable;
import android.annotation.SuppressLint;
@@ -2354,8 +2355,10 @@ public class BassClientStateMachine extends StateMachine {
        intent.addFlags(
                Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
                        | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
        mService.sendBroadcast(
                intent, BLUETOOTH_CONNECT, Utils.getTempBroadcastOptions().toBundle());
        mService.sendBroadcastMultiplePermissions(
                intent,
                new String[] {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED},
                Utils.getTempBroadcastOptions());
    }

    int getConnectionState() {
+6 −7
Original line number Diff line number Diff line
@@ -1071,7 +1071,6 @@ public class HapClientService extends ProfileService {
            return;
        }

        Intent intent = null;
        BluetoothDevice device = stackEvent.device;

        switch (stackEvent.type) {
@@ -1082,9 +1081,12 @@ public class HapClientService extends ProfileService {
                    if (device != null) {
                        mDeviceFeaturesMap.put(device, features);

                        intent = new Intent(BluetoothHapClient.ACTION_HAP_DEVICE_AVAILABLE);
                        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
                        intent.putExtra(BluetoothHapClient.EXTRA_HAP_FEATURES, features);
                        Intent intent =
                                new Intent(BluetoothHapClient.ACTION_HAP_DEVICE_AVAILABLE)
                                        .putExtra(BluetoothDevice.EXTRA_DEVICE, device)
                                        .putExtra(BluetoothHapClient.EXTRA_HAP_FEATURES, features);
                        sendBroadcastWithMultiplePermissions(
                                intent, new String[] {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED});
                    }
                }
                break;
@@ -1180,9 +1182,6 @@ public class HapClientService extends ProfileService {
                return;
        }

        if (intent != null) {
            sendBroadcast(intent, BLUETOOTH_PRIVILEGED);
        }
    }

    private void resendToStateMachine(HapClientStackEvent stackEvent) {
+11 −8
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
package com.android.bluetooth.hap;

import static android.Manifest.permission.BLUETOOTH_CONNECT;
import static android.Manifest.permission.BLUETOOTH_PRIVILEGED;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHapClient;
@@ -171,14 +172,16 @@ final class HapClientStateMachine extends StateMachine {
                        + profileStateToString(newState));

        mService.connectionStateChanged(mDevice, prevState, newState);
        Intent intent = new Intent(BluetoothHapClient.ACTION_HAP_CONNECTION_STATE_CHANGED);
        intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState);
        intent.putExtra(BluetoothProfile.EXTRA_STATE, newState);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
        intent.addFlags(
        Intent intent =
                new Intent(BluetoothHapClient.ACTION_HAP_CONNECTION_STATE_CHANGED)
                        .putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState)
                        .putExtra(BluetoothProfile.EXTRA_STATE, newState)
                        .putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice)
                        .addFlags(
                                Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
                                        | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
        mService.sendBroadcast(intent, BLUETOOTH_CONNECT);
        mService.sendBroadcastWithMultiplePermissions(
                intent, new String[] {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED});
    }

    public void dump(StringBuilder sb) {
+2 −1
Original line number Diff line number Diff line
@@ -1701,7 +1701,8 @@ public class LeAudioService extends ProfileService {
        intent.addFlags(
                Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
                        | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
        sendBroadcast(intent, BLUETOOTH_CONNECT);
        sendBroadcastWithMultiplePermissions(
                intent, new String[] {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED});
    }

    void notifyVolumeControlServiceAboutActiveGroup(BluetoothDevice device) {
Loading