Set oom adj for processes displaying app-overlays to PERCEPTIBLE_APP_ADJ

For processes with a window of type TYPE_APPLICATION_OVERLAY adjust their
oom importance to PERCEPTIBLE_APP_ADJ to reduce the chance of them getting
killed by the low-memory-killer since they are displaying something that
is perceptible to the user.

Also z-order TYPE_DREAM windows above alerts windows.

Bug: 33256752
Test: cts/.../run-test CtsAppTestCases android.app.cts.AlertWindowsTests
Change-Id: I4c05a9fee6fad61399bf4d10c8647467cc596ca6
diff --git a/services/core/java/com/android/server/am/ProcessRecord.java b/services/core/java/com/android/server/am/ProcessRecord.java
index 356781f..2d27204 100644
--- a/services/core/java/com/android/server/am/ProcessRecord.java
+++ b/services/core/java/com/android/server/am/ProcessRecord.java
@@ -31,14 +31,11 @@
 import android.app.ActivityManager;
 import android.app.Dialog;
 import android.app.IApplicationThread;
-import android.app.IInstrumentationWatcher;
-import android.app.IUiAutomationConnection;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.pm.ApplicationInfo;
 import android.content.res.CompatibilityInfo;
 import android.os.Binder;
-import android.os.Bundle;
 import android.os.IBinder;
 import android.os.Process;
 import android.os.RemoteException;
@@ -46,7 +43,6 @@
 import android.os.Trace;
 import android.os.UserHandle;
 import android.util.ArrayMap;
-import android.util.PrintWriterPrinter;
 import android.util.TimeUtils;
 
 import java.io.PrintWriter;
@@ -116,8 +112,18 @@
     boolean repForegroundActivities; // Last reported foreground activities.
     boolean systemNoUi;         // This is a system process, but not currently showing UI.
     boolean hasShownUi;         // Has UI been shown in this process since it was started?
-    boolean hasTopUi;           // Is this process currently showing "top-level" UI that is not an
-                                // activity?
+    boolean hasTopUi;           // Is this process currently showing a non-activity UI that the user
+                                // is interacting with? E.g. The status bar when it is expanded, but
+                                // not when it is minimized. When true the
+                                // process will be set to use the ProcessList#SCHED_GROUP_TOP_APP
+                                // scheduling group to boost performance.
+    boolean hasOverlayUi;       // Is the process currently showing a non-activity UI that
+                                // overlays on-top of activity UIs on screen. E.g. display a window
+                                // of type
+                                // android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY
+                                // When true the process will oom adj score will be set to
+                                // ProcessList#PERCEPTIBLE_APP_ADJ at minimum to reduce the chance
+                                // of the process getting killed.
     boolean pendingUiClean;     // Want to clean up resources from showing UI?
     boolean hasAboveClient;     // Bound using BIND_ABOVE_CLIENT, so want to be lower
     boolean treatLikeActivity;  // Bound using BIND_TREAT_LIKE_ACTIVITY
@@ -425,6 +431,9 @@
         if (hasTopUi) {
             pw.print(prefix); pw.print("hasTopUi="); pw.print(hasTopUi);
         }
+        if (hasOverlayUi) {
+            pw.print(prefix); pw.print("hasOverlayUi="); pw.print(hasOverlayUi);
+        }
     }
 
     ProcessRecord(BatteryStatsImpl _batteryStats, ApplicationInfo _info,