Merge "Handles synchronous failures of transactions"
diff --git a/services/core/java/com/android/server/location/ContextHubServiceTransaction.java b/services/core/java/com/android/server/location/ContextHubServiceTransaction.java
index 66145bb..a543daf 100644
--- a/services/core/java/com/android/server/location/ContextHubServiceTransaction.java
+++ b/services/core/java/com/android/server/location/ContextHubServiceTransaction.java
@@ -54,18 +54,10 @@
     abstract int onTransact();
 
     /**
-     * A function to invoke when a transaction times out.
-     *
-     * All instances of this class must implement this method by reporting the timeout to the
-     * client.
-     */
-    /* package */
-    abstract void onTimeout();
-
-    /**
      * A function to invoke when the transaction completes.
      *
-     * Only relevant for load, unload, enable, or disable transactions.
+     * For transactions with expected contents (such as a query), the class instance should
+     * implement the appropriate behavior (e.g. invoke onQueryResponse with an empty list).
      *
      * @param result the result of the transaction
      */
diff --git a/services/core/java/com/android/server/location/ContextHubTransactionManager.java b/services/core/java/com/android/server/location/ContextHubTransactionManager.java
index 47d9d56..3fcc682 100644
--- a/services/core/java/com/android/server/location/ContextHubTransactionManager.java
+++ b/services/core/java/com/android/server/location/ContextHubTransactionManager.java
@@ -106,17 +106,12 @@
                             contextHubId, hidlNanoAppBinary, this.getTransactionId());
                 } catch (RemoteException e) {
                     Log.e(TAG, "RemoteException while trying to load nanoapp with ID 0x" +
-                            Long.toHexString(nanoAppBinary.getNanoAppId()));
+                            Long.toHexString(nanoAppBinary.getNanoAppId()), e);
                     return Result.UNKNOWN_FAILURE;
                 }
             }
 
             @Override
-            /* package */ void onTimeout() {
-                onTransactionComplete(ContextHubTransaction.TRANSACTION_FAILED_TIMEOUT);
-            }
-
-            @Override
             /* package */ void onTransactionComplete(int result) {
                 try {
                     onCompleteCallback.onTransactionComplete(result);
@@ -124,7 +119,7 @@
                         mClientManager.onNanoAppLoaded(contextHubId, nanoAppBinary.getNanoAppId());
                     }
                 } catch (RemoteException e) {
-                    Log.e(TAG, "RemoteException while calling client onTransactionComplete");
+                    Log.e(TAG, "RemoteException while calling client onTransactionComplete", e);
                 }
             }
         };
@@ -149,17 +144,12 @@
                             contextHubId, nanoAppId, this.getTransactionId());
                 } catch (RemoteException e) {
                     Log.e(TAG, "RemoteException while trying to unload nanoapp with ID 0x" +
-                            Long.toHexString(nanoAppId));
+                            Long.toHexString(nanoAppId), e);
                     return Result.UNKNOWN_FAILURE;
                 }
             }
 
             @Override
-            /* package */ void onTimeout() {
-                onTransactionComplete(ContextHubTransaction.TRANSACTION_FAILED_TIMEOUT);
-            }
-
-            @Override
             /* package */ void onTransactionComplete(int result) {
                 try {
                     onCompleteCallback.onTransactionComplete(result);
@@ -167,7 +157,7 @@
                         mClientManager.onNanoAppUnloaded(contextHubId, nanoAppId);
                     }
                 } catch (RemoteException e) {
-                    Log.e(TAG, "RemoteException while calling client onTransactionComplete");
+                    Log.e(TAG, "RemoteException while calling client onTransactionComplete", e);
                 }
             }
         };
@@ -189,15 +179,14 @@
                 try {
                     return mContextHubProxy.queryApps(contextHubId);
                 } catch (RemoteException e) {
-                    Log.e(TAG, "RemoteException while trying to query for nanoapps");
+                    Log.e(TAG, "RemoteException while trying to query for nanoapps", e);
                     return Result.UNKNOWN_FAILURE;
                 }
             }
 
             @Override
-            /* package */ void onTimeout() {
-                onQueryResponse(ContextHubTransaction.TRANSACTION_FAILED_TIMEOUT,
-                        Collections.emptyList());
+            /* package */ void onTransactionComplete(int result) {
+                onQueryResponse(result, Collections.emptyList());
             }
 
             @Override
@@ -205,7 +194,7 @@
                 try {
                     onCompleteCallback.onQueryResponse(result, nanoAppStateList);
                 } catch (RemoteException e) {
-                    Log.e(TAG, "RemoteException while calling client onQueryComplete");
+                    Log.e(TAG, "RemoteException while calling client onQueryComplete", e);
                 }
             }
         };
@@ -333,7 +322,8 @@
                     synchronized (this) {
                         if (!transaction.isComplete()) {
                             Log.d(TAG, transaction + " timed out");
-                            transaction.onTimeout();
+                            transaction.onTransactionComplete(
+                                    ContextHubTransaction.TRANSACTION_FAILED_TIMEOUT);
 
                             removeTransactionAndStartNext();
                         }
@@ -344,6 +334,8 @@
                 mTimeoutFuture = mTimeoutExecutor.schedule(onTimeoutFunc, timeoutSeconds,
                         TimeUnit.SECONDS);
             } else {
+                transaction.onTransactionComplete(
+                        ContextHubServiceUtil.toTransactionResult(result));
                 mTransactionQueue.remove();
             }
         }