Expose UwbManager through Context.getSystemService am: 3163bf0d35
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1504101 Change-Id: I14aa423224f37447024ddb4cc67cabe06d60a30a
This commit is contained in:
@@ -189,6 +189,7 @@ import android.telephony.TelephonyRegistryManager;
|
|||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
import android.uwb.UwbManager;
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
@@ -719,6 +720,14 @@ public final class SystemServiceRegistry {
|
|||||||
return new SerialManager(ctx, ISerialManager.Stub.asInterface(b));
|
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,
|
registerService(Context.VIBRATOR_SERVICE, Vibrator.class,
|
||||||
new CachedServiceFetcher<Vibrator>() {
|
new CachedServiceFetcher<Vibrator>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -3513,6 +3513,7 @@ public abstract class Context {
|
|||||||
//@hide: TIME_ZONE_DETECTOR_SERVICE,
|
//@hide: TIME_ZONE_DETECTOR_SERVICE,
|
||||||
PERMISSION_SERVICE,
|
PERMISSION_SERVICE,
|
||||||
LIGHTS_SERVICE,
|
LIGHTS_SERVICE,
|
||||||
|
UWB_SERVICE,
|
||||||
})
|
})
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
public @interface ServiceName {}
|
public @interface ServiceName {}
|
||||||
@@ -5177,6 +5178,15 @@ public abstract class Context {
|
|||||||
*/
|
*/
|
||||||
public static final String LIGHTS_SERVICE = "lights";
|
public static final String LIGHTS_SERVICE = "lights";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Use with {@link #getSystemService(String)} to retrieve a
|
||||||
* {@link android.app.DreamManager} for controlling Dream states.
|
* {@link android.app.DreamManager} for controlling Dream states.
|
||||||
|
|||||||
@@ -2498,6 +2498,15 @@ public abstract class PackageManager {
|
|||||||
@SdkConstant(SdkConstantType.FEATURE)
|
@SdkConstant(SdkConstantType.FEATURE)
|
||||||
public static final String FEATURE_TELEPHONY_IMS = "android.hardware.telephony.ims";
|
public static final String FEATURE_TELEPHONY_IMS = "android.hardware.telephony.ims";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Feature for {@link #getSystemAvailableFeatures} and
|
||||||
* {@link #hasSystemFeature}: The device supports connecting to USB devices
|
* {@link #hasSystemFeature}: The device supports connecting to USB devices
|
||||||
|
|||||||
@@ -19,7 +19,11 @@ package android.uwb;
|
|||||||
import android.annotation.IntDef;
|
import android.annotation.IntDef;
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.annotation.SystemService;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.IBinder;
|
||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
|
import android.os.ServiceManager;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
@@ -36,7 +40,11 @@ import java.util.concurrent.Executor;
|
|||||||
*
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
|
@SystemService(Context.UWB_SERVICE)
|
||||||
public final class UwbManager {
|
public final class UwbManager {
|
||||||
|
private IUwbAdapter mUwbAdapter;
|
||||||
|
private static final String SERVICE_NAME = "uwb";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for receiving UWB adapter state changes
|
* 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.
|
* Use <code>Context.getSystemService(UwbManager.class)</code> to get an instance.
|
||||||
|
*
|
||||||
|
* @param adapter an instance of an {@link android.uwb.IUwbAdapter}
|
||||||
*/
|
*/
|
||||||
private UwbManager() {
|
private UwbManager(IUwbAdapter adapter) {
|
||||||
throw new UnsupportedOperationException();
|
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
|
* Register an {@link AdapterStateCallback} to listen for UWB adapter state changes
|
||||||
* <p>The provided callback will be invoked by the given {@link Executor}.
|
* <p>The provided callback will be invoked by the given {@link Executor}.
|
||||||
|
|||||||
49
core/tests/uwbtests/src/android/uwb/UwbManagerTest.java
Normal file
49
core/tests/uwbtests/src/android/uwb/UwbManagerTest.java
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package android.uwb;
|
package android.uwb;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -24,6 +26,11 @@ import java.util.List;
|
|||||||
public class UwbTestUtils {
|
public class UwbTestUtils {
|
||||||
private UwbTestUtils() {}
|
private UwbTestUtils() {}
|
||||||
|
|
||||||
|
public static boolean isUwbSupported(Context context) {
|
||||||
|
PackageManager packageManager = context.getPackageManager();
|
||||||
|
return packageManager.hasSystemFeature(PackageManager.FEATURE_UWB);
|
||||||
|
}
|
||||||
|
|
||||||
public static AngleMeasurement getAngleMeasurement() {
|
public static AngleMeasurement getAngleMeasurement() {
|
||||||
return new AngleMeasurement.Builder()
|
return new AngleMeasurement.Builder()
|
||||||
.setRadians(getDoubleInRange(-Math.PI, Math.PI))
|
.setRadians(getDoubleInRange(-Math.PI, Math.PI))
|
||||||
|
|||||||
Reference in New Issue
Block a user