Loading src/com/android/settings/spa/SettingsSpaEnvironment.kt +15 −11 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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, Loading @@ -52,6 +55,7 @@ open class SettingsSpaEnvironment(context: Context) : SpaEnvironment(context) { PictureInPictureListProvider, InstallUnknownAppsListProvider, AlarmsAndRemindersAppListProvider, WifiControlAppListProvider, ), ) SettingsPageProviderRepository( Loading src/com/android/settings/spa/app/specialaccess/InstallUnknownApps.kt +28 −21 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading @@ -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() } } src/com/android/settings/spa/app/specialaccess/PictureInPicture.kt +22 −19 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading @@ -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, Loading @@ -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) = Loading @@ -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() Loading src/com/android/settings/spa/app/specialaccess/SpecialAppAccess.kt +16 −12 Original line number Diff line number Diff line Loading @@ -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)) Loading @@ -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() } } } src/com/android/settings/spa/app/specialaccess/WifiControlApps.kt 0 → 100644 +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
src/com/android/settings/spa/SettingsSpaEnvironment.kt +15 −11 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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, Loading @@ -52,6 +55,7 @@ open class SettingsSpaEnvironment(context: Context) : SpaEnvironment(context) { PictureInPictureListProvider, InstallUnknownAppsListProvider, AlarmsAndRemindersAppListProvider, WifiControlAppListProvider, ), ) SettingsPageProviderRepository( Loading
src/com/android/settings/spa/app/specialaccess/InstallUnknownApps.kt +28 −21 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading @@ -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() } }
src/com/android/settings/spa/app/specialaccess/PictureInPicture.kt +22 −19 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading @@ -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, Loading @@ -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) = Loading @@ -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() Loading
src/com/android/settings/spa/app/specialaccess/SpecialAppAccess.kt +16 −12 Original line number Diff line number Diff line Loading @@ -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)) Loading @@ -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() } } }
src/com/android/settings/spa/app/specialaccess/WifiControlApps.kt 0 → 100644 +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 }