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

Commit 21a633d1 authored by Yilin Cai's avatar Yilin Cai Committed by Android (Google) Code Review
Browse files

Merge "Fork the Wi-Fi control setting page to SPA."

parents e4f2fb56 fa93f941
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.settings.spa.app.specialaccess.MediaManagementAppsAppListProv
import com.android.settings.spa.app.specialaccess.ModifySystemSettingsAppListProvider
import com.android.settings.spa.app.specialaccess.PictureInPictureListProvider
import com.android.settings.spa.app.specialaccess.SpecialAppAccessPageProvider
import com.android.settings.spa.app.specialaccess.WifiControlAppListProvider
import com.android.settings.spa.development.UsageStatsPageProvider
import com.android.settings.spa.home.HomePageProvider
import com.android.settings.spa.notification.AppListNotificationsPageProvider
@@ -43,8 +44,10 @@ import com.android.settingslib.spaprivileged.template.app.TogglePermissionAppLis

open class SettingsSpaEnvironment(context: Context) : SpaEnvironment(context) {
    override val pageProviderRepository = lazy {
        val togglePermissionAppListTemplate = TogglePermissionAppListTemplate(
            allProviders = listOf(
        val togglePermissionAppListTemplate =
            TogglePermissionAppListTemplate(
                allProviders =
                    listOf(
                        AllFilesAccessAppListProvider,
                        DisplayOverOtherAppsAppListProvider,
                        MediaManagementAppsAppListProvider,
@@ -52,6 +55,7 @@ open class SettingsSpaEnvironment(context: Context) : SpaEnvironment(context) {
                        PictureInPictureListProvider,
                        InstallUnknownAppsListProvider,
                        AlarmsAndRemindersAppListProvider,
                        WifiControlAppListProvider,
                    ),
            )
        SettingsPageProviderRepository(
+28 −21
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.settings.spa.app.specialaccess
import android.Manifest
import android.app.AppGlobals
import android.app.AppOpsManager.MODE_DEFAULT
import android.app.AppOpsManager.MODE_ERRORED
import android.app.AppOpsManager.OP_REQUEST_INSTALL_PACKAGES
import android.content.Context
import android.content.pm.ApplicationInfo
@@ -50,27 +51,32 @@ class InstallUnknownAppsListModel(private val context: Context) :
    override val pageTitleResId = R.string.install_other_apps
    override val switchTitleResId = R.string.external_source_switch_title
    override val footerResId = R.string.install_all_warning
    override val switchRestrictionKeys = listOf(
    override val switchRestrictionKeys =
        listOf(
            UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES,
            UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY,
        )

    override fun transformItem(app: ApplicationInfo) = InstallUnknownAppsRecord(
    override fun transformItem(app: ApplicationInfo) =
        InstallUnknownAppsRecord(
            app = app,
        appOpsController = AppOpsController(
            appOpsController =
                AppOpsController(
                    context = context,
                    app = app,
                    op = OP_REQUEST_INSTALL_PACKAGES,
                    modeForNotAllowed = MODE_ERRORED
                ),
        )

    override fun filter(
        userIdFlow: Flow<Int>, recordListFlow: Flow<List<InstallUnknownAppsRecord>>,
    ) = userIdFlow.map(::getPotentialPackageNames)
        .combine(recordListFlow) { potentialPackageNames, recordList ->
            recordList.filter { record ->
                isChangeable(record, potentialPackageNames)
            }
        userIdFlow: Flow<Int>,
        recordListFlow: Flow<List<InstallUnknownAppsRecord>>,
    ) =
        userIdFlow.map(::getPotentialPackageNames).combine(recordListFlow) {
            potentialPackageNames,
            recordList ->
            recordList.filter { record -> isChangeable(record, potentialPackageNames) }
        }

    @Composable
@@ -88,12 +94,13 @@ class InstallUnknownAppsListModel(private val context: Context) :
        private fun isChangeable(
            record: InstallUnknownAppsRecord,
            potentialPackageNames: Set<String>,
        ) = record.appOpsController.getMode() != MODE_DEFAULT ||
        ) =
            record.appOpsController.getMode() != MODE_DEFAULT ||
                record.app.packageName in potentialPackageNames

        private fun getPotentialPackageNames(userId: Int): Set<String> =
            AppGlobals.getPackageManager().getAppOpPermissionPackages(
                Manifest.permission.REQUEST_INSTALL_PACKAGES, userId
            ).toSet()
            AppGlobals.getPackageManager()
                .getAppOpPermissionPackages(Manifest.permission.REQUEST_INSTALL_PACKAGES, userId)
                .toSet()
    }
}
+22 −19
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.settings.spa.app.specialaccess

import android.app.AppOpsManager.MODE_ERRORED
import android.app.AppOpsManager.OP_PICTURE_IN_PICTURE
import android.content.Context
import android.content.pm.ActivityInfo
@@ -46,8 +47,8 @@ data class PictureInPictureRecord(
    val appOpsController: AppOpsController,
) : AppRecord

class PictureInPictureListModel(private val context: Context)
    : TogglePermissionAppListModel<PictureInPictureRecord> {
class PictureInPictureListModel(private val context: Context) :
    TogglePermissionAppListModel<PictureInPictureRecord> {
    override val pageTitleResId = R.string.picture_in_picture_title
    override val switchTitleResId = R.string.picture_in_picture_app_detail_switch
    override val footerResId = R.string.picture_in_picture_app_detail_summary
@@ -55,8 +56,9 @@ class PictureInPictureListModel(private val context: Context)
    private val packageManager = context.packageManager

    override fun transform(userIdFlow: Flow<Int>, appListFlow: Flow<List<ApplicationInfo>>) =
        userIdFlow.map(::getPictureInPicturePackages)
            .combine(appListFlow) { pictureInPicturePackages, appList ->
        userIdFlow.map(::getPictureInPicturePackages).combine(appListFlow) {
            pictureInPicturePackages,
            appList ->
            appList.map { app ->
                createPictureInPictureRecord(
                    app = app,
@@ -78,17 +80,17 @@ class PictureInPictureListModel(private val context: Context)
        PictureInPictureRecord(
            app = app,
            isSupport = isSupport,
            appOpsController = AppOpsController(
            appOpsController =
                AppOpsController(
                    context = context,
                    app = app,
                    op = OP_PICTURE_IN_PICTURE,
                    modeForNotAllowed = MODE_ERRORED,
                ),
        )

    override fun filter(userIdFlow: Flow<Int>, recordListFlow: Flow<List<PictureInPictureRecord>>) =
        recordListFlow.map { recordList ->
            recordList.filter { it.isSupport }
        }
        recordListFlow.map { recordList -> recordList.filter { it.isSupport } }

    @Composable
    override fun isAllowed(record: PictureInPictureRecord) =
@@ -101,7 +103,8 @@ class PictureInPictureListModel(private val context: Context)
    }

    private fun getPictureInPicturePackages(userId: Int): Set<String> =
        packageManager.getInstalledPackagesAsUser(GET_ACTIVITIES_FLAGS, userId)
        packageManager
            .getInstalledPackagesAsUser(GET_ACTIVITIES_FLAGS, userId)
            .filter { it.supportsPictureInPicture() }
            .map { it.packageName }
            .toSet()
+16 −12
Original line number Diff line number Diff line
@@ -43,10 +43,12 @@ object SpecialAppAccessPageProvider : SettingsPageProvider {

    @Composable
    fun EntryItem() {
        Preference(object : PreferenceModel {
        Preference(
            object : PreferenceModel {
                override val title = stringResource(R.string.special_access)
                override val onClick = navigator(name)
        })
            }
        )
    }

    fun buildInjectEntry() = SettingsEntryBuilder.createInject(owner = SettingsPage.create(name))
@@ -61,6 +63,8 @@ object SpecialAppAccessPageProvider : SettingsPageProvider {
                PictureInPictureListProvider,
                InstallUnknownAppsListProvider,
                AlarmsAndRemindersAppListProvider,
        ).map { it.buildAppListInjectEntry().setLink(fromPage = owner).build() }
                WifiControlAppListProvider,
            )
            .map { it.buildAppListInjectEntry().setLink(fromPage = owner).build() }
    }
}
+49 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.AppOpsManager.MODE_IGNORED
import android.content.Context
import com.android.settings.R
import com.android.settingslib.spaprivileged.model.app.IPackageManagers
import com.android.settingslib.spaprivileged.model.app.PackageManagers
import com.android.settingslib.spaprivileged.template.app.AppOpPermissionListModel
import com.android.settingslib.spaprivileged.template.app.TogglePermissionAppListProvider

object WifiControlAppListProvider : TogglePermissionAppListProvider {
    override val permissionType = "WifiControl"
    override fun createModel(context: Context) = WifiControlAppListModel(context)
}

class WifiControlAppListModel(
    private val context: Context,
    private val packageManagers: IPackageManagers = PackageManagers
) : AppOpPermissionListModel(context, packageManagers) {
    override val pageTitleResId = R.string.change_wifi_state_title
    override val switchTitleResId = R.string.change_wifi_state_app_detail_switch
    override val footerResId = R.string.change_wifi_state_app_detail_summary

    override val appOp = AppOpsManager.OP_CHANGE_WIFI_STATE
    override val permission = Manifest.permission.CHANGE_WIFI_STATE

    /** NETWORK_SETTINGS permission trumps CHANGE_WIFI_CONFIG. */
    override val broaderPermission = Manifest.permission.NETWORK_SETTINGS
    override val permissionHasAppopFlag = false
    override val modeForNotAllowed = MODE_IGNORED
}
Loading