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

Commit 3bc26ea7 authored by William Escande's avatar William Escande Committed by Android (Google) Code Review
Browse files

Merge "Removing getAnonymousDevice" into stage-aosp-master

parents 5214e84b 2f75525c
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -523,7 +523,8 @@ public class A2dpSinkService extends ProfileService {
    public native void informAudioTrackGainNative(float gain);

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

    private void onAudioConfigChanged(byte[] address, int sampleRate, int channelCount) {
        StackEvent event = StackEvent.audioConfigChanged(getAnonymousDevice(address), sampleRate,
        StackEvent event = StackEvent.audioConfigChanged(
                BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address), sampleRate,
                channelCount);
        A2dpSinkStateMachine stateMachine = getOrCreateStateMachine(event.mDevice);
        stateMachine.sendMessage(A2dpSinkStateMachine.STACK_EVENT, event);
+20 −20
Original line number Diff line number Diff line
@@ -445,7 +445,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 = getAnonymousDevice(address);
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (DBG) {
            Log.d(TAG, "onConnectionStateChanged " + remoteControlConnected + " "
                    + browsingConnected + device);
@@ -479,7 +479,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 = getAnonymousDevice(address);
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (DBG) Log.d(TAG, "getRcPsm(device=" + device + ", psm=" + psm + ")");
        AvrcpControllerStateMachine stateMachine = getOrCreateStateMachine(device);
        if (stateMachine != null) {
@@ -498,7 +498,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "handleRegisterNotificationAbsVol");
        }
        BluetoothDevice device = getAnonymousDevice(address);
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            stateMachine.sendMessage(
@@ -511,7 +511,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "handleSetAbsVolume ");
        }
        BluetoothDevice device = getAnonymousDevice(address);
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            stateMachine.sendMessage(AvrcpControllerStateMachine.MESSAGE_PROCESS_SET_ABS_VOL_CMD,
@@ -526,7 +526,7 @@ public class AvrcpControllerService extends ProfileService {
            Log.d(TAG, "onTrackChanged");
        }

        BluetoothDevice device = getAnonymousDevice(address);
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            AvrcpItem.Builder aib = new AvrcpItem.Builder();
@@ -552,7 +552,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "onPlayPositionChanged pos " + currSongPosition);
        }
        BluetoothDevice device = getAnonymousDevice(address);
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            stateMachine.sendMessage(
@@ -566,7 +566,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "onPlayStatusChanged " + playStatus);
        }
        BluetoothDevice device = getAnonymousDevice(address);
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            stateMachine.sendMessage(
@@ -581,7 +581,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "handlePlayerAppSetting rspLen = " + rspLen);
        }
        BluetoothDevice device = getAnonymousDevice(address);
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            PlayerApplicationSettings supportedSettings =
@@ -597,7 +597,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "onPlayerAppSettingChanged ");
        }
        BluetoothDevice device = getAnonymousDevice(address);
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {

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

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

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

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

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

        BluetoothDevice device = getAnonymousDevice(address);
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        AvrcpItem.Builder aib = new AvrcpItem.Builder();
        aib.setDevice(device);
        aib.setItemType(AvrcpItem.TYPE_FOLDER);
@@ -715,7 +715,7 @@ public class AvrcpControllerService extends ProfileService {
                            + transportFlags + " play status " + playStatus + " player type "
                            + playerType);
        }
        BluetoothDevice device = getAnonymousDevice(address);
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        AvrcpPlayer.Builder apb = new AvrcpPlayer.Builder();
        apb.setDevice(device);
        apb.setPlayerId(id);
@@ -730,7 +730,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "handleChangeFolderRsp count: " + count);
        }
        BluetoothDevice device = getAnonymousDevice(address);
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
            stateMachine.sendMessage(AvrcpControllerStateMachine.MESSAGE_PROCESS_FOLDER_PATH,
@@ -742,7 +742,7 @@ public class AvrcpControllerService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "handleSetBrowsedPlayerRsp depth: " + depth);
        }
        BluetoothDevice device = getAnonymousDevice(address);
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);

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

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

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

        AvrcpControllerStateMachine stateMachine = getStateMachine(device);
        if (stateMachine != null) {
+0 −27
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -336,30 +335,4 @@ public abstract class ProfileService extends Service {
        }
        stopSelf();
    }

    /**
     * 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 BluetoothAdapter.getDefaultAdapter().getRemoteDevice(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(byte[] address) {
        return BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
    }
}
+6 −5
Original line number Diff line number Diff line
@@ -1175,7 +1175,7 @@ public class GattService extends ProfileService {
                continue;
            }

            BluetoothDevice device = getAnonymousDevice(address);
            BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);

            ScanSettings settings = client.settings;
            byte[] scanRecordData;
@@ -1971,7 +1971,7 @@ public class GattService extends ProfileService {
                    extractBytes(batchRecord, i * TRUNCATED_RESULT_SIZE, TRUNCATED_RESULT_SIZE);
            byte[] address = extractBytes(record, 0, 6);
            reverse(address);
            BluetoothDevice device = getAnonymousDevice(address);
            BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
            int rssi = record[8];
            long timestampNanos = now - parseTimestampNanos(extractBytes(record, 9, 2));
            results.add(new ScanResult(device, ScanRecord.parseFromBytes(new byte[0]), rssi,
@@ -1998,7 +1998,7 @@ public class GattService extends ProfileService {
            byte[] address = extractBytes(batchRecord, position, 6);
            // TODO: remove temp hack.
            reverse(address);
            BluetoothDevice device = getAnonymousDevice(address);
            BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
            position += 6;
            // Skip address type.
            position++;
@@ -2076,7 +2076,8 @@ public class GattService extends ProfileService {
            return;
        }

        BluetoothDevice device = getAnonymousDevice(trackingInfo.getAddress());
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter()
                .getRemoteDevice(trackingInfo.getAddress());
        int advertiserState = trackingInfo.getAdvState();
        ScanResult result =
                new ScanResult(device, ScanRecord.parseFromBytes(trackingInfo.getResult()),
@@ -2208,7 +2209,7 @@ public class GattService extends ProfileService {
        connectedDevices.addAll(mServerMap.getConnectedDevices());

        for (String address : connectedDevices) {
            BluetoothDevice device = getAnonymousDevice(address);
            BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
            if (device != null) {
                deviceStates.put(device, BluetoothProfile.STATE_CONNECTED);
            }
+13 −6
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.Manifest.permission.BLUETOOTH_CONNECT;
import static com.android.bluetooth.Utils.enforceBluetoothPrivilegedPermission;

import android.annotation.RequiresPermission;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHidHost;
import android.bluetooth.BluetoothProfile;
@@ -177,7 +178,8 @@ public class HidHostService extends ProfileService {
                }
                break;
                case MESSAGE_CONNECT_STATE_CHANGED: {
                    BluetoothDevice device = getAnonymousDevice((byte[]) msg.obj);
                    BluetoothDevice device = BluetoothAdapter.getDefaultAdapter()
                            .getRemoteDevice((byte[]) msg.obj);
                    int halState = msg.arg1;
                    Integer prevStateInteger = mInputDevices.get(device);
                    int prevState =
@@ -216,7 +218,8 @@ public class HidHostService extends ProfileService {
                break;

                case MESSAGE_ON_GET_PROTOCOL_MODE: {
                    BluetoothDevice device = getAnonymousDevice((byte[]) msg.obj);
                    BluetoothDevice device = BluetoothAdapter.getDefaultAdapter()
                            .getRemoteDevice((byte[]) msg.obj);
                    int protocolMode = msg.arg1;
                    broadcastProtocolMode(device, protocolMode);
                }
@@ -250,7 +253,8 @@ public class HidHostService extends ProfileService {
                }
                break;
                case MESSAGE_ON_GET_REPORT: {
                    BluetoothDevice device = getAnonymousDevice((byte[]) msg.obj);
                    BluetoothDevice device = BluetoothAdapter.getDefaultAdapter()
                            .getRemoteDevice((byte[]) msg.obj);
                    Bundle data = msg.getData();
                    byte[] report = data.getByteArray(BluetoothHidHost.EXTRA_REPORT);
                    int bufferSize = data.getInt(BluetoothHidHost.EXTRA_REPORT_BUFFER_SIZE);
@@ -258,7 +262,8 @@ public class HidHostService extends ProfileService {
                }
                break;
                case MESSAGE_ON_HANDSHAKE: {
                    BluetoothDevice device = getAnonymousDevice((byte[]) msg.obj);
                    BluetoothDevice device = BluetoothAdapter.getDefaultAdapter()
                            .getRemoteDevice((byte[]) msg.obj);
                    int status = msg.arg1;
                    broadcastHandshake(device, status);
                }
@@ -274,7 +279,8 @@ public class HidHostService extends ProfileService {
                }
                break;
                case MESSAGE_ON_VIRTUAL_UNPLUG: {
                    BluetoothDevice device = getAnonymousDevice((byte[]) msg.obj);
                    BluetoothDevice device = BluetoothAdapter.getDefaultAdapter()
                            .getRemoteDevice((byte[]) msg.obj);
                    int status = msg.arg1;
                    broadcastVirtualUnplugStatus(device, status);
                }
@@ -287,7 +293,8 @@ public class HidHostService extends ProfileService {
                }
                break;
                case MESSAGE_ON_GET_IDLE_TIME: {
                    BluetoothDevice device = getAnonymousDevice((byte[]) msg.obj);
                    BluetoothDevice device = BluetoothAdapter.getDefaultAdapter()
                            .getRemoteDevice((byte[]) msg.obj);
                    int idleTime = msg.arg1;
                    broadcastIdleTime(device, idleTime);
                }
Loading