Loading core/java/android/hardware/location/ContextHubClient.java +37 −26 Original line number Diff line number Diff line Loading @@ -31,8 +31,8 @@ import java.util.concurrent.atomic.AtomicBoolean; /** * A class describing a client of the Context Hub Service. * <p> * Clients can send messages to nanoapps at a Context Hub through this object. The APIs supported * * <p>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 Loading Loading @@ -75,8 +75,8 @@ public class ContextHubClient implements Closeable { } /** * 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 * 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 Loading @@ -89,7 +89,7 @@ public class ContextHubClient implements Closeable { mClientProxy = clientProxy; try { mId = Integer.valueOf(mClientProxy.getId()); mId = mClientProxy.getId(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading @@ -108,16 +108,16 @@ 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. * <p> * 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. * <p>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. * * <p>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, in the range [0, 65535]. */ Loading @@ -132,13 +132,13 @@ public class ContextHubClient implements Closeable { /** * Closes the connection for this client and the Context Hub Service. * * When this function is invoked, the messaging associated with this client is invalidated. * <p>When this function is invoked, the messaging associated with this client is invalidated. * All futures messages targeted for this client are dropped at the service, and the * ContextHubClient is unregistered from the service. * <p> * If this object has a PendingIntent, i.e. the object was generated via * {@link ContextHubManager.createClient(PendingIntent, ContextHubInfo, long)}, then the * Intent events corresponding to the PendingIntent will no longer be triggered. * * <p>If this object has a PendingIntent, i.e. the object was generated via {@link * ContextHubManager#createClient(ContextHubInfo, PendingIntent, long)}, then the Intent events * corresponding to the PendingIntent will no longer be triggered. */ public void close() { if (!mIsClosed.getAndSet(true)) { Loading Loading @@ -174,13 +174,10 @@ public class ContextHubClient implements Closeable { * have sent it a message. * * @param message the message object to send * * @return the result of sending the message defined as in ContextHubTransaction.Result * * @throws NullPointerException if NanoAppMessage is null * @throws SecurityException if this client doesn't have permissions to send a message to the * nanoapp. * * @see NanoAppMessage * @see ContextHubTransaction.Result */ Loading @@ -192,8 +189,13 @@ public class ContextHubClient implements Closeable { int maxPayloadBytes = mAttachedHub.getMaxPacketLengthBytes(); byte[] payload = message.getMessageBody(); if (payload != null && payload.length > maxPayloadBytes) { Log.e(TAG, "Message (" + payload.length + " bytes) exceeds max payload length (" + maxPayloadBytes + " bytes)"); Log.e( TAG, "Message (" + payload.length + " bytes) exceeds max payload length (" + maxPayloadBytes + " bytes)"); return ContextHubTransaction.RESULT_FAILED_BAD_PARAMS; } Loading @@ -217,4 +219,13 @@ public class ContextHubClient implements Closeable { super.finalize(); } } /** @hide */ public void callbackFinished() { try { mClientProxy.callbackFinished(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } } core/java/android/hardware/location/ContextHubManager.java +39 −9 Original line number Diff line number Diff line Loading @@ -726,45 +726,75 @@ public final class ContextHubManager { return new IContextHubClientCallback.Stub() { @Override public void onMessageFromNanoApp(NanoAppMessage message) { executor.execute(() -> callback.onMessageFromNanoApp(client, message)); executor.execute( () -> { callback.onMessageFromNanoApp(client, message); client.callbackFinished(); }); } @Override public void onHubReset() { executor.execute(() -> callback.onHubReset(client)); executor.execute( () -> { callback.onHubReset(client); client.callbackFinished(); }); } @Override public void onNanoAppAborted(long nanoAppId, int abortCode) { executor.execute(() -> callback.onNanoAppAborted(client, nanoAppId, abortCode)); executor.execute( () -> { callback.onNanoAppAborted(client, nanoAppId, abortCode); client.callbackFinished(); }); } @Override public void onNanoAppLoaded(long nanoAppId) { executor.execute(() -> callback.onNanoAppLoaded(client, nanoAppId)); executor.execute( () -> { callback.onNanoAppLoaded(client, nanoAppId); client.callbackFinished(); }); } @Override public void onNanoAppUnloaded(long nanoAppId) { executor.execute(() -> callback.onNanoAppUnloaded(client, nanoAppId)); executor.execute( () -> { callback.onNanoAppUnloaded(client, nanoAppId); client.callbackFinished(); }); } @Override public void onNanoAppEnabled(long nanoAppId) { executor.execute(() -> callback.onNanoAppEnabled(client, nanoAppId)); executor.execute( () -> { callback.onNanoAppEnabled(client, nanoAppId); client.callbackFinished(); }); } @Override public void onNanoAppDisabled(long nanoAppId) { executor.execute(() -> callback.onNanoAppDisabled(client, nanoAppId)); executor.execute( () -> { callback.onNanoAppDisabled(client, nanoAppId); client.callbackFinished(); }); } @Override public void onClientAuthorizationChanged( long nanoAppId, @ContextHubManager.AuthorizationState int authorization) { executor.execute( () -> callback.onClientAuthorizationChanged( client, nanoAppId, authorization)); () -> { callback.onClientAuthorizationChanged(client, nanoAppId, authorization); client.callbackFinished(); }); } }; } Loading core/java/android/hardware/location/IContextHubClient.aidl +3 −0 Original line number Diff line number Diff line Loading @@ -32,4 +32,7 @@ interface IContextHubClient { // Returns the unique ID for this client. int getId(); // Notify direct-call message callback completed void callbackFinished(); } services/core/java/com/android/server/location/contexthub/ContextHubClientBroker.java +20 −1 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import android.hardware.location.NanoAppMessage; import android.hardware.location.NanoAppState; import android.os.Binder; import android.os.Build; import android.os.Bundle; import android.os.IBinder; import android.os.Looper; import android.os.Process; Loading Loading @@ -104,7 +105,9 @@ import java.util.function.Supplier; * @hide */ public class ContextHubClientBroker extends IContextHubClient.Stub implements IBinder.DeathRecipient, AppOpsManager.OnOpChangedListener { implements IBinder.DeathRecipient, AppOpsManager.OnOpChangedListener, PendingIntent.OnFinished { private static final String TAG = "ContextHubClientBroker"; /** Loading Loading @@ -966,4 +969,20 @@ public class ContextHubClientBroker extends IContextHubClient.Stub return out; } /** Callback that arrives when direct-call message callback delivery completed */ @Override public void callbackFinished() { // TODO(b/202447392): pending implementation. } @Override public void onSendFinished( PendingIntent pendingIntent, Intent intent, int resultCode, String resultData, Bundle resultExtras) { // TODO(b/202447392): pending implementation. } } services/core/java/com/android/server/location/contexthub/ContextHubService.java +28 −3 Original line number Diff line number Diff line Loading @@ -374,44 +374,69 @@ public class ContextHubService extends IContextHubService.Stub { */ private IContextHubClientCallback createDefaultClientCallback(int contextHubId) { return new IContextHubClientCallback.Stub() { private void finishCallback() { try { IContextHubClient client = mDefaultClientMap.get(contextHubId); client.callbackFinished(); } catch (RemoteException e) { Log.e( TAG, "RemoteException while finishing callback for hub (ID = " + contextHubId + ")", e); } } @Override public void onMessageFromNanoApp(NanoAppMessage message) { int nanoAppHandle = mNanoAppStateManager.getNanoAppHandle( contextHubId, message.getNanoAppId()); int nanoAppHandle = mNanoAppStateManager.getNanoAppHandle(contextHubId, message.getNanoAppId()); onMessageReceiptOldApi( message.getMessageType(), contextHubId, nanoAppHandle, message.getMessageType(), contextHubId, nanoAppHandle, message.getMessageBody()); finishCallback(); } @Override public void onHubReset() { byte[] data = {android.hardware.contexthub.V1_0.TransactionResult.SUCCESS}; onMessageReceiptOldApi(MSG_HUB_RESET, contextHubId, OS_APP_INSTANCE, data); finishCallback(); } @Override public void onNanoAppAborted(long nanoAppId, int abortCode) { finishCallback(); } @Override public void onNanoAppLoaded(long nanoAppId) { finishCallback(); } @Override public void onNanoAppUnloaded(long nanoAppId) { finishCallback(); } @Override public void onNanoAppEnabled(long nanoAppId) { finishCallback(); } @Override public void onNanoAppDisabled(long nanoAppId) { finishCallback(); } @Override public void onClientAuthorizationChanged(long nanoAppId, int authorization) { finishCallback(); } }; } Loading Loading
core/java/android/hardware/location/ContextHubClient.java +37 −26 Original line number Diff line number Diff line Loading @@ -31,8 +31,8 @@ import java.util.concurrent.atomic.AtomicBoolean; /** * A class describing a client of the Context Hub Service. * <p> * Clients can send messages to nanoapps at a Context Hub through this object. The APIs supported * * <p>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 Loading Loading @@ -75,8 +75,8 @@ public class ContextHubClient implements Closeable { } /** * 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 * 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 Loading @@ -89,7 +89,7 @@ public class ContextHubClient implements Closeable { mClientProxy = clientProxy; try { mId = Integer.valueOf(mClientProxy.getId()); mId = mClientProxy.getId(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading @@ -108,16 +108,16 @@ 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. * <p> * 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. * <p>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. * * <p>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, in the range [0, 65535]. */ Loading @@ -132,13 +132,13 @@ public class ContextHubClient implements Closeable { /** * Closes the connection for this client and the Context Hub Service. * * When this function is invoked, the messaging associated with this client is invalidated. * <p>When this function is invoked, the messaging associated with this client is invalidated. * All futures messages targeted for this client are dropped at the service, and the * ContextHubClient is unregistered from the service. * <p> * If this object has a PendingIntent, i.e. the object was generated via * {@link ContextHubManager.createClient(PendingIntent, ContextHubInfo, long)}, then the * Intent events corresponding to the PendingIntent will no longer be triggered. * * <p>If this object has a PendingIntent, i.e. the object was generated via {@link * ContextHubManager#createClient(ContextHubInfo, PendingIntent, long)}, then the Intent events * corresponding to the PendingIntent will no longer be triggered. */ public void close() { if (!mIsClosed.getAndSet(true)) { Loading Loading @@ -174,13 +174,10 @@ public class ContextHubClient implements Closeable { * have sent it a message. * * @param message the message object to send * * @return the result of sending the message defined as in ContextHubTransaction.Result * * @throws NullPointerException if NanoAppMessage is null * @throws SecurityException if this client doesn't have permissions to send a message to the * nanoapp. * * @see NanoAppMessage * @see ContextHubTransaction.Result */ Loading @@ -192,8 +189,13 @@ public class ContextHubClient implements Closeable { int maxPayloadBytes = mAttachedHub.getMaxPacketLengthBytes(); byte[] payload = message.getMessageBody(); if (payload != null && payload.length > maxPayloadBytes) { Log.e(TAG, "Message (" + payload.length + " bytes) exceeds max payload length (" + maxPayloadBytes + " bytes)"); Log.e( TAG, "Message (" + payload.length + " bytes) exceeds max payload length (" + maxPayloadBytes + " bytes)"); return ContextHubTransaction.RESULT_FAILED_BAD_PARAMS; } Loading @@ -217,4 +219,13 @@ public class ContextHubClient implements Closeable { super.finalize(); } } /** @hide */ public void callbackFinished() { try { mClientProxy.callbackFinished(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } }
core/java/android/hardware/location/ContextHubManager.java +39 −9 Original line number Diff line number Diff line Loading @@ -726,45 +726,75 @@ public final class ContextHubManager { return new IContextHubClientCallback.Stub() { @Override public void onMessageFromNanoApp(NanoAppMessage message) { executor.execute(() -> callback.onMessageFromNanoApp(client, message)); executor.execute( () -> { callback.onMessageFromNanoApp(client, message); client.callbackFinished(); }); } @Override public void onHubReset() { executor.execute(() -> callback.onHubReset(client)); executor.execute( () -> { callback.onHubReset(client); client.callbackFinished(); }); } @Override public void onNanoAppAborted(long nanoAppId, int abortCode) { executor.execute(() -> callback.onNanoAppAborted(client, nanoAppId, abortCode)); executor.execute( () -> { callback.onNanoAppAborted(client, nanoAppId, abortCode); client.callbackFinished(); }); } @Override public void onNanoAppLoaded(long nanoAppId) { executor.execute(() -> callback.onNanoAppLoaded(client, nanoAppId)); executor.execute( () -> { callback.onNanoAppLoaded(client, nanoAppId); client.callbackFinished(); }); } @Override public void onNanoAppUnloaded(long nanoAppId) { executor.execute(() -> callback.onNanoAppUnloaded(client, nanoAppId)); executor.execute( () -> { callback.onNanoAppUnloaded(client, nanoAppId); client.callbackFinished(); }); } @Override public void onNanoAppEnabled(long nanoAppId) { executor.execute(() -> callback.onNanoAppEnabled(client, nanoAppId)); executor.execute( () -> { callback.onNanoAppEnabled(client, nanoAppId); client.callbackFinished(); }); } @Override public void onNanoAppDisabled(long nanoAppId) { executor.execute(() -> callback.onNanoAppDisabled(client, nanoAppId)); executor.execute( () -> { callback.onNanoAppDisabled(client, nanoAppId); client.callbackFinished(); }); } @Override public void onClientAuthorizationChanged( long nanoAppId, @ContextHubManager.AuthorizationState int authorization) { executor.execute( () -> callback.onClientAuthorizationChanged( client, nanoAppId, authorization)); () -> { callback.onClientAuthorizationChanged(client, nanoAppId, authorization); client.callbackFinished(); }); } }; } Loading
core/java/android/hardware/location/IContextHubClient.aidl +3 −0 Original line number Diff line number Diff line Loading @@ -32,4 +32,7 @@ interface IContextHubClient { // Returns the unique ID for this client. int getId(); // Notify direct-call message callback completed void callbackFinished(); }
services/core/java/com/android/server/location/contexthub/ContextHubClientBroker.java +20 −1 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import android.hardware.location.NanoAppMessage; import android.hardware.location.NanoAppState; import android.os.Binder; import android.os.Build; import android.os.Bundle; import android.os.IBinder; import android.os.Looper; import android.os.Process; Loading Loading @@ -104,7 +105,9 @@ import java.util.function.Supplier; * @hide */ public class ContextHubClientBroker extends IContextHubClient.Stub implements IBinder.DeathRecipient, AppOpsManager.OnOpChangedListener { implements IBinder.DeathRecipient, AppOpsManager.OnOpChangedListener, PendingIntent.OnFinished { private static final String TAG = "ContextHubClientBroker"; /** Loading Loading @@ -966,4 +969,20 @@ public class ContextHubClientBroker extends IContextHubClient.Stub return out; } /** Callback that arrives when direct-call message callback delivery completed */ @Override public void callbackFinished() { // TODO(b/202447392): pending implementation. } @Override public void onSendFinished( PendingIntent pendingIntent, Intent intent, int resultCode, String resultData, Bundle resultExtras) { // TODO(b/202447392): pending implementation. } }
services/core/java/com/android/server/location/contexthub/ContextHubService.java +28 −3 Original line number Diff line number Diff line Loading @@ -374,44 +374,69 @@ public class ContextHubService extends IContextHubService.Stub { */ private IContextHubClientCallback createDefaultClientCallback(int contextHubId) { return new IContextHubClientCallback.Stub() { private void finishCallback() { try { IContextHubClient client = mDefaultClientMap.get(contextHubId); client.callbackFinished(); } catch (RemoteException e) { Log.e( TAG, "RemoteException while finishing callback for hub (ID = " + contextHubId + ")", e); } } @Override public void onMessageFromNanoApp(NanoAppMessage message) { int nanoAppHandle = mNanoAppStateManager.getNanoAppHandle( contextHubId, message.getNanoAppId()); int nanoAppHandle = mNanoAppStateManager.getNanoAppHandle(contextHubId, message.getNanoAppId()); onMessageReceiptOldApi( message.getMessageType(), contextHubId, nanoAppHandle, message.getMessageType(), contextHubId, nanoAppHandle, message.getMessageBody()); finishCallback(); } @Override public void onHubReset() { byte[] data = {android.hardware.contexthub.V1_0.TransactionResult.SUCCESS}; onMessageReceiptOldApi(MSG_HUB_RESET, contextHubId, OS_APP_INSTANCE, data); finishCallback(); } @Override public void onNanoAppAborted(long nanoAppId, int abortCode) { finishCallback(); } @Override public void onNanoAppLoaded(long nanoAppId) { finishCallback(); } @Override public void onNanoAppUnloaded(long nanoAppId) { finishCallback(); } @Override public void onNanoAppEnabled(long nanoAppId) { finishCallback(); } @Override public void onNanoAppDisabled(long nanoAppId) { finishCallback(); } @Override public void onClientAuthorizationChanged(long nanoAppId, int authorization) { finishCallback(); } }; } Loading