From 6100aa7e72c0506b612b575fe0cb67479710eaa4 Mon Sep 17 00:00:00 2001 From: Arthur Ishiguro Date: Wed, 20 Dec 2017 09:35:00 -0800 Subject: [PATCH 1/2] Rename ContextHubTransaction.Result IntDef Use RESULT_ instead of TRANSACTION_ to be consistent with the name. Bug: 67734082 Test: make Change-Id: Ib7cc4d527cc160ec6788449231cdffa5c3e8fc0d --- .../hardware/location/ContextHubManager.java | 4 +- .../location/ContextHubTransaction.java | 38 +++++++++---------- .../server/location/ContextHubService.java | 8 ++-- .../location/ContextHubServiceUtil.java | 10 ++--- .../ContextHubTransactionManager.java | 16 ++++---- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/core/java/android/hardware/location/ContextHubManager.java b/core/java/android/hardware/location/ContextHubManager.java index 6da6fb7bfdb7d..b7ce875ad1e1d 100644 --- a/core/java/android/hardware/location/ContextHubManager.java +++ b/core/java/android/hardware/location/ContextHubManager.java @@ -291,7 +291,7 @@ public final class ContextHubManager { public void onQueryResponse(int result, List nanoappList) { Log.e(TAG, "Received a query callback on a non-query request"); transaction.setResponse(new ContextHubTransaction.Response( - ContextHubTransaction.TRANSACTION_FAILED_SERVICE_INTERNAL_FAILURE, null)); + ContextHubTransaction.RESULT_FAILED_SERVICE_INTERNAL_FAILURE, null)); } @Override @@ -323,7 +323,7 @@ public final class ContextHubManager { public void onTransactionComplete(int result) { Log.e(TAG, "Received a non-query callback on a query request"); transaction.setResponse(new ContextHubTransaction.Response>( - ContextHubTransaction.TRANSACTION_FAILED_SERVICE_INTERNAL_FAILURE, null)); + ContextHubTransaction.RESULT_FAILED_SERVICE_INTERNAL_FAILURE, null)); } }; } diff --git a/core/java/android/hardware/location/ContextHubTransaction.java b/core/java/android/hardware/location/ContextHubTransaction.java index 2a66cbc24b778..93cc56e4dcbb6 100644 --- a/core/java/android/hardware/location/ContextHubTransaction.java +++ b/core/java/android/hardware/location/ContextHubTransaction.java @@ -66,51 +66,51 @@ public class ContextHubTransaction { * Constants describing the result of a transaction or request through the Context Hub Service. */ @Retention(RetentionPolicy.SOURCE) - @IntDef(prefix = { "TRANSACTION_" }, value = { - TRANSACTION_SUCCESS, - TRANSACTION_FAILED_UNKNOWN, - TRANSACTION_FAILED_BAD_PARAMS, - TRANSACTION_FAILED_UNINITIALIZED, - TRANSACTION_FAILED_PENDING, - TRANSACTION_FAILED_AT_HUB, - TRANSACTION_FAILED_TIMEOUT, - TRANSACTION_FAILED_SERVICE_INTERNAL_FAILURE, - TRANSACTION_FAILED_HAL_UNAVAILABLE + @IntDef(prefix = { "RESULT_" }, value = { + RESULT_SUCCESS, + RESULT_FAILED_UNKNOWN, + RESULT_FAILED_BAD_PARAMS, + RESULT_FAILED_UNINITIALIZED, + RESULT_FAILED_PENDING, + RESULT_FAILED_AT_HUB, + RESULT_FAILED_TIMEOUT, + RESULT_FAILED_SERVICE_INTERNAL_FAILURE, + RESULT_FAILED_HAL_UNAVAILABLE }) public @interface Result {} - public static final int TRANSACTION_SUCCESS = 0; + public static final int RESULT_SUCCESS = 0; /** * Generic failure mode. */ - public static final int TRANSACTION_FAILED_UNKNOWN = 1; + public static final int RESULT_FAILED_UNKNOWN = 1; /** * Failure mode when the request parameters were not valid. */ - public static final int TRANSACTION_FAILED_BAD_PARAMS = 2; + public static final int RESULT_FAILED_BAD_PARAMS = 2; /** * Failure mode when the Context Hub is not initialized. */ - public static final int TRANSACTION_FAILED_UNINITIALIZED = 3; + public static final int RESULT_FAILED_UNINITIALIZED = 3; /** * Failure mode when there are too many transactions pending. */ - public static final int TRANSACTION_FAILED_PENDING = 4; + public static final int RESULT_FAILED_PENDING = 4; /** * Failure mode when the request went through, but failed asynchronously at the hub. */ - public static final int TRANSACTION_FAILED_AT_HUB = 5; + public static final int RESULT_FAILED_AT_HUB = 5; /** * Failure mode when the transaction has timed out. */ - public static final int TRANSACTION_FAILED_TIMEOUT = 6; + public static final int RESULT_FAILED_TIMEOUT = 6; /** * Failure mode when the transaction has failed internally at the service. */ - public static final int TRANSACTION_FAILED_SERVICE_INTERNAL_FAILURE = 7; + public static final int RESULT_FAILED_SERVICE_INTERNAL_FAILURE = 7; /** * Failure mode when the Context Hub HAL was not available. */ - public static final int TRANSACTION_FAILED_HAL_UNAVAILABLE = 8; + public static final int RESULT_FAILED_HAL_UNAVAILABLE = 8; /** * A class describing the response for a ContextHubTransaction. diff --git a/services/core/java/com/android/server/location/ContextHubService.java b/services/core/java/com/android/server/location/ContextHubService.java index 26edf6270770c..dc95d41090b2a 100644 --- a/services/core/java/com/android/server/location/ContextHubService.java +++ b/services/core/java/com/android/server/location/ContextHubService.java @@ -482,7 +482,7 @@ public class ContextHubService extends IContextHubService.Stub { IContextHubClient client = mDefaultClientMap.get(contextHubHandle); success = (client.sendMessageToNanoApp(message) == - ContextHubTransaction.TRANSACTION_SUCCESS); + ContextHubTransaction.RESULT_SUCCESS); } else { Log.e(TAG, "Failed to send nanoapp message - nanoapp with handle " + nanoAppHandle + " does not exist."); @@ -642,7 +642,7 @@ public class ContextHubService extends IContextHubService.Stub { if (nanoAppBinary == null) { Log.e(TAG, "NanoAppBinary cannot be null in loadNanoAppOnHub"); transactionCallback.onTransactionComplete( - ContextHubTransaction.TRANSACTION_FAILED_BAD_PARAMS); + ContextHubTransaction.RESULT_FAILED_BAD_PARAMS); return; } @@ -817,7 +817,7 @@ public class ContextHubService extends IContextHubService.Stub { if (mContextHubProxy == null) { try { callback.onTransactionComplete( - ContextHubTransaction.TRANSACTION_FAILED_HAL_UNAVAILABLE); + ContextHubTransaction.RESULT_FAILED_HAL_UNAVAILABLE); } catch (RemoteException e) { Log.e(TAG, "RemoteException while calling onTransactionComplete", e); } @@ -828,7 +828,7 @@ public class ContextHubService extends IContextHubService.Stub { + ContextHubTransaction.typeToString(transactionType, false /* upperCase */) + " transaction for invalid hub ID " + contextHubId); try { - callback.onTransactionComplete(ContextHubTransaction.TRANSACTION_FAILED_BAD_PARAMS); + callback.onTransactionComplete(ContextHubTransaction.RESULT_FAILED_BAD_PARAMS); } catch (RemoteException e) { Log.e(TAG, "RemoteException while calling onTransactionComplete", e); } diff --git a/services/core/java/com/android/server/location/ContextHubServiceUtil.java b/services/core/java/com/android/server/location/ContextHubServiceUtil.java index 7a57dd38c95f7..c356b639deba8 100644 --- a/services/core/java/com/android/server/location/ContextHubServiceUtil.java +++ b/services/core/java/com/android/server/location/ContextHubServiceUtil.java @@ -215,17 +215,17 @@ import java.util.ArrayList; static int toTransactionResult(int halResult) { switch (halResult) { case Result.OK: - return ContextHubTransaction.TRANSACTION_SUCCESS; + return ContextHubTransaction.RESULT_SUCCESS; case Result.BAD_PARAMS: - return ContextHubTransaction.TRANSACTION_FAILED_BAD_PARAMS; + return ContextHubTransaction.RESULT_FAILED_BAD_PARAMS; case Result.NOT_INIT: - return ContextHubTransaction.TRANSACTION_FAILED_UNINITIALIZED; + return ContextHubTransaction.RESULT_FAILED_UNINITIALIZED; case Result.TRANSACTION_PENDING: - return ContextHubTransaction.TRANSACTION_FAILED_PENDING; + return ContextHubTransaction.RESULT_FAILED_PENDING; case Result.TRANSACTION_FAILED: case Result.UNKNOWN_FAILURE: default: /* fall through */ - return ContextHubTransaction.TRANSACTION_FAILED_UNKNOWN; + return ContextHubTransaction.RESULT_FAILED_UNKNOWN; } } } diff --git a/services/core/java/com/android/server/location/ContextHubTransactionManager.java b/services/core/java/com/android/server/location/ContextHubTransactionManager.java index 412d43da29f71..cced781f8e1b5 100644 --- a/services/core/java/com/android/server/location/ContextHubTransactionManager.java +++ b/services/core/java/com/android/server/location/ContextHubTransactionManager.java @@ -120,7 +120,7 @@ import java.util.concurrent.atomic.AtomicInteger; @Override /* package */ void onTransactionComplete(@ContextHubTransaction.Result int result) { - if (result == ContextHubTransaction.TRANSACTION_SUCCESS) { + if (result == ContextHubTransaction.RESULT_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 == ContextHubTransaction.TRANSACTION_SUCCESS) { + if (result == ContextHubTransaction.RESULT_SUCCESS) { mClientManager.onNanoAppLoaded(contextHubId, nanoAppBinary.getNanoAppId()); } } catch (RemoteException e) { @@ -166,12 +166,12 @@ import java.util.concurrent.atomic.AtomicInteger; @Override /* package */ void onTransactionComplete(@ContextHubTransaction.Result int result) { - if (result == ContextHubTransaction.TRANSACTION_SUCCESS) { + if (result == ContextHubTransaction.RESULT_SUCCESS) { mNanoAppStateManager.removeNanoAppInstance(contextHubId, nanoAppId); } try { onCompleteCallback.onTransactionComplete(result); - if (result == ContextHubTransaction.TRANSACTION_SUCCESS) { + if (result == ContextHubTransaction.RESULT_SUCCESS) { mClientManager.onNanoAppUnloaded(contextHubId, nanoAppId); } } catch (RemoteException e) { @@ -334,8 +334,8 @@ import java.util.concurrent.atomic.AtomicInteger; transaction.onTransactionComplete( (result == TransactionResult.SUCCESS) ? - ContextHubTransaction.TRANSACTION_SUCCESS : - ContextHubTransaction.TRANSACTION_FAILED_AT_HUB); + ContextHubTransaction.RESULT_SUCCESS : + ContextHubTransaction.RESULT_FAILED_AT_HUB); removeTransactionAndStartNext(); } @@ -356,7 +356,7 @@ import java.util.concurrent.atomic.AtomicInteger; return; } - transaction.onQueryResponse(ContextHubTransaction.TRANSACTION_SUCCESS, nanoAppStateList); + transaction.onQueryResponse(ContextHubTransaction.RESULT_SUCCESS, nanoAppStateList); removeTransactionAndStartNext(); } @@ -416,7 +416,7 @@ import java.util.concurrent.atomic.AtomicInteger; if (!transaction.isComplete()) { Log.d(TAG, transaction + " timed out"); transaction.onTransactionComplete( - ContextHubTransaction.TRANSACTION_FAILED_TIMEOUT); + ContextHubTransaction.RESULT_FAILED_TIMEOUT); removeTransactionAndStartNext(); } From 10f8ce4be583b05af9620d177c2293a6c20ee60c Mon Sep 17 00:00:00 2001 From: Arthur Ishiguro Date: Wed, 20 Dec 2017 12:09:21 -0800 Subject: [PATCH 2/2] Renames setCallbackOnComplete method in ContextHubTransaction setOnCompleteCallback seems easier to understand. Bug: 67734082 Test: None Change-Id: Ie1eb63dc5b90a35e847bd5d2a350f97ca277342d --- .../hardware/location/ContextHubTransaction.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/java/android/hardware/location/ContextHubTransaction.java b/core/java/android/hardware/location/ContextHubTransaction.java index 93cc56e4dcbb6..ec1e68fe680c3 100644 --- a/core/java/android/hardware/location/ContextHubTransaction.java +++ b/core/java/android/hardware/location/ContextHubTransaction.java @@ -34,7 +34,7 @@ import java.util.concurrent.TimeoutException; * through the ContextHubManager APIs. The caller can either retrieve the result * synchronously through a blocking call ({@link #waitForResponse(long, TimeUnit)}) or * asynchronously through a user-defined callback - * ({@link #setCallbackOnComplete(ContextHubTransaction.Callback, Handler)}). + * ({@link #setOnCompleteCallback(ContextHubTransaction.Callback, Handler)}). * * @param the type of the contents in the transaction response * @@ -271,7 +271,7 @@ public class ContextHubTransaction { * A transaction can be invalidated if the process owning the transaction is no longer active * and the reference to this object is lost. * - * This method or {@link #setCallbackOnComplete(ContextHubTransaction.Callback)} can only be + * This method or {@link #setOnCompleteCallback(ContextHubTransaction.Callback)} can only be * invoked once, or an IllegalStateException will be thrown. * * @param callback the callback to be invoked upon completion @@ -280,7 +280,7 @@ public class ContextHubTransaction { * @throws IllegalStateException if this method is called multiple times * @throws NullPointerException if the callback or handler is null */ - public void setCallbackOnComplete( + public void setOnCompleteCallback( @NonNull ContextHubTransaction.Callback callback, @NonNull Handler handler) { synchronized (this) { if (callback == null) { @@ -312,10 +312,10 @@ public class ContextHubTransaction { /** * Sets a callback to be invoked when the transaction completes. * - * Equivalent to {@link #setCallbackOnComplete(ContextHubTransaction.Callback, Handler)} + * Equivalent to {@link #setOnCompleteCallback(ContextHubTransaction.Callback, Handler)} * with the handler being that of the main thread's Looper. * - * This method or {@link #setCallbackOnComplete(ContextHubTransaction.Callback, Handler)} + * This method or {@link #setOnCompleteCallback(ContextHubTransaction.Callback, Handler)} * can only be invoked once, or an IllegalStateException will be thrown. * * @param callback the callback to be invoked upon completion @@ -323,8 +323,8 @@ public class ContextHubTransaction { * @throws IllegalStateException if this method is called multiple times * @throws NullPointerException if the callback is null */ - public void setCallbackOnComplete(@NonNull ContextHubTransaction.Callback callback) { - setCallbackOnComplete(callback, new Handler(Looper.getMainLooper())); + public void setOnCompleteCallback(@NonNull ContextHubTransaction.Callback callback) { + setOnCompleteCallback(callback, new Handler(Looper.getMainLooper())); } /**