Introducing activityType window configuration.

Used to represent the current activity type of the window
configuration which can be undefined, standard, home, recents, or
assistant. This information if currently represented in a few ways in
the window heirarchy e.g. with stack id or with fields in tasks and
activities. This change allows us to represent the idea in a more
structure way without overloading concepts like stack ids.

Test: bit FrameworksServicesTests:com.android.server.wm.ConfigurationContainerTests
Test: bit FrameworksServicesTests:com.android.server.wm.WindowConfigurationTests
Test: go/wm-smoke
Change-Id: I7d7283c72e806972eeb3a8dab448f195dd6cd811
diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java
index 4433b84..c481efc 100644
--- a/services/core/java/com/android/server/am/ActivityRecord.java
+++ b/services/core/java/com/android/server/am/ActivityRecord.java
@@ -33,6 +33,12 @@
 import static android.app.ActivityOptions.ANIM_THUMBNAIL_SCALE_UP;
 import static android.app.AppOpsManager.MODE_ALLOWED;
 import static android.app.AppOpsManager.OP_PICTURE_IN_PICTURE;
+import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT;
+import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
+import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;
+import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
+import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
+import static android.app.WindowConfiguration.activityTypeToString;
 import static android.content.Intent.ACTION_MAIN;
 import static android.content.Intent.CATEGORY_HOME;
 import static android.content.Intent.CATEGORY_LAUNCHER;
@@ -226,12 +232,6 @@
     private final boolean componentSpecified;  // did caller specify an explicit component?
     final boolean rootVoiceInteraction;  // was this the root activity of a voice interaction?
 
-    static final int APPLICATION_ACTIVITY_TYPE = 0;
-    static final int HOME_ACTIVITY_TYPE = 1;
-    static final int RECENTS_ACTIVITY_TYPE = 2;
-    static final int ASSISTANT_ACTIVITY_TYPE = 3;
-    int mActivityType;
-
     private CharSequence nonLocalizedLabel;  // the label information from the package mgr.
     private int labelRes;           // the label information from the package mgr.
     private int icon;               // resource identifier of activity's icon.
@@ -388,7 +388,8 @@
         }
         pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded);
                 pw.print(" componentSpecified="); pw.print(componentSpecified);
-                pw.print(" mActivityType="); pw.println(mActivityType);
+                pw.print(" mActivityType="); pw.println(
+                        activityTypeToString(getActivityType()));
         if (rootVoiceInteraction) {
             pw.print(prefix); pw.print("rootVoiceInteraction="); pw.println(rootVoiceInteraction);
         }
@@ -495,7 +496,7 @@
         pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
                 pw.print(" forceNewConfig="); pw.println(forceNewConfig);
         pw.print(prefix); pw.print("mActivityType=");
-                pw.println(activityTypeToString(mActivityType));
+                pw.println(activityTypeToString(getActivityType()));
         if (requestedVrComponent != null) {
             pw.print(prefix);
             pw.print("requestedVrComponent=");
@@ -938,7 +939,7 @@
                 task.voiceSession != null, mLaunchTaskBehind, isAlwaysFocusable(),
                 appInfo.targetSdkVersion, mRotationAnimationHint,
                 ActivityManagerService.getInputDispatchingTimeoutLocked(this) * 1000000L,
-                getOverrideConfiguration(), mBounds);
+                new Configuration(getOverrideConfiguration()), mBounds);
 
         task.addActivityToTop(this);
 
@@ -1028,10 +1029,11 @@
 
     private void setActivityType(boolean componentSpecified, int launchedFromUid, Intent intent,
             ActivityOptions options, ActivityRecord sourceRecord) {
+        int activityType = ACTIVITY_TYPE_UNDEFINED;
         if ((!componentSpecified || canLaunchHomeActivity(launchedFromUid, sourceRecord))
                 && isHomeIntent(intent) && !isResolverActivity()) {
             // This sure looks like a home activity!
-            mActivityType = HOME_ACTIVITY_TYPE;
+            activityType = ACTIVITY_TYPE_HOME;
 
             if (info.resizeMode == RESIZE_MODE_FORCE_RESIZEABLE
                     || info.resizeMode == RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) {
@@ -1039,13 +1041,12 @@
                 info.resizeMode = RESIZE_MODE_UNRESIZEABLE;
             }
         } else if (realActivity.getClassName().contains(RECENTS_PACKAGE_NAME)) {
-            mActivityType = RECENTS_ACTIVITY_TYPE;
+            activityType = ACTIVITY_TYPE_RECENTS;
         } else if (options != null && options.getLaunchStackId() == ASSISTANT_STACK_ID
                 && canLaunchAssistActivity(launchedFromPackage)) {
-            mActivityType = ASSISTANT_ACTIVITY_TYPE;
-        } else {
-            mActivityType = APPLICATION_ACTIVITY_TYPE;
+            activityType = ACTIVITY_TYPE_ASSISTANT;
         }
+        setActivityType(activityType);
     }
 
     void setTaskToAffiliateWith(TaskRecord taskToAffiliateWith) {
@@ -1096,18 +1097,6 @@
         return stack != null && stack.isInStackLocked(this) != null;
     }
 
-    boolean isHomeActivity() {
-        return mActivityType == HOME_ACTIVITY_TYPE;
-    }
-
-    boolean isRecentsActivity() {
-        return mActivityType == RECENTS_ACTIVITY_TYPE;
-    }
-
-    boolean isAssistantActivity() {
-        return mActivityType == ASSISTANT_ACTIVITY_TYPE;
-    }
-
     boolean isPersistable() {
         return (info.persistableMode == PERSIST_ROOT_ONLY ||
                 info.persistableMode == PERSIST_ACROSS_REBOOTS) &&
@@ -1134,7 +1123,7 @@
      * @return whether this activity supports PiP multi-window and can be put in the pinned stack.
      */
     boolean supportsPictureInPicture() {
-        return service.mSupportsPictureInPicture && !isHomeActivity()
+        return service.mSupportsPictureInPicture && isActivityTypeStandard()
                 && info.supportsPictureInPicture();
     }
 
@@ -1160,7 +1149,7 @@
      * @return whether this activity supports non-PiP multi-window.
      */
     private boolean supportsResizeableMultiWindow() {
-        return service.mSupportsMultiWindow && !isHomeActivity()
+        return service.mSupportsMultiWindow && !isActivityTypeHome()
                 && (ActivityInfo.isResizeableMode(info.resizeMode)
                         || service.mForceResizableActivities);
     }
@@ -1537,7 +1526,7 @@
 
         boolean isVisible = !behindFullscreenActivity || mLaunchTaskBehind;
 
-        if (service.mSupportsLeanbackOnly && isVisible && isRecentsActivity()) {
+        if (service.mSupportsLeanbackOnly && isVisible && isActivityTypeRecents()) {
             // On devices that support leanback only (Android TV), Recents activity can only be
             // visible if the home stack is the focused stack or we are in split-screen mode.
             isVisible = mStackSupervisor.getStack(DOCKED_STACK_ID) != null
@@ -1615,7 +1604,7 @@
         newIntents = null;
         stopped = false;
 
-        if (isHomeActivity()) {
+        if (isActivityTypeHome()) {
             ProcessRecord app = task.mActivities.get(0).app;
             if (app != null && app != service.mHomeProcess) {
                 service.mHomeProcess = app;
@@ -2145,7 +2134,7 @@
             config.getOverrideConfiguration());
     }
 
-    void setLastReportedConfiguration(Configuration global, Configuration override) {
+    private void setLastReportedConfiguration(Configuration global, Configuration override) {
         mLastReportedConfiguration.setConfiguration(global, override);
     }
 
@@ -2718,16 +2707,6 @@
         return r;
     }
 
-    private static String activityTypeToString(int type) {
-        switch (type) {
-            case APPLICATION_ACTIVITY_TYPE: return "APPLICATION_ACTIVITY_TYPE";
-            case HOME_ACTIVITY_TYPE: return "HOME_ACTIVITY_TYPE";
-            case RECENTS_ACTIVITY_TYPE: return "RECENTS_ACTIVITY_TYPE";
-            case ASSISTANT_ACTIVITY_TYPE: return "ASSISTANT_ACTIVITY_TYPE";
-            default: return Integer.toString(type);
-        }
-    }
-
     private static boolean isInVrUiMode(Configuration config) {
         return (config.uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_VR_HEADSET;
     }