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

Commit 641a52f9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add control functions to RangingSession" am: 022ba65d

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

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ib0277c191acd5ed2b27f850b57e1d4cb4b6966c4
parents 5470608a 022ba65d
Loading
Loading
Loading
Loading
+69 −15
Original line number Diff line number Diff line
@@ -119,41 +119,95 @@ interface IUwbAdapter {
  PersistableBundle getSpecificationInfo();

  /**
   * Request to start a new ranging session
   * Request to open a new ranging session
   *
   * This function must return before calling IUwbAdapterCallbacks
   * #onRangingStarted, #onRangingClosed, or #onRangingResult.
   * This function must return before calling any functions in
   * IUwbAdapterCallbacks.
   *
   * A ranging session does not need to be started before returning.
   * 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.
   *
   * IUwbAdapterCallbacks#onRangingStarted must be called within
   * RANGING_SESSION_START_THRESHOLD_MS milliseconds of #startRanging being called
   * if the ranging session is scheduled to start successfully.
   * IUwbAdapterCallbacks#onRangingOpened must be called within
   * RANGING_SESSION_OPEN_THRESHOLD_MS milliseconds of #openRanging being
   * called if the ranging session is opened successfully.
   *
   * IUwbAdapterCallbacks#onRangingStartFailed must be called within
   * RANGING_SESSION_START_THRESHOLD_MS milliseconds of #startRanging being called
   * if the ranging session fails to be scheduled to start successfully.
   * IUwbAdapterCallbacks#onRangingOpenFailed must be called within
   * RANGING_SESSION_OPEN_THRESHOLD_MS milliseconds of #openRanging being called
   * if the ranging session fails to be opened.
   *
   * @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 startRanging(in IUwbRangingCallbacks rangingCallbacks,
  SessionHandle openRanging(in IUwbRangingCallbacks rangingCallbacks,
                            in PersistableBundle parameters);

  /**
   * Request to start ranging
   *
   * IUwbAdapterCallbacks#onRangingStarted must be called within
   * RANGING_SESSION_START_THRESHOLD_MS milliseconds of #startRanging being
   * called if the ranging session starts successfully.
   *
   * IUwbAdapterCallbacks#onRangingStartFailed must be called within
   * RANGING_SESSION_START_THRESHOLD_MS milliseconds of #startRanging being
   * called if the ranging session fails to be started.
   *
   * @param sessionHandle the session handle to start ranging for
   * @param parameters additional configuration required to start ranging
   */
  void startRanging(in SessionHandle sessionHandle,
                    in PersistableBundle parameters);

  /**
   * Request to reconfigure ranging
   *
   * IUwbAdapterCallbacks#onRangingReconfigured must be called after
   * successfully reconfiguring the session.
   *
   * IUwbAdapterCallbacks#onRangingReconfigureFailed must be called after
   * failing to reconfigure the session.
   *
   * A session must not be modified by a failed call to #reconfigureRanging.
   *
   * @param sessionHandle the session handle to start ranging for
   * @param parameters the parameters to reconfigure and their new values
   */
  void reconfigureRanging(in SessionHandle sessionHandle,
                          in PersistableBundle parameters);

  /**
   * Stop and close ranging for the session associated with the given handle
   * Request to stop ranging
   *
   * IUwbAdapterCallbacks#onRangingStopped must be called after
   * successfully stopping the session.
   *
   * IUwbAdapterCallbacks#onRangingStopFailed must be called after failing
   * to stop the session.
   *
   * @param sessionHandle the session handle to stop ranging for
   */
  void stopRanging(in SessionHandle sessionHandle);

  /**
   * Close ranging for the session associated with the given handle
   *
   * Calling with an invalid handle or a handle that has already been closed
   * is a no-op.
   *
   * IUwbAdapterCallbacks#onRangingClosed must be called within
   * RANGING_SESSION_CLOSE_THRESHOLD_MS of #stopRanging being called.
   * RANGING_SESSION_CLOSE_THRESHOLD_MS of #closeRanging being called.
   *
   * @param sessionHandle the session handle to stop ranging for
   * @param sessionHandle the session handle to close ranging for
   */
  void closeRanging(in SessionHandle sessionHandle);

  /**
   * The maximum allowed time to open a ranging session.
   */
  const int RANGING_SESSION_OPEN_THRESHOLD_MS = 3000; // Value TBD

  /**
   * The maximum allowed time to start a ranging session.
   */
+63 −4
Original line number Diff line number Diff line
@@ -17,15 +17,32 @@
package android.uwb;

import android.os.PersistableBundle;
import android.uwb.CloseReason;
import android.uwb.RangingChangeReason;
import android.uwb.RangingReport;
import android.uwb.SessionHandle;
import android.uwb.StartFailureReason;

/**
 * @hide
 */
interface IUwbRangingCallbacks {
  /**
   * Called when the ranging session has been opened
   *
   * @param sessionHandle the session the callback is being invoked for
   */
  void onRangingOpened(in SessionHandle sessionHandle);

  /**
   * Called when a ranging session fails to start
   *
   * @param sessionHandle the session the callback is being invoked for
   * @param reason the reason the session failed to start
   * @param parameters protocol specific parameters
   */
  void onRangingOpenFailed(in SessionHandle sessionHandle,
                           RangingChangeReason reason,
                           in PersistableBundle parameters);

  /**
   * Called when ranging has started
   *
@@ -47,8 +64,49 @@ interface IUwbRangingCallbacks {
   * @param reason the reason the session failed to start
   * @param parameters protocol specific parameters
   */
  void onRangingStartFailed(in SessionHandle sessionHandle, StartFailureReason reason,
  void onRangingStartFailed(in SessionHandle sessionHandle,
                            RangingChangeReason reason,
                            in PersistableBundle parameters);

   /**
   * Called when ranging has been reconfigured
   *
   * @param sessionHandle the session the callback is being invoked for
   * @param parameters the updated ranging configuration
   */
  void onRangingReconfigured(in SessionHandle sessionHandle,
                             in PersistableBundle parameters);

  /**
   * Called when a ranging session fails to be reconfigured
   *
   * @param sessionHandle the session the callback is being invoked for
   * @param reason the reason the session failed to reconfigure
   * @param parameters protocol specific parameters
   */
  void onRangingReconfigureFailed(in SessionHandle sessionHandle,
                                  RangingChangeReason reason,
                                  in PersistableBundle parameters);

  /**
   * Called when the ranging session has been stopped
   *
   * @param sessionHandle the session the callback is being invoked for
   */

  void onRangingStopped(in SessionHandle sessionHandle);

  /**
   * Called when a ranging session fails to stop
   *
   * @param sessionHandle the session the callback is being invoked for
   * @param reason the reason the session failed to stop
   * @param parameters protocol specific parameters
   */
  void onRangingStopFailed(in SessionHandle sessionHandle,
                           RangingChangeReason reason,
                           in PersistableBundle parameters);

  /**
   * Called when a ranging session is closed
   *
@@ -56,7 +114,8 @@ interface IUwbRangingCallbacks {
   * @param reason the reason the session was closed
   * @param parameters protocol specific parameters
   */
  void onRangingClosed(in SessionHandle sessionHandle, CloseReason reason,
  void onRangingClosed(in SessionHandle sessionHandle,
                       RangingChangeReason reason,
                       in PersistableBundle parameters);

  /**
+15 −10
Original line number Diff line number Diff line
@@ -20,39 +20,44 @@ package android.uwb;
 * @hide
 */
@Backing(type="int")
enum CloseReason {
enum RangingChangeReason {
  /**
   * Unknown reason
   */
  UNKNOWN,

  /**
   * A local API call triggered the close, such as a call to
   * IUwbAdapter.stopRanging.
   * A local API call triggered the change, such as a call to
   * IUwbAdapter.closeRanging.
   */
  LOCAL_API,

  /**
   * The maximum number of sessions has been reached. This error may be generated
   * for an active session if a higher priority session begins.
   * The maximum number of sessions has been reached. This may be generated for
   * an active session if a higher priority session begins.
   */
  MAX_SESSIONS_REACHED,

  /**
   * The system state has changed resulting in the session ending (e.g. the user
   * disables UWB, or the user's locale changes and an active channel is no longer
   * permitted to be used).
   * The system state has changed resulting in the session changing (e.g. the
   * user disables UWB, or the user's locale changes and an active channel is no
   * longer permitted to be used).
   */
  SYSTEM_POLICY,

  /**
   * The remote device has requested to terminate the session
   * The remote device has requested to change the session
   */
  REMOTE_REQUEST,

  /**
   * The session was closed for a protocol specific reason
   * The session changed for a protocol specific reason
   */
  PROTOCOL_SPECIFIC,

  /**
   * The provided parameters were invalid
   */
  BAD_PARAMETERS,
}
+113 −41
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ public class RangingManager extends android.uwb.IUwbRangingCallbacks.Stub {
            @NonNull RangingSession.Callback callbacks) {
        SessionHandle sessionHandle;
        try {
            sessionHandle = mAdapter.startRanging(this, params);
            sessionHandle = mAdapter.openRanging(this, params);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -59,7 +59,7 @@ public class RangingManager extends android.uwb.IUwbRangingCallbacks.Stub {
            if (hasSession(sessionHandle)) {
                Log.w(TAG, "Newly created session unexpectedly reuses an active SessionHandle");
                executor.execute(() -> callbacks.onClosed(
                        RangingSession.Callback.CLOSE_REASON_LOCAL_GENERIC_ERROR,
                        RangingSession.Callback.REASON_GENERIC_ERROR,
                        new PersistableBundle()));
            }

@@ -74,6 +74,67 @@ public class RangingManager extends android.uwb.IUwbRangingCallbacks.Stub {
        return mRangingSessionTable.containsKey(sessionHandle);
    }

    @Override
    public void onRangingOpened(SessionHandle sessionHandle) {
        synchronized (this) {
            if (!hasSession(sessionHandle)) {
                Log.w(TAG,
                        "onRangingOpened - received unexpected SessionHandle: " + sessionHandle);
                return;
            }

            RangingSession session = mRangingSessionTable.get(sessionHandle);
            session.onRangingOpened();
        }
    }

    @Override
    public void onRangingOpenFailed(SessionHandle sessionHandle, @RangingChangeReason int reason,
            PersistableBundle parameters) {
        synchronized (this) {
            if (!hasSession(sessionHandle)) {
                Log.w(TAG,
                        "onRangingOpened - received unexpected SessionHandle: " + sessionHandle);
                return;
            }

            RangingSession session = mRangingSessionTable.get(sessionHandle);
            session.onRangingOpenFailed(convertToReason(reason), parameters);
            mRangingSessionTable.remove(sessionHandle);
        }
    }

    @Override
    public void onRangingReconfigured(SessionHandle sessionHandle, PersistableBundle parameters) {
        synchronized (this) {
            if (!hasSession(sessionHandle)) {
                Log.w(TAG,
                        "onRangingReconfigured - received unexpected SessionHandle: "
                                + sessionHandle);
                return;
            }

            RangingSession session = mRangingSessionTable.get(sessionHandle);
            session.onRangingReconfigured(parameters);
        }
    }

    @Override
    public void onRangingReconfigureFailed(SessionHandle sessionHandle,
            @RangingChangeReason int reason, PersistableBundle params) {
        synchronized (this) {
            if (!hasSession(sessionHandle)) {
                Log.w(TAG, "onRangingStartFailed - received unexpected SessionHandle: "
                        + sessionHandle);
                return;
            }

            RangingSession session = mRangingSessionTable.get(sessionHandle);
            session.onRangingReconfigureFailed(convertToReason(reason), params);
        }
    }


    @Override
    public void onRangingStarted(SessionHandle sessionHandle, PersistableBundle parameters) {
        synchronized (this) {
@@ -89,7 +150,7 @@ public class RangingManager extends android.uwb.IUwbRangingCallbacks.Stub {
    }

    @Override
    public void onRangingStartFailed(SessionHandle sessionHandle, int reason,
    public void onRangingStartFailed(SessionHandle sessionHandle, @RangingChangeReason int reason,
            PersistableBundle params) {
        synchronized (this) {
            if (!hasSession(sessionHandle)) {
@@ -99,13 +160,42 @@ public class RangingManager extends android.uwb.IUwbRangingCallbacks.Stub {
            }

            RangingSession session = mRangingSessionTable.get(sessionHandle);
            session.onRangingClosed(convertStartFailureToCloseReason(reason), params);
            mRangingSessionTable.remove(sessionHandle);
            session.onRangingStartFailed(convertToReason(reason), params);
        }
    }

    @Override
    public void onRangingStopped(SessionHandle sessionHandle) {
        synchronized (this) {
            if (!hasSession(sessionHandle)) {
                Log.w(TAG, "onRangingStopped - received unexpected SessionHandle: "
                        + sessionHandle);
                return;
            }

            RangingSession session = mRangingSessionTable.get(sessionHandle);
            session.onRangingStopped();
        }
    }

    @Override
    public void onRangingClosed(SessionHandle sessionHandle, int reason, PersistableBundle params) {
    public void onRangingStopFailed(SessionHandle sessionHandle, @RangingChangeReason int reason,
            PersistableBundle parameters) {
        synchronized (this) {
            if (!hasSession(sessionHandle)) {
                Log.w(TAG, "onRangingStopFailed - received unexpected SessionHandle: "
                        + sessionHandle);
                return;
            }

            RangingSession session = mRangingSessionTable.get(sessionHandle);
            session.onRangingStopFailed(convertToReason(reason), parameters);
        }
    }

    @Override
    public void onRangingClosed(SessionHandle sessionHandle, @RangingChangeReason int reason,
            PersistableBundle params) {
        synchronized (this) {
            if (!hasSession(sessionHandle)) {
                Log.w(TAG, "onRangingClosed - received unexpected SessionHandle: " + sessionHandle);
@@ -113,7 +203,7 @@ public class RangingManager extends android.uwb.IUwbRangingCallbacks.Stub {
            }

            RangingSession session = mRangingSessionTable.get(sessionHandle);
            session.onRangingClosed(convertToCloseReason(reason), params);
            session.onRangingClosed(convertToReason(reason), params);
            mRangingSessionTable.remove(sessionHandle);
        }
    }
@@ -131,48 +221,30 @@ public class RangingManager extends android.uwb.IUwbRangingCallbacks.Stub {
        }
    }

    @RangingSession.Callback.CloseReason
    private static int convertToCloseReason(@CloseReason int reason) {
    @RangingSession.Callback.Reason
    private static int convertToReason(@RangingChangeReason int reason) {
        switch (reason) {
            case CloseReason.LOCAL_API:
                return RangingSession.Callback.CLOSE_REASON_LOCAL_CLOSE_API;

            case CloseReason.MAX_SESSIONS_REACHED:
                return RangingSession.Callback.CLOSE_REASON_LOCAL_MAX_SESSIONS_REACHED;

            case CloseReason.SYSTEM_POLICY:
                return RangingSession.Callback.CLOSE_REASON_LOCAL_SYSTEM_POLICY;

            case CloseReason.REMOTE_REQUEST:
                return RangingSession.Callback.CLOSE_REASON_REMOTE_REQUEST;
            case RangingChangeReason.LOCAL_API:
                return RangingSession.Callback.REASON_LOCAL_REQUEST;

            case CloseReason.PROTOCOL_SPECIFIC:
                return RangingSession.Callback.CLOSE_REASON_PROTOCOL_SPECIFIC;
            case RangingChangeReason.MAX_SESSIONS_REACHED:
                return RangingSession.Callback.REASON_MAX_SESSIONS_REACHED;

            case CloseReason.UNKNOWN:
            default:
                return RangingSession.Callback.CLOSE_REASON_UNKNOWN;
        }
    }

    @RangingSession.Callback.CloseReason
    private static int convertStartFailureToCloseReason(@StartFailureReason int reason) {
        switch (reason) {
            case StartFailureReason.BAD_PARAMETERS:
                return RangingSession.Callback.CLOSE_REASON_LOCAL_BAD_PARAMETERS;
            case RangingChangeReason.SYSTEM_POLICY:
                return RangingSession.Callback.REASON_SYSTEM_POLICY;

            case StartFailureReason.MAX_SESSIONS_REACHED:
                return RangingSession.Callback.CLOSE_REASON_LOCAL_MAX_SESSIONS_REACHED;
            case RangingChangeReason.REMOTE_REQUEST:
                return RangingSession.Callback.REASON_REMOTE_REQUEST;

            case StartFailureReason.SYSTEM_POLICY:
                return RangingSession.Callback.CLOSE_REASON_LOCAL_SYSTEM_POLICY;
            case RangingChangeReason.PROTOCOL_SPECIFIC:
                return RangingSession.Callback.REASON_PROTOCOL_SPECIFIC_ERROR;

            case StartFailureReason.PROTOCOL_SPECIFIC:
                return RangingSession.Callback.CLOSE_REASON_PROTOCOL_SPECIFIC;
            case RangingChangeReason.BAD_PARAMETERS:
                return RangingSession.Callback.REASON_BAD_PARAMETERS;

            case StartFailureReason.UNKNOWN:
            case RangingChangeReason.UNKNOWN:
            default:
                return RangingSession.Callback.CLOSE_REASON_UNKNOWN;
                return RangingSession.Callback.REASON_UNKNOWN;
        }
    }
}
+297 −66

File changed.

Preview size limit exceeded, changes collapsed.

Loading