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.view.surfacecontrol.cts;
18 
19 import static android.view.WindowInsets.Type.displayCutout;
20 import static android.view.WindowInsets.Type.systemBars;
21 import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
22 
23 import android.app.Activity;
24 import android.graphics.Color;
25 import android.os.Bundle;
26 import android.view.WindowInsetsController;
27 import android.view.WindowManager;
28 import android.widget.FrameLayout;
29 
30 import androidx.annotation.Nullable;
31 
32 public class TestActivity extends Activity {
33     private static final int sTypeMask = systemBars() | displayCutout();
34     private FrameLayout mParentLayout;
35 
36     @Override
onCreate(@ullable Bundle savedInstanceState)37     protected void onCreate(@Nullable Bundle savedInstanceState) {
38         super.onCreate(savedInstanceState);
39 
40         mParentLayout = new FrameLayout(this);
41         mParentLayout.setBackgroundColor(Color.YELLOW);
42         FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
43                 FrameLayout.LayoutParams.MATCH_PARENT,
44                 FrameLayout.LayoutParams.MATCH_PARENT);
45         setContentView(mParentLayout, layoutParams);
46 
47         WindowInsetsController windowInsetsController = getWindow().getInsetsController();
48         windowInsetsController.hide(sTypeMask);
49         WindowManager.LayoutParams params = getWindow().getAttributes();
50         params.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
51         params.flags |= WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
52         getWindow().setAttributes(params);
53         getWindow().setDecorFitsSystemWindows(false);
54     }
55 
getParentLayout()56     public FrameLayout getParentLayout() {
57         return mParentLayout;
58     }
59 }
60