1 /* 2 * Copyright (C) 2021 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.mediaroutertest; 18 19 import android.app.Activity; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.os.Bundle; 23 import android.view.WindowManager; 24 25 import androidx.test.core.app.ActivityScenario; 26 27 public class MediaRouter2ManagerTestActivity extends Activity { 28 29 private static ActivityScenario<MediaRouter2ManagerTestActivity> sActivityScenario; 30 startActivity(Context context)31 public static ActivityScenario<MediaRouter2ManagerTestActivity> startActivity(Context context) { 32 Intent intent = new Intent(Intent.ACTION_MAIN); 33 intent.setClass(context, MediaRouter2ManagerTestActivity.class); 34 sActivityScenario = ActivityScenario.launch(intent); 35 return sActivityScenario; 36 } 37 finishActivity()38 public static void finishActivity() { 39 if (sActivityScenario != null) { 40 // TODO: Sometimes calling this takes about 5 seconds. Need to figure out why. 41 sActivityScenario.close(); 42 sActivityScenario = null; 43 } 44 } 45 46 @Override onCreate(Bundle savedInstanceState)47 public void onCreate(Bundle savedInstanceState) { 48 super.onCreate(savedInstanceState); 49 setTurnScreenOn(true); 50 setShowWhenLocked(true); 51 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 52 } 53 } 54