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
This commit is contained in:
Arthur Ishiguro
2017-12-12 15:09:31 -08:00
parent 0ed545c7e5
commit 54e1a89cd8
4 changed files with 75 additions and 1 deletions

View File

@@ -417,7 +417,17 @@ public final class ContextHubManager {
*/
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
public ContextHubTransaction<Void> disableNanoApp(ContextHubInfo hubInfo, long nanoAppId) {
throw new UnsupportedOperationException("TODO: Implement this");
ContextHubTransaction<Void> 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;
}
/**

View File

@@ -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);
}

View File

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

View File

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