| 1 |
/* |
| 2 |
* Copyright (C) 2020 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.helpers |
| 18 |
|
| 19 |
import android.view.WindowInsets.Type.ime |
| 20 |
import android.view.WindowInsets.Type.navigationBars |
| 21 |
import android.view.WindowInsets.Type.statusBars |
| 22 |
|
| 23 |
import android.app.Instrumentation |
| 24 |
import androidx.test.uiautomator.By |
| 25 |
import androidx.test.uiautomator.UiDevice |
| 26 |
import androidx.test.uiautomator.Until |
| 27 |
import com.android.server.wm.flicker.testapp.ActivityOptions |
| 28 |
import com.android.server.wm.traces.common.FlickerComponentName |
| 29 |
import com.android.server.wm.traces.parser.toFlickerComponent |
| 30 |
import com.android.server.wm.traces.parser.windowmanager.WindowManagerStateHelper |
| 31 |
|
| 32 |
import java.util.regex.Pattern |
| 33 |
|
| 34 |
class ImeAppAutoFocusHelper @JvmOverloads constructor( |
| 35 |
instr: Instrumentation, |
| 36 |
private val rotation: Int, |
| 37 |
private val imePackageName: String = IME_PACKAGE, |
| 38 |
launcherName: String = ActivityOptions.IME_ACTIVITY_AUTO_FOCUS_LAUNCHER_NAME, |
| 39 |
component: FlickerComponentName = |
| 40 |
ActivityOptions.IME_ACTIVITY_AUTO_FOCUS_COMPONENT_NAME.toFlickerComponent() |
| 41 |
) : ImeAppHelper(instr, launcherName, component) { |
| 42 |
override fun openIME( |
| 43 |
device: UiDevice, |
| 44 |
wmHelper: WindowManagerStateHelper? |
| 45 |
) { |
| 46 |
// do nothing (the app is focused automatically) |
| 47 |
waitIMEShown(device, wmHelper) |
| 48 |
} |
| 49 |
|
| 50 |
override fun launchViaIntent( |
| 51 |
wmHelper: WindowManagerStateHelper, |
| 52 |
expectedWindowName: String, |
| 53 |
action: String?, |
| 54 |
stringExtras: Map<String, String> |
| 55 |
) { |
| 56 |
super.launchViaIntent(wmHelper, expectedWindowName, action, stringExtras) |
| 57 |
waitIMEShown(uiDevice, wmHelper) |
| 58 |
} |
| 59 |
|
| 60 |
override fun open() { |
| 61 |
val expectedPackage = if (rotation.isRotated()) { |
| 62 |
imePackageName |
| 63 |
} else { |
| 64 |
getPackage() |
| 65 |
} |
| 66 |
launcherStrategy.launch(appName, expectedPackage) |
| 67 |
} |
| 68 |
|
| 69 |
fun startDialogThemedActivity(wmHelper: WindowManagerStateHelper) { |
| 70 |
val button = uiDevice.wait(Until.findObject(By.res(getPackage(), |
| 71 |
"start_dialog_themed_activity_btn")), FIND_TIMEOUT) |
| 72 |
|
| 73 |
require(button != null) { |
| 74 |
"Button not found, this usually happens when the device " + |
| 75 |
"was left in an unknown state (e.g. Screen turned off)" |
| 76 |
} |
| 77 |
button.click() |
| 78 |
wmHelper.waitForAppTransitionIdle() |
| 79 |
wmHelper.waitForFullScreenApp( |
| 80 |
ActivityOptions.DIALOG_THEMED_ACTIVITY_COMPONENT_NAME.toFlickerComponent()) |
| 81 |
mInstrumentation.waitForIdleSync() |
| 82 |
} |
| 83 |
fun dismissDialog(wmHelper: WindowManagerStateHelper) { |
| 84 |
val dialog = uiDevice.wait( |
| 85 |
Until.findObject(By.text("Dialog for test")), FIND_TIMEOUT) |
| 86 |
|
| 87 |
// Pressing back key to dismiss the dialog |
| 88 |
if (dialog != null) { |
| 89 |
uiDevice.pressBack() |
| 90 |
wmHelper.waitForAppTransitionIdle() |
| 91 |
} |
| 92 |
} |
| 93 |
fun getInsetsVisibleFromDialog(type: Int): Boolean { |
| 94 |
var insetsVisibilityTextView = uiDevice.wait( |
| 95 |
Until.findObject(By.res("android:id/text1")), FIND_TIMEOUT) |
| 96 |
if (insetsVisibilityTextView != null) { |
| 97 |
var visibility = insetsVisibilityTextView.text.toString() |
| 98 |
val matcher = when (type) { |
| 99 |
ime() -> { |
| 100 |
Pattern.compile("IME\\: (VISIBLE|INVISIBLE)").matcher(visibility) |
| 101 |
} |
| 102 |
statusBars() -> { |
| 103 |
Pattern.compile("StatusBar\\: (VISIBLE|INVISIBLE)").matcher(visibility) |
| 104 |
} |
| 105 |
navigationBars() -> { |
| 106 |
Pattern.compile("NavBar\\: (VISIBLE|INVISIBLE)").matcher(visibility) |
| 107 |
} |
| 108 |
else -> null |
| 109 |
} |
| 110 |
if (matcher != null && matcher.find()) { |
| 111 |
return matcher.group(1).equals("VISIBLE") |
| 112 |
} |
| 113 |
} |
| 114 |
return false |
| 115 |
} |
| 116 |
} |