Merge "Add new Special App Access screen for Backup Tasks." into main

This commit is contained in:
Varun Shah
2024-02-22 21:46:53 +00:00
committed by Android (Google) Code Review
12 changed files with 292 additions and 0 deletions

View File

@@ -949,6 +949,39 @@
android:value="@string/menu_key_apps"/>
</activity>
<activity-alias
android:name="BackupTasksActivity"
android:knownActivityEmbeddingCerts="@array/config_known_host_certs"
android:exported="true"
android:targetActivity=".spa.SpaBridgeActivity"
android:label="@string/run_backup_tasks_title">
<intent-filter android:priority="1">
<action android:name="android.settings.REQUEST_RUN_BACKUP_JOBS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="com.android.settings.spa.DESTINATION"
android:value="TogglePermissionAppList/BackupTasksApps"/>
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_apps"/>
</activity-alias>
<activity-alias
android:name="AppBackupTasksActivity"
android:knownActivityEmbeddingCerts="@array/config_known_host_certs"
android:exported="true"
android:targetActivity=".spa.SpaAppBridgeActivity"
android:label="@string/run_backup_tasks_title">
<intent-filter android:priority="1">
<action android:name="android.settings.REQUEST_RUN_BACKUP_JOBS" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
<meta-data android:name="com.android.settings.spa.DESTINATION"
android:value="TogglePermissionAppInfoPage/BackupTasksApps"/>
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_apps"/>
</activity-alias>
<activity
android:name="Settings$DateTimeSettingsActivity"
android:label="@string/date_and_time"

View File

@@ -0,0 +1,9 @@
package: "com.android.settings.flags"
container: "system"
flag {
name: "enable_perform_backup_tasks_in_settings"
namespace: "backstage_power"
description: "Enable the Perform Backup Tasks screen in Settings"
bug: "320563660"
}

View File

@@ -10232,6 +10232,21 @@
<!-- Keywords for settings screen for controlling apps that can run long background tasks [CHAR LIMIT=NONE] -->
<string name="keywords_long_background_tasks">long jobs, data transfer, background tasks</string>
<!-- Title for the settings screen for controlling apps that hold the run backup jobs permission [CHAR LIMIT=60] -->
<string name="run_backup_tasks_title">Perform backup tasks in background</string>
<!-- Label for the switch to toggle the run backup jobs permission [CHAR LIMIT=100] -->
<string name="run_backup_tasks_switch_title">Allow app to run backup-related background tasks</string>
<!-- Description that appears below the run_backup_tasks switch [CHAR LIMIT=NONE] -->
<string name="run_backup_tasks_footer_title">
Indicates that this app has a major use-case where it needs to backup or sync content.
Granting this permission allows the app to run in the background for a slightly longer time
in order to complete the backup-related work.
\n\nIf this permission is denied, the system will not give any special exemption to this
app to complete backup-related work in the background.
</string>
<!-- Keywords for settings screen for controlling apps that hold the run backup tasks permission [CHAR LIMIT=NONE] -->
<string name="keywords_run_backup_tasks">backup tasks, backup jobs</string>
<!-- Reset rate-limiting in the system service ShortcutManager. "ShortcutManager" is the name of a system service and not translatable.
If the word "rate-limit" is hard to translate, use "Reset ShortcutManager API call limit" as the source text, which means
the same thing in this context.

View File

@@ -19,6 +19,14 @@
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/special_access">
<Preference
android:key="run_backup_tasks"
android:title="@string/run_backup_tasks_title"
android:order="-2000"
settings:keywords="@string/keywords_run_backup_tasks"
settings:controller="com.android.settings.spa.app.specialaccess.BackupTasksAppsPreferenceController">
</Preference>
<Preference
android:key="manage_external_storage"
android:title="@string/manage_external_storage_title"

View File

@@ -31,6 +31,7 @@ import com.android.settings.spa.SpaActivity.Companion.startSpaActivity
import com.android.settings.spa.SpaAppBridgeActivity.Companion.getDestinationForApp
import com.android.settings.spa.app.specialaccess.AlarmsAndRemindersAppListProvider
import com.android.settings.spa.app.specialaccess.AllFilesAccessAppListProvider
import com.android.settings.spa.app.specialaccess.BackupTasksAppsListProvider
import com.android.settings.spa.app.specialaccess.DisplayOverOtherAppsAppListProvider
import com.android.settings.spa.app.specialaccess.InstallUnknownAppsListProvider
import com.android.settings.spa.app.specialaccess.MediaManagementAppsAppListProvider
@@ -68,6 +69,8 @@ object SettingsActivityUtil {
NfcTagAppsSettingsProvider.getAppInfoRoutePrefix(),
VoiceActivationAppsListProvider::class.qualifiedName to
VoiceActivationAppsListProvider.getAppInfoRoutePrefix(),
BackupTasksAppsListProvider::class.qualifiedName to
BackupTasksAppsListProvider.getAppInfoRoutePrefix(),
)
@JvmStatic

View File

@@ -29,6 +29,7 @@ import com.android.settings.spa.app.appinfo.CloneAppInfoSettingsProvider
import com.android.settings.spa.app.backgroundinstall.BackgroundInstalledAppsPageProvider
import com.android.settings.spa.app.specialaccess.AlarmsAndRemindersAppListProvider
import com.android.settings.spa.app.specialaccess.AllFilesAccessAppListProvider
import com.android.settings.spa.app.specialaccess.BackupTasksAppsListProvider
import com.android.settings.spa.app.specialaccess.DisplayOverOtherAppsAppListProvider
import com.android.settings.spa.app.specialaccess.InstallUnknownAppsListProvider
import com.android.settings.spa.app.specialaccess.LongBackgroundTasksAppListProvider
@@ -79,6 +80,7 @@ open class SettingsSpaEnvironment(context: Context) : SpaEnvironment(context) {
NfcTagAppsSettingsProvider,
LongBackgroundTasksAppListProvider,
TurnScreenOnAppsAppListProvider,
BackupTasksAppsListProvider,
)
}

View File

@@ -38,6 +38,7 @@ import com.android.settings.flags.Flags
import com.android.settings.spa.SpaActivity.Companion.startSpaActivity
import com.android.settings.spa.app.appcompat.UserAspectRatioAppPreference
import com.android.settings.spa.app.specialaccess.AlarmsAndRemindersAppListProvider
import com.android.settings.spa.app.specialaccess.BackupTasksAppsListProvider
import com.android.settings.spa.app.specialaccess.DisplayOverOtherAppsAppListProvider
import com.android.settings.spa.app.specialaccess.InstallUnknownAppsListProvider
import com.android.settings.spa.app.specialaccess.ModifySystemSettingsAppListProvider
@@ -169,6 +170,9 @@ private fun AppInfoSettings(packageInfoPresenter: PackageInfoPresenter) {
if (Flags.enableVoiceActivationAppsInSettings()) {
VoiceActivationAppsListProvider.InfoPageEntryItem(app)
}
if (Flags.enablePerformBackupTasksInSettings()) {
BackupTasksAppsListProvider.InfoPageEntryItem(app)
}
}
Category(title = stringResource(R.string.app_install_details_group_title)) {

View File

@@ -0,0 +1,54 @@
/*
* Copyright (C) 2024 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 com.android.settings.R
import com.android.settings.overlay.FeatureFactory.Companion.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 BackupTasksAppsListProvider : TogglePermissionAppListProvider {
override val permissionType = "BackupTasksApps"
override fun createModel(context: Context) = BackupTasksAppsListModel(context)
}
class BackupTasksAppsListModel(context: Context) : AppOpPermissionListModel(context) {
override val pageTitleResId = R.string.run_backup_tasks_title
override val switchTitleResId = R.string.run_backup_tasks_switch_title
override val footerResId = R.string.run_backup_tasks_footer_title
override val appOp = AppOpsManager.OP_RUN_BACKUP_JOBS
override val permission = Manifest.permission.RUN_BACKUP_JOBS
override val setModeByUid = true
override fun setAllowed(record: AppOpPermissionRecord, newAllowed: Boolean) {
super.setAllowed(record, newAllowed)
logPermissionChange(newAllowed)
}
private fun logPermissionChange(newAllowed: Boolean) {
featureFactory.metricsFeatureProvider.action(
context,
SettingsEnums.ACTION_RUN_BACKUP_TASKS_TOGGLE,
if (newAllowed) 1 else 0
)
}
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright (C) 2024 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 BackupTasksAppsPreferenceController(context: Context, preferenceKey: String) :
BasePreferenceController(context, preferenceKey) {
override fun getAvailabilityStatus() =
if (Flags.enablePerformBackupTasksInSettings()) AVAILABLE
else CONDITIONALLY_UNAVAILABLE
override fun handlePreferenceTreeClick(preference: Preference): Boolean {
if (preference.key == mPreferenceKey) {
mContext.startSpaActivity(BackupTasksAppsListProvider.getAppListRoute())
return true
}
return false
}
}

View File

@@ -71,6 +71,7 @@ object SpecialAppAccessPageProvider : SettingsPageProvider {
WifiControlAppListProvider,
LongBackgroundTasksAppListProvider,
TurnScreenOnAppsAppListProvider,
BackupTasksAppsListProvider,
)
.map { it.buildAppListInjectEntry().setLink(fromPage = owner).build() }
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) 2024 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 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 BackupTasksAppsPreferenceControllerTest {
@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 = BackupTasksAppsPreferenceController(context, preferenceKey)
@Test
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_PERFORM_BACKUP_TASKS_IN_SETTINGS)
fun getAvailabilityStatus_enableBackupTasksApps_returnAvailable() {
assertThat(controller.isAvailable).isTrue()
}
@Test
@RequiresFlagsDisabled(Flags.FLAG_ENABLE_PERFORM_BACKUP_TASKS_IN_SETTINGS)
fun getAvailableStatus_disableBackupTasksApps_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 = "backup_tasks_apps"
private const val testPreferenceKey: String = "test_key"
}
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright (C) 2024 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.content.Context
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import com.android.settings.R
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class BackupTasksAppsTest {
private val context: Context = ApplicationProvider.getApplicationContext()
private val listModel = BackupTasksAppsListModel(context)
@Test
fun modelResourceIdAndProperties() {
assertThat(listModel.pageTitleResId).isEqualTo(R.string.run_backup_tasks_title)
assertThat(listModel.switchTitleResId).isEqualTo(R.string.run_backup_tasks_switch_title)
assertThat(listModel.footerResId).isEqualTo(R.string.run_backup_tasks_footer_title)
assertThat(listModel.appOp).isEqualTo(AppOpsManager.OP_RUN_BACKUP_JOBS)
assertThat(listModel.permission).isEqualTo(Manifest.permission.RUN_BACKUP_JOBS)
assertThat(listModel.setModeByUid).isTrue()
}
}