Merge "Create gesture navication test on Assistant test app." into tm-qpr-dev

This commit is contained in:
Benno Lin
2022-10-09 03:54:28 +00:00
committed by Android (Google) Code Review
2 changed files with 89 additions and 8 deletions

View File

@@ -0,0 +1,80 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.server.wm.flicker.helpers
import android.app.Instrumentation
import android.content.ComponentName
import android.provider.Settings
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until
import com.android.server.wm.flicker.testapp.ActivityOptions
import org.junit.Assert.assertNotNull
class AssistantAppHelper @JvmOverloads constructor(
val instr: Instrumentation,
val component: ComponentName = ActivityOptions.ASSISTANT_SERVICE_COMPONENT_NAME,
) {
protected val uiDevice: UiDevice = UiDevice.getInstance(instr)
protected val defaultAssistant: String? = Settings.Secure.getString(
instr.targetContext.contentResolver,
Settings.Secure.ASSISTANT)
protected val defaultVoiceInteractionService: String? = Settings.Secure.getString(
instr.targetContext.contentResolver,
Settings.Secure.VOICE_INTERACTION_SERVICE)
fun setDefaultAssistant() {
Settings.Secure.putString(
instr.targetContext.contentResolver,
Settings.Secure.VOICE_INTERACTION_SERVICE,
component.flattenToString())
Settings.Secure.putString(
instr.targetContext.contentResolver,
Settings.Secure.ASSISTANT,
component.flattenToString())
}
fun resetDefaultAssistant() {
Settings.Secure.putString(
instr.targetContext.contentResolver,
Settings.Secure.VOICE_INTERACTION_SERVICE,
defaultVoiceInteractionService)
Settings.Secure.putString(
instr.targetContext.contentResolver,
Settings.Secure.ASSISTANT,
defaultAssistant)
}
/**
* Open Assistance UI.
*
* @param longpress open the UI by long pressing power button.
* Otherwise open the UI through vioceinteraction shell command directly.
*/
@JvmOverloads
fun openUI(longpress: Boolean = false) {
if (longpress) {
uiDevice.executeShellCommand("input keyevent --longpress KEYCODE_POWER")
} else {
uiDevice.executeShellCommand("cmd voiceinteraction show")
}
val ui = uiDevice.wait(
Until.findObject(By.res(ActivityOptions.FLICKER_APP_PACKAGE, "vis_frame")),
FIND_TIMEOUT)
assertNotNull("Can't find Assistant UI after long pressing power button.", ui)
}
}

View File

@@ -80,20 +80,21 @@ public class ActivityOptions {
public static final String SHOW_WHEN_LOCKED_ACTIVITY_LAUNCHER_NAME = "ShowWhenLockedApp"; public static final String SHOW_WHEN_LOCKED_ACTIVITY_LAUNCHER_NAME = "ShowWhenLockedApp";
public static final ComponentName SHOW_WHEN_LOCKED_ACTIVITY_COMPONENT_NAME = public static final ComponentName SHOW_WHEN_LOCKED_ACTIVITY_COMPONENT_NAME =
new ComponentName(FLICKER_APP_PACKAGE, new ComponentName(FLICKER_APP_PACKAGE, FLICKER_APP_PACKAGE + ".ShowWhenLockedActivity");
FLICKER_APP_PACKAGE + ".ShowWhenLockedActivity");
public static final String NOTIFICATION_ACTIVITY_LAUNCHER_NAME = "NotificationApp"; public static final String NOTIFICATION_ACTIVITY_LAUNCHER_NAME = "NotificationApp";
public static final ComponentName NOTIFICATION_ACTIVITY_COMPONENT_NAME = public static final ComponentName NOTIFICATION_ACTIVITY_COMPONENT_NAME =
new ComponentName(FLICKER_APP_PACKAGE, new ComponentName(FLICKER_APP_PACKAGE, FLICKER_APP_PACKAGE + ".NotificationActivity");
FLICKER_APP_PACKAGE + ".NotificationActivity");
public static final String MAIL_ACTIVITY_LAUNCHER_NAME = "MailActivity"; public static final String MAIL_ACTIVITY_LAUNCHER_NAME = "MailActivity";
public static final ComponentName MAIL_ACTIVITY_COMPONENT_NAME = new ComponentName( public static final ComponentName MAIL_ACTIVITY_COMPONENT_NAME =
FLICKER_APP_PACKAGE, FLICKER_APP_PACKAGE + ".MailActivity"); new ComponentName(FLICKER_APP_PACKAGE, FLICKER_APP_PACKAGE + ".MailActivity");
public static final String GAME_ACTIVITY_LAUNCHER_NAME = "GameApp"; public static final String GAME_ACTIVITY_LAUNCHER_NAME = "GameApp";
public static final ComponentName GAME_ACTIVITY_COMPONENT_NAME = public static final ComponentName GAME_ACTIVITY_COMPONENT_NAME =
new ComponentName(FLICKER_APP_PACKAGE, new ComponentName(FLICKER_APP_PACKAGE, FLICKER_APP_PACKAGE + ".GameActivity");
FLICKER_APP_PACKAGE + ".GameActivity");
public static final ComponentName ASSISTANT_SERVICE_COMPONENT_NAME =
new ComponentName(
FLICKER_APP_PACKAGE, FLICKER_APP_PACKAGE + ".AssistantInteractionService");
} }