Fix NPE in TestSatelliteService
Bug: 308781799
Test: atest SatelliteManagerTestOnMockService. Manually tested the satellite test app.
Change-Id: I9ef4f199b3272cd536d58a67356bf29ed4dd7431
diff --git a/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/TestSatelliteService.java b/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/TestSatelliteService.java
index af3da0b..047c8d4 100644
--- a/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/TestSatelliteService.java
+++ b/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/TestSatelliteService.java
@@ -44,6 +44,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
+import java.util.concurrent.atomic.AtomicBoolean;
/**
* Test service for Satellite to verify end to end flow via testapp.
@@ -77,6 +78,8 @@
private final LocalBinder mBinder = new LocalBinder();
@SatelliteResult
private int mErrorCode = SatelliteResult.SATELLITE_RESULT_SUCCESS;
+ private final AtomicBoolean mShouldNotifyRemoteServiceConnected =
+ new AtomicBoolean(false);
// For local access of this Service.
class LocalBinder extends Binder {
@@ -389,6 +392,9 @@
public void setLocalSatelliteListener(@NonNull ILocalSatelliteListener listener) {
logd("setLocalSatelliteListener: listener=" + listener);
mLocalListener = listener;
+ if (mShouldNotifyRemoteServiceConnected.get()) {
+ notifyRemoteServiceConnected();
+ }
}
public void setErrorCode(@SatelliteResult int errorCode) {
@@ -494,7 +500,12 @@
private void notifyRemoteServiceConnected() {
logd("notifyRemoteServiceConnected");
- runWithExecutor(() -> mLocalListener.onRemoteServiceConnected());
+ if (mLocalListener != null) {
+ runWithExecutor(() -> mLocalListener.onRemoteServiceConnected());
+ mShouldNotifyRemoteServiceConnected.set(false);
+ } else {
+ mShouldNotifyRemoteServiceConnected.set(true);
+ }
}
/**