Add LongBackgroundTasksApps

Bug: 284032922

Test: Unit test
Change-Id: Ic58f45c41c3d35803591afaf25829ff104dc493d
This commit is contained in:
FanWu
2023-11-02 12:32:14 +08:00
committed by Fan Wu
parent 5e98b96fab
commit 0e9682eb31
5 changed files with 103 additions and 0 deletions

View File

@@ -64,6 +64,7 @@ import com.android.settings.spa.app.specialaccess.AlarmsAndRemindersAppListProvi
import com.android.settings.spa.app.specialaccess.AllFilesAccessAppListProvider
import com.android.settings.spa.app.specialaccess.DisplayOverOtherAppsAppListProvider
import com.android.settings.spa.app.specialaccess.InstallUnknownAppsListProvider
import com.android.settings.spa.app.specialaccess.LongBackgroundTasksAppListProvider
import com.android.settings.spa.app.specialaccess.MediaManagementAppsAppListProvider
import com.android.settings.spa.app.specialaccess.ModifySystemSettingsAppListProvider
import com.android.settings.spa.app.specialaccess.NfcTagAppsSettingsProvider
@@ -121,6 +122,7 @@ object ManageApplicationsUtil {
LIST_TYPE_MAIN -> AllAppListPageProvider.name
LIST_TYPE_NFC_TAG_APPS -> NfcTagAppsSettingsProvider.getAppListRoute()
LIST_TYPE_USER_ASPECT_RATIO_APPS -> UserAspectRatioAppsPageProvider.name
LIST_TYPE_LONG_BACKGROUND_TASKS -> LongBackgroundTasksAppListProvider.getAppListRoute()
LIST_TYPE_TURN_SCREEN_ON -> TurnScreenOnAppsAppListProvider.getAppListRoute()
// TODO(b/292165031) enable once sorting is supported
//LIST_TYPE_STORAGE -> StorageAppListPageProvider.Apps.name

View File

@@ -30,6 +30,7 @@ import com.android.settings.spa.app.specialaccess.AlarmsAndRemindersAppListProvi
import com.android.settings.spa.app.specialaccess.AllFilesAccessAppListProvider
import com.android.settings.spa.app.specialaccess.DisplayOverOtherAppsAppListProvider
import com.android.settings.spa.app.specialaccess.InstallUnknownAppsListProvider
import com.android.settings.spa.app.specialaccess.LongBackgroundTasksAppListProvider
import com.android.settings.spa.app.specialaccess.MediaManagementAppsAppListProvider
import com.android.settings.spa.app.specialaccess.ModifySystemSettingsAppListProvider
import com.android.settings.spa.app.specialaccess.NfcTagAppsSettingsProvider
@@ -71,6 +72,7 @@ open class SettingsSpaEnvironment(context: Context) : SpaEnvironment(context) {
VoiceActivationAppsListProvider,
WifiControlAppListProvider,
NfcTagAppsSettingsProvider,
LongBackgroundTasksAppListProvider,
TurnScreenOnAppsAppListProvider,
)
}

View File

@@ -0,0 +1,54 @@
/*
* 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 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 LongBackgroundTasksAppListProvider : TogglePermissionAppListProvider {
override val permissionType = "LongBackgroundTasksApps"
override fun createModel(context: Context) = LongBackgroundTasksAppsListModel(context)
}
class LongBackgroundTasksAppsListModel(context: Context) : AppOpPermissionListModel(context) {
override val pageTitleResId = R.string.long_background_tasks_title
override val switchTitleResId = R.string.long_background_tasks_switch_title
override val footerResId = R.string.long_background_tasks_footer_title
override val appOp = AppOpsManager.OP_RUN_USER_INITIATED_JOBS
override val permission = Manifest.permission.RUN_USER_INITIATED_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_LONG_BACKGROUND_TASKS_TOGGLE,
if (newAllowed) 1 else 0
)
}
}

View File

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

View File

@@ -0,0 +1,44 @@
/*
* 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.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 LongBackgroundTasksAppsTest {
private val context: Context = ApplicationProvider.getApplicationContext()
private val listModel = LongBackgroundTasksAppsListModel(context)
@Test
fun modelResourceIdAndProperties() {
assertThat(listModel.pageTitleResId).isEqualTo(R.string.long_background_tasks_title)
assertThat(listModel.switchTitleResId).isEqualTo(R.string.long_background_tasks_switch_title)
assertThat(listModel.footerResId).isEqualTo(R.string.long_background_tasks_footer_title)
assertThat(listModel.appOp).isEqualTo(AppOpsManager.OP_RUN_USER_INITIATED_JOBS)
assertThat(listModel.permission).isEqualTo(Manifest.permission.RUN_USER_INITIATED_JOBS)
assertThat(listModel.setModeByUid).isTrue()
}
}