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

Commit f8b33c5f authored by Christine Hallstrom's avatar Christine Hallstrom Committed by Automerger Merge Worker
Browse files

Merge "Return null if identity address unknown" into main am: bfd21f90

parents 66c3d1de bfd21f90
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -126,6 +126,7 @@ import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.bluetooth.btservice.storage.MetadataDatabase;
import com.android.bluetooth.csip.CsipSetCoordinatorService;
import com.android.bluetooth.flags.FeatureFlagsImpl;
import com.android.bluetooth.flags.Flags;
import com.android.bluetooth.gatt.GattService;
import com.android.bluetooth.le_scan.ScanManager;
import com.android.bluetooth.hap.HapClientService;
@@ -5897,6 +5898,11 @@ public class AdapterService extends Service {
        DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device);
        if (deviceProp != null && deviceProp.getIdentityAddress() != null) {
            return Utils.getBytesFromAddress(deviceProp.getIdentityAddress());
        }

        if (Flags.identityAddressNullIfUnknown()) {
            // Return null if identity address unknown
            return null;
        } else {
            return Utils.getByteAddress(device);
        }
@@ -5916,10 +5922,15 @@ public class AdapterService extends Service {
        DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device);
        if (deviceProp != null && deviceProp.getIdentityAddress() != null) {
            return deviceProp.getIdentityAddress();
        } else {
            if (Flags.identityAddressNullIfUnknown()) {
                // Return null if identity address unknown
                return null;
            } else {
                return address;
            }
        }
    }

    private static class CallerInfo {
        public String callerPackageName;
+15 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import android.os.UserManager;
import android.os.test.TestLooper;
import android.permission.PermissionCheckerManager;
import android.permission.PermissionManager;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import android.sysprop.BluetoothProperties;
import android.test.mock.MockContentProvider;
@@ -72,6 +73,7 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.bluetooth.TestUtils;
import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.bluetoothkeystore.BluetoothKeystoreNativeInterface;
import com.android.bluetooth.flags.Flags;
import com.android.bluetooth.gatt.AdvertiseManagerNativeInterface;
import com.android.bluetooth.gatt.DistanceMeasurementNativeInterface;
import com.android.bluetooth.gatt.GattNativeInterface;
@@ -84,6 +86,7 @@ import libcore.util.HexEncoding;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -132,6 +135,8 @@ public class AdapterServiceTest {
    private @Mock PeriodicScanNativeInterface mPeriodicNativeInterface;
    private @Mock JniCallbacks mJniCallbacks;

    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    // SystemService that are not mocked
    private BluetoothManager mBluetoothManager;
    private CompanionDeviceManager mCompanionDeviceManager;
@@ -871,6 +876,16 @@ public class AdapterServiceTest {
        assertThat(identityAddress).isEqualTo(TEST_BT_ADDR_2);
    }

    @Test
    public void testIdentityAddressNullIfUnknown() {
        mSetFlagsRule.enableFlags(Flags.FLAG_IDENTITY_ADDRESS_NULL_IF_UNKNOWN);

        BluetoothDevice device = TestUtils.getTestDevice(BluetoothAdapter.getDefaultAdapter(), 0);

        assertThat(mAdapterService.getByteIdentityAddress(device)).isNull();
        assertThat(mAdapterService.getIdentityAddress(device.getAddress())).isNull();
    }

    public static byte[] getMetricsSalt(HashMap<String, HashMap<String, String>> adapterConfig) {
        HashMap<String, String> metricsSection = adapterConfig.get("Metrics");
        if (metricsSection == null) {