Merge "Loading NanoApps now works." into nyc-mr1-dev
diff --git a/core/java/android/hardware/location/ContextHubService.java b/core/java/android/hardware/location/ContextHubService.java
index fcbc962..062c958 100644
--- a/core/java/android/hardware/location/ContextHubService.java
+++ b/core/java/android/hardware/location/ContextHubService.java
@@ -166,9 +166,12 @@
         msgHeader[HEADER_FIELD_LOAD_APP_ID_LO] = (int)(appId & 0xFFFFFFFF);
         msgHeader[HEADER_FIELD_LOAD_APP_ID_HI] = (int)((appId >> 32) & 0xFFFFFFFF);
 
-        if (nativeSendMessage(msgHeader, app.getAppBinary()) != 0) {
+        int errVal = nativeSendMessage(msgHeader, app.getAppBinary());
+        if (errVal != 0) {
+            Log.e(TAG, "Send Message returns error" + contextHubHandle);
             return -1;
         }
+
         // Do not add an entry to mNanoAppInstance Hash yet. The HAL may reject the app
         return 0;
     }
diff --git a/core/jni/android_hardware_location_ContextHubService.cpp b/core/jni/android_hardware_location_ContextHubService.cpp
index 46f76de..9515a0e 100644
--- a/core/jni/android_hardware_location_ContextHubService.cpp
+++ b/core/jni/android_hardware_location_ContextHubService.cpp
@@ -423,7 +423,7 @@
     txnInfo->appInfo.num_mem_ranges = 0;
     txnInfo->appInfo.version = -1; // Awaited
 
-    if (!addTxn(CONTEXT_HUB_LOAD_APP, txnInfo)) {
+    if (addTxn(CONTEXT_HUB_LOAD_APP, txnInfo) != 0) {
         return_id(instanceId);
         free(txnInfo);
         return -1;
@@ -726,6 +726,7 @@
           if (isValidOsStatus(msg, msgLen, &rsp)) {
               rsp.result = 0;
               ALOGW("Context Hub handle %d restarted", hubHandle);
+              closeTxn();
               passOnOsResponse(hubHandle, msgType, &rsp, nullptr, 0);
               invalidateNanoApps(hubHandle);
               query_hub_for_apps(ALL_APPS, hubHandle);
@@ -1012,10 +1013,12 @@
 
         if (msgType == CONTEXT_HUB_LOAD_APP) {
             if (startLoadAppTxn(appId, hubHandle) != 0) {
+                ALOGW("Cannot Start Load Transaction");
                 return -1;
             }
         } else if (msgType == CONTEXT_HUB_UNLOAD_APP) {
             if (startUnloadAppTxn(appInstanceHandle) != 0) {
+                ALOGW("Cannot Start UnLoad Transaction");
                 return -1;
             }
         }