Expose ContextHubClient ID

Bug: 194287786
Test: Manual check ID is correct
Change-Id: Ia240a88e5687564fd339da3fab61437e3015da83
This commit is contained in:
Arthur Ishiguro
2021-12-06 17:35:45 +00:00
parent b4d9a3dfec
commit b6f02300a8
4 changed files with 41 additions and 0 deletions

View File

@@ -3893,6 +3893,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);
}

View File

@@ -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();
}
}
/**
@@ -97,6 +104,31 @@ public class ContextHubClient implements Closeable {
return mAttachedHub;
}
/**
* 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.
*

View File

@@ -29,4 +29,7 @@ interface IContextHubClient {
// Closes the connection with the Context Hub
void close();
// Returns the unique ID for this client.
int getId();
}

View File

@@ -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.
*/