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

Commit 683fa212 authored by Fan Wu's avatar Fan Wu
Browse files

Add AppList screen for three permissions

Bug: 410684972
Bug: 409493290
Bug: 410433204
Test: Compile
Flag: com.android.settings.flags.device_state
Change-Id: I11b031d8b7e217907b393f791d8071c8308e3c49
parent 93a35f9c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ class AppInfoAllFilesAccessScreen(context: Context, override val arguments: Bund
            }
        }

        private fun ApplicationInfo.hasExternalStoragePermission(context: Context): Boolean =
        fun ApplicationInfo.hasExternalStoragePermission(context: Context): Boolean =
            try {
                val packageInfo: PackageInfo =
                    context.packageManager.getPackageInfo(
+1 −1
Original line number Diff line number Diff line
@@ -105,7 +105,7 @@ class AppInfoDisplayOverOtherAppsScreen(context: Context, override val arguments
            }
        }

        private fun ApplicationInfo.hasOverlayPermission(context: Context): Boolean =
        fun ApplicationInfo.hasOverlayPermission(context: Context): Boolean =
            try {
                val packageInfo: PackageInfo =
                    context.packageManager.getPackageInfo(
+1 −1
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ class AppInfoFullScreenIntentScreen(context: Context, override val arguments: Bu
            }
        }

        private fun ApplicationInfo.hasFullScreenPermission(context: Context): Boolean {
        fun ApplicationInfo.hasFullScreenPermission(context: Context): Boolean {
            return try {
                val packageInfo: PackageInfo =
                    context.packageManager.getPackageInfo(
+78 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.catalyst

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.android.settings.R
import com.android.settings.Settings.ManageExternalStorageActivity
import com.android.settings.contract.TAG_DEVICE_STATE_SCREEN
import com.android.settings.flags.Flags
import com.android.settings.spa.app.catalyst.AppInfoAllFilesAccessScreen.Companion.hasExternalStoragePermission
import com.android.settingslib.metadata.PreferenceHierarchy
import com.android.settingslib.metadata.PreferenceHierarchyGenerator
import com.android.settingslib.metadata.PreferenceMetadata
import com.android.settingslib.metadata.ProvidePreferenceScreen
import com.android.settingslib.metadata.asyncPreferenceHierarchy
import com.android.settingslib.metadata.preferenceHierarchy
import com.android.settingslib.preference.PreferenceFragment
import com.android.settingslib.preference.PreferenceScreenCreator
import com.android.settingslib.spaprivileged.model.app.AppListRepositoryImpl

@ProvidePreferenceScreen(AppsAllFilesAccessAppListScreen.KEY)
class AppsAllFilesAccessAppListScreen : PreferenceScreenCreator, PreferenceHierarchyGenerator<Boolean> {

    override val key: String
        get() = KEY

    override val title: Int
        get() = R.string.manage_external_storage_title

    override fun tags(context: Context) = arrayOf(TAG_DEVICE_STATE_SCREEN)

    override fun isFlagEnabled(context: Context) = Flags.deviceState()

    override fun hasCompleteHierarchy() = false

    override fun fragmentClass() = PreferenceFragment::class.java

    override fun getLaunchIntent(context: Context, metadata: PreferenceMetadata?): Intent =
        Intent(context, ManageExternalStorageActivity::class.java)

    override fun getPreferenceHierarchy(context: Context) = preferenceHierarchy(context, this) {}

    override val defaultType: Boolean
        get() = true // include system apps

    override suspend fun generatePreferenceHierarchy(
        context: Context,
        type: Boolean, // whether to include system apps
    ): PreferenceHierarchy =
        asyncPreferenceHierarchy(context, this) {
            AppListRepositoryImpl(context).loadAndFilterApps(context.userId, type).forEach {
                if (it.hasExternalStoragePermission(context)) {
                    val arguments = Bundle(1).apply { putString("app", it.packageName) }
                    +(AppInfoAllFilesAccessScreen.KEY args arguments)
                }
            }
        }

    companion object {
        const val KEY = "device_state_apps_all_files_access"
    }
}
+79 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.catalyst

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.android.settings.R
import com.android.settings.Settings.OverlaySettingsActivity
import com.android.settings.contract.TAG_DEVICE_STATE_SCREEN
import com.android.settings.flags.Flags
import com.android.settings.spa.app.catalyst.AppInfoDisplayOverOtherAppsScreen.Companion.hasOverlayPermission
import com.android.settingslib.metadata.PreferenceHierarchy
import com.android.settingslib.metadata.PreferenceHierarchyGenerator
import com.android.settingslib.metadata.PreferenceMetadata
import com.android.settingslib.metadata.ProvidePreferenceScreen
import com.android.settingslib.metadata.asyncPreferenceHierarchy
import com.android.settingslib.metadata.preferenceHierarchy
import com.android.settingslib.preference.PreferenceFragment
import com.android.settingslib.preference.PreferenceScreenCreator
import com.android.settingslib.spaprivileged.model.app.AppListRepositoryImpl

@ProvidePreferenceScreen(AppsDisplayOverOtherAppsAppListScreen.KEY)
class AppsDisplayOverOtherAppsAppListScreen :
    PreferenceScreenCreator, PreferenceHierarchyGenerator<Boolean> {

    override val key: String
        get() = KEY

    override val title: Int
        get() = R.string.draw_overlay

    override fun tags(context: Context) = arrayOf(TAG_DEVICE_STATE_SCREEN)

    override fun isFlagEnabled(context: Context) = Flags.deviceState()

    override fun hasCompleteHierarchy() = false

    override fun fragmentClass() = PreferenceFragment::class.java

    override fun getLaunchIntent(context: Context, metadata: PreferenceMetadata?): Intent =
        Intent(context, OverlaySettingsActivity::class.java)

    override fun getPreferenceHierarchy(context: Context) = preferenceHierarchy(context, this) {}

    override val defaultType: Boolean
        get() = true // include system apps

    override suspend fun generatePreferenceHierarchy(
        context: Context,
        type: Boolean, // whether to include system apps
    ): PreferenceHierarchy =
        asyncPreferenceHierarchy(context, this) {
            AppListRepositoryImpl(context).loadAndFilterApps(context.userId, type).forEach {
                if (it.hasOverlayPermission(context)) {
                    val arguments = Bundle(1).apply { putString("app", it.packageName) }
                    +(AppInfoDisplayOverOtherAppsScreen.KEY args arguments)
                }
            }
        }

    companion object {
        const val KEY = "device_state_apps_display_over_other_apps"
    }
}
Loading