summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-11-22 20:10:31 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-11-22 20:10:31 +0000
commit8caa04ecd64a218993102249114a67809b4832a8 (patch)
tree01ccb5db86f94099a9ccaec081687b2bb424bd67
parent5543371141fa8ca40e9d0f923b88ae7ab2c3849d (diff)
parentf9a89f82d0d664fd515ad6d3be1000392071caf7 (diff)
Merge "Refactors reason to common HubEndpoint.Reason" into main
-rw-r--r--core/api/system-current.txt10
-rw-r--r--core/java/android/hardware/contexthub/HubEndpoint.java51
-rw-r--r--core/java/android/hardware/contexthub/IContextHubEndpointDiscoveryCallback.aidl3
-rw-r--r--core/java/android/hardware/contexthub/IHubEndpointDiscoveryCallback.java5
-rw-r--r--core/java/android/hardware/contexthub/IHubEndpointLifecycleCallback.java24
-rw-r--r--core/java/android/hardware/location/ContextHubManager.java4
6 files changed, 59 insertions, 38 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index 4b83b43bfd8f..1a9ae3e4a12f 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -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 {
diff --git a/core/java/android/hardware/contexthub/HubEndpoint.java b/core/java/android/hardware/contexthub/HubEndpoint.java
index 078b4d4629e0..7efdd6dbdf41 100644
--- a/core/java/android/hardware/contexthub/HubEndpoint.java
+++ b/core/java/android/hardware/contexthub/HubEndpoint.java
@@ -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();
diff --git a/core/java/android/hardware/contexthub/IContextHubEndpointDiscoveryCallback.aidl b/core/java/android/hardware/contexthub/IContextHubEndpointDiscoveryCallback.aidl
index 85775c05bad9..245be930a897 100644
--- a/core/java/android/hardware/contexthub/IContextHubEndpointDiscoveryCallback.aidl
+++ b/core/java/android/hardware/contexthub/IContextHubEndpointDiscoveryCallback.aidl
@@ -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);
}
diff --git a/core/java/android/hardware/contexthub/IHubEndpointDiscoveryCallback.java b/core/java/android/hardware/contexthub/IHubEndpointDiscoveryCallback.java
index 0b77ddb8cb0b..a61a7ebd0de9 100644
--- a/core/java/android/hardware/contexthub/IHubEndpointDiscoveryCallback.java
+++ b/core/java/android/hardware/contexthub/IHubEndpointDiscoveryCallback.java
@@ -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);
}
diff --git a/core/java/android/hardware/contexthub/IHubEndpointLifecycleCallback.java b/core/java/android/hardware/contexthub/IHubEndpointLifecycleCallback.java
index 46884393b49b..fe449bb5ce0e 100644
--- a/core/java/android/hardware/contexthub/IHubEndpointLifecycleCallback.java
+++ b/core/java/android/hardware/contexthub/IHubEndpointLifecycleCallback.java
@@ -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);
}
diff --git a/core/java/android/hardware/location/ContextHubManager.java b/core/java/android/hardware/location/ContextHubManager.java
index 5e8a18724cdf..117d8fe24809 100644
--- a/core/java/android/hardware/location/ContextHubManager.java
+++ b/core/java/android/hardware/location/ContextHubManager.java
@@ -791,7 +791,7 @@ public final class ContextHubManager {
}
@Override
- public void onEndpointsStopped(HubEndpointInfo[] hubEndpointInfoList) {
+ public void onEndpointsStopped(HubEndpointInfo[] hubEndpointInfoList, int reason) {
if (hubEndpointInfoList.length == 0) {
Log.w(TAG, "onEndpointsStopped: received empty discovery list");
return;
@@ -815,7 +815,7 @@ public final class ContextHubManager {
if (discoveryList.isEmpty()) {
Log.w(TAG, "onEndpointsStopped: no matching service descriptor");
} else {
- callback.onEndpointsStopped(discoveryList);
+ callback.onEndpointsStopped(discoveryList, reason);
}
});
}