From 57f00904cbfeb7eae23c8aed71fbfbdff6d05ea4 Mon Sep 17 00:00:00 2001 From: Arthur Ishiguro Date: Wed, 29 Nov 2017 11:54:51 -0800 Subject: Reorganize use of error code enums For consistency use client-facing error code enums in ContextHubServiceTransaction, and convert as necessary within the ContextHubTransactionManager class. Bug: 67734082 Test: None Change-Id: Ie1686e826b6390b11418a7bd8b0119030c89cadb --- .../location/ContextHubServiceTransaction.java | 5 +++-- .../location/ContextHubTransactionManager.java | 26 +++++++++++++--------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/services/core/java/com/android/server/location/ContextHubServiceTransaction.java b/services/core/java/com/android/server/location/ContextHubServiceTransaction.java index ce92f722e2d2..c1fc98248e08 100644 --- a/services/core/java/com/android/server/location/ContextHubServiceTransaction.java +++ b/services/core/java/com/android/server/location/ContextHubServiceTransaction.java @@ -61,7 +61,7 @@ import java.util.concurrent.TimeUnit; * * @param result the result of the transaction */ - /* package */ void onTransactionComplete(int result) { + /* package */ void onTransactionComplete(@ContextHubTransaction.Result int result) { } /** @@ -72,7 +72,8 @@ import java.util.concurrent.TimeUnit; * @param result the result of the query * @param nanoAppStateList the list of nanoapps given by the query response */ - /* package */ void onQueryResponse(int result, List nanoAppStateList) { + /* package */ void onQueryResponse( + @ContextHubTransaction.Result int result, List nanoAppStateList) { } /** diff --git a/services/core/java/com/android/server/location/ContextHubTransactionManager.java b/services/core/java/com/android/server/location/ContextHubTransactionManager.java index 15c8672b41c9..934b2cd5f00d 100644 --- a/services/core/java/com/android/server/location/ContextHubTransactionManager.java +++ b/services/core/java/com/android/server/location/ContextHubTransactionManager.java @@ -119,8 +119,8 @@ import java.util.concurrent.atomic.AtomicInteger; } @Override - /* package */ void onTransactionComplete(int result) { - if (result == TransactionResult.SUCCESS) { + /* package */ void onTransactionComplete(@ContextHubTransaction.Result int result) { + if (result == ContextHubTransaction.TRANSACTION_SUCCESS) { // NOTE: The legacy JNI code used to do a query right after a load success // to synchronize the service cache. Instead store the binary that was // requested to load to update the cache later without doing a query. @@ -130,7 +130,7 @@ import java.util.concurrent.atomic.AtomicInteger; } try { onCompleteCallback.onTransactionComplete(result); - if (result == Result.OK) { + if (result == ContextHubTransaction.TRANSACTION_SUCCESS) { mClientManager.onNanoAppLoaded(contextHubId, nanoAppBinary.getNanoAppId()); } } catch (RemoteException e) { @@ -165,13 +165,13 @@ import java.util.concurrent.atomic.AtomicInteger; } @Override - /* package */ void onTransactionComplete(int result) { - if (result == TransactionResult.SUCCESS) { + /* package */ void onTransactionComplete(@ContextHubTransaction.Result int result) { + if (result == ContextHubTransaction.TRANSACTION_SUCCESS) { mNanoAppStateManager.removeNanoAppInstance(contextHubId, nanoAppId); } try { onCompleteCallback.onTransactionComplete(result); - if (result == Result.OK) { + if (result == ContextHubTransaction.TRANSACTION_SUCCESS) { mClientManager.onNanoAppUnloaded(contextHubId, nanoAppId); } } catch (RemoteException e) { @@ -203,12 +203,13 @@ import java.util.concurrent.atomic.AtomicInteger; } @Override - /* package */ void onTransactionComplete(int result) { + /* package */ void onTransactionComplete(@ContextHubTransaction.Result int result) { onQueryResponse(result, Collections.emptyList()); } @Override - /* package */ void onQueryResponse(int result, List nanoAppStateList) { + /* package */ void onQueryResponse( + @ContextHubTransaction.Result int result, List nanoAppStateList) { try { onCompleteCallback.onQueryResponse(result, nanoAppStateList); } catch (RemoteException e) { @@ -245,7 +246,7 @@ import java.util.concurrent.atomic.AtomicInteger; * Handles a transaction response from a Context Hub. * * @param transactionId the transaction ID of the response - * @param result the result of the transaction + * @param result the result of the transaction as defined by the HAL TransactionResult */ /* package */ synchronized void onTransactionResponse(int transactionId, int result) { @@ -260,7 +261,10 @@ import java.util.concurrent.atomic.AtomicInteger; return; } - transaction.onTransactionComplete(result); + transaction.onTransactionComplete( + (result == TransactionResult.SUCCESS) ? + ContextHubTransaction.TRANSACTION_SUCCESS : + ContextHubTransaction.TRANSACTION_FAILED_AT_HUB); removeTransactionAndStartNext(); } @@ -281,7 +285,7 @@ import java.util.concurrent.atomic.AtomicInteger; return; } - transaction.onQueryResponse(TransactionResult.SUCCESS, nanoAppStateList); + transaction.onQueryResponse(ContextHubTransaction.TRANSACTION_SUCCESS, nanoAppStateList); removeTransactionAndStartNext(); } -- cgit v1.2.3-59-g8ed1b