diff options
Diffstat (limited to 'android/hardware/location/ContextHubClient.java')
-rw-r--r-- | android/hardware/location/ContextHubClient.java | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/android/hardware/location/ContextHubClient.java b/android/hardware/location/ContextHubClient.java index 52527ed6..0a21083a 100644 --- a/android/hardware/location/ContextHubClient.java +++ b/android/hardware/location/ContextHubClient.java @@ -15,9 +15,13 @@ */ package android.hardware.location; +import android.annotation.NonNull; import android.annotation.RequiresPermission; +import android.annotation.SystemApi; import android.os.RemoteException; +import com.android.internal.util.Preconditions; + import dalvik.system.CloseGuard; import java.io.Closeable; @@ -31,16 +35,12 @@ import java.util.concurrent.atomic.AtomicBoolean; * * @hide */ +@SystemApi public class ContextHubClient implements Closeable { /* * The proxy to the client interface at the service. */ - private final IContextHubClient mClientProxy; - - /* - * The callback interface associated with this client. - */ - private final IContextHubClientCallback mCallbackInterface; + private IContextHubClient mClientProxy = null; /* * The Context Hub that this client is attached to. @@ -51,20 +51,33 @@ public class ContextHubClient implements Closeable { private final AtomicBoolean mIsClosed = new AtomicBoolean(false); - /* package */ ContextHubClient( - IContextHubClient clientProxy, IContextHubClientCallback callback, - ContextHubInfo hubInfo) { - mClientProxy = clientProxy; - mCallbackInterface = callback; + /* package */ ContextHubClient(ContextHubInfo hubInfo) { mAttachedHub = hubInfo; mCloseGuard.open("close"); } /** + * Sets the proxy interface of the client at the service. This method should always be called + * by the ContextHubManager after the client is registered at the service, and should only be + * called once. + * + * @param clientProxy the proxy of the client at the service + */ + /* package */ void setClientProxy(IContextHubClient clientProxy) { + Preconditions.checkNotNull(clientProxy, "IContextHubClient cannot be null"); + if (mClientProxy != null) { + throw new IllegalStateException("Cannot change client proxy multiple times"); + } + + mClientProxy = clientProxy; + } + + /** * Returns the hub that this client is attached to. * * @return the ContextHubInfo of the attached hub */ + @NonNull public ContextHubInfo getAttachedHub() { return mAttachedHub; } @@ -96,12 +109,16 @@ public class ContextHubClient implements Closeable { * * @return the result of sending the message defined as in ContextHubTransaction.Result * + * @throws NullPointerException if NanoAppMessage is null + * * @see NanoAppMessage * @see ContextHubTransaction.Result */ @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) @ContextHubTransaction.Result - public int sendMessageToNanoApp(NanoAppMessage message) { + public int sendMessageToNanoApp(@NonNull NanoAppMessage message) { + Preconditions.checkNotNull(message, "NanoAppMessage cannot be null"); + try { return mClientProxy.sendMessageToNanoApp(message); } catch (RemoteException e) { |