Merge "Generate WindowInsets with new insets API" into rvc-dev am: 2a77f43bee am: c20552508d
Change-Id: Ia428c42924c6c813032150f2f36c4fe0de32e483
This commit is contained in:
@@ -60,7 +60,6 @@ public class WindowContext extends ContextWrapper {
|
|||||||
mWms = WindowManagerGlobal.getWindowManagerService();
|
mWms = WindowManagerGlobal.getWindowManagerService();
|
||||||
mToken = new WindowTokenClient();
|
mToken = new WindowTokenClient();
|
||||||
|
|
||||||
|
|
||||||
final ContextImpl contextImpl = createBaseWindowContext(base, mToken);
|
final ContextImpl contextImpl = createBaseWindowContext(base, mToken);
|
||||||
attachBaseContext(contextImpl);
|
attachBaseContext(contextImpl);
|
||||||
contextImpl.setOuterContext(this);
|
contextImpl.setOuterContext(this);
|
||||||
|
|||||||
@@ -724,11 +724,12 @@ interface IWindowManager
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called to get the expected window insets.
|
* Called to get the expected window insets.
|
||||||
* TODO(window-context): Remove when new insets flag is available.
|
*
|
||||||
|
* @return {@code true} if system bars are always comsumed.
|
||||||
*/
|
*/
|
||||||
void getWindowInsets(in WindowManager.LayoutParams attrs, int displayId,
|
boolean getWindowInsets(in WindowManager.LayoutParams attrs, int displayId,
|
||||||
out Rect outContentInsets, out Rect outStableInsets,
|
out Rect outContentInsets, out Rect outStableInsets,
|
||||||
out DisplayCutout.ParcelableWrapper displayCutout);
|
out DisplayCutout.ParcelableWrapper outDisplayCutout, out InsetsState outInsetsState);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called to show global actions.
|
* Called to show global actions.
|
||||||
|
|||||||
@@ -80,6 +80,12 @@ public class InsetsState implements Parcelable {
|
|||||||
})
|
})
|
||||||
public @interface InternalInsetsType {}
|
public @interface InternalInsetsType {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Special value to be used to by methods returning an {@link InternalInsetsType} to indicate
|
||||||
|
* that the objects/parameters aren't associated with an {@link InternalInsetsType}
|
||||||
|
*/
|
||||||
|
public static final int ITYPE_INVALID = -1;
|
||||||
|
|
||||||
static final int FIRST_TYPE = 0;
|
static final int FIRST_TYPE = 0;
|
||||||
|
|
||||||
public static final int ITYPE_STATUS_BAR = FIRST_TYPE;
|
public static final int ITYPE_STATUS_BAR = FIRST_TYPE;
|
||||||
|
|||||||
@@ -18,8 +18,11 @@ package android.view;
|
|||||||
|
|
||||||
import static android.view.View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
|
import static android.view.View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
|
||||||
import static android.view.View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
|
import static android.view.View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
|
||||||
|
import static android.view.View.SYSTEM_UI_FLAG_VISIBLE;
|
||||||
|
import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL;
|
||||||
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.SOFT_INPUT_ADJUST_NOTHING;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.app.ResourcesManager;
|
import android.app.ResourcesManager;
|
||||||
@@ -215,9 +218,9 @@ public final class WindowManagerImpl implements WindowManager {
|
|||||||
@Override
|
@Override
|
||||||
public WindowMetrics getCurrentWindowMetrics() {
|
public WindowMetrics getCurrentWindowMetrics() {
|
||||||
final Context context = mParentWindow != null ? mParentWindow.getContext() : mContext;
|
final Context context = mParentWindow != null ? mParentWindow.getContext() : mContext;
|
||||||
final Rect bound = getCurrentBounds(context);
|
final Rect bounds = getCurrentBounds(context);
|
||||||
|
|
||||||
return new WindowMetrics(toSize(bound), computeWindowInsets());
|
return new WindowMetrics(toSize(bounds), computeWindowInsets(bounds));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Rect getCurrentBounds(Context context) {
|
private static Rect getCurrentBounds(Context context) {
|
||||||
@@ -228,7 +231,8 @@ public final class WindowManagerImpl implements WindowManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WindowMetrics getMaximumWindowMetrics() {
|
public WindowMetrics getMaximumWindowMetrics() {
|
||||||
return new WindowMetrics(toSize(getMaximumBounds()), computeWindowInsets());
|
final Rect maxBounds = getMaximumBounds();
|
||||||
|
return new WindowMetrics(toSize(maxBounds), computeWindowInsets(maxBounds));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Size toSize(Rect frame) {
|
private Size toSize(Rect frame) {
|
||||||
@@ -244,9 +248,8 @@ public final class WindowManagerImpl implements WindowManager {
|
|||||||
return new Rect(0, 0, displaySize.x, displaySize.y);
|
return new Rect(0, 0, displaySize.x, displaySize.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
private WindowInsets computeWindowInsets() {
|
// TODO(b/150095967): Set window type to LayoutParams
|
||||||
// TODO(b/118118435): This can only be properly implemented
|
private WindowInsets computeWindowInsets(Rect bounds) {
|
||||||
// once we flip the new insets mode flag.
|
|
||||||
// Initialize params which used for obtaining all system insets.
|
// Initialize params which used for obtaining all system insets.
|
||||||
final WindowManager.LayoutParams params = new WindowManager.LayoutParams();
|
final WindowManager.LayoutParams params = new WindowManager.LayoutParams();
|
||||||
params.flags = FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR;
|
params.flags = FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR;
|
||||||
@@ -257,21 +260,34 @@ public final class WindowManagerImpl implements WindowManager {
|
|||||||
params.setFitInsetsTypes(0);
|
params.setFitInsetsTypes(0);
|
||||||
params.setFitInsetsSides(0);
|
params.setFitInsetsSides(0);
|
||||||
|
|
||||||
return getWindowInsetsFromServer(params);
|
return getWindowInsetsFromServer(params, bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
private WindowInsets getWindowInsetsFromServer(WindowManager.LayoutParams attrs) {
|
private WindowInsets getWindowInsetsFromServer(WindowManager.LayoutParams attrs, Rect bounds) {
|
||||||
try {
|
try {
|
||||||
final Rect systemWindowInsets = new Rect();
|
final Rect systemWindowInsets = new Rect();
|
||||||
final Rect stableInsets = new Rect();
|
final Rect stableInsets = new Rect();
|
||||||
final DisplayCutout.ParcelableWrapper displayCutout =
|
final DisplayCutout.ParcelableWrapper displayCutout =
|
||||||
new DisplayCutout.ParcelableWrapper();
|
new DisplayCutout.ParcelableWrapper();
|
||||||
WindowManagerGlobal.getWindowManagerService().getWindowInsets(attrs,
|
final InsetsState insetsState = new InsetsState();
|
||||||
mContext.getDisplayId(), systemWindowInsets, stableInsets, displayCutout);
|
final boolean alwaysConsumeSystemBars = WindowManagerGlobal.getWindowManagerService()
|
||||||
return new WindowInsets.Builder()
|
.getWindowInsets(attrs, mContext.getDisplayId(), systemWindowInsets,
|
||||||
.setSystemWindowInsets(Insets.of(systemWindowInsets))
|
stableInsets, displayCutout, insetsState);
|
||||||
.setStableInsets(Insets.of(stableInsets))
|
final boolean isScreenRound =
|
||||||
.setDisplayCutout(displayCutout.get()).build();
|
mContext.getResources().getConfiguration().isScreenRound();
|
||||||
|
if (ViewRootImpl.sNewInsetsMode == NEW_INSETS_MODE_FULL) {
|
||||||
|
return insetsState.calculateInsets(bounds, null /* ignoringVisibilityState*/,
|
||||||
|
isScreenRound, alwaysConsumeSystemBars, displayCutout.get(),
|
||||||
|
systemWindowInsets, stableInsets, SOFT_INPUT_ADJUST_NOTHING,
|
||||||
|
SYSTEM_UI_FLAG_VISIBLE, null /* typeSideMap */);
|
||||||
|
} else {
|
||||||
|
return new WindowInsets.Builder()
|
||||||
|
.setAlwaysConsumeSystemBars(alwaysConsumeSystemBars)
|
||||||
|
.setRound(isScreenRound)
|
||||||
|
.setSystemWindowInsets(Insets.of(systemWindowInsets))
|
||||||
|
.setStableInsets(Insets.of(stableInsets))
|
||||||
|
.setDisplayCutout(displayCutout.get()).build();
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,14 @@ package com.android.server.wm;
|
|||||||
|
|
||||||
import static android.view.InsetsState.ITYPE_CAPTION_BAR;
|
import static android.view.InsetsState.ITYPE_CAPTION_BAR;
|
||||||
import static android.view.InsetsState.ITYPE_IME;
|
import static android.view.InsetsState.ITYPE_IME;
|
||||||
|
import static android.view.InsetsState.ITYPE_INVALID;
|
||||||
import static android.view.InsetsState.ITYPE_NAVIGATION_BAR;
|
import static android.view.InsetsState.ITYPE_NAVIGATION_BAR;
|
||||||
import static android.view.InsetsState.ITYPE_STATUS_BAR;
|
import static android.view.InsetsState.ITYPE_STATUS_BAR;
|
||||||
import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL;
|
import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL;
|
||||||
import static android.view.ViewRootImpl.sNewInsetsMode;
|
import static android.view.ViewRootImpl.sNewInsetsMode;
|
||||||
|
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_STATUS_BAR;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
@@ -32,6 +36,7 @@ import android.view.InsetsSource;
|
|||||||
import android.view.InsetsSourceControl;
|
import android.view.InsetsSourceControl;
|
||||||
import android.view.InsetsState;
|
import android.view.InsetsState;
|
||||||
import android.view.InsetsState.InternalInsetsType;
|
import android.view.InsetsState.InternalInsetsType;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -74,15 +79,40 @@ class InsetsStateController {
|
|||||||
* @param target The client we dispatch the state to.
|
* @param target The client we dispatch the state to.
|
||||||
* @return The state stripped of the necessary information.
|
* @return The state stripped of the necessary information.
|
||||||
*/
|
*/
|
||||||
InsetsState getInsetsForDispatch(WindowState target) {
|
InsetsState getInsetsForDispatch(@NonNull WindowState target) {
|
||||||
final InsetsSourceProvider provider = target.getControllableInsetProvider();
|
final InsetsSourceProvider provider = target.getControllableInsetProvider();
|
||||||
if (provider == null) {
|
if (provider == null) {
|
||||||
return mState;
|
return mState;
|
||||||
}
|
}
|
||||||
|
final @InternalInsetsType int type = provider.getSource().getType();
|
||||||
|
return getInsetsForType(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
InsetsState getInsetsForWindowMetrics(@NonNull WindowManager.LayoutParams attrs) {
|
||||||
|
final @InternalInsetsType int type = getInsetsTypeForWindowType(attrs.type);
|
||||||
|
if (type == ITYPE_INVALID) {
|
||||||
|
return mState;
|
||||||
|
}
|
||||||
|
return getInsetsForType(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@InternalInsetsType
|
||||||
|
private static int getInsetsTypeForWindowType(int type) {
|
||||||
|
switch(type) {
|
||||||
|
case TYPE_STATUS_BAR:
|
||||||
|
return ITYPE_STATUS_BAR;
|
||||||
|
case TYPE_NAVIGATION_BAR:
|
||||||
|
return ITYPE_NAVIGATION_BAR;
|
||||||
|
case TYPE_INPUT_METHOD:
|
||||||
|
return ITYPE_IME;
|
||||||
|
default:
|
||||||
|
return ITYPE_INVALID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private InsetsState getInsetsForType(@InternalInsetsType int type) {
|
||||||
final InsetsState state = new InsetsState();
|
final InsetsState state = new InsetsState();
|
||||||
state.set(mState);
|
state.set(mState);
|
||||||
final int type = provider.getSource().getType();
|
|
||||||
state.removeSource(type);
|
state.removeSource(type);
|
||||||
|
|
||||||
// Navigation bar doesn't get influenced by anything else
|
// Navigation bar doesn't get influenced by anything else
|
||||||
|
|||||||
@@ -8018,9 +8018,9 @@ public class WindowManagerService extends IWindowManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getWindowInsets(WindowManager.LayoutParams attrs,
|
public boolean getWindowInsets(WindowManager.LayoutParams attrs,
|
||||||
int displayId, Rect outContentInsets, Rect outStableInsets,
|
int displayId, Rect outContentInsets, Rect outStableInsets,
|
||||||
DisplayCutout.ParcelableWrapper displayCutout) {
|
DisplayCutout.ParcelableWrapper outDisplayCutout, InsetsState outInsetsState) {
|
||||||
final long origId = Binder.clearCallingIdentity();
|
final long origId = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
synchronized (mGlobalLock) {
|
synchronized (mGlobalLock) {
|
||||||
@@ -8030,8 +8030,13 @@ public class WindowManagerService extends IWindowManager.Stub
|
|||||||
+ "could not be found!");
|
+ "could not be found!");
|
||||||
}
|
}
|
||||||
final WindowToken windowToken = dc.getWindowToken(attrs.token);
|
final WindowToken windowToken = dc.getWindowToken(attrs.token);
|
||||||
dc.getDisplayPolicy().getLayoutHint(attrs, windowToken, mTmpRect /* outFrame */,
|
final InsetsStateController insetsStateController =
|
||||||
outContentInsets, outStableInsets, displayCutout);
|
dc.getInsetsStateController();
|
||||||
|
outInsetsState.set(insetsStateController.getInsetsForWindowMetrics(attrs));
|
||||||
|
|
||||||
|
return dc.getDisplayPolicy().getLayoutHint(attrs, windowToken,
|
||||||
|
mTmpRect /* outFrame */, outContentInsets, outStableInsets,
|
||||||
|
outDisplayCutout);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(origId);
|
Binder.restoreCallingIdentity(origId);
|
||||||
|
|||||||
Reference in New Issue
Block a user