summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--androidx_backend/Android.bp2
-rw-r--r--framework/java/android/uwb/AdapterStateListener.java3
-rw-r--r--framework/java/android/uwb/IUwbAdapter.aidl3
-rw-r--r--framework/java/android/uwb/UwbManager.java4
-rw-r--r--service/Android.bp1
-rw-r--r--service/java/com/android/server/uwb/UwbServiceCore.java256
-rw-r--r--service/java/com/android/server/uwb/UwbServiceImpl.java6
-rw-r--r--service/java/com/android/server/uwb/UwbShellCommand.java37
-rw-r--r--service/tests/src/com/android/server/uwb/UwbServiceCoreTest.java1
-rw-r--r--service/tests/src/com/android/server/uwb/UwbSessionManagerTest.java34
-rw-r--r--tests/cts/tests/Android.bp2
-rw-r--r--tests/cts/tests/src/android/uwb/cts/UwbManagerTest.java119
12 files changed, 62 insertions, 406 deletions
diff --git a/androidx_backend/Android.bp b/androidx_backend/Android.bp
index 78dad067..acfa5664 100644
--- a/androidx_backend/Android.bp
+++ b/androidx_backend/Android.bp
@@ -74,7 +74,7 @@ java_library {
android_app {
name: "uwb_androidx_backend_app",
- sdk_version: "system_34",
+ sdk_version: "system_UpsideDownCake",
min_sdk_version: "32",
certificate: "platform",
privileged: true,
diff --git a/framework/java/android/uwb/AdapterStateListener.java b/framework/java/android/uwb/AdapterStateListener.java
index ce3fc264..5a4acbc5 100644
--- a/framework/java/android/uwb/AdapterStateListener.java
+++ b/framework/java/android/uwb/AdapterStateListener.java
@@ -194,9 +194,6 @@ public class AdapterStateListener extends IUwbAdapterStateCallbacks.Stub {
case AdapterState.STATE_ENABLED_ACTIVE:
return AdapterStateCallback.STATE_ENABLED_ACTIVE;
- case AdapterState.STATE_ENABLED_HW_IDLE:
- return AdapterStateCallback.STATE_ENABLED_HW_IDLE;
-
case AdapterState.STATE_DISABLED:
default:
return AdapterStateCallback.STATE_DISABLED;
diff --git a/framework/java/android/uwb/IUwbAdapter.aidl b/framework/java/android/uwb/IUwbAdapter.aidl
index 8574e4bd..287dc6cf 100644
--- a/framework/java/android/uwb/IUwbAdapter.aidl
+++ b/framework/java/android/uwb/IUwbAdapter.aidl
@@ -17,7 +17,6 @@
package android.uwb;
import android.content.AttributionSource;
-import android.os.IBinder;
import android.os.PersistableBundle;
import android.uwb.IUwbAdapterStateCallbacks;
import android.uwb.IUwbAdfProvisionStateCallbacks;
@@ -302,7 +301,7 @@ interface IUwbAdapter {
int getAdapterState();
boolean isHwIdleTurnOffEnabled();
- void requestHwEnabled(boolean enabled, in AttributionSource attributionSource, IBinder binder);
+ void requestHwEnabled(boolean enabled, in AttributionSource attributionSource);
boolean isHwEnableRequested(in AttributionSource attributionSource);
/**
diff --git a/framework/java/android/uwb/UwbManager.java b/framework/java/android/uwb/UwbManager.java
index 704a548e..d19ff9bb 100644
--- a/framework/java/android/uwb/UwbManager.java
+++ b/framework/java/android/uwb/UwbManager.java
@@ -816,9 +816,7 @@ public final class UwbManager {
@RequiresPermission(permission.UWB_PRIVILEGED)
public void requestUwbHwEnabled(boolean enabled) {
try {
- mUwbAdapter.requestHwEnabled(
- enabled, mContext.getAttributionSource(),
- new Binder(mContext.getPackageName()));
+ mUwbAdapter.requestHwEnabled(enabled, mContext.getAttributionSource());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
diff --git a/service/Android.bp b/service/Android.bp
index 5ccb7779..3d4e3db1 100644
--- a/service/Android.bp
+++ b/service/Android.bp
@@ -56,6 +56,7 @@ java_library {
"framework-statsd.stubs.module_lib",
"framework-wifi.stubs.module_lib",
"framework-bluetooth.stubs.module_lib",
+ "framework-location.stubs.module_lib",
],
static_libs: [
diff --git a/service/java/com/android/server/uwb/UwbServiceCore.java b/service/java/com/android/server/uwb/UwbServiceCore.java
index 8098bd55..de33b36a 100644
--- a/service/java/com/android/server/uwb/UwbServiceCore.java
+++ b/service/java/com/android/server/uwb/UwbServiceCore.java
@@ -25,7 +25,6 @@ import android.annotation.NonNull;
import android.content.AttributionSource;
import android.content.Context;
import android.os.Handler;
-import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.PersistableBundle;
@@ -85,8 +84,6 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutionException;
@@ -108,10 +105,6 @@ public class UwbServiceCore implements INativeUwbManager.DeviceNotification,
public static final int TASK_RESTART = 3;
@VisibleForTesting
public static final int TASK_GET_POWER_STATS = 4;
- @VisibleForTesting
- public static final int TASK_HW_ENABLE = 5;
- @VisibleForTesting
- public static final int TASK_HW_DISABLE = 6;
@VisibleForTesting
public static final int WATCHDOG_MS = 10000;
@@ -134,8 +127,6 @@ public class UwbServiceCore implements INativeUwbManager.DeviceNotification,
private final UwbInjector mUwbInjector;
private final Map<String, /* @UwbManager.AdapterStateCallback.State */ Integer>
mChipIdToStateMap;
-
- private final UwbClientHwState mUwbClientHwState = new UwbClientHwState();
private Map<String, UwbDeviceInfoResponse> mChipIdToDeviceInfoResponseMap = new HashMap<>();
private @StateChangeReason int mLastAdapterStateChangedReason = StateChangeReason.UNKNOWN;
private @AdapterStateCallback.State int mLastAdapterStateNotification = -1;
@@ -146,130 +137,6 @@ public class UwbServiceCore implements INativeUwbManager.DeviceNotification,
private boolean mNeedCachedSpecParamsUpdate = true;
private final Set<InitializationFailureListener> mListeners = new ArraySet<>();
- /**
- * Wrapper class to hold {@link AttributionSource} and override it's equals
- * to remove the check for token since we want to uniquely identify client (not different binder
- * tokens* from the same client).
- */
- private class AttributionSourceHolder implements IBinder.DeathRecipient {
- private final AttributionSource mAttributionSource;
- private final IBinder mBinder;
-
- AttributionSourceHolder(AttributionSource attributionSource, IBinder binder) {
- mAttributionSource = attributionSource;
- mBinder = binder;
- }
-
- public AttributionSource getAttributionSource() {
- return mAttributionSource;
- }
-
- public void linkToDeath() {
- try {
- mBinder.linkToDeath(this, 0);
- } catch (RemoteException e) {
- Log.e(TAG, "Failed to register for death recipient for "
- + mAttributionSource);
- }
- }
-
- public void unlinkToDeath() {
- try {
- mBinder.unlinkToDeath(this, 0);
- } catch (NoSuchElementException e) { }
- }
-
- @Override
- public boolean equals(@Nullable Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- AttributionSourceHolder that = (AttributionSourceHolder) o;
- return mAttributionSource.getUid() == that.mAttributionSource.getUid()
- && Objects.equals(mAttributionSource.getPackageName(),
- that.mAttributionSource.getPackageName())
- && Objects.equals(mAttributionSource.getAttributionTag(),
- that.mAttributionSource.getAttributionTag())
- && Objects.equals(mAttributionSource.getNext(), that.mAttributionSource.getNext());
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(mAttributionSource.getUid(), mAttributionSource.getPackageName(),
- mAttributionSource.getAttributionTag(), mAttributionSource.getNext());
- }
-
- @Override
- public String toString() {
- return mAttributionSource.toString();
- }
-
- @Override
- public void binderDied() {
- Log.i(TAG, "binderDied : reset hw enable for " + this);
- mUwbClientHwState.setEnabled(this, false);
- }
- }
-
- /**
- * Storing a map of {@link AttributionSource} to enable/disable state of each client.
- */
- private class UwbClientHwState {
- private final Map<AttributionSourceHolder, Boolean> mMap = new HashMap<>();
-
- public void setEnabled(AttributionSourceHolder attributionSourceHolder, boolean enable) {
- Boolean prevValue = mMap.put(attributionSourceHolder, Boolean.valueOf(enable));
- if (prevValue == null) prevValue = false;
- // If enabling, add link to death.
- if (!prevValue && enable) {
- attributionSourceHolder.linkToDeath();
- }
- // If disabling, remove link to death.
- if (prevValue && !enable) {
- attributionSourceHolder.unlinkToDeath();
- }
- }
-
- /**
- * We use AttributionSourceHolder to linkToDeath, so avoid creating duplicate objects in the
- * map for the same client.
- */
- public AttributionSourceHolder getOrCreate(
- AttributionSource attributionSource, IBinder binder) {
- for (AttributionSourceHolder k : mMap.keySet()) {
- if (Objects.equals(k.getAttributionSource(), attributionSource)) {
- return k;
- }
- }
- return new AttributionSourceHolder(attributionSource, binder);
- }
-
- public boolean isEnabled(AttributionSourceHolder attributionSourceHolder) {
- return mMap.getOrDefault(attributionSourceHolder, false);
- }
-
- /**
- * Check all the client states to figure out if we should enable the hardware.
- *
- * <li> If feature {@link DeviceConfigFacade#isHwIdleTurnOffEnabled()} is disabled -> true
- * </li>
- * <li> If there is at least 1 client vote to enable -> true </li>
- * <li> Else -> false </li>
- *
- * @return
- */
- public boolean shouldHwBeEnabled() {
- // If the feature is disabled, always return true.
- if (!mUwbInjector.getDeviceConfigFacade().isHwIdleTurnOffEnabled()) return true;
- // Unless all clients vote to disable the hardware, enable it.
- return mMap.values().stream().filter(v -> v).findAny().orElse(false);
- }
-
- @Override
- public String toString() {
- return "UwbClientHwState [" + mMap + "]";
- }
- }
-
public UwbServiceCore(Context uwbApplicationContext, NativeUwbManager nativeUwbManager,
UwbMetrics uwbMetrics, UwbCountryCode uwbCountryCode,
UwbSessionManager uwbSessionManager, UwbConfigurationManager uwbConfigurationManager,
@@ -857,13 +724,6 @@ public class UwbServiceCore implements INativeUwbManager.DeviceNotification,
}
private int computeAdapterState(String countryCode, Optional<Integer> setCountryCodeStatus) {
- int internalAdapterState = getInternalAdapterState();
- if (internalAdapterState == AdapterStateCallback.STATE_DISABLED
- && !mUwbClientHwState.shouldHwBeEnabled()) {
- // If the UWB chip was disabled due to lack of vote for uwb hardware, then
- // send corresponding state.
- return AdapterStateCallback.STATE_ENABLED_HW_IDLE;
- }
// When either the country code is not valid or setting it in UWBS failed with an error,
// notify the UWB stack state as DISABLED (even though internally the UWB device state
// may be stored as READY), so that applications wait for starting a ranging session.
@@ -872,7 +732,7 @@ public class UwbServiceCore implements INativeUwbManager.DeviceNotification,
&& setCountryCodeStatus.get() != STATUS_CODE_OK)) {
return AdapterStateCallback.STATE_DISABLED;
}
- return internalAdapterState;
+ return getInternalAdapterState();
}
/**
@@ -926,32 +786,12 @@ public class UwbServiceCore implements INativeUwbManager.DeviceNotification,
}
public synchronized void requestHwEnabled(
- boolean enabled, AttributionSource attributionSource, IBinder binder) {
- int task = enabled ? TASK_HW_ENABLE : TASK_HW_DISABLE;
- AttributionSourceHolder attributionSourceHolder =
- mUwbClientHwState.getOrCreate(attributionSource, binder);
- if (enabled && mUwbClientHwState.isEnabled(attributionSourceHolder)) {
- Log.w(TAG, "Uwb hardware is already enabled by " + attributionSource);
- } else if (!enabled && !mUwbClientHwState.isEnabled(attributionSourceHolder)) {
- Log.w(TAG, "Uwb hardware is already disabled by " + attributionSource);
- }
- mUwbTask.execute(task, attributionSourceHolder);
- }
-
- private void updateHwState(AttributionSourceHolder attributionSourceHolder, boolean enable) {
- Log.d(TAG, "updateHwState(): state=" + enable
- + ", attributionSource=" + attributionSourceHolder);
- synchronized (UwbServiceCore.this) {
- mUwbClientHwState.setEnabled(attributionSourceHolder, enable);
- Log.d(TAG, "mUwbClientHwState= " + mUwbClientHwState);
- }
+ boolean enabled, AttributionSource attributionSource) {
}
public boolean isHwEnableRequested(AttributionSource attributionSource) {
synchronized (UwbServiceCore.this) {
- AttributionSourceHolder attributionSourceHolder =
- mUwbClientHwState.getOrCreate(attributionSource, null);
- return mUwbClientHwState.isEnabled(attributionSourceHolder);
+ return true;
}
}
@@ -1055,14 +895,6 @@ public class UwbServiceCore implements INativeUwbManager.DeviceNotification,
handleDisable();
break;
- case TASK_HW_ENABLE:
- handleHwEnable((AttributionSourceHolder) msg.obj);
- break;
-
- case TASK_HW_DISABLE:
- handleHwDisable((AttributionSourceHolder) msg.obj);
- break;
-
case TASK_RESTART:
mSessionManager.deinitAllSession();
handleDisable();
@@ -1116,7 +948,12 @@ public class UwbServiceCore implements INativeUwbManager.DeviceNotification,
this.sendMessageDelayed(msg, delayMillis);
}
- private void initializeHw() {
+ private void handleEnable() {
+ if (isUwbEnabledInternal()) {
+ Log.i(TAG, "UWB chip is already enabled, notify adapter state = "
+ + getAdapterState());
+ return;
+ }
try {
WatchDogThread watchDog = new WatchDogThread("handleEnable", WATCHDOG_MS);
watchDog.start();
@@ -1125,6 +962,7 @@ public class UwbServiceCore implements INativeUwbManager.DeviceNotification,
synchronized (mUwbWakeLock) {
mUwbWakeLock.acquire();
}
+
try {
Map<String, UwbDeviceInfoResponse> result = mNativeUwbManager.doInitialize();
if (result == null) {
@@ -1185,7 +1023,13 @@ public class UwbServiceCore implements INativeUwbManager.DeviceNotification,
}
}
- private void deInitializeHw() {
+ private void handleDisable() {
+ if (!isUwbEnabledInternal()) {
+ Log.i(TAG, "UWB chip is already disabled, notify adapter state = "
+ + getAdapterState());
+ return;
+ }
+
WatchDogThread watchDog = new WatchDogThread("handleDisable", WATCHDOG_MS);
watchDog.start();
@@ -1206,15 +1050,9 @@ public class UwbServiceCore implements INativeUwbManager.DeviceNotification,
for (String chipId : mUwbInjector.getMultichipData().getChipIds()) {
updateDeviceState(UwbUciConstants.DEVICE_STATE_OFF, chipId);
}
- int adapterState = getAdapterStateFromDeviceState(UwbUciConstants.DEVICE_STATE_OFF);
- int adapterReason = getReasonFromDeviceState(UwbUciConstants.DEVICE_STATE_OFF);
- if (!mUwbClientHwState.shouldHwBeEnabled()) {
- // If the UWB chip was disabled due to lack of vote for uwb hardware, then
- // send corresponding state.
- adapterState = AdapterStateCallback.STATE_ENABLED_HW_IDLE;
- adapterReason = StateChangeReason.SYSTEM_POLICY;
- }
- notifyAdapterState(adapterState, adapterReason);
+ notifyAdapterState(
+ getAdapterStateFromDeviceState(UwbUciConstants.DEVICE_STATE_OFF),
+ getReasonFromDeviceState(UwbUciConstants.DEVICE_STATE_OFF));
} finally {
synchronized (mUwbWakeLock) {
if (mUwbWakeLock.isHeld()) {
@@ -1225,60 +1063,6 @@ public class UwbServiceCore implements INativeUwbManager.DeviceNotification,
}
}
-
- private void handleEnable() {
- if (isUwbEnabledInternal()) {
- Log.i(TAG, "UWB chip is already enabled, notify adapter state = "
- + getAdapterState());
- return;
- }
- if (mUwbClientHwState.shouldHwBeEnabled()) {
- initializeHw();
- } else {
- Log.i(TAG, "UWB Hw not requested, not enabling");
- // If no clients have voted to enable hardware, just send notification to external
- // clients with corresponding reason.
- notifyAdapterState(
- AdapterStateCallback.STATE_ENABLED_HW_IDLE,
- StateChangeReason.SYSTEM_POLICY);
- }
- }
-
- private void handleDisable() {
- if (!isUwbEnabledInternal()) {
- Log.i(TAG, "UWB chip is already disabled, notify adapter state = "
- + getAdapterState());
- return;
- }
- deInitializeHw();
- }
-
- private void handleHwEnable(AttributionSourceHolder attributionSourceHolder) {
- if (mUwbClientHwState.isEnabled(attributionSourceHolder)) {
- Log.i(TAG, "UWB hardware is already enabled by " + attributionSourceHolder);
- return;
- }
- boolean prevShouldHwBeEnabled = mUwbClientHwState.shouldHwBeEnabled();
- updateHwState(attributionSourceHolder, true);
- if (!prevShouldHwBeEnabled && mUwbClientHwState.shouldHwBeEnabled()) {
- Log.i(TAG, "UWB Hw requested, enabling");
- initializeHw();
- }
- }
-
- private void handleHwDisable(AttributionSourceHolder attributionSourceHolder) {
- if (!mUwbClientHwState.isEnabled(attributionSourceHolder)) {
- Log.i(TAG, "UWB hardware is already disabled by " + attributionSourceHolder);
- return;
- }
- boolean prevShouldHwBeEnabled = mUwbClientHwState.shouldHwBeEnabled();
- updateHwState(attributionSourceHolder, false);
- if (prevShouldHwBeEnabled && !mUwbClientHwState.shouldHwBeEnabled()) {
- Log.i(TAG, "UWB Hw not requested, disabling");
- deInitializeHw();
- }
- }
-
private void computeAndNotifyAdapterStateChange(int reason,
String countryCode, Optional<Integer> setCountryCodeStatus) {
// When either the country code is not valid or setting it in UWBS failed with the error
diff --git a/service/java/com/android/server/uwb/UwbServiceImpl.java b/service/java/com/android/server/uwb/UwbServiceImpl.java
index a8306909..a4e5ada0 100644
--- a/service/java/com/android/server/uwb/UwbServiceImpl.java
+++ b/service/java/com/android/server/uwb/UwbServiceImpl.java
@@ -27,7 +27,6 @@ import android.content.IntentFilter;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Binder;
-import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle;
import android.os.Process;
@@ -434,14 +433,13 @@ public class UwbServiceImpl extends IUwbAdapter.Stub {
}
@Override
- public synchronized void requestHwEnabled(
- boolean enabled, AttributionSource attributionSource, IBinder binder)
+ public synchronized void requestHwEnabled(boolean enabled, AttributionSource attributionSource)
throws RemoteException {
enforceUwbPrivilegedPermission();
if (!mUwbInjector.getDeviceConfigFacade().isHwIdleTurnOffEnabled()) {
throw new IllegalStateException("Hw Idle turn off not enabled");
}
- mUwbServiceCore.requestHwEnabled(enabled, attributionSource, binder);
+ mUwbServiceCore.requestHwEnabled(enabled, attributionSource);
}
@Override
diff --git a/service/java/com/android/server/uwb/UwbShellCommand.java b/service/java/com/android/server/uwb/UwbShellCommand.java
index b3e107f9..116bb1c6 100644
--- a/service/java/com/android/server/uwb/UwbShellCommand.java
+++ b/service/java/com/android/server/uwb/UwbShellCommand.java
@@ -155,8 +155,6 @@ public class UwbShellCommand extends BasicShellCommandHandler {
"get-log-mode",
"enable-uwb",
"disable-uwb",
- "enable-uwb-hw",
- "disable-uwb-hw",
"simulate-app-state-change",
"start-fira-ranging-session",
"start-ccc-ranging-session",
@@ -1257,22 +1255,6 @@ public class UwbShellCommand extends BasicShellCommandHandler {
case "disable-uwb":
mUwbService.setEnabled(false);
return 0;
- case "enable-uwb-hw": {
- AttributionSource attributionSource = new AttributionSource.Builder(
- Process.SHELL_UID)
- .setPackageName(SHELL_PACKAGE_NAME)
- .build();
- mUwbService.requestHwEnabled(true, attributionSource, new Binder());
- return 0;
- }
- case "disable-uwb-hw": {
- AttributionSource attributionSource = new AttributionSource.Builder(
- Process.SHELL_UID)
- .setPackageName(SHELL_PACKAGE_NAME)
- .build();
- mUwbService.requestHwEnabled(false, attributionSource, new Binder());
- return 0;
- }
case "start-dl-tdoa-ranging-session":
startDlTDoaRangingSession(pw);
return 0;
@@ -1414,18 +1396,9 @@ public class UwbShellCommand extends BasicShellCommandHandler {
}
private void printStatus(PrintWriter pw) throws RemoteException {
- int adapterState = mUwbService.getAdapterState();
- boolean uwbEnabled = adapterState != UwbManager.AdapterStateCallback.STATE_DISABLED;
- boolean uwbHwIdle = adapterState == UwbManager.AdapterStateCallback.STATE_ENABLED_HW_IDLE;
- String status;
- if (uwbHwIdle) {
- status = "enabled by user, but no clients have voted to enable hw";
- } else if (uwbEnabled) {
- status = "enabled";
- } else {
- status = "disabled";
- }
- pw.println("Uwb is " + status);
+ boolean uwbEnabled =
+ mUwbService.getAdapterState() != UwbManager.AdapterStateCallback.STATE_DISABLED;
+ pw.println("Uwb is " + (uwbEnabled ? "enabled" : "disabled"));
}
private void onHelpNonPrivileged(PrintWriter pw) {
@@ -1439,10 +1412,6 @@ public class UwbShellCommand extends BasicShellCommandHandler {
pw.println(" Toggle UWB on");
pw.println(" disable-uwb");
pw.println(" Toggle UWB off");
- pw.println(" enable-uwb-hw");
- pw.println(" If 'hw_idle_turn_off_enabled' feature is enabled, vote for UWB on");
- pw.println(" disable-uwb-hw");
- pw.println(" If 'hw_idle_turn_off_enabled' feature is enabled, vote for UWB off");
pw.println(" start-fira-ranging-session"
+ " [-b](blocking call)"
+ " [-i <sessionId>](session-id)"
diff --git a/service/tests/src/com/android/server/uwb/UwbServiceCoreTest.java b/service/tests/src/com/android/server/uwb/UwbServiceCoreTest.java
index b928c777..0dff1df7 100644
--- a/service/tests/src/com/android/server/uwb/UwbServiceCoreTest.java
+++ b/service/tests/src/com/android/server/uwb/UwbServiceCoreTest.java
@@ -271,7 +271,6 @@ public class UwbServiceCoreTest {
when(mUwbInjector.getMultichipData()).thenReturn(uwbMultichipData);
when(mDeviceConfigFacade.getBugReportMinIntervalMs())
.thenReturn(DeviceConfigFacade.DEFAULT_BUG_REPORT_MIN_INTERVAL_MS);
- when(mDeviceConfigFacade.isHwIdleTurnOffEnabled()).thenReturn(false);
when(mUwbInjector.getProfileManager()).thenReturn(mProfileManager);
doAnswer(invocation -> {
FutureTask t = invocation.getArgument(0);
diff --git a/service/tests/src/com/android/server/uwb/UwbSessionManagerTest.java b/service/tests/src/com/android/server/uwb/UwbSessionManagerTest.java
index f861acc4..2bf5e997 100644
--- a/service/tests/src/com/android/server/uwb/UwbSessionManagerTest.java
+++ b/service/tests/src/com/android/server/uwb/UwbSessionManagerTest.java
@@ -19,6 +19,7 @@ package com.android.server.uwb;
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
+import static com.android.modules.utils.build.SdkLevel.isAtLeastV;
import static com.android.server.uwb.UwbSessionManager.SESSION_OPEN_RANGING;
import static com.android.server.uwb.UwbTestUtils.DATA_PAYLOAD;
import static com.android.server.uwb.UwbTestUtils.MAX_DATA_SIZE;
@@ -85,6 +86,8 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.ActivityManager.OnUidImportanceListener;
import android.app.AlarmManager;
@@ -94,6 +97,7 @@ import android.os.PersistableBundle;
import android.os.Process;
import android.os.RemoteException;
import android.os.test.TestLooper;
+import android.permission.flags.Flags;
import android.util.Pair;
import android.uwb.IUwbAdapter;
import android.uwb.IUwbRangingCallbacks;
@@ -2090,18 +2094,28 @@ public class UwbSessionManagerTest {
assertThat(mTestLooper.isIdle()).isFalse();
}
+ private AttributionSource.Builder setNextAttributionSource(
+ @NonNull AttributionSource.Builder builder,
+ @Nullable AttributionSource nextAttributionSource) {
+ if (isAtLeastV() && Flags.setNextAttributionSource()) {
+ return builder.setNextAttributionSource(nextAttributionSource);
+ } else {
+ return builder.setNext(nextAttributionSource);
+ }
+ }
+
private UwbSession initUwbSessionForNonSystemAppInFgInChain() throws Exception {
when(mUwbInjector.isSystemApp(UID_2, PACKAGE_NAME_2)).thenReturn(false);
when(mUwbInjector.isForegroundAppOrService(UID_2, PACKAGE_NAME_2))
.thenReturn(true);
// simulate system app triggered the request on behalf of a fg app in fg.
- AttributionSource attributionSource = new AttributionSource.Builder(UID)
- .setPackageName(PACKAGE_NAME)
- .setNext(new AttributionSource.Builder(UID_2)
+ AttributionSource.Builder builder = new AttributionSource.Builder(UID)
+ .setPackageName(PACKAGE_NAME);
+ builder = setNextAttributionSource(builder, new AttributionSource.Builder(UID_2)
.setPackageName(PACKAGE_NAME_2)
- .build())
- .build();
+ .build());
+ AttributionSource attributionSource = builder.build();
UwbSession uwbSession = setUpUwbSessionForExecution(attributionSource);
mUwbSessionManager.initSession(attributionSource, uwbSession.getSessionHandle(),
@@ -2339,12 +2353,12 @@ public class UwbSessionManagerTest {
.thenReturn(false);
// simulate system app triggered the request on behalf of a fg app not in fg.
- AttributionSource attributionSource = new AttributionSource.Builder(UID)
- .setPackageName(PACKAGE_NAME)
- .setNext(new AttributionSource.Builder(UID_2)
+ AttributionSource.Builder builder = new AttributionSource.Builder(UID)
+ .setPackageName(PACKAGE_NAME);
+ builder = setNextAttributionSource(builder, new AttributionSource.Builder(UID_2)
.setPackageName(PACKAGE_NAME_2)
- .build())
- .build();
+ .build());
+ AttributionSource attributionSource = builder.build();
UwbSession uwbSession = setUpUwbSessionForExecution(attributionSource);
mUwbSessionManager.initSession(attributionSource, uwbSession.getSessionHandle(),
TEST_SESSION_ID, TEST_SESSION_TYPE, FiraParams.PROTOCOL_NAME,
diff --git a/tests/cts/tests/Android.bp b/tests/cts/tests/Android.bp
index c527be04..6675dda7 100644
--- a/tests/cts/tests/Android.bp
+++ b/tests/cts/tests/Android.bp
@@ -38,8 +38,6 @@ android_test {
"com.uwb.support.multichip",
"com.uwb.support.oemextension",
"com.uwb.support.dltdoa",
- "flag-junit",
- "uwb_flags_lib",
],
srcs: ["src/**/*.java"],
platform_apis: true,
diff --git a/tests/cts/tests/src/android/uwb/cts/UwbManagerTest.java b/tests/cts/tests/src/android/uwb/cts/UwbManagerTest.java
index 38edd886..6e1178fc 100644
--- a/tests/cts/tests/src/android/uwb/cts/UwbManagerTest.java
+++ b/tests/cts/tests/src/android/uwb/cts/UwbManagerTest.java
@@ -20,7 +20,6 @@ import static android.Manifest.permission.UWB_PRIVILEGED;
import static android.Manifest.permission.UWB_RANGING;
import static android.uwb.UwbManager.AdapterStateCallback.STATE_DISABLED;
import static android.uwb.UwbManager.AdapterStateCallback.STATE_ENABLED_ACTIVE;
-import static android.uwb.UwbManager.AdapterStateCallback.STATE_ENABLED_HW_IDLE;
import static android.uwb.UwbManager.AdapterStateCallback.STATE_ENABLED_INACTIVE;
import static android.uwb.UwbManager.MESSAGE_TYPE_COMMAND;
@@ -49,9 +48,6 @@ import android.os.Process;
import android.os.UserHandle;
import android.permission.PermissionManager;
import android.platform.test.annotations.AppModeFull;
-import android.platform.test.annotations.RequiresFlagsEnabled;
-import android.platform.test.flag.junit.CheckFlagsRule;
-import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.util.Log;
import android.uwb.RangingMeasurement;
import android.uwb.RangingReport;
@@ -65,6 +61,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
import com.android.compatibility.common.util.CddTest;
+import com.android.compatibility.common.util.ShellIdentityUtils;
import com.android.modules.utils.build.SdkLevel;
import com.google.uwb.support.dltdoa.DlTDoAMeasurement;
@@ -83,11 +80,9 @@ import com.google.uwb.support.oemextension.RangingReportMetadata;
import com.google.uwb.support.oemextension.SessionConfigParams;
import com.google.uwb.support.oemextension.SessionStatus;
-import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Ignore;
-import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -114,9 +109,6 @@ public class UwbManagerTest {
public static final int UWB_SESSION_STATE_IDLE = 0x03;
public static final byte DEVICE_STATE_ACTIVE = 0x02;
public static final int REASON_STATE_CHANGE_WITH_SESSION_MANAGEMENT_COMMANDS = 0x00;
- @Rule
- public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
-
@Before
public void setup() throws Exception {
@@ -125,37 +117,16 @@ public class UwbManagerTest {
assertThat(mUwbManager).isNotNull();
// Ensure UWB is toggled on.
- UiAutomation uiAutomation = getInstrumentation().getUiAutomation();
- try {
- // Needs UWB_PRIVILEGED permission which is held by shell.
- uiAutomation.adoptShellPermissionIdentity();
+ ShellIdentityUtils.invokeWithShellPermissions(() -> {
if (!mUwbManager.isUwbEnabled()) {
- setUwbEnabledAndWaitForCompletion(true);
- }
- if (mUwbManager.isUwbHwIdleTurnOffEnabled()) {
- // If HW idle mode is turned on, vote for the UWB hardware for tests to pass.
- requestUwbHwEnabledAndWaitForCompletion(true, mUwbManager, true);
- }
- mDefaultChipId = mUwbManager.getDefaultChipId();
- } finally {
- uiAutomation.dropShellPermissionIdentity();
- }
- }
-
- @After
- public void teardown() throws Exception {
- UiAutomation uiAutomation = getInstrumentation().getUiAutomation();
- try {
- // Needs UWB_PRIVILEGED permission which is held by shell.
- uiAutomation.adoptShellPermissionIdentity();
- if (mUwbManager.isUwbHwIdleTurnOffEnabled()) {
- // If HW idle mode is turned on, reset vote for the UWB hardware.
- requestUwbHwEnabledAndWaitForCompletion(false, mUwbManager, false);
+ try {
+ setUwbEnabledAndWaitForCompletion(true);
+ } catch (Exception e) {
+ fail("Exception while processing UWB toggle " + e);
+ }
}
mDefaultChipId = mUwbManager.getDefaultChipId();
- } finally {
- uiAutomation.dropShellPermissionIdentity();
- }
+ });
}
// Should be invoked with shell permissions.
@@ -1491,7 +1462,7 @@ public class UwbManagerTest {
});
}
- private static class AdapterStateCallback implements UwbManager.AdapterStateCallback {
+ private class AdapterStateCallback implements UwbManager.AdapterStateCallback {
private final CountDownLatch mCountDownLatch;
private final Integer mWaitForState;
public int state;
@@ -1993,76 +1964,4 @@ public class UwbManagerTest {
() -> mUwbManager.getUwbActivityEnergyInfoAsync(Executors.newSingleThreadExecutor(),
null));
}
-
- private UwbManager createUwbManagerWithAttrTag(String attributionTag) {
- Context contextWithAttrTag = mContext.createContext(
- new ContextParams.Builder()
- .setAttributionTag(attributionTag)
- .build()
- );
- return contextWithAttrTag.getSystemService(UwbManager.class);
- }
-
- // Should be invoked with shell permissions.
- private static void requestUwbHwEnabledAndWaitForCompletion(boolean enabled,
- UwbManager uwbManager, boolean expectAdapterEnable) throws Exception {
- CountDownLatch countDownLatch = new CountDownLatch(1);
- int adapterState = expectAdapterEnable ? STATE_ENABLED_INACTIVE : STATE_ENABLED_HW_IDLE;
- AdapterStateCallback adapterStateCallback =
- new AdapterStateCallback(countDownLatch, adapterState);
- try {
- uwbManager.registerAdapterStateCallback(
- Executors.newSingleThreadExecutor(), adapterStateCallback);
- uwbManager.requestUwbHwEnabled(enabled);
- assertThat(countDownLatch.await(2, TimeUnit.SECONDS)).isTrue();
- assertThat(adapterStateCallback.state).isEqualTo(adapterState);
- } finally {
- uwbManager.unregisterAdapterStateCallback(adapterStateCallback);
- }
- }
-
- @Test
- @CddTest(requirements = {"7.3.13/C-1-1,C-1-2,C-1-4"})
- @RequiresFlagsEnabled("com.android.uwb.flags.hw_state")
- public void testUwbHwStateToggle() throws Exception {
- assumeTrue(mUwbManager.isUwbHwIdleTurnOffEnabled());
- UiAutomation uiAutomation = getInstrumentation().getUiAutomation();
- try {
- // Needs UWB_PRIVILEGED permission which is held by shell.
- uiAutomation.adoptShellPermissionIdentity();
- assertThat(mUwbManager.isUwbHwEnableRequested()).isEqualTo(true);
- assertThat(mUwbManager.getAdapterState()).isEqualTo(STATE_ENABLED_INACTIVE);
- // Toggle the HW state on & off.
- requestUwbHwEnabledAndWaitForCompletion(false, mUwbManager, false);
- requestUwbHwEnabledAndWaitForCompletion(true, mUwbManager, true);
- } finally {
- uiAutomation.dropShellPermissionIdentity();
- }
- }
-
- @Test
- @CddTest(requirements = {"7.3.13/C-1-1,C-1-2,C-1-4"})
- @RequiresFlagsEnabled("com.android.uwb.flags.hw_state")
- public void testUwbHwStateToggleMultipleClients() throws Exception {
- assumeTrue(mUwbManager.isUwbHwIdleTurnOffEnabled());
- UiAutomation uiAutomation = getInstrumentation().getUiAutomation();
- UwbManager uwbManagerWithAttrTag1 = createUwbManagerWithAttrTag("tag1");
- UwbManager uwbManagerWithAttrTag2 = createUwbManagerWithAttrTag("tag2");
- try {
- // Needs UWB_PRIVILEGED permission which is held by shell.
- uiAutomation.adoptShellPermissionIdentity();
- // First remove the vote from the test setup
- requestUwbHwEnabledAndWaitForCompletion(false, mUwbManager, false);
-
- // Toggle the HW state on & off.
- requestUwbHwEnabledAndWaitForCompletion(true, uwbManagerWithAttrTag1, true);
- requestUwbHwEnabledAndWaitForCompletion(true, uwbManagerWithAttrTag2, true);
- requestUwbHwEnabledAndWaitForCompletion(false, uwbManagerWithAttrTag1, true);
- requestUwbHwEnabledAndWaitForCompletion(false, uwbManagerWithAttrTag2, false);
- } finally {
- // Reset back to vote as expected by the setup.
- requestUwbHwEnabledAndWaitForCompletion(true, mUwbManager, true);
- uiAutomation.dropShellPermissionIdentity();
- }
- }
}