Merge "Adjust toast window parameters to support FLAG_SHOW_WHEN_LOCKED" into qt-dev
This commit is contained in:
@@ -822,6 +822,10 @@ public class DisplayPolicy {
|
|||||||
(int) attrs.hideTimeoutMilliseconds,
|
(int) attrs.hideTimeoutMilliseconds,
|
||||||
AccessibilityManager.FLAG_CONTENT_TEXT);
|
AccessibilityManager.FLAG_CONTENT_TEXT);
|
||||||
attrs.windowAnimations = com.android.internal.R.style.Animation_Toast;
|
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;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -831,6 +835,16 @@ 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 */);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preflight adding a window to the system.
|
* Preflight adding a window to the system.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -22,13 +22,17 @@ import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
|||||||
import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
|
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_DIM_BEHIND;
|
||||||
import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
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_INSET_DECOR;
|
||||||
import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
|
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_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.ROTATION_ANIMATION_SEAMLESS;
|
import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_SEAMLESS;
|
||||||
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
|
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
|
||||||
import static android.view.WindowManager.LayoutParams.TYPE_BASE_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_INPUT_METHOD;
|
||||||
|
import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
|
||||||
|
|
||||||
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
|
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
|
||||||
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
|
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
|
||||||
@@ -38,6 +42,7 @@ import static com.android.server.policy.WindowManagerPolicy.NAV_BAR_RIGHT;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
@@ -232,4 +237,40 @@ public class DisplayPolicyTests extends WindowTestsBase {
|
|||||||
displayRotation, Surface.ROTATION_0, Surface.ROTATION_90));
|
displayRotation, Surface.ROTATION_0, Surface.ROTATION_90));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShouldShowToastWhenScreenLocked() {
|
||||||
|
final DisplayPolicy policy = mDisplayContent.getDisplayPolicy();
|
||||||
|
final WindowState activity = createApplicationWindow();
|
||||||
|
final WindowState toast = createToastWindow();
|
||||||
|
|
||||||
|
synchronized (mWm.mGlobalLock) {
|
||||||
|
policy.adjustWindowParamsLw(
|
||||||
|
toast, toast.mAttrs, 0 /* callingPid */, 0 /* callingUid */);
|
||||||
|
|
||||||
|
assertTrue(policy.canToastShowWhenLocked(0 /* callingUid */));
|
||||||
|
assertNotEquals(0, toast.getAttrs().flags & FLAG_SHOW_WHEN_LOCKED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
attrs.width = MATCH_PARENT;
|
||||||
|
attrs.height = MATCH_PARENT;
|
||||||
|
attrs.flags = FLAG_SHOW_WHEN_LOCKED | FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR;
|
||||||
|
attrs.format = PixelFormat.OPAQUE;
|
||||||
|
win.mHasSurface = true;
|
||||||
|
return win;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user