Merge "Report bounds instead of size in WindowMetrics" into rvc-dev am: 363edf449a am: f8bb4fef74

Change-Id: I03b8e519c34c4c9318239540a20d6923672b2272
This commit is contained in:
Andrii Kulian
2020-03-27 01:15:53 +00:00
committed by Automerger Merge Worker
25 changed files with 84 additions and 94 deletions

View File

@@ -55767,8 +55767,8 @@ package android.view {
}
public final class WindowMetrics {
ctor public WindowMetrics(@NonNull android.util.Size, @NonNull android.view.WindowInsets);
method @NonNull public android.util.Size getSize();
ctor public WindowMetrics(@NonNull android.graphics.Rect, @NonNull android.view.WindowInsets);
method @NonNull public android.graphics.Rect getBounds();
method @NonNull public android.view.WindowInsets getWindowInsets();
}

View File

@@ -60,7 +60,6 @@ import android.text.method.MovementMethod;
import android.util.Log;
import android.util.PrintWriterPrinter;
import android.util.Printer;
import android.util.Size;
import android.view.Gravity;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
@@ -1480,8 +1479,8 @@ public class InputMethodService extends AbstractInputMethodService {
*/
public int getMaxWidth() {
final WindowManager windowManager = getSystemService(WindowManager.class);
final Size windowSize = windowManager.getCurrentWindowMetrics().getSize();
return windowSize.getWidth();
final Rect windowBounds = windowManager.getCurrentWindowMetrics().getBounds();
return windowBounds.width();
}
/**

View File

@@ -57,8 +57,8 @@ import java.util.List;
* <li>The application display area specifies the part of the display that may contain
* an application window, excluding the system decorations. The application display area may
* be smaller than the real display area because the system subtracts the space needed
* for decor elements such as the status bar. Use {@link WindowMetrics#getSize()} to query the
* application window size.</li>
* for decor elements such as the status bar. Use {@link WindowMetrics#getBounds()} to query the
* application window bounds.</li>
* <li>The real display area specifies the part of the display that contains content
* including the system decorations. Even so, the real display area may be smaller than the
* physical size of the display if the window manager is emulating a smaller display
@@ -673,7 +673,7 @@ public final class Display {
*
* @param outSize A {@link Point} object to receive the size information.
* @deprecated Use {@link WindowManager#getCurrentWindowMetrics()} to obtain an instance of
* {@link WindowMetrics} and use {@link WindowMetrics#getSize()} instead.
* {@link WindowMetrics} and use {@link WindowMetrics#getBounds()} instead.
*/
@Deprecated
public void getSize(Point outSize) {
@@ -689,7 +689,7 @@ public final class Display {
* Gets the size of the display as a rectangle, in pixels.
*
* @param outSize A {@link Rect} object to receive the size information.
* @deprecated Use {@link WindowMetrics#getSize()} to get the dimensions of the application
* @deprecated Use {@link WindowMetrics#getBounds()} to get the dimensions of the application
* window area.
*/
@Deprecated
@@ -755,7 +755,7 @@ public final class Display {
}
/**
* @deprecated Use {@link WindowMetrics#getSize()} instead.
* @deprecated Use {@link WindowMetrics#getBounds#width()} instead.
*/
@Deprecated
public int getWidth() {
@@ -766,7 +766,7 @@ public final class Display {
}
/**
* @deprecated Use {@link WindowMetrics#getSize()} instead.
* @deprecated Use {@link WindowMetrics#getBounds()#height()} instead.
*/
@Deprecated
public int getHeight() {
@@ -1105,7 +1105,7 @@ public final class Display {
* </p>
*
* @param outMetrics A {@link DisplayMetrics} object to receive the metrics.
* @deprecated Use {@link WindowMetrics#getSize()} to get the dimensions of the application
* @deprecated Use {@link WindowMetrics#getBounds()} to get the dimensions of the application
* window area, and {@link Configuration#densityDpi} to get the current density.
*/
@Deprecated

View File

@@ -23,11 +23,11 @@ import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Rect;
import android.os.Build;
import android.os.RemoteException;
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.util.Size;
import android.util.SparseArray;
import android.util.TypedValue;
@@ -410,8 +410,8 @@ public class ViewConfiguration {
// Size of the screen in bytes, in ARGB_8888 format
final WindowManager windowManager = context.getSystemService(WindowManager.class);
final Size maxWindowSize = windowManager.getMaximumWindowMetrics().getSize();
mMaximumDrawingCacheSize = 4 * maxWindowSize.getWidth() * maxWindowSize.getHeight();
final Rect maxWindowBounds = windowManager.getMaximumWindowMetrics().getBounds();
mMaximumDrawingCacheSize = 4 * maxWindowBounds.width() * maxWindowBounds.height();
mOverscrollDistance = (int) (sizeAndDensity * OVERSCROLL_DISTANCE + 0.5f);
mOverflingDistance = (int) (sizeAndDensity * OVERFLING_DISTANCE + 0.5f);

View File

@@ -35,7 +35,6 @@ import android.graphics.Region;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Size;
import com.android.internal.os.IResultReceiver;
@@ -220,7 +219,7 @@ public final class WindowManagerImpl implements WindowManager {
final Context context = mParentWindow != null ? mParentWindow.getContext() : mContext;
final Rect bounds = getCurrentBounds(context);
return new WindowMetrics(toSize(bounds), computeWindowInsets(bounds));
return new WindowMetrics(bounds, computeWindowInsets(bounds));
}
private static Rect getCurrentBounds(Context context) {
@@ -232,11 +231,7 @@ public final class WindowManagerImpl implements WindowManager {
@Override
public WindowMetrics getMaximumWindowMetrics() {
final Rect maxBounds = getMaximumBounds();
return new WindowMetrics(toSize(maxBounds), computeWindowInsets(maxBounds));
}
private Size toSize(Rect frame) {
return new Size(frame.width(), frame.height());
return new WindowMetrics(maxBounds, computeWindowInsets(maxBounds));
}
private Rect getMaximumBounds() {

View File

@@ -18,10 +18,10 @@ package android.view;
import android.annotation.NonNull;
import android.graphics.Point;
import android.util.Size;
import android.graphics.Rect;
/**
* Metrics about a Window, consisting of the size and {@link WindowInsets}.
* Metrics about a Window, consisting of the bounds and {@link WindowInsets}.
* <p>
* This is usually obtained from {@link WindowManager#getCurrentWindowMetrics()} and
* {@link WindowManager#getMaximumWindowMetrics()}.
@@ -31,21 +31,22 @@ import android.util.Size;
* @see WindowManager#getMaximumWindowMetrics()
*/
public final class WindowMetrics {
private final @NonNull Size mSize;
private final @NonNull Rect mBounds;
private final @NonNull WindowInsets mWindowInsets;
public WindowMetrics(@NonNull Size size, @NonNull WindowInsets windowInsets) {
mSize = size;
public WindowMetrics(@NonNull Rect bounds, @NonNull WindowInsets windowInsets) {
mBounds = bounds;
mWindowInsets = windowInsets;
}
/**
* Returns the size of the window.
* Returns the bounds of the area associated with this window or visual context.
* <p>
* <b>Note that this reports a different size than {@link Display#getSize(Point)}.</b>
* This method reports the window size including all system bars area, while
* {@link Display#getSize(Point)} reports the area excluding navigation bars and display cutout
* areas. The value reported by {@link Display#getSize(Point)} can be obtained by using:
* <b>Note that the size of the reported bounds can have different size than
* {@link Display#getSize(Point)}.</b> This method reports the window size including all system
* bar areas, while {@link Display#getSize(Point)} reports the area excluding navigation bars
* and display cutout areas. The value reported by {@link Display#getSize(Point)} can be
* obtained by using:
* <pre class="prettyprint">
* final WindowMetrics metrics = windowManager.getCurrentMetrics();
* // Gets all excluding insets
@@ -66,16 +67,16 @@ public final class WindowMetrics {
* </pre>
* </p>
*
* @return window size in pixel.
* @return window bounds in pixels.
*/
public @NonNull Size getSize() {
return mSize;
public @NonNull Rect getBounds() {
return mBounds;
}
/**
* Returns the {@link WindowInsets} of the window.
* Returns the {@link WindowInsets} of the area associated with this window or visual context.
*
* @return the {@link WindowInsets} of the window.
* @return the {@link WindowInsets} of the visual area.
*/
public @NonNull WindowInsets getWindowInsets() {
return mWindowInsets;

View File

@@ -25,7 +25,6 @@ import android.os.IBinder;
import android.os.RemoteException;
import android.transition.Transition;
import android.util.Log;
import android.util.Size;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewTreeObserver;
@@ -129,10 +128,10 @@ public class AutofillPopupWindow extends PopupWindow {
// Gravity.BOTTOM because PopupWindow base class does not expose computeGravity().
final WindowManager windowManager = anchor.getContext()
.getSystemService(WindowManager.class);
final Size windowSize = windowManager.getCurrentWindowMetrics().getSize();
width = windowSize.getWidth();
final Rect windowBounds = windowManager.getCurrentWindowMetrics().getBounds();
width = windowBounds.width();
if (height != LayoutParams.MATCH_PARENT) {
offsetY = windowSize.getHeight() - height;
offsetY = windowBounds.height() - height;
}
actualAnchor = anchor;
} else if (virtualBounds != null) {

View File

@@ -22,14 +22,10 @@ import android.annotation.Nullable;
import android.annotation.StyleRes;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.graphics.Point;
import android.graphics.Rect;
import android.util.Size;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.view.WindowMetrics;
import android.widget.PopupWindow.OnDismissListener;
import com.android.internal.view.menu.MenuPresenter.Callback;
@@ -227,9 +223,9 @@ public class MenuPopupHelper implements MenuHelper {
@NonNull
private MenuPopup createPopup() {
final WindowManager windowManager = mContext.getSystemService(WindowManager.class);
final Size maxWindowSize = windowManager.getMaximumWindowMetrics().getSize();
final Rect maxWindowBounds = windowManager.getMaximumWindowMetrics().getBounds();
final int smallestWidth = Math.min(maxWindowSize.getWidth(), maxWindowSize.getHeight());
final int smallestWidth = Math.min(maxWindowBounds.width(), maxWindowBounds.height());
final int minSmallestWidthCascading = mContext.getResources().getDimensionPixelSize(
com.android.internal.R.dimen.cascading_menus_min_smallest_width);
final boolean enableCascadingSubmenus = smallestWidth >= minSmallestWidthCascading;

View File

@@ -25,13 +25,13 @@ import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Rect;
import android.hardware.display.DisplayManager;
import android.os.Handler;
import android.os.IBinder;
import android.os.Process;
import android.os.RemoteException;
import android.util.Log;
import android.util.Size;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
@@ -119,15 +119,15 @@ public class TestService extends Service {
@Override
public void showApplicationOverlay() throws RemoteException {
final WindowManager wm = mOverlayContext.getSystemService(WindowManager.class);
final Size size = wm.getCurrentWindowMetrics().getSize();
final Rect bounds = wm.getCurrentWindowMetrics().getBounds();
final WindowManager.LayoutParams wmlp = new WindowManager.LayoutParams(
TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
wmlp.width = size.getWidth() / 2;
wmlp.height = size.getHeight() / 2;
wmlp.width = bounds.width() / 2;
wmlp.height = bounds.height() / 2;
wmlp.gravity = Gravity.CENTER | Gravity.LEFT;
wmlp.setTitle(TAG);

View File

@@ -233,7 +233,7 @@ public abstract class GridScenario extends Activity {
// turn off title bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
mScreenHeight = getWindowManager().getCurrentWindowMetrics().getSize().getHeight();
mScreenHeight = getWindowManager().getCurrentWindowMetrics().getBounds().height();
final Params params = new Params();
init(params);

View File

@@ -306,7 +306,7 @@ public abstract class ListScenario extends Activity {
requestWindowFeature(Window.FEATURE_NO_TITLE);
mScreenHeight = getWindowManager().getCurrentWindowMetrics().getSize().getHeight();
mScreenHeight = getWindowManager().getCurrentWindowMetrics().getBounds().height();
final Params params = createParams();
init(params);

View File

@@ -239,7 +239,7 @@ public abstract class ScrollViewScenario extends Activity {
// for test stability, turn off title bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
int screenHeight = getWindowManager().getCurrentWindowMetrics().getSize().getHeight()
int screenHeight = getWindowManager().getCurrentWindowMetrics().getBounds().height()
- 25;
mLinearLayout = new LinearLayout(this);
mLinearLayout.setOrientation(LinearLayout.VERTICAL);

View File

@@ -17,8 +17,8 @@
package android.view;
import android.app.Activity;
import android.graphics.Rect;
import android.os.Bundle;
import android.util.Size;
import android.widget.LinearLayout;
import android.widget.ScrollView;
@@ -39,9 +39,9 @@ public class BigCache extends Activity {
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
final int cacheSize = ViewConfiguration.getMaximumDrawingCacheSize();
final Size windowSize = getWindowManager().getCurrentWindowMetrics().getSize();
final int screenWidth = windowSize.getWidth();
final int screenHeight = windowSize.getHeight();
final Rect windowBounds = getWindowManager().getCurrentWindowMetrics().getBounds();
final int screenWidth = windowBounds.width();
final int screenHeight = windowBounds.height();
final View tiny = new View(this);
tiny.setId(R.id.a);

View File

@@ -22,7 +22,7 @@ import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import android.util.Size;
import android.graphics.Rect;
import android.widget.TextView;
import androidx.test.filters.LargeTest;
@@ -55,9 +55,9 @@ public class ScaleGestureDetectorTest {
// Specify start and end coordinates with respect to the window size.
final WindowManager wm = mScaleGestureActivity.getSystemService(WindowManager.class);
final Size windowSize = wm.getCurrentWindowMetrics().getSize();
final int windowWidth = windowSize.getWidth();
final int windowHeight = windowSize.getHeight();
final Rect windowBounds = wm.getCurrentWindowMetrics().getBounds();
final int windowWidth = windowBounds.width();
final int windowHeight = windowBounds.height();
// Obtain coordinates to perform pinch and zoom from the center, to 75% of the display.
final int centerX = windowWidth / 2;

View File

@@ -22,10 +22,10 @@ import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
import static org.junit.Assert.assertTrue;
import android.content.Context;
import android.graphics.Rect;
import android.hardware.display.DisplayManager;
import android.os.Handler;
import android.platform.test.annotations.Presubmit;
import android.util.Size;
import androidx.test.filters.FlakyTest;
import androidx.test.filters.SmallTest;
@@ -87,10 +87,12 @@ public class WindowMetricsTest {
private static void verifyMetricsSanity(WindowMetrics currentMetrics,
WindowMetrics maxMetrics) {
Size currentSize = currentMetrics.getSize();
Size maxSize = maxMetrics.getSize();
Rect currentBounds = currentMetrics.getBounds();
Rect maxBounds = maxMetrics.getBounds();
assertTrue(maxSize.getWidth() >= currentSize.getWidth());
assertTrue(maxSize.getHeight() >= currentSize.getHeight());
assertTrue(maxBounds.width() >= currentBounds.width());
assertTrue(maxBounds.height() >= currentBounds.height());
assertTrue(maxBounds.left >= 0);
assertTrue(maxBounds.top >= 0);
}
}

View File

@@ -16,9 +16,9 @@
package android.view.menu;
import android.graphics.Rect;
import android.test.ActivityInstrumentationTestCase;
import android.util.PollingCheck;
import android.util.Size;
import android.view.View;
import android.view.WindowManager;
import android.widget.espresso.ContextMenuUtils;
@@ -81,8 +81,8 @@ public class ContextMenuTest extends ActivityInstrumentationTestCase<ContextMenu
*/
private int getMinScreenDimension() {
final WindowManager windowManager = getActivity().getSystemService(WindowManager.class);
final Size maxWindowSize = windowManager.getMaximumWindowMetrics().getSize();
return Math.min(maxWindowSize.getWidth(), maxWindowSize.getHeight());
final Rect maxWindowBounds = windowManager.getMaximumWindowMetrics().getBounds();
return Math.min(maxWindowBounds.width(), maxWindowBounds.height());
}
/**

View File

@@ -111,7 +111,7 @@ public class ListOfInternalSelectionViews extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
mScreenHeight = getWindowManager().getCurrentWindowMetrics().getSize().getHeight();
mScreenHeight = getWindowManager().getCurrentWindowMetrics().getBounds().height();
Bundle extras = getIntent().getExtras();
if (extras != null) {

View File

@@ -106,8 +106,8 @@ public class GridTouchVerticalSpacingStackFromBottomTest extends ActivityInstrum
int firstTop = firstChild.getTop();
int windowHeight = mActivity.getWindowManager().getCurrentWindowMetrics().getSize()
.getHeight();
int windowHeight = mActivity.getWindowManager().getCurrentWindowMetrics().getBounds()
.height();
int distance = TouchUtils.dragViewBy(this, firstChild,
Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, (int) (windowHeight * 0.75f));

View File

@@ -66,7 +66,7 @@ public class AdjacentListsWithAdjacentISVsInside extends Activity {
super.onCreate(savedInstanceState);
final int desiredHeight =
(int) (0.8 * getWindowManager().getCurrentWindowMetrics().getSize().getHeight());
(int) (0.8 * getWindowManager().getCurrentWindowMetrics().getBounds().height());
mLeftListView = new ListView(this);
mLeftListView.setAdapter(new AdjacentISVAdapter(desiredHeight));

View File

@@ -2210,14 +2210,14 @@ public class CameraTestUtils extends Assert {
}
public static Size getPreviewSizeBound(WindowManager windowManager, Size bound) {
Size windowSize = windowManager.getCurrentWindowMetrics().getSize();
Rect windowBounds = windowManager.getCurrentWindowMetrics().getBounds();
int width = windowSize.getWidth();
int height = windowSize.getHeight();
int width = windowBounds.width();
int height = windowBounds.height();
if (height > width) {
height = width;
width = windowSize.getHeight();
width = windowBounds.height();
}
if (bound.getWidth() <= width &&

View File

@@ -28,11 +28,11 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.graphics.Rect;
import android.hardware.display.DisplayManager;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.util.Size;
import android.util.Slog;
import android.view.Display;
import android.view.ViewGroup;
@@ -134,8 +134,8 @@ public class FakeApp extends Application {
}
lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
Size maxWindowSize = wm.getMaximumWindowMetrics().getSize();
int maxSize = Math.max(maxWindowSize.getWidth(), maxWindowSize.getHeight());
Rect maxWindowBounds = wm.getMaximumWindowMetrics().getBounds();
int maxSize = Math.max(maxWindowBounds.width(), maxWindowBounds.height());
maxSize *= 2;
lp.x = maxSize;
lp.y = maxSize;

View File

@@ -19,22 +19,22 @@ package com.android.fakeoemfeatures;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
import java.util.ArrayList;
import java.util.Random;
import android.app.Dialog;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.hardware.display.DisplayManager;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.util.Size;
import android.view.Display;
import android.view.ViewGroup;
import android.view.WindowManager;
import java.util.ArrayList;
import java.util.Random;
public class FakeBackgroundService extends Service {
final ArrayList<int[]> mAllocs = new ArrayList<int[]>();
@@ -99,8 +99,8 @@ public class FakeBackgroundService extends Service {
// Create an instance of WindowManager that is adjusted to the area of the display dedicated
// for windows with type TYPE_APPLICATION_OVERLAY.
final WindowManager wm = windowContext.getSystemService(WindowManager.class);
Size maxWindowSize = wm.getMaximumWindowMetrics().getSize();
int maxSize = Math.max(maxWindowSize.getWidth(), maxWindowSize.getHeight());
Rect maxWindowBounds = wm.getMaximumWindowMetrics().getBounds();
int maxSize = Math.max(maxWindowBounds.width(), maxWindowBounds.height());
maxSize *= 2;
lp.x = maxSize;
lp.y = maxSize;

View File

@@ -37,7 +37,6 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.util.Size;
import android.view.Display;
import android.view.View;
import android.widget.Toast;
@@ -358,8 +357,8 @@ public class WallpaperCropActivity extends Activity {
// Get the crop
boolean ltr = mCropView.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR;
Size windowSize = getWindowManager().getCurrentWindowMetrics().getSize();
boolean isPortrait = windowSize.getWidth() < windowSize.getHeight();
Rect windowBounds = getWindowManager().getCurrentWindowMetrics().getBounds();
boolean isPortrait = windowBounds.width() < windowBounds.height();
Point defaultWallpaperSize = getDefaultWallpaperSize(getResources(),
getDisplay());

View File

@@ -223,7 +223,7 @@ public class TouchUtils {
public static void dragViewToBottom(InstrumentationTestCase test, Activity activity, View v,
int stepCount) {
int screenHeight =
activity.getWindowManager().getCurrentWindowMetrics().getSize().getHeight();
activity.getWindowManager().getCurrentWindowMetrics().getBounds().height();
int[] xy = new int[2];
v.getLocationOnScreen(xy);

View File

@@ -27,7 +27,6 @@ import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.os.RemoteException;
import android.util.Size;
import android.view.Gravity;
import android.view.IWindowManager;
import android.view.MotionEvent;
@@ -90,8 +89,8 @@ public class MirrorSurfaceActivity extends Activity implements View.OnClickListe
.getSystemService(WindowManager.class);
mIWm = WindowManagerGlobal.getWindowManagerService();
Size windowSize = mWm.getCurrentWindowMetrics().getSize();
mWindowBounds.set(0, 0, windowSize.getWidth(), windowSize.getHeight());
Rect windowBounds = mWm.getCurrentWindowMetrics().getBounds();
mWindowBounds.set(0, 0, windowBounds.width(), windowBounds.height());
mScaleText = findViewById(R.id.scale);
mDisplayFrameText = findViewById(R.id.displayFrame);