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

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

Expose Context Hub Service PendingIntent APIs

Exposes APIs related to new PendingIntent-based APIs of
ContextHubManager, allowing the creation of persistent
ContextHubClients.

Bug: 117612105
Test: Compile only
Change-Id: Iaddbc4685285ffa8186b867def21fbbff370756c
parent 0430c3ce
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -1821,9 +1821,19 @@ package android.hardware.location {
    field public static final android.os.Parcelable.Creator<android.hardware.location.ContextHubInfo> CREATOR;
  }

  public class ContextHubIntentEvent {
    method public static android.hardware.location.ContextHubIntentEvent fromIntent(android.content.Intent);
    method public android.hardware.location.ContextHubInfo getContextHubInfo();
    method public int getEventType();
    method public int getNanoAppAbortCode();
    method public long getNanoAppId();
    method public android.hardware.location.NanoAppMessage getNanoAppMessage();
  }

  public final class ContextHubManager {
    method public android.hardware.location.ContextHubClient createClient(android.hardware.location.ContextHubInfo, android.hardware.location.ContextHubClientCallback, java.util.concurrent.Executor);
    method public android.hardware.location.ContextHubClient createClient(android.hardware.location.ContextHubInfo, android.hardware.location.ContextHubClientCallback);
    method public android.hardware.location.ContextHubClient createClient(android.hardware.location.ContextHubInfo, android.app.PendingIntent, long);
    method public android.hardware.location.ContextHubTransaction<java.lang.Void> disableNanoApp(android.hardware.location.ContextHubInfo, long);
    method public android.hardware.location.ContextHubTransaction<java.lang.Void> enableNanoApp(android.hardware.location.ContextHubInfo, long);
    method public deprecated int[] findNanoAppOnHub(int, android.hardware.location.NanoAppFilter);
@@ -1840,6 +1850,18 @@ package android.hardware.location {
    method public deprecated int unloadNanoApp(int);
    method public android.hardware.location.ContextHubTransaction<java.lang.Void> unloadNanoApp(android.hardware.location.ContextHubInfo, long);
    method public deprecated int unregisterCallback(android.hardware.location.ContextHubManager.Callback);
    field public static final int EVENT_HUB_RESET = 6; // 0x6
    field public static final int EVENT_NANOAPP_ABORTED = 4; // 0x4
    field public static final int EVENT_NANOAPP_DISABLED = 3; // 0x3
    field public static final int EVENT_NANOAPP_ENABLED = 2; // 0x2
    field public static final int EVENT_NANOAPP_LOADED = 0; // 0x0
    field public static final int EVENT_NANOAPP_MESSAGE = 5; // 0x5
    field public static final int EVENT_NANOAPP_UNLOADED = 1; // 0x1
    field public static final java.lang.String EXTRA_CONTEXT_HUB_INFO = "android.hardware.location.extra.CONTEXT_HUB_INFO";
    field public static final java.lang.String EXTRA_EVENT_TYPE = "android.hardware.location.extra.EVENT_TYPE";
    field public static final java.lang.String EXTRA_MESSAGE = "android.hardware.location.extra.MESSAGE";
    field public static final java.lang.String EXTRA_NANOAPP_ABORT_CODE = "android.hardware.location.extra.NANOAPP_ABORT_CODE";
    field public static final java.lang.String EXTRA_NANOAPP_ID = "android.hardware.location.extra.NANOAPP_ID";
  }

  public static abstract deprecated class ContextHubManager.Callback {
+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package android.hardware.location;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.app.PendingIntent;
import android.content.Intent;

@@ -30,6 +31,7 @@ import com.android.internal.util.Preconditions;
 *
 * @hide
 */
@SystemApi
public class ContextHubIntentEvent {
    @ContextHubManager.Event private final int mEventType;

+13 −39
Original line number Diff line number Diff line
@@ -56,38 +56,28 @@ public final class ContextHubManager {

    /**
     * An extra of type {@link ContextHubInfo} describing the source of the event.
     *
     * @hide
     */
    public static final String EXTRA_CONTEXT_HUB_INFO =
            "android.hardware.location.extra.CONTEXT_HUB_INFO";

    /**
     * An extra of type {@link ContextHubManager.Event} describing the event type.
     *
     * @hide
     */
    public static final String EXTRA_EVENT_TYPE = "android.hardware.location.extra.EVENT_TYPE";

    /**
     * An extra of type long describing the ID of the nanoapp an event is for.
     *
     * @hide
     */
    public static final String EXTRA_NANOAPP_ID = "android.hardware.location.extra.NANOAPP_ID";

    /**
     * An extra of type int describing the nanoapp-specific abort code.
     *
     * @hide
     */
    public static final String EXTRA_NANOAPP_ABORT_CODE =
            "android.hardware.location.extra.NANOAPP_ABORT_CODE";

    /**
     * An extra of type {@link NanoAppMessage} describing contents of a message from a nanoapp.
     *
     * @hide
     */
    public static final String EXTRA_MESSAGE = "android.hardware.location.extra.MESSAGE";

@@ -109,56 +99,41 @@ public final class ContextHubManager {

    /**
     * An event describing that a nanoapp has been loaded. Contains the EXTRA_NANOAPP_ID extra.
     *
     * @hide
     */
    public static final int EVENT_NANOAPP_LOADED = 0;

    /**
     * An event describing that a nanoapp has been unloaded. Contains the EXTRA_NANOAPP_ID extra.
     *
     * @hide
     */
    public static final int EVENT_NANOAPP_UNLOADED = 1;

    /**
     * An event describing that a nanoapp has been enabled. Contains the EXTRA_NANOAPP_ID extra.
     *
     * @hide
     */
    public static final int EVENT_NANOAPP_ENABLED = 2;

    /**
     * An event describing that a nanoapp has been disabled. Contains the EXTRA_NANOAPP_ID extra.
     *
     * @hide
     */
    public static final int EVENT_NANOAPP_DISABLED = 3;

    /**
     * An event describing that a nanoapp has aborted. Contains the EXTRA_NANOAPP_ID and
     * EXTRA_NANOAPP_ABORT_CODE extras.
     *
     * @hide
     */
    public static final int EVENT_NANOAPP_ABORTED = 4;

    /**
     * An event containing a message sent from a nanoapp. Contains the EXTRA_NANOAPP_ID and
     * EXTRA_NANOAPP_MESSAGE extras.
     *
     * @hide
     */
    public static final int EVENT_NANOAPP_MESSAGE = 5;

    /**
     * An event describing that the Context Hub has reset.
     *
     * @hide
     */
    public static final int EVENT_HUB_RESET = 6;


    private final Looper mMainLooper;
    private final IContextHubService mService;
    private Callback mCallback;
@@ -797,14 +772,14 @@ public final class ContextHubManager {
     * Creates a ContextHubClient that will receive notifications based on Intent events.
     *
     * This method should be used instead of {@link #createClient(ContextHubInfo,
     * ContextHubClientCallback)} and the equivalent API if the caller wants to preserve the
     * messaging endpoint of a ContextHubClient, even after a process exits. If the PendingIntent
     * with the provided nanoapp has already been registered at the service previously, then the
     * same ContextHubClient will be regenerated without creating a new client connection at the
     * service. Note that the PendingIntent, nanoapp, and Context Hub must all match in identifying
     * a previously registered ContextHubClient. If a client is regenerated, it can be treated as
     * the same endpoint entity from a nanoapp's perspective, and can be continued to be
     * used to send messages even if the original process has exited.
     * ContextHubClientCallback)} or {@link #createClient(ContextHubInfo, ContextHubClientCallback,
     * Executor)} if the caller wants to preserve the messaging endpoint of a ContextHubClient, even
     * after a process exits. If the PendingIntent with the provided nanoapp has already been
     * registered at the service, then the same ContextHubClient will be regenerated without
     * creating a new client connection at the service. Note that the PendingIntent, nanoapp, and
     * Context Hub must all match in identifying a previously registered ContextHubClient.
     * If a client is regenerated, the host endpoint identifier attached to messages sent to the
     * nanoapp remains consistent, even if the original process has exited.
     *
     * If registered successfully, intents will be delivered regarding events or messages from the
     * specified nanoapp from the attached Context Hub. The intent will have an extra
@@ -815,10 +790,11 @@ public final class ContextHubManager {
     * each event type, along with event-specific extra fields. The client can also use
     * {@link ContextHubIntentEvent.fromIntent(Intent)} to parse the Intent generated by the event.
     *
     * Intent events will be delivered until it is unregistered through
     * {@link ContextHubClient.close()}. Note that the registration of this
     * ContextHubClient at the Context Hub Service will continued to be maintained until
     * {@link ContextHubClient.close()} is called.
     * Intent events will be delivered until {@link ContextHubClient.close()} is called. Note that
     * the registration of this ContextHubClient at the Context Hub Service will be maintained until
     * {@link ContextHubClient.close()} is called. If {@link PendingIntent.cancel()} is called
     * on the provided PendingIntent, then the client will be automatically unregistered by the
     * service.
     *
     * @param hubInfo       the hub to attach this client to
     * @param pendingIntent the PendingIntent to register to the client
@@ -828,8 +804,6 @@ public final class ContextHubManager {
     * @throws IllegalArgumentException if hubInfo does not represent a valid hub
     * @throws IllegalStateException    if there were too many registered clients at the service
     * @throws NullPointerException     if pendingIntent or hubInfo is null
     *
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
    @NonNull public ContextHubClient createClient(