Fix inconsistent OomAdjuster computation result

In case of cycle dependencies, while one of the process within
the cycle gets bound by mutliple other processes, the procState
result would be inconsistent across runs. Fix is to pick the
minimum one of the raw and current scores prior to scanning the
service/provider lists in case of cycles-reevaluation.

Bug: 138673927
Test: atest MockingOomAdjusterTests
      cts-tradefed run singleCommand cts-dev -m CtsAppTestCases \
      -t android.app.cts.ActivityManagerProcessStateTest

Change-Id: I8f33c12c1625da6f336d79e44e91158c84beb6ac
diff --git a/services/core/java/com/android/server/am/OomAdjuster.java b/services/core/java/com/android/server/am/OomAdjuster.java
index 97e5293..7a3d3c2 100644
--- a/services/core/java/com/android/server/am/OomAdjuster.java
+++ b/services/core/java/com/android/server/am/OomAdjuster.java
@@ -1102,10 +1102,13 @@
         // this gives us a baseline and makes sure we don't get into an
         // infinite recursion. If we're re-evaluating due to cycles, use the previously computed
         // values.
-        app.setCurRawAdj(!cycleReEval ? adj : Math.min(adj, app.getCurRawAdj()));
-        app.setCurRawProcState(!cycleReEval
-                ? procState
-                : Math.min(procState, app.getCurRawProcState()));
+        if (cycleReEval) {
+            procState = Math.min(procState, app.getCurRawProcState());
+            adj = Math.min(adj, app.getCurRawAdj());
+            schedGroup = Math.max(schedGroup, app.getCurrentSchedulingGroup());
+        }
+        app.setCurRawAdj(adj);
+        app.setCurRawProcState(procState);
 
         app.hasStartedServices = false;
         app.adjSeq = mAdjSeq;