Clean up the behavior to support toast shown on Lockscreen.
I7092f2d, Support to show toast over lockscreen for Pixel dialer with carrier requirement. Text toasts will be rendered by SystemUI instead of in-app to prevent abuse and snackbars are preferred for brief messages while the app is in the foreground. Pixel Dialer also confirms they don’t need the behavior from R. Clean up the code which is useless. Bug: 163441727 Test: atest DisplayPolicyTests Change-Id: Ia6cd9c0ec2ca39825d6d3e74f7852a3ce6b305c4
This commit is contained in:
@@ -913,10 +913,6 @@ public class DisplayPolicy {
|
||||
(int) attrs.hideTimeoutMilliseconds,
|
||||
AccessibilityManager.FLAG_CONTENT_TEXT);
|
||||
attrs.windowAnimations = com.android.internal.R.style.Animation_Toast;
|
||||
// Toast can show with below conditions when the screen is locked.
|
||||
if (canToastShowWhenLocked(callingPid)) {
|
||||
attrs.flags |= WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
|
||||
}
|
||||
// Toasts can't be clickable
|
||||
attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
|
||||
break;
|
||||
@@ -946,16 +942,6 @@ public class DisplayPolicy {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if the calling activity initiate toast and is visible with
|
||||
* {@link WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} flag.
|
||||
*/
|
||||
boolean canToastShowWhenLocked(int callingPid) {
|
||||
return mDisplayContent.forAllWindows(w -> {
|
||||
return callingPid == w.mSession.mPid && w.isVisible() && w.canShowWhenLocked();
|
||||
}, true /* traverseTopToBottom */);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a window can be added to the system.
|
||||
*
|
||||
|
||||
@@ -27,11 +27,9 @@ import static android.view.WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_TOUCH;
|
||||
import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
|
||||
import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
|
||||
import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
||||
import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
|
||||
import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR;
|
||||
import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
|
||||
import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
||||
import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
|
||||
import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
|
||||
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DRAW_BAR_BACKGROUNDS;
|
||||
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION;
|
||||
@@ -39,7 +37,6 @@ import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
|
||||
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
|
||||
import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
|
||||
import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
|
||||
import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
|
||||
|
||||
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
|
||||
import static com.android.server.policy.WindowManagerPolicy.NAV_BAR_BOTTOM;
|
||||
@@ -47,7 +44,6 @@ import static com.android.server.policy.WindowManagerPolicy.NAV_BAR_RIGHT;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -235,18 +231,6 @@ public class DisplayPolicyTests extends WindowTestsBase {
|
||||
assertEquals(mAppWindow, policy.getTopFullscreenOpaqueWindow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldShowToastWhenScreenLocked() {
|
||||
final DisplayPolicy policy = mDisplayContent.getDisplayPolicy();
|
||||
final WindowState activity = createApplicationWindow();
|
||||
final WindowState toast = createToastWindow();
|
||||
|
||||
policy.adjustWindowParamsLw(toast, toast.mAttrs, 0 /* callingPid */, 0 /* callingUid */);
|
||||
|
||||
assertTrue(policy.canToastShowWhenLocked(0 /* callingUid */));
|
||||
assertNotEquals(0, toast.getAttrs().flags & FLAG_SHOW_WHEN_LOCKED);
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void testMainAppWindowDisallowFitSystemWindowTypes() {
|
||||
final DisplayPolicy policy = mDisplayContent.getDisplayPolicy();
|
||||
@@ -257,16 +241,6 @@ public class DisplayPolicyTests extends WindowTestsBase {
|
||||
0 /* callingUid */);
|
||||
}
|
||||
|
||||
private WindowState createToastWindow() {
|
||||
final WindowState win = createWindow(null, TYPE_TOAST, "Toast");
|
||||
final WindowManager.LayoutParams attrs = win.mAttrs;
|
||||
attrs.width = WRAP_CONTENT;
|
||||
attrs.height = WRAP_CONTENT;
|
||||
attrs.flags = FLAG_KEEP_SCREEN_ON | FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCHABLE;
|
||||
attrs.format = PixelFormat.TRANSLUCENT;
|
||||
return win;
|
||||
}
|
||||
|
||||
private WindowState createApplicationWindow() {
|
||||
final WindowState win = createWindow(null, TYPE_APPLICATION, "Application");
|
||||
final WindowManager.LayoutParams attrs = win.mAttrs;
|
||||
|
||||
Reference in New Issue
Block a user