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

Commit 5de187f2 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Automerger Merge Worker
Browse files

Merge changes from topic "jun24" into sc-dev am: ff982239

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Bluetooth/+/15092786

Change-Id: I27eb6e2230d79165989d898f6ecce743bd47cee2
parents d014dc4e ff982239
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -436,6 +436,7 @@ public final class Utils {
    @SuppressLint("AndroidFrameworkRequiresPermission")
    private static boolean checkPermissionForDataDelivery(Context context, String permission,
            AttributionSource attributionSource, String message) {
        attributionSource.enforceCallingUid();
        final int result = PermissionChecker.checkPermissionForDataDeliveryFromDataSource(
                context, permission, PID_UNKNOWN,
                new AttributionSource(context.getAttributionSource(), attributionSource), message);
@@ -676,6 +677,7 @@ public final class Utils {
            return false;
        }

        attributionSource.enforceCallingUid();
        if (PermissionChecker.checkPermissionForDataDeliveryFromDataSource(
                context, ACCESS_COARSE_LOCATION, PID_UNKNOWN,
                new AttributionSource(context.getAttributionSource(), attributionSource),
@@ -702,6 +704,7 @@ public final class Utils {
            return false;
        }

        attributionSource.enforceCallingUid();
        if (PermissionChecker.checkPermissionForDataDeliveryFromDataSource(
                context, ACCESS_FINE_LOCATION, PID_UNKNOWN,
                new AttributionSource(context.getAttributionSource(), attributionSource),
@@ -734,6 +737,7 @@ public final class Utils {
            return false;
        }

        attributionSource.enforceCallingUid();
        if (PermissionChecker.checkPermissionForDataDeliveryFromDataSource(
                context, ACCESS_FINE_LOCATION, PID_UNKNOWN,
                new AttributionSource(context.getAttributionSource(), attributionSource),
+2 −2
Original line number Diff line number Diff line
@@ -523,7 +523,7 @@ public class A2dpSinkService extends ProfileService {
    public native void informAudioTrackGainNative(float gain);

    private void onConnectionStateChanged(byte[] address, int state) {
        StackEvent event = StackEvent.connectionStateChanged(getDevice(address), state);
        StackEvent event = StackEvent.connectionStateChanged(getAnonymousDevice(address), state);
        A2dpSinkStateMachine stateMachine = getOrCreateStateMachine(event.mDevice);
        stateMachine.sendMessage(A2dpSinkStateMachine.STACK_EVENT, event);
    }
@@ -545,7 +545,7 @@ public class A2dpSinkService extends ProfileService {
    }

    private void onAudioConfigChanged(byte[] address, int sampleRate, int channelCount) {
        StackEvent event = StackEvent.audioConfigChanged(getDevice(address), sampleRate,
        StackEvent event = StackEvent.audioConfigChanged(getAnonymousDevice(address), sampleRate,
                channelCount);
        A2dpSinkStateMachine stateMachine = getOrCreateStateMachine(event.mDevice);
        stateMachine.sendMessage(A2dpSinkStateMachine.STACK_EVENT, event);
+25 −28
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.util.Log;
import com.android.bluetooth.R;
import com.android.bluetooth.Utils;
import com.android.bluetooth.a2dpsink.A2dpSinkService;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ProfileService;

import java.util.ArrayList;
@@ -98,7 +99,8 @@ public class AvrcpControllerService extends ProfileService {

    static BrowseTree sBrowseTree;
    private static AvrcpControllerService sService;
    private final BluetoothAdapter mAdapter;

    private AdapterService mAdapterService;

    protected Map<BluetoothDevice, AvrcpControllerStateMachine> mDeviceStateMap =
            new ConcurrentHashMap<>(1);
@@ -131,14 +133,10 @@ public class AvrcpControllerService extends ProfileService {
        classInitNative();
    }

    public AvrcpControllerService() {
        super();
        mAdapter = BluetoothAdapter.getDefaultAdapter();
    }

    @Override
    protected synchronized boolean start() {
        initNative();
        mAdapterService = AdapterService.getAdapterService();
        mCoverArtEnabled = getResources().getBoolean(R.bool.avrcp_controller_enable_cover_art);
        if (mCoverArtEnabled) {
            mCoverArtManager = new AvrcpCoverArtManager(this, new ImageDownloadCallback());
@@ -449,7 +447,7 @@ public class AvrcpControllerService extends ProfileService {
    // Called by JNI when a device has connected or disconnected.
    private synchronized void onConnectionStateChanged(boolean remoteControlConnected,
            boolean browsingConnected, byte[] address) {
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        BluetoothDevice device = getAnonymousDevice(address);
        if (DBG) {
            Log.d(TAG, "onConnectionStateChanged " + remoteControlConnected + " "
                    + browsingConnected + device);
@@ -483,7 +481,7 @@ public class AvrcpControllerService extends ProfileService {

    // Called by JNI to notify Avrcp of a remote device's Cover Art PSM
    private void getRcPsm(byte[] address, int psm) {
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        BluetoothDevice device = getAnonymousDevice(address);
        if (DBG) Log.d(TAG, "getRcPsm(device=" + device + ", psm=" + psm + ")");
        AvrcpControllerStateMachine stateMachine = getOrCreateStateMachine(device);
        if (stateMachine != null) {
@@ -502,7 +500,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "handleRegisterNotificationAbsVol");
        }
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        BluetoothDevice device = getAnonymousDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            stateMachine.sendMessage(
@@ -515,7 +513,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "handleSetAbsVolume ");
        }
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        BluetoothDevice device = getAnonymousDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            stateMachine.sendMessage(AvrcpControllerStateMachine.MESSAGE_PROCESS_SET_ABS_VOL_CMD,
@@ -530,7 +528,7 @@ public class AvrcpControllerService extends ProfileService {
            Log.d(TAG, "onTrackChanged");
        }

        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        BluetoothDevice device = getAnonymousDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            AvrcpItem.Builder aib = new AvrcpItem.Builder();
@@ -556,7 +554,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "onPlayPositionChanged pos " + currSongPosition);
        }
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        BluetoothDevice device = getAnonymousDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            stateMachine.sendMessage(
@@ -570,7 +568,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "onPlayStatusChanged " + playStatus);
        }
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        BluetoothDevice device = getAnonymousDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            stateMachine.sendMessage(
@@ -585,7 +583,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "handlePlayerAppSetting rspLen = " + rspLen);
        }
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        BluetoothDevice device = getAnonymousDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            PlayerApplicationSettings supportedSettings =
@@ -601,7 +599,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "onPlayerAppSettingChanged ");
        }
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        BluetoothDevice device = getAnonymousDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {

@@ -617,7 +615,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG," onAvailablePlayerChanged");
        }
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        BluetoothDevice device = getAnonymousDevice(address);

        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
@@ -632,7 +630,7 @@ public class AvrcpControllerService extends ProfileService {
                    + items.length + " items.");
        }

        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        BluetoothDevice device = getAnonymousDevice(address);
        List<AvrcpItem> itemsList = new ArrayList<>();
        for (AvrcpItem item : items) {
            if (VDBG) Log.d(TAG, item.toString());
@@ -663,7 +661,7 @@ public class AvrcpControllerService extends ProfileService {
            itemsList.add(item);
        }

        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        BluetoothDevice device = getAnonymousDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            stateMachine.sendMessage(AvrcpControllerStateMachine.MESSAGE_PROCESS_GET_PLAYER_ITEMS,
@@ -679,7 +677,7 @@ public class AvrcpControllerService extends ProfileService {
                    + " attrids: " + attrIds + " attrVals: " + attrVals);
        }

        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        BluetoothDevice device = getAnonymousDevice(address);
        AvrcpItem.Builder aib = new AvrcpItem.Builder().fromAvrcpAttributeArray(attrIds, attrVals);
        aib.setDevice(device);
        aib.setItemType(AvrcpItem.TYPE_MEDIA);
@@ -698,7 +696,7 @@ public class AvrcpControllerService extends ProfileService {
                    + name + " playable " + playable);
        }

        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        BluetoothDevice device = getAnonymousDevice(address);
        AvrcpItem.Builder aib = new AvrcpItem.Builder();
        aib.setDevice(device);
        aib.setItemType(AvrcpItem.TYPE_FOLDER);
@@ -719,8 +717,7 @@ public class AvrcpControllerService extends ProfileService {
                            + transportFlags + " play status " + playStatus + " player type "
                            + playerType);
        }

        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        BluetoothDevice device = getAnonymousDevice(address);
        AvrcpPlayer.Builder apb = new AvrcpPlayer.Builder();
        apb.setDevice(device);
        apb.setPlayerId(id);
@@ -735,7 +732,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "handleChangeFolderRsp count: " + count);
        }
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        BluetoothDevice device = getAnonymousDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            stateMachine.sendMessage(AvrcpControllerStateMachine.MESSAGE_PROCESS_FOLDER_PATH,
@@ -747,7 +744,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "handleSetBrowsedPlayerRsp depth: " + depth);
        }
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        BluetoothDevice device = getAnonymousDevice(address);

        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
@@ -760,7 +757,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "handleSetAddressedPlayerRsp status: " + status);
        }
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        BluetoothDevice device = getAnonymousDevice(address);

        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
@@ -773,7 +770,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "handleAddressedPlayerChanged id: " + id);
        }
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        BluetoothDevice device = getAnonymousDevice(address);

        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
@@ -786,7 +783,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "handleNowPlayingContentChanged");
        }
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        BluetoothDevice device = getAnonymousDevice(address);

        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
@@ -867,7 +864,7 @@ public class AvrcpControllerService extends ProfileService {
    List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
        if (DBG) Log.d(TAG, "getDevicesMatchingConnectionStates" + Arrays.toString(states));
        List<BluetoothDevice> deviceList = new ArrayList<>();
        Set<BluetoothDevice> bondedDevices = mAdapter.getBondedDevices();
        BluetoothDevice[] bondedDevices = mAdapterService.getBondedDevices();
        int connectionState;
        for (BluetoothDevice device : bondedDevices) {
            connectionState = getConnectionState(device);
+4 −0
Original line number Diff line number Diff line
@@ -2472,6 +2472,10 @@ public class AdapterService extends Service {

    // ----API Methods--------

    public boolean isEnabled() {
        return getState() == BluetoothAdapter.STATE_ON;
    }

    public int getState() {
        if (mAdapterProperties != null) {
            return mAdapterProperties.getState();
+27 −5
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.app.ActivityManager;
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Attributable;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -338,10 +339,31 @@ public abstract class ProfileService extends Service {
        stopSelf();
    }

    protected BluetoothDevice getDevice(byte[] address) {
        if (mAdapter != null) {
            return mAdapter.getRemoteDevice(Utils.getAddressStringFromByte(address));
    /**
     * Returns a {@link BluetoothDevice} instance for the given address, but
     * with any {@link AttributionSource} details removed, making it "anonymous"
     * and not suitable for local use within this process.
     * <p>
     * The returned object is intended to be returned to a remote caller for
     * actual use, where {@link Attributable#setAttributionSource} will populate
     * it accurately.
     */
    protected BluetoothDevice getAnonymousDevice(String address) {
        return Attributable.setAttributionSource(
                BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address), null);
    }
        return null;

    /**
     * Returns a {@link BluetoothDevice} instance for the given address, but
     * with any {@link AttributionSource} details removed, making it "anonymous"
     * and not suitable for local use within this process.
     * <p>
     * The returned object is intended to be returned to a remote caller for
     * actual use, where {@link Attributable#setAttributionSource} will populate
     * it accurately.
     */
    protected BluetoothDevice getAnonymousDevice(byte[] address) {
        return Attributable.setAttributionSource(
                BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address), null);
    }
}
Loading