1 /**
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy
6  * 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, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations
14  * under the License.
15  */
16 package android.app.usage.cts;
17 
18 import android.annotation.Nullable;
19 import android.app.Activity;
20 import android.content.Intent;
21 import android.os.Bundle;
22 import android.support.test.uiautomator.By;
23 import android.support.test.uiautomator.UiDevice;
24 import android.support.test.uiautomator.Until;
25 import android.view.WindowManager;
26 
27 import androidx.test.InstrumentationRegistry;
28 
29 public class TaskRootActivity extends Activity  {
30     public static final String TEST_APP_PKG = "android.app.usage.cts.test1";
31     public static final String TEST_APP_CLASS = "android.app.usage.cts.test1.SomeActivity";
32     private static final long TIMEOUT = 5000;
33     private UiDevice mUiDevice;
34 
35     @Override
onCreate(@ullable Bundle savedInstanceState)36     protected void onCreate(@Nullable Bundle savedInstanceState) {
37         super.onCreate(savedInstanceState);
38         mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
39         getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
40     }
41 
42     @Override
onResume()43     protected void onResume() {
44         super.onResume();
45         Intent intent = new Intent();
46         intent.setClassName(TEST_APP_PKG, TEST_APP_CLASS);
47         startActivity(intent);
48         mUiDevice.wait(Until.hasObject(By.clazz(TEST_APP_PKG, TEST_APP_CLASS)), TIMEOUT);
49     }
50 }
51