summaryrefslogtreecommitdiff
path: root/libs/WindowManager
diff options
context:
space:
mode:
authorChris Li <lihongyu@google.com>2020-05-04 17:24:14 -0700
committerChris Li <lihongyu@google.com>2020-05-08 18:00:31 -0700
commit50df43e3543c33e0411b50046b881c73a7122f88 (patch)
tree1ec9aeb43eaded8372e15a4d2a30466ac3c8b2f9 /libs/WindowManager
parent0a64cfbb3c83e15c4a7ee5aeb1852d61d97c5dae (diff)
Update WM Jetpack impl to use WindowMetrics
Before, SettingsExtensionImpl#getWindowLayoutInfo returned empty window info when Activity was not attached. Now, it returns the correct info after Activity create. Test: atest CtsWindowManagerJetpackTestCases:ExtensionTest Fixes: 152534741 Fixes: 155121604 Fixes: 155692339 Change-Id: Ieded3b70ff14aba03581bf7501cc5e923b5eed33
Diffstat (limited to 'libs/WindowManager')
-rw-r--r--libs/WindowManager/Jetpack/src/androidx/window/extensions/ExtensionHelper.java15
1 files changed, 8 insertions, 7 deletions
diff --git a/libs/WindowManager/Jetpack/src/androidx/window/extensions/ExtensionHelper.java b/libs/WindowManager/Jetpack/src/androidx/window/extensions/ExtensionHelper.java
index c4f11a0a370c..c61f1ed2d179 100644
--- a/libs/WindowManager/Jetpack/src/androidx/window/extensions/ExtensionHelper.java
+++ b/libs/WindowManager/Jetpack/src/androidx/window/extensions/ExtensionHelper.java
@@ -30,6 +30,8 @@ import android.os.IBinder;
import android.view.DisplayInfo;
import android.view.Surface;
+import androidx.annotation.Nullable;
+
/**
* Toolkit class for calculation of the display feature bounds within the window.
* NOTE: This sample implementation only works for Activity windows, because there is no public APIs
@@ -84,7 +86,7 @@ class ExtensionHelper {
/** Transform rectangle from absolute coordinate space to the window coordinate space. */
static void transformToWindowSpaceRect(Rect inOutRect, IBinder windowToken) {
- Rect windowRect = getWindowRect(windowToken);
+ Rect windowRect = getWindowBounds(windowToken);
if (windowRect == null) {
inOutRect.setEmpty();
return;
@@ -101,13 +103,12 @@ class ExtensionHelper {
* Get the current window bounds in absolute coordinates.
* NOTE: Only works with Activity windows.
*/
- private static Rect getWindowRect(IBinder windowToken) {
+ @Nullable
+ private static Rect getWindowBounds(IBinder windowToken) {
Activity activity = ActivityThread.currentActivityThread().getActivity(windowToken);
- final Rect windowRect = new Rect();
- if (activity != null) {
- activity.getWindow().getDecorView().getWindowDisplayFrame(windowRect);
- }
- return windowRect;
+ return activity != null
+ ? activity.getWindowManager().getCurrentWindowMetrics().getBounds()
+ : null;
}
/**