Allow error/abort for non-oneway calls.

Low-level processes like init might not want to make blocking calls.
This provides the mechanism to programmatically enforce that.

Test: enable ERROR_BLOCKING on process and look at callstacks
Bug: 36424585

Change-Id: I6dad33271108768f8bfc4723bf3eeddbf9720395
diff --git a/IPCThreadState.cpp b/IPCThreadState.cpp
index c7c71be..9910d4f 100644
--- a/IPCThreadState.cpp
+++ b/IPCThreadState.cpp
@@ -25,6 +25,7 @@
 #include <hwbinder/binder_kernel.h>
 
 #include <android-base/macros.h>
+#include <utils/CallStack.h>
 #include <utils/Log.h>
 #include <utils/SystemClock.h>
 #include <utils/threads.h>
@@ -635,6 +636,16 @@
     }
 
     if ((flags & TF_ONE_WAY) == 0) {
+        if (UNLIKELY(mCallRestriction != ProcessState::CallRestriction::NONE)) {
+            if (mCallRestriction == ProcessState::CallRestriction::ERROR_IF_NOT_ONEWAY) {
+                ALOGE("Process making non-oneway call but is restricted.");
+                CallStack::logStack("non-oneway call", CallStack::getCurrent(10).get(),
+                    ANDROID_LOG_ERROR);
+            } else /* FATAL_IF_NOT_ONEWAY */ {
+                LOG_ALWAYS_FATAL("Process may not make oneway calls.");
+            }
+        }
+
         #if 0
         if (code == 4) { // relayout
             ALOGI(">>>>>> CALLING transaction 4");
@@ -757,7 +768,8 @@
       mStrictModePolicy(0),
       mLastTransactionBinderFlags(0),
       mIsLooper(false),
-      mIsPollingThread(false) {
+      mIsPollingThread(false),
+      mCallRestriction(mProcess->mCallRestriction) {
     pthread_setspecific(gTLS, this);
     clearCaller();
     mIn.setDataCapacity(256);