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

Commit 848cc69c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "uwb_api_changes" into sc-dev

* changes:
  Pass SessionHandle to UWB Service when opening a session
  Return CancellationSignal when opening UWB session
  Address UWB API feedback
parents 3b1852bd 16fddb44
Loading
Loading
Loading
Loading
+3 −11
Original line number Diff line number Diff line
@@ -13840,6 +13840,7 @@ package android.util {
package android.uwb {
  public final class AngleMeasurement implements android.os.Parcelable {
    ctor public AngleMeasurement(double, double, double);
    method public int describeContents();
    method @FloatRange(from=0.0, to=1.0) public double getConfidenceLevel();
    method @FloatRange(from=0.0, to=3.141592653589793) public double getErrorRadians();
@@ -13848,14 +13849,6 @@ package android.uwb {
    field @NonNull public static final android.os.Parcelable.Creator<android.uwb.AngleMeasurement> CREATOR;
  }
  public static final class AngleMeasurement.Builder {
    ctor public AngleMeasurement.Builder();
    method @NonNull public android.uwb.AngleMeasurement build();
    method @NonNull public android.uwb.AngleMeasurement.Builder setConfidenceLevel(double);
    method @NonNull public android.uwb.AngleMeasurement.Builder setErrorRadians(double);
    method @NonNull public android.uwb.AngleMeasurement.Builder setRadians(double);
  }
  public final class AngleOfArrivalMeasurement implements android.os.Parcelable {
    method public int describeContents();
    method @Nullable public android.uwb.AngleMeasurement getAltitude();
@@ -13865,10 +13858,9 @@ package android.uwb {
  }
  public static final class AngleOfArrivalMeasurement.Builder {
    ctor public AngleOfArrivalMeasurement.Builder();
    ctor public AngleOfArrivalMeasurement.Builder(@NonNull android.uwb.AngleMeasurement);
    method @NonNull public android.uwb.AngleOfArrivalMeasurement build();
    method @NonNull public android.uwb.AngleOfArrivalMeasurement.Builder setAltitude(@NonNull android.uwb.AngleMeasurement);
    method @NonNull public android.uwb.AngleOfArrivalMeasurement.Builder setAzimuth(@NonNull android.uwb.AngleMeasurement);
  }
  public final class DistanceMeasurement implements android.os.Parcelable {
@@ -13968,7 +13960,7 @@ package android.uwb {
  public final class UwbManager {
    method @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public long elapsedRealtimeResolutionNanos();
    method @NonNull @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public android.os.PersistableBundle getSpecificationInfo();
    method @NonNull @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public AutoCloseable openRangingSession(@NonNull android.os.PersistableBundle, @NonNull java.util.concurrent.Executor, @NonNull android.uwb.RangingSession.Callback);
    method @NonNull @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public android.os.CancellationSignal openRangingSession(@NonNull android.os.PersistableBundle, @NonNull java.util.concurrent.Executor, @NonNull android.uwb.RangingSession.Callback);
    method @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public void registerAdapterStateCallback(@NonNull java.util.concurrent.Executor, @NonNull android.uwb.UwbManager.AdapterStateCallback);
    method @RequiresPermission(android.Manifest.permission.UWB_PRIVILEGED) public void unregisterAdapterStateCallback(@NonNull android.uwb.UwbManager.AdapterStateCallback);
  }
+23 −84
Original line number Diff line number Diff line
@@ -38,9 +38,30 @@ public final class AngleMeasurement implements Parcelable {
    private final double mErrorRadians;
    private final double mConfidenceLevel;

    private AngleMeasurement(double radians, double errorRadians, double confidenceLevel) {
    /**
     * Constructs a new {@link AngleMeasurement} object
     *
     * @param radians the angle in radians
     * @param errorRadians the error of the angle measurement in radians
     * @param confidenceLevel confidence level of the angle measurement
     *
     * @throws IllegalArgumentException if the radians, errorRadians, or confidenceLevel is out of
     *                                  allowed range
     */
    public AngleMeasurement(double radians, double errorRadians, double confidenceLevel) {
        if (radians < -Math.PI || radians > Math.PI) {
            throw new IllegalArgumentException("Invalid radians: " + radians);
        }
        mRadians = radians;

        if (errorRadians < 0.0 || errorRadians > Math.PI) {
            throw new IllegalArgumentException("Invalid error radians: " + errorRadians);
        }
        mErrorRadians = errorRadians;

        if (confidenceLevel < 0.0 || confidenceLevel > 1.0) {
            throw new IllegalArgumentException("Invalid confidence level: " + confidenceLevel);
        }
        mConfidenceLevel = confidenceLevel;
    }

@@ -122,11 +143,7 @@ public final class AngleMeasurement implements Parcelable {
            new Creator<AngleMeasurement>() {
                @Override
                public AngleMeasurement createFromParcel(Parcel in) {
                    Builder builder = new Builder();
                    builder.setRadians(in.readDouble());
                    builder.setErrorRadians(in.readDouble());
                    builder.setConfidenceLevel(in.readDouble());
                    return builder.build();
                    return new AngleMeasurement(in.readDouble(), in.readDouble(), in.readDouble());
                }

                @Override
@@ -134,82 +151,4 @@ public final class AngleMeasurement implements Parcelable {
                    return new AngleMeasurement[size];
                }
    };

    /**
     * Builder class for {@link AngleMeasurement}.
     */
    public static final class Builder {
        private double mRadians = Double.NaN;
        private double mErrorRadians = Double.NaN;
        private double mConfidenceLevel = Double.NaN;

        /**
         * Set the angle in radians
         *
         * @param radians angle in radians
         * @throws IllegalArgumentException if angle exceeds allowed limits of [-Math.PI, +Math.PI]
         */
        @NonNull
        public Builder setRadians(double radians) {
            if (radians < -Math.PI || radians > Math.PI) {
                throw new IllegalArgumentException("Invalid radians: " + radians);
            }
            mRadians = radians;
            return this;
        }

        /**
         * Set the angle error in radians
         *
         * @param errorRadians error of the angle in radians
         * @throws IllegalArgumentException if the error exceeds the allowed limits of [0, +Math.PI]
         */
        @NonNull
        public Builder setErrorRadians(double errorRadians) {
            if (errorRadians < 0.0 || errorRadians > Math.PI) {
                throw new IllegalArgumentException(
                        "Invalid error radians: " + errorRadians);
            }
            mErrorRadians = errorRadians;
            return this;
        }

        /**
         * Set the angle confidence level
         *
         * @param confidenceLevel level of confidence of the angle measurement
         * @throws IllegalArgumentException if the error exceeds the allowed limits of [0.0, 1.0]
         */
        @NonNull
        public Builder setConfidenceLevel(double confidenceLevel) {
            if (confidenceLevel < 0.0 || confidenceLevel > 1.0) {
                throw new IllegalArgumentException(
                        "Invalid confidence level: " + confidenceLevel);
            }
            mConfidenceLevel = confidenceLevel;
            return this;
        }

        /**
         * Build the {@link AngleMeasurement} object
         *
         * @throws IllegalStateException if angle, error, or confidence values are missing
         */
        @NonNull
        public AngleMeasurement build() {
            if (Double.isNaN(mRadians)) {
                throw new IllegalStateException("Angle is not set");
            }

            if (Double.isNaN(mErrorRadians)) {
                throw new IllegalStateException("Angle error is not set");
            }

            if (Double.isNaN(mConfidenceLevel)) {
                throw new IllegalStateException("Angle confidence level is not set");
            }

            return new AngleMeasurement(mRadians, mErrorRadians, mConfidenceLevel);
        }
    }
}
+6 −15
Original line number Diff line number Diff line
@@ -116,9 +116,8 @@ public final class AngleOfArrivalMeasurement implements Parcelable {
            new Creator<AngleOfArrivalMeasurement>() {
                @Override
                public AngleOfArrivalMeasurement createFromParcel(Parcel in) {
                    Builder builder = new Builder();

                    builder.setAzimuth(in.readParcelable(AngleMeasurement.class.getClassLoader()));
                    Builder builder =
                            new Builder(in.readParcelable(AngleMeasurement.class.getClassLoader()));

                    builder.setAltitude(in.readParcelable(AngleMeasurement.class.getClassLoader()));

@@ -135,18 +134,16 @@ public final class AngleOfArrivalMeasurement implements Parcelable {
     * Builder class for {@link AngleOfArrivalMeasurement}.
     */
    public static final class Builder {
        private AngleMeasurement mAzimuthAngleMeasurement = null;
        private final AngleMeasurement mAzimuthAngleMeasurement;
        private AngleMeasurement mAltitudeAngleMeasurement = null;

        /**
         * Set the azimuth angle
         * Constructs an {@link AngleOfArrivalMeasurement} object
         *
         * @param azimuthAngle azimuth angle
         * @param azimuthAngle the azimuth angle of the measurement
         */
        @NonNull
        public Builder setAzimuth(@NonNull AngleMeasurement azimuthAngle) {
        public Builder(@NonNull AngleMeasurement azimuthAngle) {
            mAzimuthAngleMeasurement = azimuthAngle;
            return this;
        }

        /**
@@ -162,15 +159,9 @@ public final class AngleOfArrivalMeasurement implements Parcelable {

        /**
         * Build the {@link AngleOfArrivalMeasurement} object
         *
         * @throws IllegalStateException if the required azimuth angle is not provided
         */
        @NonNull
        public AngleOfArrivalMeasurement build() {
            if (mAzimuthAngleMeasurement == null) {
                throw new IllegalStateException("Azimuth angle measurement is not set");
            }

            return new AngleOfArrivalMeasurement(mAzimuthAngleMeasurement,
                    mAltitudeAngleMeasurement);
        }
+7 −6
Original line number Diff line number Diff line
@@ -62,9 +62,6 @@ interface IUwbAdapter {
  /**
   * Request to open a new ranging session
   *
   * This function must return before calling any functions in
   * IUwbAdapterCallbacks.
   *
   * This function does not start the ranging session, but all necessary
   * components must be initialized and ready to start a new ranging
   * session prior to calling IUwbAdapterCallback#onRangingOpened.
@@ -77,11 +74,15 @@ interface IUwbAdapter {
   * RANGING_SESSION_OPEN_THRESHOLD_MS milliseconds of #openRanging being called
   * if the ranging session fails to be opened.
   *
   * If the provided sessionHandle is already open for the calling client, then
   * #onRangingOpenFailed must be called and the new session must not be opened.
   *
   * @param sessionHandle the session handle to open ranging for
   * @param rangingCallbacks the callbacks used to deliver ranging information
   * @param parameters the configuration to use for ranging
   * @return a SessionHandle used to identify this ranging request
   */
  SessionHandle openRanging(in IUwbRangingCallbacks rangingCallbacks,
  void openRanging(in SessionHandle sessionHandle,
                   in IUwbRangingCallbacks rangingCallbacks,
                   in PersistableBundle parameters);

  /**
+16 −17
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.uwb;

import android.annotation.NonNull;
import android.os.CancellationSignal;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.util.Log;
@@ -32,6 +33,7 @@ public class RangingManager extends android.uwb.IUwbRangingCallbacks.Stub {

    private final IUwbAdapter mAdapter;
    private final Hashtable<SessionHandle, RangingSession> mRangingSessionTable = new Hashtable<>();
    private int mNextSessionId = 1;

    public RangingManager(IUwbAdapter adapter) {
        mAdapter = adapter;
@@ -44,29 +46,26 @@ public class RangingManager extends android.uwb.IUwbRangingCallbacks.Stub {
     * @param executor {@link Executor} to run callbacks
     * @param callbacks {@link RangingSession.Callback} to associate with the {@link RangingSession}
     *                  that is being opened.
     * @return a new {@link RangingSession}
     * @return a {@link CancellationSignal} that may be used to cancel the opening of the
     *         {@link RangingSession}.
     */
    public RangingSession openSession(@NonNull PersistableBundle params, @NonNull Executor executor,
    public CancellationSignal openSession(@NonNull PersistableBundle params,
            @NonNull Executor executor,
            @NonNull RangingSession.Callback callbacks) {
        SessionHandle sessionHandle;
        synchronized (this) {
            SessionHandle sessionHandle = new SessionHandle(mNextSessionId++);
            RangingSession session =
                    new RangingSession(executor, callbacks, mAdapter, sessionHandle);
            mRangingSessionTable.put(sessionHandle, session);
            try {
            sessionHandle = mAdapter.openRanging(this, params);
                mAdapter.openRanging(sessionHandle, this, params);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }

        synchronized (this) {
            if (hasSession(sessionHandle)) {
                Log.w(TAG, "Newly created session unexpectedly reuses an active SessionHandle");
                executor.execute(() -> callbacks.onClosed(
                        RangingSession.Callback.REASON_GENERIC_ERROR,
                        new PersistableBundle()));
            }

            RangingSession session =
                    new RangingSession(executor, callbacks, mAdapter, sessionHandle);
            mRangingSessionTable.put(sessionHandle, session);
            return session;
            CancellationSignal cancellationSignal = new CancellationSignal();
            cancellationSignal.setOnCancelListener(() -> session.close());
            return cancellationSignal;
        }
    }

Loading