From a5a510ab5ba19a8302d7f3ccbe482f8067ab8f0c Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Fri, 16 May 2025 11:59:46 +0800 Subject: [SP 2025-09-01] Do not allow custom animation of untrusted Toast Since target API level 30 (Android 11), regular text toast is shown by SystemUI (See#CHANGE_TEXT_TOASTS_IN_THE_SYSTEM). While legacy apps and deprecated custom view show the toast in its own processes, so force the default animation style for these usages to avoid unexpected animation duration. Such when setForceHideNonSystemOverlayWindowIfNeeded is triggered, the regular Toast displayed by SystemUI won't be affected (because SystemUI has internal permission), and the untrusted Toast can be hidden in a short time (config_longAnimTime=500ms) instead of a customized duration. Bug: 408215749 Flag: EXEMPT bugfix Test: Show a Toast with modified WindowManager.LayoutParams#windowAnimations (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:3beed7b34e54f2147aef9e9e5bbb413527b399fa) Merged-In: Ib2844dedebfa3ec9fc8333af3f66bb07cd4d3d7f Change-Id: Ib2844dedebfa3ec9fc8333af3f66bb07cd4d3d7f --- services/core/java/com/android/server/wm/DisplayPolicy.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java index dbae9c4b3a0f..2c1ba2a3540f 100644 --- a/services/core/java/com/android/server/wm/DisplayPolicy.java +++ b/services/core/java/com/android/server/wm/DisplayPolicy.java @@ -985,6 +985,10 @@ public class DisplayPolicy { AccessibilityManager.FLAG_CONTENT_TEXT); // Toasts can't be clickable attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; + // Do not allow untrusted toast to customize animation. + if (!win.mSession.mCanAddInternalSystemWindow) { + attrs.windowAnimations = R.style.Animation_Toast; + } break; case TYPE_BASE_APPLICATION: -- cgit v1.2.3-59-g8ed1b