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

Commit f9a89f82 authored by Arthur Ishiguro's avatar Arthur Ishiguro
Browse files

Refactors reason to common HubEndpoint.Reason

Also adds the reason parameter to the onEndpointsStopped discovery
callback.

API-Coverage-Bug: 377554469
Bug: 375487784
Flag: android.chre.flags.offload_api
Test: Compile

Change-Id: I4a0749bd56cdbce6a5eed739faa61c2b3b6cbeb2
parent 4190b9a6
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -5209,6 +5209,11 @@ package android.hardware.contexthub {
    method @NonNull public java.util.Collection<android.hardware.contexthub.HubServiceInfo> getServiceInfoCollection();
    method @Nullable public String getTag();
    method public int getVersion();
    field public static final int REASON_CLOSE_ENDPOINT_SESSION_REQUESTED = 4; // 0x4
    field public static final int REASON_ENDPOINT_INVALID = 5; // 0x5
    field public static final int REASON_ENDPOINT_STOPPED = 6; // 0x6
    field public static final int REASON_FAILURE = 0; // 0x0
    field public static final int REASON_OPEN_ENDPOINT_SESSION_REQUEST_REJECTED = 3; // 0x3
  }
  public static final class HubEndpoint.Builder {
@@ -5295,16 +5300,13 @@ package android.hardware.contexthub {
  @FlaggedApi("android.chre.flags.offload_api") public interface IHubEndpointDiscoveryCallback {
    method public void onEndpointsStarted(@NonNull java.util.List<android.hardware.contexthub.HubDiscoveryInfo>);
    method public void onEndpointsStopped(@NonNull java.util.List<android.hardware.contexthub.HubDiscoveryInfo>);
    method public void onEndpointsStopped(@NonNull java.util.List<android.hardware.contexthub.HubDiscoveryInfo>, int);
  }
  @FlaggedApi("android.chre.flags.offload_api") public interface IHubEndpointLifecycleCallback {
    method public void onSessionClosed(@NonNull android.hardware.contexthub.HubEndpointSession, int);
    method @NonNull public android.hardware.contexthub.HubEndpointSessionResult onSessionOpenRequest(@NonNull android.hardware.contexthub.HubEndpointInfo, @Nullable android.hardware.contexthub.HubServiceInfo);
    method public void onSessionOpened(@NonNull android.hardware.contexthub.HubEndpointSession);
    field public static final int REASON_CLOSE_ENDPOINT_SESSION_REQUESTED = 4; // 0x4
    field public static final int REASON_OPEN_ENDPOINT_SESSION_REQUEST_REJECTED = 3; // 0x3
    field public static final int REASON_UNSPECIFIED = 0; // 0x0
  }
  @FlaggedApi("android.chre.flags.offload_api") public interface IHubEndpointMessageCallback {
+45 −6
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.hardware.contexthub;

import android.annotation.CallbackExecutor;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
@@ -31,6 +32,8 @@ import android.util.SparseArray;

import androidx.annotation.GuardedBy;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -48,6 +51,46 @@ import java.util.concurrent.Executor;
public class HubEndpoint {
    private static final String TAG = "HubEndpoint";

    /**
     * Constants describing the outcome of operations through HubEndpoints (like opening/closing of
     * sessions or stopping of endpoints).
     *
     * @hide
     */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(
            prefix = {"REASON_"},
            value = {
                REASON_FAILURE,
                REASON_OPEN_ENDPOINT_SESSION_REQUEST_REJECTED,
                REASON_CLOSE_ENDPOINT_SESSION_REQUESTED,
                REASON_ENDPOINT_INVALID,
                REASON_ENDPOINT_STOPPED,
            })
    public @interface Reason {}

    /** Unclassified failure */
    public static final int REASON_FAILURE = 0;

    // The values 1 and 2 are reserved at the Context Hub HAL but not exposed to apps.

    /** The peer rejected the request to open this endpoint session. */
    public static final int REASON_OPEN_ENDPOINT_SESSION_REQUEST_REJECTED = 3;

    /** The peer closed this endpoint session. */
    public static final int REASON_CLOSE_ENDPOINT_SESSION_REQUESTED = 4;

    /** The peer endpoint is invalid. */
    public static final int REASON_ENDPOINT_INVALID = 5;

    /**
     * The endpoint is now stopped. The app should retrieve the endpoint info using {@link
     * android.hardware.location.ContextHubManager#findEndpoints} or register updates through
     * {@link android.hardware.location.ContextHubManager#registerEndpointDiscoveryCallback}
     * to get notified if the endpoint restarts.
     */
    public static final int REASON_ENDPOINT_STOPPED = 6;

    private final Object mLock = new Object();
    private final HubEndpointInfo mPendingHubEndpointInfo;
    @Nullable private final IHubEndpointLifecycleCallback mLifecycleCallback;
@@ -173,9 +216,7 @@ public class HubEndpoint {

                    try {
                        mServiceToken.closeSession(
                                sessionId,
                                IHubEndpointLifecycleCallback
                                        .REASON_OPEN_ENDPOINT_SESSION_REQUEST_REJECTED);
                                sessionId, REASON_OPEN_ENDPOINT_SESSION_REQUEST_REJECTED);
                    } catch (RemoteException e) {
                        e.rethrowFromSystemServer();
                    }
@@ -396,9 +437,7 @@ public class HubEndpoint {

        try {
            // Oneway notification to system service
            serviceToken.closeSession(
                    session.getId(),
                    IHubEndpointLifecycleCallback.REASON_CLOSE_ENDPOINT_SESSION_REQUESTED);
            serviceToken.closeSession(session.getId(), REASON_CLOSE_ENDPOINT_SESSION_REQUESTED);
        } catch (RemoteException e) {
            Log.e(TAG, "closeSession: failed to close session " + session, e);
            e.rethrowFromSystemServer();
+2 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ oneway interface IContextHubEndpointDiscoveryCallback {
    /**
     * Called when endpoint(s) stopped.
     * @param hubEndpointInfoList The list of endpoints that started.
     * @param reason The reason why the endpoints stopped.
     */
    void onEndpointsStopped(in HubEndpointInfo[] hubEndpointInfoList);
    void onEndpointsStopped(in HubEndpointInfo[] hubEndpointInfoList, int reason);
}
+3 −2
Original line number Diff line number Diff line
@@ -42,7 +42,8 @@ public interface IHubEndpointDiscoveryCallback {
     * Called when a list of hub endpoints have stopped.
     *
     * @param discoveryInfoList The list containing hub discovery information.
     * @param reason The reason the endpoints stopped.
     */
    // TODO(b/375487784): Add endpoint stop reason
    void onEndpointsStopped(@NonNull List<HubDiscoveryInfo> discoveryInfoList);
    void onEndpointsStopped(
            @NonNull List<HubDiscoveryInfo> discoveryInfoList, @HubEndpoint.Reason int reason);
}
+1 −23
Original line number Diff line number Diff line
@@ -17,15 +17,11 @@
package android.hardware.contexthub;

import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.chre.flags.Flags;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Interface for listening to lifecycle events of a hub endpoint.
 *
@@ -34,24 +30,6 @@ import java.lang.annotation.RetentionPolicy;
@SystemApi
@FlaggedApi(Flags.FLAG_OFFLOAD_API)
public interface IHubEndpointLifecycleCallback {
    /** Unknown reason. */
    int REASON_UNSPECIFIED = 0;

    /** The peer rejected the request to open this endpoint session. */
    int REASON_OPEN_ENDPOINT_SESSION_REQUEST_REJECTED = 3;

    /** The peer closed this endpoint session. */
    int REASON_CLOSE_ENDPOINT_SESSION_REQUESTED = 4;

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({
        REASON_UNSPECIFIED,
        REASON_OPEN_ENDPOINT_SESSION_REQUEST_REJECTED,
        REASON_CLOSE_ENDPOINT_SESSION_REQUESTED,
    })
    @interface EndpointLifecycleReason {}

    /**
     * Called when an endpoint is requesting a session be opened with another endpoint.
     *
@@ -78,5 +56,5 @@ public interface IHubEndpointLifecycleCallback {
     *     used.
     * @param reason The reason why this session was closed.
     */
    void onSessionClosed(@NonNull HubEndpointSession session, @EndpointLifecycleReason int reason);
    void onSessionClosed(@NonNull HubEndpointSession session, @HubEndpoint.Reason int reason);
}
Loading