1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.server.wm; 18 19 import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; 20 21 import android.os.Bundle; 22 import android.view.WindowManager; 23 import android.view.WindowMetrics; 24 25 public class MetricsActivity extends WindowManagerTestBase.FocusableActivity { 26 private WindowMetrics mOnCreateMaximumMetrics; 27 private WindowMetrics mOnCreateCurrentMetrics; 28 private final WindowMetricsTestHelper.OnLayoutChangeListener mListener = 29 new WindowMetricsTestHelper.OnLayoutChangeListener(); 30 getListener()31 public WindowMetricsTestHelper.OnLayoutChangeListener getListener() { 32 return mListener; 33 } 34 getOnCreateMaximumMetrics()35 public WindowMetrics getOnCreateMaximumMetrics() { 36 return mOnCreateMaximumMetrics; 37 } 38 getOnCreateCurrentMetrics()39 public WindowMetrics getOnCreateCurrentMetrics() { 40 return mOnCreateCurrentMetrics; 41 } 42 43 @Override onCreate(Bundle savedInstanceState)44 protected void onCreate(Bundle savedInstanceState) { 45 super.onCreate(savedInstanceState); 46 mOnCreateCurrentMetrics = getWindowManager().getCurrentWindowMetrics(); 47 mOnCreateMaximumMetrics = getWindowManager().getMaximumWindowMetrics(); 48 getWindow().getDecorView().addOnLayoutChangeListener(mListener); 49 50 // Always extend the cutout areas because layout doesn't get the waterfall cutout. 51 final WindowManager.LayoutParams attrs = getWindow().getAttributes(); 52 attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; 53 getWindow().setAttributes(attrs); 54 } 55 56 @Override onDestroy()57 protected void onDestroy() { 58 super.onDestroy(); 59 getWindow().getDecorView().removeOnLayoutChangeListener(mListener); 60 } 61 } 62