Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +12 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } Loading @@ -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; Loading android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java +15 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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) { Loading Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +12 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } Loading @@ -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; Loading
android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java +15 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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) { Loading