Display on-going notification for apps using alert windows.

Allows the user to associate alert windows with specific apps
and revoke the permission if they want.

Test: manual
Bug: 33256752
Change-Id: Ie28325b6bb799b3df253770ebe655f97ebbadd90
diff --git a/services/core/java/com/android/server/wm/Session.java b/services/core/java/com/android/server/wm/Session.java
index e6fd0ab..5355f31 100644
--- a/services/core/java/com/android/server/wm/Session.java
+++ b/services/core/java/com/android/server/wm/Session.java
@@ -80,8 +80,10 @@
     // Set of visible alert window surfaces connected to this session.
     private final Set<WindowSurfaceController> mAlertWindowSurfaces = new HashSet<>();
     final boolean mCanAddInternalSystemWindow;
+    private AlertWindowNotification mAlertWindowNotification;
     private boolean mClientDead = false;
     private float mLastReportedAnimatorScale;
+    private String mPackageName;
 
     public Session(WindowManagerService service, IWindowSessionCallback callback,
             IInputMethodClient client, IInputContext inputContext) {
@@ -555,7 +557,8 @@
         }
     }
 
-    void windowAddedLocked() {
+    void windowAddedLocked(String packageName) {
+        mPackageName = packageName;
         if (mSurfaceSession == null) {
             if (WindowManagerService.localLOGV) Slog.v(
                 TAG_WM, "First window added to " + this + ", creating SurfaceSession");
@@ -595,7 +598,12 @@
             }
 
             if (changed) {
-                // TODO: Update notification.
+                if (mAlertWindowSurfaces.isEmpty()) {
+                    cancelAlertWindowNotification();
+                } else if (mAlertWindowNotification == null){
+                    mAlertWindowNotification = new AlertWindowNotification(
+                            mService, mPackageName, mUid);
+                }
             }
         }
 
@@ -636,14 +644,24 @@
                     + " in session " + this + ": " + e.toString());
         }
         mSurfaceSession = null;
+        mAlertWindowSurfaces.clear();
+        mAppOverlaySurfaces.clear();
         setHasOverlayUi(false);
-        // TODO: Update notification
+        cancelAlertWindowNotification();
     }
 
     private void setHasOverlayUi(boolean hasOverlayUi) {
         mService.mH.obtainMessage(H.SET_HAS_OVERLAY_UI, mPid, hasOverlayUi ? 1 : 0).sendToTarget();
     }
 
+    private void cancelAlertWindowNotification() {
+        if (mAlertWindowNotification == null) {
+            return;
+        }
+        mAlertWindowNotification.cancel();
+        mAlertWindowNotification = null;
+    }
+
     void dump(PrintWriter pw, String prefix) {
         pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
                 pw.print(" mAppOverlaySurfaces="); pw.print(mAppOverlaySurfaces);