summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorArthur Ishiguro <arthuri@google.com>2017-11-16 11:54:42 -0800
committerArthur Ishiguro <arthuri@google.com>2017-11-29 10:35:31 -0800
commit49e030fbd2ce6e4e12d2c468f0ef3d329a54fca0 (patch)
treeb97bc6811e2d58b1ba8e88eb675d28bccd41b922 /core/java
parent4e39aa1e1956ef0b363f38630865acd3ef65761f (diff)
Implements client close and death notification
Bug: 67734082 Test: make from root Change-Id: Ia139fd6d4bb04c569a9ee3672e21e2700daa40a9
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/hardware/location/ContextHubClient.java32
-rw-r--r--core/java/android/hardware/location/IContextHubClient.aidl3
2 files changed, 33 insertions, 2 deletions
diff --git a/core/java/android/hardware/location/ContextHubClient.java b/core/java/android/hardware/location/ContextHubClient.java
index 32ec1138e8f3..52527ed67ae4 100644
--- a/core/java/android/hardware/location/ContextHubClient.java
+++ b/core/java/android/hardware/location/ContextHubClient.java
@@ -18,12 +18,16 @@ package android.hardware.location;
import android.annotation.RequiresPermission;
import android.os.RemoteException;
+import dalvik.system.CloseGuard;
+
import java.io.Closeable;
+import java.util.concurrent.atomic.AtomicBoolean;
/**
* A class describing a client of the Context Hub Service.
*
- * Clients can send messages to nanoapps at a Context Hub through this object.
+ * Clients can send messages to nanoapps at a Context Hub through this object. The APIs supported
+ * by this object are thread-safe and can be used without external synchronization.
*
* @hide
*/
@@ -43,12 +47,17 @@ public class ContextHubClient implements Closeable {
*/
private final ContextHubInfo mAttachedHub;
+ private final CloseGuard mCloseGuard = CloseGuard.get();
+
+ private final AtomicBoolean mIsClosed = new AtomicBoolean(false);
+
/* package */ ContextHubClient(
IContextHubClient clientProxy, IContextHubClientCallback callback,
ContextHubInfo hubInfo) {
mClientProxy = clientProxy;
mCallbackInterface = callback;
mAttachedHub = hubInfo;
+ mCloseGuard.open("close");
}
/**
@@ -67,7 +76,14 @@ public class ContextHubClient implements Closeable {
* All futures messages targeted for this client are dropped at the service.
*/
public void close() {
- throw new UnsupportedOperationException("TODO: Implement this");
+ if (!mIsClosed.getAndSet(true)) {
+ mCloseGuard.close();
+ try {
+ mClientProxy.close();
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
}
/**
@@ -92,4 +108,16 @@ public class ContextHubClient implements Closeable {
throw e.rethrowFromSystemServer();
}
}
+
+ @Override
+ protected void finalize() throws Throwable {
+ try {
+ if (mCloseGuard != null) {
+ mCloseGuard.warnIfOpen();
+ }
+ close();
+ } finally {
+ super.finalize();
+ }
+ }
}
diff --git a/core/java/android/hardware/location/IContextHubClient.aidl b/core/java/android/hardware/location/IContextHubClient.aidl
index cdaa15f0d59a..d81126a0ac54 100644
--- a/core/java/android/hardware/location/IContextHubClient.aidl
+++ b/core/java/android/hardware/location/IContextHubClient.aidl
@@ -25,4 +25,7 @@ interface IContextHubClient {
// Sends a message to a nanoapp
int sendMessageToNanoApp(in NanoAppMessage message);
+
+ // Closes the connection with the Context Hub
+ void close();
}