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

Commit da7c2f35 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Obtain remote names directly from AdapterService.

BluetoothDevice instances are designed for use by public API
developers, and internal usages should call directly through to
AdapterService to avoid AttributionSource mismatch issues.

Bug: 188391719
Test: atest BluetoothInstrumentationTests
Change-Id: I585cf2ac438716cea9eeb93380acf5693f01a408
parent 7d46698a
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import static android.os.PowerExemptionManager.TEMPORARY_ALLOW_LIST_TYPE_FOREGRO

import android.Manifest;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.app.AppGlobals;
@@ -62,6 +63,7 @@ import android.provider.DeviceConfig;
import android.provider.Telephony;
import android.util.Log;

import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ProfileService;

import org.xmlpull.v1.XmlPullParser;
@@ -113,6 +115,15 @@ public final class Utils {
        return c == 'w' || c == 'W';
    }

    public static @Nullable String getName(@Nullable BluetoothDevice device) {
        final AdapterService service = AdapterService.getAdapterService();
        if (service != null && device != null) {
            return service.getRemoteName(device);
        } else {
            return null;
        }
    }

    public static String getAddressStringFromByte(byte[] address) {
        if (address == null || address.length != BD_ADDR_LEN) {
            return null;
+1 −1
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ public class A2dpSinkStateMachine extends StateMachine {
     */
    public void dump(StringBuilder sb) {
        ProfileService.println(sb, "mDevice: " + mDevice.getAddress() + "("
                + mDevice.getName() + ") " + this.toString());
                + Utils.getName(mDevice) + ") " + this.toString());
    }

    @Override
+1 −1
Original line number Diff line number Diff line
@@ -251,7 +251,7 @@ class AvrcpControllerStateMachine extends StateMachine {
     */
    public void dump(StringBuilder sb) {
        ProfileService.println(sb, "mDevice: " + mDevice.getAddress() + "("
                + mDevice.getName() + ") " + this.toString());
                + Utils.getName(mDevice) + ") " + this.toString());
        ProfileService.println(sb, "isActive: " + isActive());
        ProfileService.println(sb, "Control: " + mRemoteControlConnected);
        ProfileService.println(sb, "Browsing: " + mBrowsingConnected);
+6 −3
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.net.Uri;
import android.support.v4.media.MediaBrowserCompat.MediaItem;
import android.util.Log;

import com.android.bluetooth.Utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -76,8 +78,9 @@ public class BrowseTree {
        } else {
            mRootNode = new BrowseNode(new AvrcpItem.Builder().setDevice(device)
                    .setUuid(ROOT + device.getAddress().toString())
                    .setTitle(device.getName()).setBrowsable(true).build());
                    .setTitle(Utils.getName(device)).setBrowsable(true).build());
        }

        mRootNode.mBrowseScope = AvrcpControllerService.BROWSE_SCOPE_PLAYER_LIST;
        mRootNode.setExpectedChildren(255);

@@ -156,8 +159,8 @@ public class BrowseTree {
            AvrcpItem.Builder aid = new AvrcpItem.Builder();
            aid.setDevice(device);
            aid.setUuid(playerKey);
            aid.setDisplayableName(device.getName());
            aid.setTitle(device.getName());
            aid.setDisplayableName(Utils.getName(device));
            aid.setTitle(Utils.getName(device));
            aid.setBrowsable(true);
            mItem = aid.build();
        }
+1 −1
Original line number Diff line number Diff line
@@ -1066,7 +1066,7 @@ class AdapterProperties {
        for (BluetoothDevice device : mBondedDevices) {
            writer.println(
                    "    " + device.getAddress() + " [" + dumpDeviceType(device.getType()) + "] "
                            + device.getName());
                            + Utils.getName(device));
        }
    }

Loading