summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/app/SystemServiceRegistry.java9
-rw-r--r--core/java/android/content/Context.java10
-rw-r--r--core/java/android/content/pm/PackageManager.java9
-rw-r--r--core/java/android/uwb/UwbManager.java32
-rw-r--r--core/tests/uwbtests/src/android/uwb/UwbManagerTest.java49
-rw-r--r--core/tests/uwbtests/src/android/uwb/UwbTestUtils.java7
6 files changed, 114 insertions, 2 deletions
diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java
index d10e33f1577f..496ac3bbb8e9 100644
--- a/core/java/android/app/SystemServiceRegistry.java
+++ b/core/java/android/app/SystemServiceRegistry.java
@@ -189,6 +189,7 @@ import android.telephony.TelephonyRegistryManager;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Slog;
+import android.uwb.UwbManager;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.WindowManager;
@@ -719,6 +720,14 @@ public final class SystemServiceRegistry {
return new SerialManager(ctx, ISerialManager.Stub.asInterface(b));
}});
+ registerService(Context.UWB_SERVICE, UwbManager.class,
+ new CachedServiceFetcher<UwbManager>() {
+ @Override
+ public UwbManager createService(ContextImpl ctx) {
+ return UwbManager.getInstance();
+ }
+ });
+
registerService(Context.VIBRATOR_SERVICE, Vibrator.class,
new CachedServiceFetcher<Vibrator>() {
@Override
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index 7ffcead2d234..92ede1ca45fb 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -3513,6 +3513,7 @@ public abstract class Context {
//@hide: TIME_ZONE_DETECTOR_SERVICE,
PERMISSION_SERVICE,
LIGHTS_SERVICE,
+ UWB_SERVICE,
})
@Retention(RetentionPolicy.SOURCE)
public @interface ServiceName {}
@@ -5179,6 +5180,15 @@ public abstract class Context {
/**
* Use with {@link #getSystemService(String)} to retrieve a
+ * {@link android.uwb.UwbManager}.
+ *
+ * @see #getSystemService(String)
+ * @hide
+ */
+ public static final String UWB_SERVICE = "uwb";
+
+ /**
+ * Use with {@link #getSystemService(String)} to retrieve a
* {@link android.app.DreamManager} for controlling Dream states.
*
* @see #getSystemService(String)
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index 74463fd18887..50ef08a9598a 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -2500,6 +2500,15 @@ public abstract class PackageManager {
/**
* Feature for {@link #getSystemAvailableFeatures} and
+ * {@link #hasSystemFeature}: The device is capable of communicating with
+ * other devices via ultra wideband.
+ * @hide
+ */
+ @SdkConstant(SdkConstantType.FEATURE)
+ public static final String FEATURE_UWB = "android.hardware.uwb";
+
+ /**
+ * Feature for {@link #getSystemAvailableFeatures} and
* {@link #hasSystemFeature}: The device supports connecting to USB devices
* as the USB host.
*/
diff --git a/core/java/android/uwb/UwbManager.java b/core/java/android/uwb/UwbManager.java
index 2f1e2ded26ac..6488490b8863 100644
--- a/core/java/android/uwb/UwbManager.java
+++ b/core/java/android/uwb/UwbManager.java
@@ -19,7 +19,11 @@ package android.uwb;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SuppressLint;
+import android.annotation.SystemService;
+import android.content.Context;
+import android.os.IBinder;
import android.os.PersistableBundle;
+import android.os.ServiceManager;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -36,7 +40,11 @@ import java.util.concurrent.Executor;
*
* @hide
*/
+@SystemService(Context.UWB_SERVICE)
public final class UwbManager {
+ private IUwbAdapter mUwbAdapter;
+ private static final String SERVICE_NAME = "uwb";
+
/**
* Interface for receiving UWB adapter state changes
*/
@@ -96,10 +104,30 @@ public final class UwbManager {
/**
* Use <code>Context.getSystemService(UwbManager.class)</code> to get an instance.
+ *
+ * @param adapter an instance of an {@link android.uwb.IUwbAdapter}
*/
- private UwbManager() {
- throw new UnsupportedOperationException();
+ private UwbManager(IUwbAdapter adapter) {
+ mUwbAdapter = adapter;
+ }
+
+ /**
+ * @hide
+ */
+ public static UwbManager getInstance() {
+ IBinder b = ServiceManager.getService(SERVICE_NAME);
+ if (b == null) {
+ return null;
+ }
+
+ IUwbAdapter adapter = IUwbAdapter.Stub.asInterface(b);
+ if (adapter == null) {
+ return null;
+ }
+
+ return new UwbManager(adapter);
}
+
/**
* Register an {@link AdapterStateCallback} to listen for UWB adapter state changes
* <p>The provided callback will be invoked by the given {@link Executor}.
diff --git a/core/tests/uwbtests/src/android/uwb/UwbManagerTest.java b/core/tests/uwbtests/src/android/uwb/UwbManagerTest.java
new file mode 100644
index 000000000000..4983bed742fd
--- /dev/null
+++ b/core/tests/uwbtests/src/android/uwb/UwbManagerTest.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.uwb;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import android.content.Context;
+
+import androidx.test.InstrumentationRegistry;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.SmallTest;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Test of {@link UwbManager}.
+ */
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class UwbManagerTest {
+
+ public final Context mContext = InstrumentationRegistry.getContext();
+
+ @Test
+ public void testServiceAvailable() {
+ UwbManager manager = mContext.getSystemService(UwbManager.class);
+ if (UwbTestUtils.isUwbSupported(mContext)) {
+ assertNotNull(manager);
+ } else {
+ assertNull(manager);
+ }
+ }
+}
diff --git a/core/tests/uwbtests/src/android/uwb/UwbTestUtils.java b/core/tests/uwbtests/src/android/uwb/UwbTestUtils.java
index 62e0b629539b..fb7509248b38 100644
--- a/core/tests/uwbtests/src/android/uwb/UwbTestUtils.java
+++ b/core/tests/uwbtests/src/android/uwb/UwbTestUtils.java
@@ -16,6 +16,8 @@
package android.uwb;
+import android.content.Context;
+import android.content.pm.PackageManager;
import android.os.SystemClock;
import java.util.ArrayList;
@@ -24,6 +26,11 @@ import java.util.List;
public class UwbTestUtils {
private UwbTestUtils() {}
+ public static boolean isUwbSupported(Context context) {
+ PackageManager packageManager = context.getPackageManager();
+ return packageManager.hasSystemFeature(PackageManager.FEATURE_UWB);
+ }
+
public static AngleMeasurement getAngleMeasurement() {
return new AngleMeasurement.Builder()
.setRadians(getDoubleInRange(-Math.PI, Math.PI))