From 0ed545c7e580c3dab63bf2771d9c67d57c9d2600 Mon Sep 17 00:00:00 2001 From: Arthur Ishiguro Date: Tue, 12 Dec 2017 15:01:32 -0800 Subject: [PATCH 1/2] Implements enableNanoApp Bug: 67734082 Test: Run a test app to issue an enable request, verify HAL code is executed via logs and client receives an error response. Change-Id: Ie4ec660a094082887eaefbdfc2e1fd8d1ee7c0e3 --- .../hardware/location/ContextHubManager.java | 16 ++++++-- .../hardware/location/IContextHubService.aidl | 5 +++ .../server/location/ContextHubService.java | 41 ++++++++++++++----- .../ContextHubTransactionManager.java | 37 ++++++++++++++++- 4 files changed, 85 insertions(+), 14 deletions(-) diff --git a/core/java/android/hardware/location/ContextHubManager.java b/core/java/android/hardware/location/ContextHubManager.java index 1d66dc6d939fd..8a0d2e6c981d4 100644 --- a/core/java/android/hardware/location/ContextHubManager.java +++ b/core/java/android/hardware/location/ContextHubManager.java @@ -271,7 +271,7 @@ public final class ContextHubManager { throw new UnsupportedOperationException("TODO: Implement this"); } - /* + /** * Helper function to generate a stub for a non-query transaction callback. * * @param transaction the transaction to unblock when complete @@ -297,7 +297,7 @@ public final class ContextHubManager { }; } - /* + /** * Helper function to generate a stub for a query transaction callback. * * @param transaction the transaction to unblock when complete @@ -392,7 +392,17 @@ public final class ContextHubManager { */ @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public ContextHubTransaction enableNanoApp(ContextHubInfo hubInfo, long nanoAppId) { - throw new UnsupportedOperationException("TODO: Implement this"); + ContextHubTransaction transaction = + new ContextHubTransaction<>(ContextHubTransaction.TYPE_ENABLE_NANOAPP); + IContextHubTransactionCallback callback = createTransactionCallback(transaction); + + try { + mService.enableNanoApp(hubInfo.getId(), callback, nanoAppId); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + + return transaction; } /** diff --git a/core/java/android/hardware/location/IContextHubService.aidl b/core/java/android/hardware/location/IContextHubService.aidl index 628ebc7d4579f..471c639c542fa 100644 --- a/core/java/android/hardware/location/IContextHubService.aidl +++ b/core/java/android/hardware/location/IContextHubService.aidl @@ -70,6 +70,11 @@ interface IContextHubService { int contextHubId, in IContextHubTransactionCallback transactionCallback, long nanoAppId); + // Enables a nanoapp at the specified hub + void enableNanoApp( + int contextHubId, in IContextHubTransactionCallback transactionCallback, + long nanoAppId); + // Queries for a list of nanoapps void queryNanoApps(int contextHubId, in IContextHubTransactionCallback transactionCallback); } diff --git a/services/core/java/com/android/server/location/ContextHubService.java b/services/core/java/com/android/server/location/ContextHubService.java index 90c912a5aee43..694dd26b9f293 100644 --- a/services/core/java/com/android/server/location/ContextHubService.java +++ b/services/core/java/com/android/server/location/ContextHubService.java @@ -642,11 +642,10 @@ public class ContextHubService extends IContextHubService.Stub { /** * Loads a nanoapp binary at the specified Context hub. * - * @param contextHubId the ID of the hub to load the binary + * @param contextHubId the ID of the hub to load the binary * @param transactionCallback the client-facing transaction callback interface - * @param nanoAppBinary the binary to load + * @param nanoAppBinary the binary to load * - * @throws RemoteException * @throws IllegalStateException if the transaction queue is full */ @Override @@ -673,11 +672,10 @@ public class ContextHubService extends IContextHubService.Stub { /** * Unloads a nanoapp from the specified Context Hub. * - * @param contextHubId the ID of the hub to unload the nanoapp + * @param contextHubId the ID of the hub to unload the nanoapp * @param transactionCallback the client-facing transaction callback interface - * @param nanoAppId the ID of the nanoapp to unload + * @param nanoAppId the ID of the nanoapp to unload * - * @throws RemoteException * @throws IllegalStateException if the transaction queue is full */ @Override @@ -695,13 +693,36 @@ public class ContextHubService extends IContextHubService.Stub { mTransactionManager.addTransaction(transaction); } + /** + * Enables a nanoapp at the specified Context Hub. + * + * @param contextHubId the ID of the hub to enable the nanoapp + * @param transactionCallback the client-facing transaction callback interface + * @param nanoAppId the ID of the nanoapp to enable + * + * @throws IllegalStateException if the transaction queue is full + */ + @Override + public void enableNanoApp( + int contextHubId, IContextHubTransactionCallback transactionCallback, long nanoAppId) + throws RemoteException { + checkPermissions(); + if (!checkHalProxyAndContextHubId( + contextHubId, transactionCallback, ContextHubTransaction.TYPE_ENABLE_NANOAPP)) { + return; + } + + ContextHubServiceTransaction transaction = mTransactionManager.createEnableTransaction( + contextHubId, nanoAppId, transactionCallback); + mTransactionManager.addTransaction(transaction); + } + /** * Queries for a list of nanoapps from the specified Context hub. * - * @param contextHubId the ID of the hub to query + * @param contextHubId the ID of the hub to query * @param transactionCallback the client-facing transaction callback interface * - * @throws RemoteException * @throws IllegalStateException if the transaction queue is full */ @Override @@ -713,8 +734,8 @@ public class ContextHubService extends IContextHubService.Stub { return; } - ContextHubServiceTransaction transaction = - mTransactionManager.createQueryTransaction(contextHubId, transactionCallback); + ContextHubServiceTransaction transaction = mTransactionManager.createQueryTransaction( + contextHubId, transactionCallback); mTransactionManager.addTransaction(transaction); } diff --git a/services/core/java/com/android/server/location/ContextHubTransactionManager.java b/services/core/java/com/android/server/location/ContextHubTransactionManager.java index 00252bc75bbf4..30468bfcc9e93 100644 --- a/services/core/java/com/android/server/location/ContextHubTransactionManager.java +++ b/services/core/java/com/android/server/location/ContextHubTransactionManager.java @@ -143,7 +143,7 @@ import java.util.concurrent.atomic.AtomicInteger; /** * Creates a transaction for unloading a nanoapp. * - * @param contextHubId the ID of the hub to load the nanoapp to + * @param contextHubId the ID of the hub to unload the nanoapp from * @param nanoAppId the ID of the nanoapp to unload * @param onCompleteCallback the client on complete callback * @return the generated transaction @@ -181,6 +181,41 @@ import java.util.concurrent.atomic.AtomicInteger; }; } + /** + * Creates a transaction for enabling a nanoapp. + * + * @param contextHubId the ID of the hub to enable the nanoapp on + * @param nanoAppId the ID of the nanoapp to enable + * @param onCompleteCallback the client on complete callback + * @return the generated transaction + */ + /* package */ ContextHubServiceTransaction createEnableTransaction( + int contextHubId, long nanoAppId, IContextHubTransactionCallback onCompleteCallback) { + return new ContextHubServiceTransaction( + mNextAvailableId.getAndIncrement(), ContextHubTransaction.TYPE_ENABLE_NANOAPP) { + @Override + /* package */ int onTransact() { + try { + return mContextHubProxy.enableNanoApp( + contextHubId, nanoAppId, this.getTransactionId()); + } catch (RemoteException e) { + Log.e(TAG, "RemoteException while trying to enable nanoapp with ID 0x" + + Long.toHexString(nanoAppId), e); + return Result.UNKNOWN_FAILURE; + } + } + + @Override + /* package */ void onTransactionComplete(@ContextHubTransaction.Result int result) { + try { + onCompleteCallback.onTransactionComplete(result); + } catch (RemoteException e) { + Log.e(TAG, "RemoteException while calling client onTransactionComplete", e); + } + } + }; + } + /** * Creates a transaction for querying for a list of nanoapps. * From 54e1a89cd8ac316c16e4d932811875aeb2fa93af Mon Sep 17 00:00:00 2001 From: Arthur Ishiguro Date: Tue, 12 Dec 2017 15:09:31 -0800 Subject: [PATCH 2/2] Implements disableNanoApp Bug: 67734082 Test: Run a test app to issue an disable request, verify HAL code is executed via logs and client receives an error response. Change-Id: I5a26c85372bd10a0224bf2a696982dccbca0c275 --- .../hardware/location/ContextHubManager.java | 12 ++++++- .../hardware/location/IContextHubService.aidl | 5 +++ .../server/location/ContextHubService.java | 24 +++++++++++++ .../ContextHubTransactionManager.java | 35 +++++++++++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/core/java/android/hardware/location/ContextHubManager.java b/core/java/android/hardware/location/ContextHubManager.java index 8a0d2e6c981d4..5b89f54b50504 100644 --- a/core/java/android/hardware/location/ContextHubManager.java +++ b/core/java/android/hardware/location/ContextHubManager.java @@ -417,7 +417,17 @@ public final class ContextHubManager { */ @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public ContextHubTransaction disableNanoApp(ContextHubInfo hubInfo, long nanoAppId) { - throw new UnsupportedOperationException("TODO: Implement this"); + ContextHubTransaction transaction = + new ContextHubTransaction<>(ContextHubTransaction.TYPE_DISABLE_NANOAPP); + IContextHubTransactionCallback callback = createTransactionCallback(transaction); + + try { + mService.disableNanoApp(hubInfo.getId(), callback, nanoAppId); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + + return transaction; } /** diff --git a/core/java/android/hardware/location/IContextHubService.aidl b/core/java/android/hardware/location/IContextHubService.aidl index 471c639c542fa..db5bd36e11091 100644 --- a/core/java/android/hardware/location/IContextHubService.aidl +++ b/core/java/android/hardware/location/IContextHubService.aidl @@ -75,6 +75,11 @@ interface IContextHubService { int contextHubId, in IContextHubTransactionCallback transactionCallback, long nanoAppId); + // Disables a nanoapp at the specified hub + void disableNanoApp( + int contextHubId, in IContextHubTransactionCallback transactionCallback, + long nanoAppId); + // Queries for a list of nanoapps void queryNanoApps(int contextHubId, in IContextHubTransactionCallback transactionCallback); } diff --git a/services/core/java/com/android/server/location/ContextHubService.java b/services/core/java/com/android/server/location/ContextHubService.java index 694dd26b9f293..1ad0cf931165a 100644 --- a/services/core/java/com/android/server/location/ContextHubService.java +++ b/services/core/java/com/android/server/location/ContextHubService.java @@ -717,6 +717,30 @@ public class ContextHubService extends IContextHubService.Stub { mTransactionManager.addTransaction(transaction); } + /** + * Disables a nanoapp at the specified Context Hub. + * + * @param contextHubId the ID of the hub to disable the nanoapp + * @param transactionCallback the client-facing transaction callback interface + * @param nanoAppId the ID of the nanoapp to disable + * + * @throws IllegalStateException if the transaction queue is full + */ + @Override + public void disableNanoApp( + int contextHubId, IContextHubTransactionCallback transactionCallback, long nanoAppId) + throws RemoteException { + checkPermissions(); + if (!checkHalProxyAndContextHubId( + contextHubId, transactionCallback, ContextHubTransaction.TYPE_DISABLE_NANOAPP)) { + return; + } + + ContextHubServiceTransaction transaction = mTransactionManager.createDisableTransaction( + contextHubId, nanoAppId, transactionCallback); + mTransactionManager.addTransaction(transaction); + } + /** * Queries for a list of nanoapps from the specified Context hub. * diff --git a/services/core/java/com/android/server/location/ContextHubTransactionManager.java b/services/core/java/com/android/server/location/ContextHubTransactionManager.java index 30468bfcc9e93..412d43da29f71 100644 --- a/services/core/java/com/android/server/location/ContextHubTransactionManager.java +++ b/services/core/java/com/android/server/location/ContextHubTransactionManager.java @@ -216,6 +216,41 @@ import java.util.concurrent.atomic.AtomicInteger; }; } + /** + * Creates a transaction for disabling a nanoapp. + * + * @param contextHubId the ID of the hub to disable the nanoapp on + * @param nanoAppId the ID of the nanoapp to disable + * @param onCompleteCallback the client on complete callback + * @return the generated transaction + */ + /* package */ ContextHubServiceTransaction createDisableTransaction( + int contextHubId, long nanoAppId, IContextHubTransactionCallback onCompleteCallback) { + return new ContextHubServiceTransaction( + mNextAvailableId.getAndIncrement(), ContextHubTransaction.TYPE_DISABLE_NANOAPP) { + @Override + /* package */ int onTransact() { + try { + return mContextHubProxy.disableNanoApp( + contextHubId, nanoAppId, this.getTransactionId()); + } catch (RemoteException e) { + Log.e(TAG, "RemoteException while trying to disable nanoapp with ID 0x" + + Long.toHexString(nanoAppId), e); + return Result.UNKNOWN_FAILURE; + } + } + + @Override + /* package */ void onTransactionComplete(@ContextHubTransaction.Result int result) { + try { + onCompleteCallback.onTransactionComplete(result); + } catch (RemoteException e) { + Log.e(TAG, "RemoteException while calling client onTransactionComplete", e); + } + } + }; + } + /** * Creates a transaction for querying for a list of nanoapps. *