• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 com.android.server.wm.utils;
18 
19 import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
20 
21 import android.app.Activity;
22 import android.app.KeyguardManager;
23 import android.os.Bundle;
24 import android.widget.FrameLayout;
25 
26 import androidx.annotation.Nullable;
27 
28 /**
29  * TestActivity that will ensure it dismisses keyguard and shows as a fullscreen activity.
30  */
31 public class TestActivity extends Activity {
32     private FrameLayout mParentLayout;
33 
34     @Override
onCreate(@ullable Bundle savedInstanceState)35     protected void onCreate(@Nullable Bundle savedInstanceState) {
36         super.onCreate(savedInstanceState);
37 
38         mParentLayout = new FrameLayout(this);
39         FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
40                 FrameLayout.LayoutParams.MATCH_PARENT,
41                 FrameLayout.LayoutParams.MATCH_PARENT);
42         setContentView(mParentLayout, layoutParams);
43 
44         final KeyguardManager keyguardManager = getInstrumentation().getContext().getSystemService(
45                 KeyguardManager.class);
46         if (keyguardManager != null && keyguardManager.isKeyguardLocked()) {
47             keyguardManager.requestDismissKeyguard(this, null);
48         }
49     }
50 
getParentLayout()51     public FrameLayout getParentLayout() {
52         return mParentLayout;
53     }
54 }
55