Add AppOpenByDefaultPreference for Spa
The "Open by Default" in App Info page. Bug: 236346018 Test: Manual with App Info page Test: Settings Unit tests Change-Id: I20f827241ff46bca28440b56fd32a0712ee439f9
This commit is contained in:
@@ -35,9 +35,12 @@ android_test {
|
||||
"androidx.compose.ui_ui-test-manifest",
|
||||
"androidx.test.ext.junit",
|
||||
"androidx.test.runner",
|
||||
"mockito-target-minus-junit4",
|
||||
"mockito-target-inline-minus-junit4",
|
||||
"truth-prebuilt",
|
||||
],
|
||||
jni_libs: [
|
||||
"libdexmakerjvmtiagent",
|
||||
],
|
||||
kotlincflags: [
|
||||
"-Xjvm-default=all",
|
||||
"-opt-in=kotlin.RequiresOptIn",
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.android.settings.tests.spa_unit">
|
||||
|
||||
<application>
|
||||
<application android:debuggable="true">
|
||||
<provider android:name="com.android.settings.slices.SettingsSliceProvider"
|
||||
android:authorities="${applicationId}.slices"
|
||||
tools:replace="android:authorities"/>
|
||||
|
||||
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* 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.settings.spa.app.appinfo
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.pm.ResolveInfo
|
||||
import android.content.pm.verify.domain.DomainVerificationManager
|
||||
import android.content.pm.verify.domain.DomainVerificationUserState
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.assertIsEnabled
|
||||
import androidx.compose.ui.test.assertIsNotDisplayed
|
||||
import androidx.compose.ui.test.assertIsNotEnabled
|
||||
import androidx.compose.ui.test.junit4.createComposeRule
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.onRoot
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.android.settings.R
|
||||
import com.android.settingslib.spaprivileged.framework.common.domainVerificationManager
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.any
|
||||
import org.mockito.Mockito.anyInt
|
||||
import org.mockito.Mockito.doReturn
|
||||
import org.mockito.Spy
|
||||
import org.mockito.junit.MockitoJUnit
|
||||
import org.mockito.junit.MockitoRule
|
||||
import org.mockito.Mockito.`when` as whenever
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class AppOpenByDefaultPreferenceTest {
|
||||
@JvmField
|
||||
@Rule
|
||||
val mockito: MockitoRule = MockitoJUnit.rule()
|
||||
|
||||
@get:Rule
|
||||
val composeTestRule = createComposeRule()
|
||||
|
||||
@Spy
|
||||
private val context: Context = ApplicationProvider.getApplicationContext()
|
||||
|
||||
@Mock
|
||||
private lateinit var packageManager: PackageManager
|
||||
|
||||
@Mock
|
||||
private lateinit var domainVerificationManager: DomainVerificationManager
|
||||
|
||||
@Mock
|
||||
private lateinit var allowedUserState: DomainVerificationUserState
|
||||
|
||||
@Mock
|
||||
private lateinit var notAllowedUserState: DomainVerificationUserState
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
whenever(context.packageManager).thenReturn(packageManager)
|
||||
doReturn(context).`when`(context).createContextAsUser(any(), anyInt())
|
||||
whenever(context.domainVerificationManager).thenReturn(domainVerificationManager)
|
||||
whenever(allowedUserState.isLinkHandlingAllowed).thenReturn(true)
|
||||
whenever(notAllowedUserState.isLinkHandlingAllowed).thenReturn(false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun instantApp_notDisplay() {
|
||||
val instantApp = ApplicationInfo().apply {
|
||||
packageName = PACKAGE_NAME
|
||||
privateFlags = ApplicationInfo.PRIVATE_FLAG_INSTANT
|
||||
}
|
||||
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(LocalContext provides context) {
|
||||
AppOpenByDefaultPreference(instantApp)
|
||||
}
|
||||
}
|
||||
|
||||
composeTestRule.onRoot().assertIsNotDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun browserApp_notDisplay() {
|
||||
val browserApp = ApplicationInfo().apply {
|
||||
packageName = PACKAGE_NAME
|
||||
privateFlags = ApplicationInfo.PRIVATE_FLAG_INSTANT
|
||||
}
|
||||
val resolveInfo = ResolveInfo().apply {
|
||||
activityInfo = ActivityInfo()
|
||||
handleAllWebDataURI = true
|
||||
}
|
||||
whenever(packageManager.queryIntentActivitiesAsUser(any(), anyInt(), anyInt()))
|
||||
.thenReturn(listOf(resolveInfo))
|
||||
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(LocalContext provides context) {
|
||||
AppOpenByDefaultPreference(browserApp)
|
||||
}
|
||||
}
|
||||
|
||||
composeTestRule.onRoot().assertIsNotDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun allowedUserState_alwaysOpen() {
|
||||
whenever(domainVerificationManager.getDomainVerificationUserState(PACKAGE_NAME))
|
||||
.thenReturn(allowedUserState)
|
||||
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(LocalContext provides context) {
|
||||
AppOpenByDefaultPreference(INSTALLED_ENABLED_APP)
|
||||
}
|
||||
}
|
||||
|
||||
composeTestRule.onNodeWithText(context.getString(R.string.launch_by_default))
|
||||
.assertIsDisplayed()
|
||||
.assertIsEnabled()
|
||||
composeTestRule.onNodeWithText(context.getString(R.string.app_link_open_always))
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun notAllowedUserState_neverOpen() {
|
||||
whenever(domainVerificationManager.getDomainVerificationUserState(PACKAGE_NAME))
|
||||
.thenReturn(notAllowedUserState)
|
||||
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(LocalContext provides context) {
|
||||
AppOpenByDefaultPreference(INSTALLED_ENABLED_APP)
|
||||
}
|
||||
}
|
||||
|
||||
composeTestRule.onNodeWithText(context.getString(R.string.launch_by_default))
|
||||
.assertIsDisplayed()
|
||||
.assertIsEnabled()
|
||||
composeTestRule.onNodeWithText(context.getString(R.string.app_link_open_never))
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun notInstalledApp_disabled() {
|
||||
val notInstalledApp = ApplicationInfo().apply {
|
||||
packageName = PACKAGE_NAME
|
||||
}
|
||||
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(LocalContext provides context) {
|
||||
AppOpenByDefaultPreference(notInstalledApp)
|
||||
}
|
||||
}
|
||||
|
||||
composeTestRule.onNodeWithText(context.getString(R.string.launch_by_default))
|
||||
.assertIsNotEnabled()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun notEnabledApp_disabled() {
|
||||
val notEnabledApp = ApplicationInfo().apply {
|
||||
packageName = PACKAGE_NAME
|
||||
flags = ApplicationInfo.FLAG_INSTALLED
|
||||
enabled = false
|
||||
}
|
||||
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(LocalContext provides context) {
|
||||
AppOpenByDefaultPreference(notEnabledApp)
|
||||
}
|
||||
}
|
||||
|
||||
composeTestRule.onNodeWithText(context.getString(R.string.launch_by_default))
|
||||
.assertIsNotEnabled()
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val PACKAGE_NAME = "package name"
|
||||
|
||||
val INSTALLED_ENABLED_APP = ApplicationInfo().apply {
|
||||
packageName = PACKAGE_NAME
|
||||
flags = ApplicationInfo.FLAG_INSTALLED
|
||||
enabled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,12 +68,12 @@ class AppStoragePreferenceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun uninstalledApp_notDisplayed() {
|
||||
val uninstalledApp = ApplicationInfo()
|
||||
fun notInstalledApp_notDisplayed() {
|
||||
val notInstalledApp = ApplicationInfo()
|
||||
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(LocalContext provides context) {
|
||||
AppStoragePreference(uninstalledApp)
|
||||
AppStoragePreference(notInstalledApp)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -120,15 +120,15 @@ class AppTimeSpentPreferenceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun uninstalledApp_disabled() {
|
||||
fun notInstalledApp_disabled() {
|
||||
mockActivitiesQueryResult(listOf(MATCHED_RESOLVE_INFO))
|
||||
val uninstalledApp = ApplicationInfo().apply {
|
||||
val notInstalledApp = ApplicationInfo().apply {
|
||||
packageName = PACKAGE_NAME
|
||||
}
|
||||
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(LocalContext provides context) {
|
||||
AppTimeSpentPreference(uninstalledApp)
|
||||
AppTimeSpentPreference(notInstalledApp)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user