Prevent activity config override for system processes.

To improve app compatibility in multi-display and multi-window
environments WM overrides the process config with the config of the
most recently launched activity. However, doing so has caused issues with
system applications (notably System UI) who currently rely on this config.

This change ensures that system processes and system ui do not receive
this compatibility override and revert back to the old functionality. In
the future this will be replaced with dedicated channels to report
display configurations.

Test: WindowProcessControllerTests
Test: ActivityRecordTests

Bug: 148675523
Fixes: 148675523

Change-Id: I811d4f60c1e79b5526a5f9e9973b8d6355ee8c15
diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
index 21d300a..7bacc42 100644
--- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
+++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
@@ -356,6 +356,8 @@
     ActivityManagerInternal mAmInternal;
     UriGrantsManagerInternal mUgmInternal;
     private PackageManagerInternal mPmInternal;
+    /** The cached sys ui service component name from package manager. */
+    private ComponentName mSysUiServiceComponent;
     private PermissionPolicyInternal mPermissionPolicyInternal;
     @VisibleForTesting
     final ActivityTaskManagerInternal mInternal;
@@ -5869,6 +5871,14 @@
         return mPmInternal;
     }
 
+    ComponentName getSysUiServiceComponentLocked() {
+        if (mSysUiServiceComponent == null) {
+            final PackageManagerInternal pm = getPackageManagerInternalLocked();
+            mSysUiServiceComponent = pm.getSystemUiServiceComponent();
+        }
+        return mSysUiServiceComponent;
+    }
+
     PermissionPolicyInternal getPermissionPolicyInternal() {
         if (mPermissionPolicyInternal == null) {
             mPermissionPolicyInternal = LocalServices.getService(PermissionPolicyInternal.class);
diff --git a/services/core/java/com/android/server/wm/WindowProcessController.java b/services/core/java/com/android/server/wm/WindowProcessController.java
index 833bb83..32eb932 100644
--- a/services/core/java/com/android/server/wm/WindowProcessController.java
+++ b/services/core/java/com/android/server/wm/WindowProcessController.java
@@ -53,6 +53,7 @@
 import android.content.res.Configuration;
 import android.os.Build;
 import android.os.Message;
+import android.os.Process;
 import android.os.RemoteException;
 import android.os.SystemClock;
 import android.util.ArraySet;
@@ -200,6 +201,9 @@
     /** Whether our process is currently running a {@link IRemoteAnimationRunner} */
     private boolean mRunningRemoteAnimation;
 
+    /** Whether this process is owned by the System UI package. */
+    final boolean mIsSysUiPackage;
+
     public WindowProcessController(@NonNull ActivityTaskManagerService atm, ApplicationInfo info,
             String name, int uid, int userId, Object owner, WindowProcessListener listener) {
         mInfo = info;
@@ -210,6 +214,10 @@
         mListener = listener;
         mAtm = atm;
         mDisplayId = INVALID_DISPLAY;
+
+        mIsSysUiPackage = info.packageName.equals(
+                mAtm.getSysUiServiceComponentLocked().getPackageName());
+
         onConfigurationChanged(atm.getGlobalConfiguration());
     }
 
@@ -1077,6 +1085,12 @@
      * always track the configuration of the non-finishing activity last added to the process.
      */
     private void updateActivityConfigurationListener() {
+        if (mIsSysUiPackage || mUid == Process.SYSTEM_UID) {
+            // This is a system owned process and should not use an activity config.
+            // TODO(b/151161907): Remove after support for display-independent (raw) SysUi configs.
+            return;
+        }
+
         for (int i = mActivities.size() - 1; i >= 0; i--) {
             final ActivityRecord activityRecord = mActivities.get(i);
             if (!activityRecord.finishing && !activityRecord.containsListener(this)) {