Fix robo test crash.
Test: robo test
Bug: 216213766
Change-Id: I6c81ccdc5ca3d385f4960cff552a03791fe21cc8
diff --git a/nearby/tests/robotests/src/com/android/libraries/testing/deviceshadower/shadows/bluetooth/ShadowBluetoothAdapter.java b/nearby/tests/robotests/src/com/android/libraries/testing/deviceshadower/shadows/bluetooth/ShadowBluetoothAdapter.java
index c9f83a6..394afbc 100644
--- a/nearby/tests/robotests/src/com/android/libraries/testing/deviceshadower/shadows/bluetooth/ShadowBluetoothAdapter.java
+++ b/nearby/tests/robotests/src/com/android/libraries/testing/deviceshadower/shadows/bluetooth/ShadowBluetoothAdapter.java
@@ -17,6 +17,7 @@
package com.android.libraries.testing.deviceshadower.shadows.bluetooth;
import android.bluetooth.BluetoothAdapter;
+import android.content.AttributionSource;
import com.android.libraries.testing.deviceshadower.internal.DeviceShadowEnvironmentImpl;
import com.android.libraries.testing.deviceshadower.internal.bluetooth.BlueletImpl;
@@ -49,4 +50,16 @@
BlueletImpl localBluelet = DeviceShadowEnvironmentImpl.getLocalBlueletImpl();
return localBluelet.getAdapter();
}
+
+ @Implementation
+ public static BluetoothAdapter createAdapter(AttributionSource attributionSource) {
+ // Add a device and set local devicelet in case no local bluelet set
+ if (!DeviceShadowEnvironmentImpl.hasLocalDeviceletImpl()) {
+ String address = MacAddressGenerator.get().generateMacAddress();
+ DeviceShadowEnvironmentImpl.addDevice(address);
+ DeviceShadowEnvironmentImpl.setLocalDevice(address);
+ }
+ BlueletImpl localBluelet = DeviceShadowEnvironmentImpl.getLocalBlueletImpl();
+ return localBluelet.getAdapter();
+ }
}