• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.server.wm.flicker.rules
18 
19 import android.app.Instrumentation
20 import android.util.Log
21 import androidx.test.platform.app.InstrumentationRegistry
22 import com.android.server.wm.flicker.FLICKER_TAG
23 import com.android.server.wm.flicker.helpers.StandardAppHelper
24 import com.android.server.wm.traces.common.FlickerComponentName
25 import com.android.server.wm.traces.parser.windowmanager.WindowManagerStateHelper
26 import org.junit.rules.TestWatcher
27 import org.junit.runner.Description
28 
29 /**
30  * Launched an app before the test
31  *
32  * @param instrumentation Instrumentation mechanism to use
33  * @param wmHelper WM/SF synchronization helper
34  * @param appHelper App to launch
35  */
36 class LaunchAppRule @JvmOverloads constructor(
37     private val appHelper: StandardAppHelper,
38     private val instrumentation: Instrumentation = appHelper.mInstrumentation,
39     private val wmHelper: WindowManagerStateHelper = WindowManagerStateHelper()
40 ) : TestWatcher() {
41     @JvmOverloads
42     constructor(
43         component: FlickerComponentName,
44         appName: String = "",
45         instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation(),
46         wmHelper: WindowManagerStateHelper = WindowManagerStateHelper()
47     ): this(StandardAppHelper(instrumentation, appName, component), instrumentation, wmHelper)
48 
startingnull49     override fun starting(description: Description?) {
50         Log.v(FLICKER_TAG, "Launching app $appHelper")
51         appHelper.launchViaIntent()
52         appHelper.exit(wmHelper)
53     }
54 }