diff options
4 files changed, 41 insertions, 0 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt index c1d151813092..cc719ab21437 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -3910,6 +3910,7 @@ package android.hardware.location { public class ContextHubClient implements java.io.Closeable { method public void close(); method @NonNull public android.hardware.location.ContextHubInfo getAttachedHub(); + method public int getId(); method @RequiresPermission(android.Manifest.permission.ACCESS_CONTEXT_HUB) public int sendMessageToNanoApp(@NonNull android.hardware.location.NanoAppMessage); } diff --git a/core/java/android/hardware/location/ContextHubClient.java b/core/java/android/hardware/location/ContextHubClient.java index bcdd519b1006..a525f58371f5 100644 --- a/core/java/android/hardware/location/ContextHubClient.java +++ b/core/java/android/hardware/location/ContextHubClient.java @@ -60,6 +60,8 @@ public class ContextHubClient implements Closeable { */ private final boolean mPersistent; + private Integer mId = null; + /* package */ ContextHubClient(ContextHubInfo hubInfo, boolean persistent) { mAttachedHub = hubInfo; mPersistent = persistent; @@ -85,6 +87,11 @@ public class ContextHubClient implements Closeable { } mClientProxy = clientProxy; + try { + mId = Integer.valueOf(mClientProxy.getId()); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } } /** @@ -98,6 +105,31 @@ public class ContextHubClient implements Closeable { } /** + * Returns the system-wide unique identifier for this ContextHubClient. + * + * This value can be used as an identifier for the messaging channel between a + * ContextHubClient and the Context Hub. This may be used as a routing mechanism + * between various ContextHubClient objects within an application. + * + * The value returned by this method will remain the same if it is associated with + * the same client reference at the ContextHubService (for instance, the ID of a + * PendingIntent ContextHubClient will remain the same even if the local object + * has been regenerated with the equivalent PendingIntent). If the ContextHubClient + * is newly generated (e.g. any regeneration of a callback client, or generation + * of a non-equal PendingIntent client), the ID will not be the same. + * + * @return The ID of this ContextHubClient. + * + * @throws IllegalStateException if the ID was not set internally. + */ + public int getId() { + if (mId == null) { + throw new IllegalStateException("ID was not set"); + } + return mId; + } + + /** * Closes the connection for this client and the Context Hub Service. * * When this function is invoked, the messaging associated with this client is invalidated. diff --git a/core/java/android/hardware/location/IContextHubClient.aidl b/core/java/android/hardware/location/IContextHubClient.aidl index e33545c40360..2423a583a5c3 100644 --- a/core/java/android/hardware/location/IContextHubClient.aidl +++ b/core/java/android/hardware/location/IContextHubClient.aidl @@ -29,4 +29,7 @@ interface IContextHubClient { // Closes the connection with the Context Hub void close(); + + // Returns the unique ID for this client. + int getId(); } diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubClientBroker.java b/services/core/java/com/android/server/location/contexthub/ContextHubClientBroker.java index efd30377851b..0fd7cc18a11c 100644 --- a/services/core/java/com/android/server/location/contexthub/ContextHubClientBroker.java +++ b/services/core/java/com/android/server/location/contexthub/ContextHubClientBroker.java @@ -427,6 +427,11 @@ public class ContextHubClientBroker extends IContextHubClient.Stub onClientExit(); } + @Override + public int getId() { + return mHostEndPointId; + } + /** * Invoked when the underlying binder of this broker has died at the client process. */ |