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

Commit 20826ab0 authored by Fan Wu's avatar Fan Wu Committed by Android (Google) Code Review
Browse files

Merge "Add TurnScreenOnApps" into main

parents 7f2fbc2e 2aeeaebb
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.VoiceActivationAppsListProvider
import com.android.settings.spa.app.specialaccess.WifiControlAppListProvider
@@ -70,6 +71,7 @@ open class SettingsSpaEnvironment(context: Context) : SpaEnvironment(context) {
            VoiceActivationAppsListProvider,
            WifiControlAppListProvider,
            NfcTagAppsSettingsProvider,
            TurnScreenOnAppsAppListProvider,
        )
    }

+1 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ object SpecialAppAccessPageProvider : SettingsPageProvider {
                AlarmsAndRemindersAppListProvider,
                VoiceActivationAppsListProvider,
                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