change -EAGAIN to throw ServiceSpecificException

- -EAGAIN state should not persist and if it persists,
  it is system wide error.
- For now, check exception and return default value when
  get fails. This fixes car service crash in some cases.
- also increase retry timeout for EAGAIN to 5 secs.
- TODO: needs to add persistent failure check and if that
  happens, error state should be reported to user.

bug: 27834209
Change-Id: Idf55b8a2e5d4d5b8edeb806c7962ce04e4a35dda
diff --git a/libvehiclenetwork/native/IVehicleNetwork.cpp b/libvehiclenetwork/native/IVehicleNetwork.cpp
index 09da0ee..c0b2119 100644
--- a/libvehiclenetwork/native/IVehicleNetwork.cpp
+++ b/libvehiclenetwork/native/IVehicleNetwork.cpp
@@ -20,6 +20,7 @@
 #include <string.h>
 
 #include <binder/IPCThreadState.h>
+#include <binder/Status.h>
 
 #include <utils/Log.h>
 
@@ -127,7 +128,13 @@
         }
         status = remote()->transact(GET_PROPERTY, data, &reply);
         if (status == NO_ERROR) {
-            reply.readExceptionCode(); // for compatibility with java
+            int32_t exceptionCode = reply.readExceptionCode();
+            if (exceptionCode != NO_ERROR) {
+                if (exceptionCode == binder::Status::EX_SERVICE_SPECIFIC) {
+                    return -EAGAIN;
+                }
+                return exceptionCode;
+            }
             status = VehiclePropValueBinderUtil::readFromParcel(reply, value);
         }
         return status;
@@ -302,6 +309,10 @@
                 reply->writeNoException();
                 r = VehiclePropValueBinderUtil::writeToParcel(*reply, value);
                 releaseMemoryFromGet(&value);
+            } else if (r == -EAGAIN) {
+                // this should be handled specially to throw ServiceSpecificException in java.
+                reply->writeInt32(binder::Status::EX_SERVICE_SPECIFIC);
+                return NO_ERROR;
             }
             return r;
         } break;