Merge "PhoneWindow: Fix potential memory leak" into rvc-dev am: ee540c3245
Change-Id: I52718dc154a699eca84d841d8a49fd6d3e1d3707
This commit is contained in:
@@ -11468,7 +11468,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
|||||||
outLocalInsets.setEmpty();
|
outLocalInsets.setEmpty();
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
Pair<Insets, WindowInsets> result = listener.onContentApplyWindowInsets(in);
|
Pair<Insets, WindowInsets> result = listener.onContentApplyWindowInsets(this, in);
|
||||||
outLocalInsets.set(result.first.toRect());
|
outLocalInsets.set(result.first.toRect());
|
||||||
return result.second;
|
return result.second;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -712,13 +712,14 @@ public abstract class Window {
|
|||||||
* {@link View#setOnApplyWindowInsetsListener(OnApplyWindowInsetsListener)} through the view
|
* {@link View#setOnApplyWindowInsetsListener(OnApplyWindowInsetsListener)} through the view
|
||||||
* hierarchy.
|
* hierarchy.
|
||||||
*
|
*
|
||||||
|
* @param view The view for which to apply insets. Must not be directly modified.
|
||||||
* @param insets The root level insets that are about to be dispatched
|
* @param insets The root level insets that are about to be dispatched
|
||||||
* @return A pair, with the first element containing the insets to apply as margin to the
|
* @return A pair, with the first element containing the insets to apply as margin to the
|
||||||
* root-level content views, and the second element determining what should be
|
* root-level content views, and the second element determining what should be
|
||||||
* dispatched to the content view.
|
* dispatched to the content view.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
Pair<Insets, WindowInsets> onContentApplyWindowInsets(
|
Pair<Insets, WindowInsets> onContentApplyWindowInsets(@NonNull View view,
|
||||||
@NonNull WindowInsets insets);
|
@NonNull WindowInsets insets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -135,6 +135,29 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
|
|||||||
|
|
||||||
private final static String TAG = "PhoneWindow";
|
private final static String TAG = "PhoneWindow";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Window#setDecorFitsSystemWindows
|
||||||
|
*/
|
||||||
|
private static final OnContentApplyWindowInsetsListener sDefaultContentInsetsApplier =
|
||||||
|
(view, insets) -> {
|
||||||
|
if ((view.getWindowSystemUiVisibility() & SYSTEM_UI_LAYOUT_FLAGS) != 0) {
|
||||||
|
return new Pair<>(Insets.NONE, insets);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean includeIme = (view.getViewRootImpl().mWindowAttributes.softInputMode
|
||||||
|
& SOFT_INPUT_MASK_ADJUST)
|
||||||
|
== SOFT_INPUT_ADJUST_RESIZE;
|
||||||
|
Insets insetsToApply;
|
||||||
|
if (ViewRootImpl.sNewInsetsMode == 0) {
|
||||||
|
insetsToApply = insets.getSystemWindowInsets();
|
||||||
|
} else {
|
||||||
|
insetsToApply = insets.getInsets(systemBars() | (includeIme ? ime() : 0));
|
||||||
|
}
|
||||||
|
insets = insets.inset(insetsToApply);
|
||||||
|
return new Pair<>(insetsToApply,
|
||||||
|
insets.inset(insetsToApply).consumeSystemWindowInsets());
|
||||||
|
};
|
||||||
|
|
||||||
/* If true, shadows drawn around the window will be rendered by the system compositor. If
|
/* If true, shadows drawn around the window will be rendered by the system compositor. If
|
||||||
* false, shadows will be drawn by the client by setting an elevation on the root view and
|
* false, shadows will be drawn by the client by setting an elevation on the root view and
|
||||||
* the contents will be inset by the shadow radius. */
|
* the contents will be inset by the shadow radius. */
|
||||||
@@ -320,8 +343,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
|
|||||||
/** @see ViewRootImpl#mActivityConfigCallback */
|
/** @see ViewRootImpl#mActivityConfigCallback */
|
||||||
private ActivityConfigCallback mActivityConfigCallback;
|
private ActivityConfigCallback mActivityConfigCallback;
|
||||||
|
|
||||||
private OnContentApplyWindowInsetsListener mPendingOnContentApplyWindowInsetsListener
|
private OnContentApplyWindowInsetsListener mPendingOnContentApplyWindowInsetsListener =
|
||||||
= createDefaultContentWindowInsetsListener();
|
sDefaultContentInsetsApplier;
|
||||||
|
|
||||||
static class WindowManagerHolder {
|
static class WindowManagerHolder {
|
||||||
static final IWindowManager sWindowManager = IWindowManager.Stub.asInterface(
|
static final IWindowManager sWindowManager = IWindowManager.Stub.asInterface(
|
||||||
@@ -2120,27 +2143,6 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
|
|||||||
mPendingOnContentApplyWindowInsetsListener = null;
|
mPendingOnContentApplyWindowInsetsListener = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private OnContentApplyWindowInsetsListener createDefaultContentWindowInsetsListener() {
|
|
||||||
return insets -> {
|
|
||||||
if ((getDecorView().getWindowSystemUiVisibility() & SYSTEM_UI_LAYOUT_FLAGS) != 0) {
|
|
||||||
return new Pair<>(Insets.NONE, insets);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean includeIme =
|
|
||||||
(getViewRootImpl().mWindowAttributes.softInputMode & SOFT_INPUT_MASK_ADJUST)
|
|
||||||
== SOFT_INPUT_ADJUST_RESIZE;
|
|
||||||
Insets insetsToApply;
|
|
||||||
if (ViewRootImpl.sNewInsetsMode == 0) {
|
|
||||||
insetsToApply = insets.getSystemWindowInsets();
|
|
||||||
} else {
|
|
||||||
insetsToApply = insets.getInsets(systemBars() | (includeIme ? ime() : 0));
|
|
||||||
}
|
|
||||||
insets = insets.inset(insetsToApply);
|
|
||||||
return new Pair<>(insetsToApply,
|
|
||||||
insets.inset(insetsToApply).consumeSystemWindowInsets());
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
static private final String FOCUSED_ID_TAG = "android:focusedViewId";
|
static private final String FOCUSED_ID_TAG = "android:focusedViewId";
|
||||||
static private final String VIEWS_TAG = "android:views";
|
static private final String VIEWS_TAG = "android:views";
|
||||||
static private final String PANELS_TAG = "android:Panels";
|
static private final String PANELS_TAG = "android:Panels";
|
||||||
@@ -3907,7 +3909,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
|
|||||||
public void setDecorFitsSystemWindows(boolean decorFitsSystemWindows) {
|
public void setDecorFitsSystemWindows(boolean decorFitsSystemWindows) {
|
||||||
ViewRootImpl impl = getViewRootImplOrNull();
|
ViewRootImpl impl = getViewRootImplOrNull();
|
||||||
OnContentApplyWindowInsetsListener listener = decorFitsSystemWindows
|
OnContentApplyWindowInsetsListener listener = decorFitsSystemWindows
|
||||||
? createDefaultContentWindowInsetsListener()
|
? sDefaultContentInsetsApplier
|
||||||
: null;
|
: null;
|
||||||
if (impl != null) {
|
if (impl != null) {
|
||||||
impl.setOnContentApplyWindowInsetsListener(listener);
|
impl.setOnContentApplyWindowInsetsListener(listener);
|
||||||
|
|||||||
Reference in New Issue
Block a user