Fix issue with translucent animations

If a translucent has overridden their activityOpenEnter/exit
animation in the resources, they won't be used anymore because the
system always forces the translucent animations, which is a bug.

Instead, we only use the translucent animation in case the app has
not overridden their animations manually.

Test: Open WhatsApp profile picture.
Test: go/wm-smoke
Change-Id: I7e81815e78453392773ac2ac96c47540e6146381
Fixes: 78270476
diff --git a/services/core/java/com/android/server/wm/AppTransition.java b/services/core/java/com/android/server/wm/AppTransition.java
index a24ac21..0dc06b2 100644
--- a/services/core/java/com/android/server/wm/AppTransition.java
+++ b/services/core/java/com/android/server/wm/AppTransition.java
@@ -554,7 +554,7 @@
         return null;
     }
 
-    Animation loadAnimationAttr(LayoutParams lp, int animAttr) {
+    Animation loadAnimationAttr(LayoutParams lp, int animAttr, int transit) {
         int anim = 0;
         Context context = mContext;
         if (animAttr >= 0) {
@@ -564,6 +564,7 @@
                 anim = ent.array.getResourceId(animAttr, 0);
             }
         }
+        anim = updateToTranslucentAnimIfNeeded(anim, transit);
         if (anim != 0) {
             return AnimationUtils.loadAnimation(context, anim);
         }
@@ -598,6 +599,16 @@
         return null;
     }
 
+    private int updateToTranslucentAnimIfNeeded(int anim, int transit) {
+        if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_OPEN && anim == R.anim.activity_open_enter) {
+            return R.anim.activity_translucent_open_enter;
+        }
+        if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE && anim == R.anim.activity_close_exit) {
+            return R.anim.activity_translucent_close_exit;
+        }
+        return anim;
+    }
+
     /**
      * Compute the pivot point for an animation that is scaling from a small
      * rect on screen to a larger rect.  The pivot point varies depending on
@@ -1664,29 +1675,17 @@
                     "applyAnimation NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:"
                             + " anim=" + a + " transit=" + appTransitionToString(transit)
                             + " isEntrance=true" + " Callers=" + Debug.getCallers(3));
-        } else if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_OPEN && enter) {
-            a = loadAnimationRes("android",
-                    com.android.internal.R.anim.activity_translucent_open_enter);
-            Slog.v(TAG,
-                    "applyAnimation TRANSIT_TRANSLUCENT_ACTIVITY_OPEN:"
-                            + " anim=" + a + " transit=" + appTransitionToString(transit)
-                            + " isEntrance=true" + " Callers=" + Debug.getCallers(3));
-        } else if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE && !enter) {
-            a = loadAnimationRes("android",
-                    com.android.internal.R.anim.activity_translucent_close_exit);
-            Slog.v(TAG,
-                    "applyAnimation TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE:"
-                            + " anim=" + a + " transit=" + appTransitionToString(transit)
-                            + " isEntrance=false" + " Callers=" + Debug.getCallers(3));
         } else {
             int animAttr = 0;
             switch (transit) {
                 case TRANSIT_ACTIVITY_OPEN:
+                case TRANSIT_TRANSLUCENT_ACTIVITY_OPEN:
                     animAttr = enter
                             ? WindowAnimation_activityOpenEnterAnimation
                             : WindowAnimation_activityOpenExitAnimation;
                     break;
                 case TRANSIT_ACTIVITY_CLOSE:
+                case TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE:
                     animAttr = enter
                             ? WindowAnimation_activityCloseEnterAnimation
                             : WindowAnimation_activityCloseExitAnimation;
@@ -1737,7 +1736,7 @@
                             ? WindowAnimation_launchTaskBehindSourceAnimation
                             : WindowAnimation_launchTaskBehindTargetAnimation;
             }
-            a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
+            a = animAttr != 0 ? loadAnimationAttr(lp, animAttr, transit) : null;
             if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
                     "applyAnimation:"
                     + " anim=" + a