Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c57e2123 authored by Brian Stack's avatar Brian Stack Committed by Automerger Merge Worker
Browse files

Expose UwbManager through Context.getSystemService am: 3163bf0d am: 2557747c

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1504101

Change-Id: I5213f04b2bf1f0db39a872ab7dd7f0d45fd60103
parents 88bfa915 2557747c
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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
+10 −0
Original line number Diff line number Diff line
@@ -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 {}
@@ -5177,6 +5178,15 @@ public abstract class Context {
     */
    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
     * {@link android.app.DreamManager} for controlling Dream states.
+9 −0
Original line number Diff line number Diff line
@@ -2512,6 +2512,15 @@ public abstract class PackageManager {
    @SdkConstant(SdkConstantType.FEATURE)
    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
     * {@link #hasSystemFeature}: The device supports connecting to USB devices
+30 −2
Original line number Diff line number Diff line
@@ -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}.
+49 −0
Original line number Diff line number Diff line
/*
 * 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);
        }
    }
}
Loading