Correctly set minimum priority on nodes.

It looks like libbinder has always set the minimum priority
for a node to 0x7f (127). This is an invalid value as far
as the kernel is concerned, since the current driver only
accepts positive nice values (0..19). The effect of using
0xf7 is that the nice value was clamped to MAX_NICE (19) -
so effectively the kernel never raised the priority
based on the min_priority setting of a node. Correct this
by just using MAX_NICE directly.

Additionally, a recent change removed the use of the
gDisableBackgroundScheduling flag, which system_server
used to make sure that incoming transactions were not
executed at a lower priority. That behavior is actually
still desired, so this change sets the min_priorirty
value to 0 for processes that have requested background
scheduling to be disabled. The effect of that is that
all transactions into those nodes will be executed with
a priority of at least nice 0 (and potentially higher,
depending on the priority of the caller).

Bug: 37677242
Test: verified /d/binder output
Change-Id: I7cbfd309d04cbd052f868fbfe0930529ff21a48a
(cherry picked from commit 2b6317436d2035ce98331906aaaca87e6026c9c8)
diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp
index d0cd8f2..e832961 100644
--- a/libs/binder/IPCThreadState.cpp
+++ b/libs/binder/IPCThreadState.cpp
@@ -338,6 +338,11 @@
     gDisableBackgroundScheduling = disable;
 }
 
+bool IPCThreadState::backgroundSchedulingDisabled()
+{
+    return gDisableBackgroundScheduling;
+}
+
 sp<ProcessState> IPCThreadState::process()
 {
     return mProcess;
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index 39bb078..aec8f10 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -211,7 +211,14 @@
 {
     flat_binder_object obj;
 
-    obj.flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
+    if (IPCThreadState::self()->backgroundSchedulingDisabled()) {
+        /* minimum priority for all nodes is nice 0 */
+        obj.flags = FLAT_BINDER_FLAG_ACCEPTS_FDS;
+    } else {
+        /* minimum priority for all nodes is MAX_NICE(19) */
+        obj.flags = 0x13 | FLAT_BINDER_FLAG_ACCEPTS_FDS;
+    }
+
     if (binder != NULL) {
         IBinder *local = binder->localBinder();
         if (!local) {
diff --git a/libs/binder/include/binder/IPCThreadState.h b/libs/binder/include/binder/IPCThreadState.h
index 7b826d6..245607e 100644
--- a/libs/binder/include/binder/IPCThreadState.h
+++ b/libs/binder/include/binder/IPCThreadState.h
@@ -83,6 +83,7 @@
     // in to it but doesn't want to acquire locks in its services while in
     // the background.
     static  void                disableBackgroundScheduling(bool disable);
+            bool                backgroundSchedulingDisabled();
 
             // Call blocks until the number of executing binder threads is less than
             // the maximum number of binder threads threads allowed for this process.