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

Commit b49a00f9 authored by Hui Peng's avatar Hui Peng Committed by Gerrit Code Review
Browse files

Merge changes from topic "BluetoothDevice-toString"

* changes:
  [redact_log]Address test failures caused by changes to BluetoothDevice#toString
  [redact_log] Mark the change in BluetoothDevice#toString
parents 4c39f403 07df0b0d
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -680,7 +680,7 @@ public class AvrcpControllerStateMachineTest {

        //Get the root of the device
        BrowseTree.BrowseNode results = mAvrcpStateMachine.findNode(rootName);
        Assert.assertEquals(rootName + mTestDevice.toString(), results.getID());
        Assert.assertEquals(rootName + mTestDevice.getAddress(), results.getID());

        //Request fetch the list of players
        BrowseTree.BrowseNode playerNodes = mAvrcpStateMachine.findNode(results.getID());
@@ -872,7 +872,7 @@ public class AvrcpControllerStateMachineTest {

        //Get the root of the device
        BrowseTree.BrowseNode results = mAvrcpStateMachine.findNode(rootName);
        Assert.assertEquals(rootName + mTestDevice.toString(), results.getID());
        Assert.assertEquals(rootName + mTestDevice.getAddress(), results.getID());

        //Request fetch the list of players
        BrowseTree.BrowseNode playerNodes = mAvrcpStateMachine.findNode(results.getID());
@@ -938,7 +938,7 @@ public class AvrcpControllerStateMachineTest {

        //Get the root of the device
        BrowseTree.BrowseNode rootNode = mAvrcpStateMachine.findNode(rootName);
        Assert.assertEquals(rootName + mTestDevice.toString(), rootNode.getID());
        Assert.assertEquals(rootName + mTestDevice.getAddress(), rootNode.getID());

        //Request fetch the list of players
        BrowseTree.BrowseNode playerNodes = mAvrcpStateMachine.findNode(rootNode.getID());
@@ -997,7 +997,7 @@ public class AvrcpControllerStateMachineTest {

        //Get the root of the device
        BrowseTree.BrowseNode rootNode = mAvrcpStateMachine.findNode(rootName);
        Assert.assertEquals(rootName + mTestDevice.toString(), rootNode.getID());
        Assert.assertEquals(rootName + mTestDevice.getAddress(), rootNode.getID());

        //Request fetch the list of players
        BrowseTree.BrowseNode playerNodes = mAvrcpStateMachine.findNode(rootNode.getID());
@@ -1062,7 +1062,7 @@ public class AvrcpControllerStateMachineTest {

        //Get the root of the device
        BrowseTree.BrowseNode results = mAvrcpStateMachine.findNode(rootName);
        Assert.assertEquals(rootName + mTestDevice.toString(), results.getID());
        Assert.assertEquals(rootName + mTestDevice.getAddress(), results.getID());

        //Request fetch the list of players
        BrowseTree.BrowseNode playerNodes = mAvrcpStateMachine.findNode(results.getID());
+4 −1
Original line number Diff line number Diff line
@@ -20,7 +20,10 @@ apex {
    manifest: "apex_manifest.json",
    bootclasspath_fragments: ["com.android.btservices-bootclasspath-fragment"],
    systemserverclasspath_fragments: ["com.android.btservices-systemserverclasspath-fragment"],
    compat_configs: ["bluetooth-compat-config"],
    compat_configs: [
        "bluetooth-compat-config",
        "framework-bluetooth-compat-config",
    ],
    apps: ["Bluetooth"],

    multilib: {
+8 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ java_defaults {
    libs: [
        "framework-tethering.stubs.module_lib",
        "unsupportedappusage", // for android.compat.annotation.UnsupportedAppUsage
        "app-compat-annotations",
    ],
    stub_only_libs: ["framework-tethering.stubs.module_lib"],
    srcs: [
@@ -102,6 +103,7 @@ java_defaults {

        // if sdk_version="" this gets automatically included, but here we need to add manually.
        "framework-res",
        "app-compat-annotations",
    ],
    defaults_visibility: ["//visibility:public"],
}
@@ -119,3 +121,9 @@ java_api_contribution {
        "//build/orchestrator/apis",
    ],
}

platform_compat_config
{
    name: "framework-bluetooth-compat-config",
    src: ":framework-bluetooth",
}
+26 −5
Original line number Diff line number Diff line
@@ -27,12 +27,15 @@ import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.app.compat.CompatChanges;
import android.bluetooth.annotations.RequiresBluetoothConnectPermission;
import android.bluetooth.annotations.RequiresBluetoothLocationPermission;
import android.bluetooth.annotations.RequiresBluetoothScanPermission;
import android.bluetooth.annotations.RequiresLegacyBluetoothAdminPermission;
import android.bluetooth.annotations.RequiresLegacyBluetoothPermission;
import android.companion.AssociationRequest;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledSince;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.AttributionSource;
import android.content.Context;
@@ -856,6 +859,15 @@ public final class BluetoothDevice implements Parcelable, Attributable {
    public static final String ACTION_PAIRING_REQUEST =
            "android.bluetooth.device.action.PAIRING_REQUEST";

    /**
     * Starting from {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE},
     * the return value of {@link BluetoothDevice#toString()} has changed
     * to improve privacy.
     */
    @ChangeId
    @EnabledSince(targetSdkVersion = android.os.Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
    private static final long CHANGE_TO_STRING_REDACTED = 265103382L;

    /**
     * Broadcast Action: This intent is used to broadcast PAIRING CANCEL
     *
@@ -1422,17 +1434,26 @@ public final class BluetoothDevice implements Parcelable, Attributable {

    /**
     * Returns a string representation of this BluetoothDevice.
     * <p>Currently this is the Bluetooth hardware address, for example
     * "00:11:22:AA:BB:CC". However, you should always use {@link #getAddress}
     * if you explicitly require the Bluetooth hardware address in case the
     * {@link #toString} representation changes in the future.
     * <p> For apps targeting {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}
     * (API level 34) or higher, this returns the MAC address of the device redacted
     * by replacing the hexadecimal digits of leftmost 4 bytes (in big endian order)
     * with "XX", e.g., "XX:XX:XX:XX:12:34". For apps targeting earlier versions,
     * the MAC address is returned without redaction.
     *
     * Warning: The return value of {@link #toString()} may change in the future.
     * It is intended to be used in logging statements. Thus apps should never rely
     * on the return value of {@link #toString()} in their logic. Always use other
     * appropriate APIs instead (e.g., use {@link #getAddress()} to get the MAC address).
     *
     * @return string representation of this BluetoothDevice
     */
    @Override
    public String toString() {
        if (!CompatChanges.isChangeEnabled(CHANGE_TO_STRING_REDACTED)) {
            return mAddress;
        }
        return toStringForLogging();
    }

    private static boolean shouldLogBeRedacted() {
        boolean defaultValue = true;