Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2aeeaebb authored by FanWu's avatar FanWu
Browse files

Add TurnScreenOnApps

Bug: 284032615

Test: Manually on device and unit test
Change-Id: I4ccbf5892b3830a6c4657e43850d9b0eab5aecba
parent 4e806989
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ import com.android.settings.spa.app.specialaccess.InstallUnknownAppsListProvider
import com.android.settings.spa.app.specialaccess.MediaManagementAppsAppListProvider
import com.android.settings.spa.app.specialaccess.ModifySystemSettingsAppListProvider
import com.android.settings.spa.app.specialaccess.NfcTagAppsSettingsProvider
import com.android.settings.spa.app.specialaccess.TurnScreenOnAppsAppListProvider
import com.android.settings.spa.app.specialaccess.WifiControlAppListProvider
import com.android.settings.spa.app.storage.StorageAppListPageProvider
import com.android.settings.spa.notification.AppListNotificationsPageProvider
@@ -120,6 +121,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_TURN_SCREEN_ON -> TurnScreenOnAppsAppListProvider.getAppListRoute()
            // TODO(b/292165031) enable once sorting is supported
            //LIST_TYPE_STORAGE -> StorageAppListPageProvider.Apps.name
            //LIST_TYPE_GAMES -> StorageAppListPageProvider.Games.name
+2 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import com.android.settings.spa.app.specialaccess.ModifySystemSettingsAppListPro
import com.android.settings.spa.app.specialaccess.NfcTagAppsSettingsProvider
import com.android.settings.spa.app.specialaccess.PictureInPictureListProvider
import com.android.settings.spa.app.specialaccess.SpecialAppAccessPageProvider
import com.android.settings.spa.app.specialaccess.TurnScreenOnAppsAppListProvider
import com.android.settings.spa.app.specialaccess.UseFullScreenIntentAppListProvider
import com.android.settings.spa.app.specialaccess.WifiControlAppListProvider
import com.android.settings.spa.app.storage.StorageAppListPageProvider
@@ -68,6 +69,7 @@ open class SettingsSpaEnvironment(context: Context) : SpaEnvironment(context) {
            AlarmsAndRemindersAppListProvider,
            WifiControlAppListProvider,
            NfcTagAppsSettingsProvider,
            TurnScreenOnAppsAppListProvider,
        )
    }

+1 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ object SpecialAppAccessPageProvider : SettingsPageProvider {
                InstallUnknownAppsListProvider,
                AlarmsAndRemindersAppListProvider,
                WifiControlAppListProvider,
                TurnScreenOnAppsAppListProvider,
            )
            .map { it.buildAppListInjectEntry().setLink(fromPage = owner).build() }
    }
+54 −0
Original line number Diff line number Diff line
/*
 * 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 TurnScreenOnAppsAppListProvider : TogglePermissionAppListProvider {
    override val permissionType = "TurnScreenOnApps"
    override fun createModel(context: Context) = TurnScreenOnAppsListModel(context)
}

class TurnScreenOnAppsListModel(context: Context) : AppOpPermissionListModel(context) {
    override val pageTitleResId = com.android.settingslib.R.string.turn_screen_on_title
    override val switchTitleResId = com.android.settingslib.R.string.allow_turn_screen_on
    override val footerResId = com.android.settingslib.R.string.allow_turn_screen_on_description
    override val appOp = AppOpsManager.OP_TURN_SCREEN_ON
    override val permission = Manifest.permission.TURN_SCREEN_ON
    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.SETTINGS_MANAGE_TURN_SCREEN_ON,
            if (newAllowed) 1 else 0
        )
    }
}
 No newline at end of file
+62 −0
Original line number Diff line number Diff line
/*
 * 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 org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class TurnScreenOnAppsTest {
    private val context: Context = ApplicationProvider.getApplicationContext()

    private val listModel = TurnScreenOnAppsListModel(context)

    @Test
    fun pageTitleResId() {
        assertThat(listModel.pageTitleResId).isEqualTo(com.android.settingslib.R.string.turn_screen_on_title)
    }

    @Test
    fun switchTitleResId() {
        assertThat(listModel.switchTitleResId).isEqualTo(com.android.settingslib.R.string.allow_turn_screen_on)
    }

    @Test
    fun footerResId() {
        assertThat(listModel.footerResId).isEqualTo(com.android.settingslib.R.string.allow_turn_screen_on_description)
    }

    @Test
    fun appOp() {
        assertThat(listModel.appOp).isEqualTo(AppOpsManager.OP_TURN_SCREEN_ON)
    }

    @Test
    fun permission() {
        assertThat(listModel.permission).isEqualTo(Manifest.permission.TURN_SCREEN_ON)
    }

    @Test
    fun setModeByUid() {
        assertThat(listModel.setModeByUid).isTrue()
    }
}
 No newline at end of file