Add try/catch, shim in Nearby initialization
The try/catch allows using a stub NearbyService on branches that do not
support it yet.
Also update Context.NEARBY_SERVICE to ConstantsShim to be compatible
with all branches.
Bug: 189355156
Test: boots
Change-Id: I7db0035b0d9ada79f00d6ef1ac5b54b2e98489d0
diff --git a/service-t/src/com/android/server/ConnectivityServiceInitializer.java b/service-t/src/com/android/server/ConnectivityServiceInitializer.java
index d11f0f2..25fe5e9 100644
--- a/service-t/src/com/android/server/ConnectivityServiceInitializer.java
+++ b/service-t/src/com/android/server/ConnectivityServiceInitializer.java
@@ -20,6 +20,7 @@
import android.util.Log;
import com.android.modules.utils.build.SdkLevel;
+import com.android.networkstack.apishim.ConstantsShim;
import com.android.server.nearby.NearbyService;
/**
@@ -60,8 +61,8 @@
}
if (mNearbyService != null) {
- Log.i(TAG, "Registering " + Context.NEARBY_SERVICE);
- publishBinderService(Context.NEARBY_SERVICE, mNearbyService,
+ Log.i(TAG, "Registering " + ConstantsShim.NEARBY_SERVICE);
+ publishBinderService(ConstantsShim.NEARBY_SERVICE, mNearbyService,
/* allowIsolated= */ false);
}
}
@@ -96,6 +97,13 @@
/** Return Nearby service instance or null if current SDK is lower than T */
private NearbyService createNearbyService(final Context context) {
if (!SdkLevel.isAtLeastT()) return null;
- return new NearbyService(context);
+ try {
+ return new NearbyService(context);
+ } catch (UnsupportedOperationException e) {
+ // Nearby is not yet supported in all branches
+ // TODO: remove catch clause when it is available.
+ Log.i(TAG, "Skipping unsupported service " + ConstantsShim.NEARBY_SERVICE);
+ return null;
+ }
}
}