AIDL NDK logger bugfix

1. When the error occurs in server side, it exits before log, so make
logger called before exit.
2. service_specific_code had wrong data, so change it to valid code.

Bug: 126501406
Test: m
Change-Id: Ibbb072a067ab2c16f3fdefcc777c4900fb8492ae
diff --git a/aidl_to_cpp_common.cpp b/aidl_to_cpp_common.cpp
index 3208e72..8978311 100644
--- a/aidl_to_cpp_common.cpp
+++ b/aidl_to_cpp_common.cpp
@@ -314,7 +314,8 @@
               << statusVarName << ".get()));\n";
     (*writer) << "_log_status[\"transaction_error\"] = Json::Value(AStatus_getStatus("
               << statusVarName << ".get()));\n";
-    (*writer) << "_log_status[\"service_specific_error_code\"] = Json::Value(AStatus_getMessage("
+    (*writer) << "_log_status[\"service_specific_error_code\"] = "
+                 "Json::Value(AStatus_getServiceSpecificError("
               << statusVarName << ".get()));\n";
   } else {
     (*writer) << "_log_status[\"exception_code\"] = Json::Value(" << statusVarName
diff --git a/generate_ndk.cpp b/generate_ndk.cpp
index f7a2b45..f0445f7 100644
--- a/generate_ndk.cpp
+++ b/generate_ndk.cpp
@@ -370,6 +370,11 @@
   out << "::ndk::ScopedAStatus _aidl_status = _aidl_impl->" << method.GetName() << "("
       << NdkArgList(types, method, FormatArgForCall) << ");\n";
 
+  if (options.GenLog()) {
+    out << cpp::GenLogAfterExecute(ClassName(defined_type, ClassNames::SERVER), defined_type,
+                                   method, "_aidl_status", "_aidl_return", true /* isServer */,
+                                   true /* isNdk */);
+  }
   if (method.IsOneway()) {
     // For a oneway transaction, the kernel will have already returned a result. This is for the
     // in-process case when a oneway transaction is parceled/unparceled in the same process.
@@ -393,11 +398,6 @@
       StatusCheckBreak(out);
     }
   }
-  if (options.GenLog()) {
-    out << cpp::GenLogAfterExecute(ClassName(defined_type, ClassNames::SERVER), defined_type,
-                                   method, "_aidl_status", "_aidl_return", true /* isServer */,
-                                   true /* isNdk */);
-  }
   out << "break;\n";
   out.Dedent();
   out << "}\n";