diff --git a/core/java/android/uwb/RangingParams.java b/core/java/android/uwb/RangingParams.java deleted file mode 100644 index f23d9ed0dd3a0..0000000000000 --- a/core/java/android/uwb/RangingParams.java +++ /dev/null @@ -1,477 +0,0 @@ -/* - * 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 android.annotation.IntDef; -import android.annotation.NonNull; -import android.annotation.Nullable; -import android.os.Parcel; -import android.os.Parcelable; -import android.os.PersistableBundle; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.time.Duration; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Set; - -/** - * An object used when requesting to open a new {@link RangingSession}. - *
Use {@link RangingParams.Builder} to create an instance of this class.
- *
- * @hide
- */
-public final class RangingParams implements Parcelable {
- private final boolean mIsInitiator;
- private final boolean mIsController;
- private final Duration mSamplePeriod;
- private final UwbAddress mLocalDeviceAddress;
- private final List Simultaneous {@link RangingSession}s on the same device can have different results for
- * {@link #getLocalDeviceAddress()}.
- *
- * @return the local device's {@link UwbAddress}
- */
- @NonNull
- public UwbAddress getLocalDeviceAddress() {
- return mLocalDeviceAddress;
- }
-
- /**
- * Gets a list of all remote device's {@link UwbAddress}
- *
- * @return a {@link List} of {@link UwbAddress} representing the remote devices
- */
- @NonNull
- public List Android reserves the '^android.*' namespace
- *
- * @return a {@link PersistableBundle} copy of protocol specific parameters
- */
- public @Nullable PersistableBundle getSpecificationParameters() {
- return new PersistableBundle(mSpecificationParameters);
- }
-
- /**
- * @hide
- */
- @Override
- public boolean equals(@Nullable Object obj) {
- if (this == obj) {
- return true;
- }
-
- if (obj instanceof RangingParams) {
- RangingParams other = (RangingParams) obj;
-
- return mIsInitiator == other.mIsInitiator
- && mIsController == other.mIsController
- && mSamplePeriod.equals(other.mSamplePeriod)
- && mLocalDeviceAddress.equals(other.mLocalDeviceAddress)
- && mRemoteDeviceAddresses.equals(other.mRemoteDeviceAddresses)
- && mChannelNumber == other.mChannelNumber
- && mTransmitPreambleCodeIndex == other.mTransmitPreambleCodeIndex
- && mReceivePreambleCodeIndex == other.mReceivePreambleCodeIndex
- && mStsPhyPacketType == other.mStsPhyPacketType
- && mSpecificationParameters.size() == other.mSpecificationParameters.size()
- && mSpecificationParameters.kindofEquals(other.mSpecificationParameters);
- }
- return false;
- }
-
- /**
- * @hide
- */
- @Override
- public int hashCode() {
- return Objects.hash(mIsInitiator, mIsController, mSamplePeriod, mLocalDeviceAddress,
- mRemoteDeviceAddresses, mChannelNumber, mTransmitPreambleCodeIndex,
- mReceivePreambleCodeIndex, mStsPhyPacketType, mSpecificationParameters);
- }
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeBoolean(mIsInitiator);
- dest.writeBoolean(mIsController);
- dest.writeLong(mSamplePeriod.getSeconds());
- dest.writeInt(mSamplePeriod.getNano());
- dest.writeParcelable(mLocalDeviceAddress, flags);
-
- UwbAddress[] remoteAddresses = new UwbAddress[mRemoteDeviceAddresses.size()];
- mRemoteDeviceAddresses.toArray(remoteAddresses);
- dest.writeParcelableArray(remoteAddresses, flags);
-
- dest.writeInt(mChannelNumber);
- dest.writeInt(mTransmitPreambleCodeIndex);
- dest.writeInt(mReceivePreambleCodeIndex);
- dest.writeInt(mStsPhyPacketType);
- dest.writePersistableBundle(mSpecificationParameters);
- }
-
- public static final @android.annotation.NonNull Creator Valid values are in the range [-1, 15]
- *
- * @param channelNumber the channel to use for the {@link RangingSession}
- * @throws IllegalArgumentException if {@code channelNumber} is invalid.
- */
- public Builder setChannelNumber(int channelNumber) {
- if (channelNumber < -1 || channelNumber > 15) {
- throw new IllegalArgumentException("Invalid channel number");
- }
- mChannelNumber = channelNumber;
- return this;
- }
-
- private static final Set Valid values are in the ranges: [0], [13-16], [21-32]
- *
- * @param transmitPreambleCodeIndex preamble code index to use for transmitting
- * @throws IllegalArgumentException if {@code transmitPreambleCodeIndex} is invalid.
- */
- public Builder setTransmitPreambleCodeIndex(int transmitPreambleCodeIndex) {
- if (!VALID_TX_PREAMBLE_CODES.contains(transmitPreambleCodeIndex)) {
- throw new IllegalArgumentException(
- "Invalid transmit preamble: " + transmitPreambleCodeIndex);
- }
- mTransmitPreambleCodeIndex = transmitPreambleCodeIndex;
- return this;
- }
-
- private static final Set Creates a copy of the parameters
- *
- * @param parameters specification parameters built from support library
- */
- public Builder setSpecificationParameters(@NonNull PersistableBundle parameters) {
- mSpecificationParameters = new PersistableBundle(parameters);
- return this;
- }
-
- /**
- * Build the {@link RangingParams} object.
- *
- * @throws IllegalStateException if required parameters are missing
- */
- public RangingParams build() {
- if (mSamplePeriod == null) {
- throw new IllegalStateException("No sample period provided");
- }
-
- if (mLocalDeviceAddress == null) {
- throw new IllegalStateException("Local device address not provided");
- }
-
- if (mRemoteDeviceAddresses.size() == 0) {
- throw new IllegalStateException("No remote device address(es) provided");
- }
-
- return new RangingParams(mIsInitiator, mIsController, mSamplePeriod,
- mLocalDeviceAddress, mRemoteDeviceAddresses, mChannelNumber,
- mTransmitPreambleCodeIndex, mReceivePreambleCodeIndex, mStsPhyPacketType,
- mSpecificationParameters);
- }
- }
-}
diff --git a/core/java/android/uwb/RangingSession.java b/core/java/android/uwb/RangingSession.java
index f4033fe0d29e9..863926924aad5 100644
--- a/core/java/android/uwb/RangingSession.java
+++ b/core/java/android/uwb/RangingSession.java
@@ -30,7 +30,7 @@ import java.util.concurrent.Executor;
* {@link RangingSession}.
*
* To get an instance of {@link RangingSession}, first use
- * {@link UwbManager#openRangingSession(RangingParams, Executor, Callback)} to request to open a
+ * {@link UwbManager#openRangingSession(PersistableBundle, Executor, Callback)} to request to open a
* session. Once the session is opened, a {@link RangingSession} object is provided through
* {@link RangingSession.Callback#onOpenSuccess(RangingSession, PersistableBundle)}. If opening a
* session fails, the failure is reported through {@link RangingSession.Callback#onClosed(int)} with
@@ -44,7 +44,7 @@ public final class RangingSession implements AutoCloseable {
*/
public interface Callback {
/**
- * Invoked when {@link UwbManager#openRangingSession(RangingParams, Executor, Callback)}
+ * Invoked when {@link UwbManager#openRangingSession(PersistableBundle, Executor, Callback)}
* is successful
*
* @param session the newly opened {@link RangingSession}
@@ -77,7 +77,7 @@ public final class RangingSession implements AutoCloseable {
/**
* Indicates that the session failed to open due to erroneous parameters passed
- * to {@link UwbManager#openRangingSession(RangingParams, Executor, Callback)}
+ * to {@link UwbManager#openRangingSession(PersistableBundle, Executor, Callback)}
*/
int CLOSE_REASON_LOCAL_BAD_PARAMETERS = 2;
@@ -137,8 +137,8 @@ public final class RangingSession implements AutoCloseable {
* will still be invoked.
*
* {@link Callback#onClosed(int)} will be invoked using the same callback
- * object given to {@link UwbManager#openRangingSession(RangingParams, Executor, Callback)} when
- * the {@link RangingSession} was opened. The callback will be invoked after each call to
+ * object given to {@link UwbManager#openRangingSession(PersistableBundle, Executor, Callback)}
+ * when the {@link RangingSession} was opened. The callback will be invoked after each call to
* {@link #close()}, even if the {@link RangingSession} is already closed.
*/
@Override
diff --git a/core/java/android/uwb/UwbManager.java b/core/java/android/uwb/UwbManager.java
index 6bf7d6ffa5d91..2f1e2ded26ac6 100644
--- a/core/java/android/uwb/UwbManager.java
+++ b/core/java/android/uwb/UwbManager.java
@@ -279,7 +279,10 @@ public final class UwbManager {
* An open {@link RangingSession} will be automatically closed if client application process
* dies.
*
- * @param params {@link RangingParams} used to initialize this {@link RangingSession}
+ * A UWB support library must be used in order to construct the {@code parameter}
+ * {@link PersistableBundle}.
+ *
+ * @param parameters the parameters that define the ranging session
* @param executor {@link Executor} to run callbacks
* @param callbacks {@link RangingSession.Callback} to associate with the
* {@link RangingSession} that is being opened.
@@ -290,8 +293,9 @@ public final class UwbManager {
* {@link RangingSession.Callback#onOpenSuccess}.
*/
@NonNull
- public AutoCloseable openRangingSession(@NonNull RangingParams params,
- @NonNull Executor executor, @NonNull RangingSession.Callback callbacks) {
+ public AutoCloseable openRangingSession(@NonNull PersistableBundle parameters,
+ @NonNull Executor executor,
+ @NonNull RangingSession.Callback callbacks) {
throw new UnsupportedOperationException();
}
}
diff --git a/core/tests/uwbtests/src/android/uwb/RangingParamsTest.java b/core/tests/uwbtests/src/android/uwb/RangingParamsTest.java
deleted file mode 100644
index 8095c995b8a9a..0000000000000
--- a/core/tests/uwbtests/src/android/uwb/RangingParamsTest.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import android.os.Parcel;
-import android.os.PersistableBundle;
-
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-import androidx.test.filters.SmallTest;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import java.time.Duration;
-
-/**
- * Test of {@link RangingParams}.
- */
-@SmallTest
-@RunWith(AndroidJUnit4.class)
-public class RangingParamsTest {
-
- @Test
- public void testParams_Build() {
- UwbAddress local = UwbAddress.fromBytes(new byte[] {(byte) 0xA0, (byte) 0x57});
- UwbAddress remote = UwbAddress.fromBytes(new byte[] {(byte) 0x4D, (byte) 0x8C});
- int channel = 9;
- int rxPreamble = 16;
- int txPreamble = 21;
- boolean isController = true;
- boolean isInitiator = false;
- @RangingParams.StsPhyPacketType int stsPhyType = RangingParams.STS_PHY_PACKET_TYPE_SP2;
- Duration samplePeriod = Duration.ofSeconds(1, 234);
- PersistableBundle specParams = new PersistableBundle();
- specParams.putString("protocol", "some_protocol");
-
- RangingParams params = new RangingParams.Builder()
- .setChannelNumber(channel)
- .setReceivePreambleCodeIndex(rxPreamble)
- .setTransmitPreambleCodeIndex(txPreamble)
- .setLocalDeviceAddress(local)
- .addRemoteDeviceAddress(remote)
- .setIsController(isController)
- .setIsInitiator(isInitiator)
- .setSamplePeriod(samplePeriod)
- .setStsPhPacketType(stsPhyType)
- .setSpecificationParameters(specParams)
- .build();
-
- assertEquals(params.getLocalDeviceAddress(), local);
- assertEquals(params.getRemoteDeviceAddresses().size(), 1);
- assertEquals(params.getRemoteDeviceAddresses().get(0), remote);
- assertEquals(params.getChannelNumber(), channel);
- assertEquals(params.isController(), isController);
- assertEquals(params.isInitiator(), isInitiator);
- assertEquals(params.getRxPreambleIndex(), rxPreamble);
- assertEquals(params.getTxPreambleIndex(), txPreamble);
- assertEquals(params.getStsPhyPacketType(), stsPhyType);
- assertEquals(params.getSamplingPeriod(), samplePeriod);
- assertTrue(params.getSpecificationParameters().kindofEquals(specParams));
- }
-
- @Test
- public void testParcel() {
- Parcel parcel = Parcel.obtain();
- RangingParams params = new RangingParams.Builder()
- .setChannelNumber(9)
- .setReceivePreambleCodeIndex(16)
- .setTransmitPreambleCodeIndex(21)
- .setLocalDeviceAddress(UwbTestUtils.getUwbAddress(false))
- .addRemoteDeviceAddress(UwbTestUtils.getUwbAddress(true))
- .setIsController(false)
- .setIsInitiator(true)
- .setSamplePeriod(Duration.ofSeconds(2))
- .setStsPhPacketType(RangingParams.STS_PHY_PACKET_TYPE_SP1)
- .build();
- params.writeToParcel(parcel, 0);
- parcel.setDataPosition(0);
- RangingParams fromParcel = RangingParams.CREATOR.createFromParcel(parcel);
- assertEquals(params, fromParcel);
- }
-}