Add Voice activation apps into Settings->Apps->Special app access
This change is flag controlled by `com.android.settings.flags.enable_voice_activation_apps_in_settings`. Bug: 306447565 Bug: 303727896 Test: atest com.android.settings.spa.app.specialaccess.VoiceActivationAppsTest Test: atest com.android.settings.spa.app.specialaccess.VoiceActivationAppsPreferenceControllerTest Test: manual Settings CUJs Change-Id: I71a0dc2303263c9957220b56e4dcacec9a561b02
This commit is contained in:
@@ -9520,6 +9520,13 @@
|
|||||||
<!-- Label for showing apps that can manage external storage[CHAR LIMIT=45] -->
|
<!-- Label for showing apps that can manage external storage[CHAR LIMIT=45] -->
|
||||||
<string name="filter_manage_external_storage">Can access all files</string>
|
<string name="filter_manage_external_storage">Can access all files</string>
|
||||||
|
|
||||||
|
<!-- Voice Activation apps settings title [CHAR LIMIT=40] -->
|
||||||
|
<string name="voice_activation_apps_title">Voice activation apps</string>
|
||||||
|
<!-- Label for a setting which controls whether an app can be voice activated [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="permit_voice_activation_apps">Allow voice activation</string>
|
||||||
|
<!-- Description for a setting which controls whether an app can be voice activated [CHAR LIMIT=NONE] -->
|
||||||
|
<string name ="allow_voice_activation_apps_description">Voice activation turns-on approved apps, hands-free, using voice command.\n\nUntill activated, none of these apps can directly access your microphone.Instead, this device uses built-in proteced adaptive sensing to turn-on aprroved apps for you.\n\n<a href="">More about protected adaptive sensing</a></string>
|
||||||
|
|
||||||
<!-- Manage full screen intent permission title [CHAR LIMIT=40] -->
|
<!-- Manage full screen intent permission title [CHAR LIMIT=40] -->
|
||||||
<string name="full_screen_intent_title">Full screen notifications</string>
|
<string name="full_screen_intent_title">Full screen notifications</string>
|
||||||
|
|
||||||
|
@@ -99,6 +99,11 @@
|
|||||||
android:title="@string/full_screen_intent_title"
|
android:title="@string/full_screen_intent_title"
|
||||||
settings:controller="com.android.settings.spa.app.specialaccess.UseFullScreenIntentPreferenceController" />
|
settings:controller="com.android.settings.spa.app.specialaccess.UseFullScreenIntentPreferenceController" />
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="voice_activation_apps"
|
||||||
|
android:title="@string/voice_activation_apps_title"
|
||||||
|
settings:controller="com.android.settings.spa.app.specialaccess.VoiceActivationAppsPreferenceController" />
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="picture_in_picture"
|
android:key="picture_in_picture"
|
||||||
android:title="@string/picture_in_picture_title"
|
android:title="@string/picture_in_picture_title"
|
||||||
|
@@ -37,6 +37,7 @@ import com.android.settings.spa.app.specialaccess.MediaManagementAppsAppListProv
|
|||||||
import com.android.settings.spa.app.specialaccess.ModifySystemSettingsAppListProvider
|
import com.android.settings.spa.app.specialaccess.ModifySystemSettingsAppListProvider
|
||||||
import com.android.settings.spa.app.specialaccess.NfcTagAppsSettingsProvider
|
import com.android.settings.spa.app.specialaccess.NfcTagAppsSettingsProvider
|
||||||
import com.android.settings.spa.app.specialaccess.PictureInPictureListProvider
|
import com.android.settings.spa.app.specialaccess.PictureInPictureListProvider
|
||||||
|
import com.android.settings.spa.app.specialaccess.VoiceActivationAppsListProvider
|
||||||
import com.android.settings.spa.app.specialaccess.WifiControlAppListProvider
|
import com.android.settings.spa.app.specialaccess.WifiControlAppListProvider
|
||||||
import com.android.settings.wifi.ChangeWifiStateDetails
|
import com.android.settings.wifi.ChangeWifiStateDetails
|
||||||
|
|
||||||
@@ -65,6 +66,8 @@ object SettingsActivityUtil {
|
|||||||
WifiControlAppListProvider.getAppInfoRoutePrefix(),
|
WifiControlAppListProvider.getAppInfoRoutePrefix(),
|
||||||
NfcTagAppsSettingsProvider::class.qualifiedName to
|
NfcTagAppsSettingsProvider::class.qualifiedName to
|
||||||
NfcTagAppsSettingsProvider.getAppInfoRoutePrefix(),
|
NfcTagAppsSettingsProvider.getAppInfoRoutePrefix(),
|
||||||
|
VoiceActivationAppsListProvider::class.qualifiedName to
|
||||||
|
VoiceActivationAppsListProvider.getAppInfoRoutePrefix(),
|
||||||
)
|
)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
@@ -36,6 +36,7 @@ import com.android.settings.spa.app.specialaccess.NfcTagAppsSettingsProvider
|
|||||||
import com.android.settings.spa.app.specialaccess.PictureInPictureListProvider
|
import com.android.settings.spa.app.specialaccess.PictureInPictureListProvider
|
||||||
import com.android.settings.spa.app.specialaccess.SpecialAppAccessPageProvider
|
import com.android.settings.spa.app.specialaccess.SpecialAppAccessPageProvider
|
||||||
import com.android.settings.spa.app.specialaccess.UseFullScreenIntentAppListProvider
|
import com.android.settings.spa.app.specialaccess.UseFullScreenIntentAppListProvider
|
||||||
|
import com.android.settings.spa.app.specialaccess.VoiceActivationAppsListProvider
|
||||||
import com.android.settings.spa.app.specialaccess.WifiControlAppListProvider
|
import com.android.settings.spa.app.specialaccess.WifiControlAppListProvider
|
||||||
import com.android.settings.spa.app.storage.StorageAppListPageProvider
|
import com.android.settings.spa.app.storage.StorageAppListPageProvider
|
||||||
import com.android.settings.spa.core.instrumentation.SpaLogProvider
|
import com.android.settings.spa.core.instrumentation.SpaLogProvider
|
||||||
@@ -66,6 +67,7 @@ open class SettingsSpaEnvironment(context: Context) : SpaEnvironment(context) {
|
|||||||
PictureInPictureListProvider,
|
PictureInPictureListProvider,
|
||||||
InstallUnknownAppsListProvider,
|
InstallUnknownAppsListProvider,
|
||||||
AlarmsAndRemindersAppListProvider,
|
AlarmsAndRemindersAppListProvider,
|
||||||
|
VoiceActivationAppsListProvider,
|
||||||
WifiControlAppListProvider,
|
WifiControlAppListProvider,
|
||||||
NfcTagAppsSettingsProvider,
|
NfcTagAppsSettingsProvider,
|
||||||
)
|
)
|
||||||
|
@@ -66,6 +66,7 @@ object SpecialAppAccessPageProvider : SettingsPageProvider {
|
|||||||
PictureInPictureListProvider,
|
PictureInPictureListProvider,
|
||||||
InstallUnknownAppsListProvider,
|
InstallUnknownAppsListProvider,
|
||||||
AlarmsAndRemindersAppListProvider,
|
AlarmsAndRemindersAppListProvider,
|
||||||
|
VoiceActivationAppsListProvider,
|
||||||
WifiControlAppListProvider,
|
WifiControlAppListProvider,
|
||||||
)
|
)
|
||||||
.map { it.buildAppListInjectEntry().setLink(fromPage = owner).build() }
|
.map { it.buildAppListInjectEntry().setLink(fromPage = owner).build() }
|
||||||
|
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 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.specialaccess
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
|
import android.app.AppOpsManager
|
||||||
|
import android.app.settings.SettingsEnums
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.res.Resources
|
||||||
|
import com.android.settings.R
|
||||||
|
import com.android.settings.overlay.FeatureFactory
|
||||||
|
import com.android.settingslib.spaprivileged.template.app.AppOpPermissionListModel
|
||||||
|
import com.android.settingslib.spaprivileged.template.app.AppOpPermissionRecord
|
||||||
|
import com.android.settingslib.spaprivileged.template.app.TogglePermissionAppListProvider
|
||||||
|
|
||||||
|
|
||||||
|
object VoiceActivationAppsListProvider : TogglePermissionAppListProvider {
|
||||||
|
override val permissionType = "VoiceActivationApps"
|
||||||
|
override fun createModel(context: Context) = VoiceActivationAppsListModel(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
class VoiceActivationAppsListModel(context: Context) : AppOpPermissionListModel(context) {
|
||||||
|
override val pageTitleResId = R.string.voice_activation_apps_title
|
||||||
|
override val switchTitleResId = R.string.permit_voice_activation_apps
|
||||||
|
override val footerResId = R.string.allow_voice_activation_apps_description
|
||||||
|
override val appOp = AppOpsManager.OP_RECEIVE_SANDBOX_TRIGGER_AUDIO
|
||||||
|
override val permission = Manifest.permission.RECEIVE_SANDBOX_TRIGGER_AUDIO
|
||||||
|
override val setModeByUid = true
|
||||||
|
|
||||||
|
override fun setAllowed(record: AppOpPermissionRecord, newAllowed: Boolean) {
|
||||||
|
super.setAllowed(record, newAllowed)
|
||||||
|
logPermissionChange(newAllowed)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun logPermissionChange(newAllowed: Boolean) {
|
||||||
|
val category = when {
|
||||||
|
newAllowed -> SettingsEnums.APP_SPECIAL_PERMISSION_RECEIVE_SANDBOX_TRIGGER_AUDIO_ALLOW
|
||||||
|
else -> SettingsEnums.APP_SPECIAL_PERMISSION_RECEIVE_SANDBOX_TRIGGER_AUDIO_DENY
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Leave the package string empty as we should not log the package names for the collected
|
||||||
|
* metrics.
|
||||||
|
*/
|
||||||
|
FeatureFactory.featureFactory.metricsFeatureProvider.action(context, category, "")
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 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.specialaccess
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.preference.Preference
|
||||||
|
import com.android.settings.core.BasePreferenceController
|
||||||
|
import com.android.settings.flags.Flags
|
||||||
|
import com.android.settings.spa.SpaActivity.Companion.startSpaActivity
|
||||||
|
|
||||||
|
class VoiceActivationAppsPreferenceController(context: Context, preferenceKey: String) :
|
||||||
|
BasePreferenceController(context, preferenceKey) {
|
||||||
|
override fun getAvailabilityStatus() =
|
||||||
|
if (Flags.enableVoiceActivationAppsInSettings()) AVAILABLE
|
||||||
|
else CONDITIONALLY_UNAVAILABLE
|
||||||
|
|
||||||
|
override fun handlePreferenceTreeClick(preference: Preference): Boolean {
|
||||||
|
if (preference.key == mPreferenceKey) {
|
||||||
|
mContext.startSpaActivity(VoiceActivationAppsListProvider.getAppListRoute())
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
@@ -34,6 +34,7 @@ android_test {
|
|||||||
"androidx.compose.runtime_runtime",
|
"androidx.compose.runtime_runtime",
|
||||||
"androidx.test.ext.junit",
|
"androidx.test.ext.junit",
|
||||||
"androidx.test.runner",
|
"androidx.test.runner",
|
||||||
|
"flag-junit",
|
||||||
"mockito-target-extended-minus-junit4",
|
"mockito-target-extended-minus-junit4",
|
||||||
],
|
],
|
||||||
jni_libs: [
|
jni_libs: [
|
||||||
|
@@ -0,0 +1,65 @@
|
|||||||
|
package com.android.settings.spa.app.specialaccess
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.platform.test.annotations.RequiresFlagsDisabled
|
||||||
|
import android.platform.test.annotations.RequiresFlagsEnabled
|
||||||
|
import android.platform.test.flag.junit.CheckFlagsRule
|
||||||
|
import android.platform.test.flag.junit.DeviceFlagsValueProvider
|
||||||
|
import androidx.preference.Preference
|
||||||
|
import androidx.test.core.app.ApplicationProvider
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
|
||||||
|
import com.android.settings.flags.Flags
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.mockito.kotlin.any
|
||||||
|
import org.mockito.kotlin.doNothing
|
||||||
|
import org.mockito.kotlin.spy
|
||||||
|
import org.mockito.kotlin.whenever
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
class VoiceActivationAppsPreferenceControllerTest {
|
||||||
|
|
||||||
|
@get:Rule
|
||||||
|
val checkFlagsRule: CheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule()
|
||||||
|
|
||||||
|
private val context: Context = spy(ApplicationProvider.getApplicationContext()) {
|
||||||
|
doNothing().whenever(mock).startActivity(any())
|
||||||
|
}
|
||||||
|
|
||||||
|
private val matchedPreference = Preference(context).apply { key = preferenceKey }
|
||||||
|
|
||||||
|
private val misMatchedPreference = Preference(context).apply { key = testPreferenceKey }
|
||||||
|
|
||||||
|
private val controller = VoiceActivationAppsPreferenceController(context, preferenceKey)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_VOICE_ACTIVATION_APPS_IN_SETTINGS)
|
||||||
|
fun getAvailabilityStatus_enableVoiceActivationApps_returnAvailable() {
|
||||||
|
assertThat(controller.isAvailable).isTrue()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@RequiresFlagsDisabled(Flags.FLAG_ENABLE_VOICE_ACTIVATION_APPS_IN_SETTINGS)
|
||||||
|
fun getAvailableStatus_disableVoiceActivationApps_returnConditionallyUnavailable() {
|
||||||
|
assertThat(controller.isAvailable).isFalse()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun handlePreferenceTreeClick_keyMatched_returnTrue() {
|
||||||
|
assertThat(controller.handlePreferenceTreeClick(matchedPreference)).isTrue()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun handlePreferenceTreeClick_keyMisMatched_returnFalse() {
|
||||||
|
assertThat(controller.handlePreferenceTreeClick(misMatchedPreference)).isFalse()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val preferenceKey: String = "voice_activation_apps"
|
||||||
|
private const val testPreferenceKey: String = "test_key"
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,50 @@
|
|||||||
|
package com.android.settings.spa.app.specialaccess
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
|
import android.app.AppOpsManager
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.test.core.app.ApplicationProvider
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
import com.android.settings.R
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
class VoiceActivationAppsTest {
|
||||||
|
private val context: Context = ApplicationProvider.getApplicationContext()
|
||||||
|
|
||||||
|
private val listModel = VoiceActivationAppsListModel(context)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun pageTitleResId() {
|
||||||
|
assertThat(listModel.pageTitleResId).isEqualTo(R.string.voice_activation_apps_title)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun switchTitleResId() {
|
||||||
|
assertThat(listModel.switchTitleResId).isEqualTo(R.string.permit_voice_activation_apps)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun footerResId() {
|
||||||
|
assertThat(listModel.footerResId)
|
||||||
|
.isEqualTo(R.string.allow_voice_activation_apps_description)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun appOp() {
|
||||||
|
assertThat(listModel.appOp).isEqualTo(AppOpsManager.OP_RECEIVE_SANDBOX_TRIGGER_AUDIO)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun permission() {
|
||||||
|
assertThat(listModel.permission).isEqualTo(
|
||||||
|
Manifest.permission.RECEIVE_SANDBOX_TRIGGER_AUDIO)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun setModeByUid() {
|
||||||
|
assertThat(listModel.setModeByUid).isTrue()
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user