Merge "Migrate PlatformCompat App List to SPA" into udc-qpr-dev am: 879ff5f271 am: 78981afdc2

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/23410196

Change-Id: I09189fc2dfe6789db9c7745dd43cf5168c2e9dfc
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Chaohui Wang
2023-06-16 09:24:26 +00:00
committed by Automerger Merge Worker
9 changed files with 267 additions and 94 deletions

View File

@@ -37,6 +37,7 @@ import com.android.settings.spa.app.specialaccess.WifiControlAppListProvider
import com.android.settings.spa.app.specialaccess.UseFullScreenIntentAppListProvider
import com.android.settings.spa.core.instrumentation.SpaLogProvider
import com.android.settings.spa.development.UsageStatsPageProvider
import com.android.settings.spa.development.compat.PlatformCompatAppListPageProvider
import com.android.settings.spa.home.HomePageProvider
import com.android.settings.spa.network.NetworkAndInternetPageProvider
import com.android.settings.spa.notification.AppListNotificationsPageProvider
@@ -84,6 +85,7 @@ open class SettingsSpaEnvironment(context: Context) : SpaEnvironment(context) {
LanguageAndInputPageProvider,
AppLanguagesPageProvider,
UsageStatsPageProvider,
PlatformCompatAppListPageProvider,
BackgroundInstalledAppsPageProvider,
CloneAppInfoSettingsProvider,
NetworkAndInternetPageProvider,
@@ -97,5 +99,5 @@ open class SettingsSpaEnvironment(context: Context) : SpaEnvironment(context) {
override val logger =
if (FeatureFlagUtils.isEnabled(context, FeatureFlagUtils.SETTINGS_ENABLE_SPA_METRICS))
SpaLogProvider
else object: SpaLogger {}
else object : SpaLogger {}
}

View File

@@ -0,0 +1,38 @@
/*
* 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.development.compat
import android.os.Bundle
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import com.android.settings.R
import com.android.settingslib.spa.framework.common.SettingsPageProvider
import com.android.settingslib.spa.framework.compose.rememberContext
import com.android.settingslib.spaprivileged.template.app.AppListPage
object PlatformCompatAppListPageProvider : SettingsPageProvider {
override val name = "PlatformCompatAppList"
@Composable
override fun Page(arguments: Bundle?) {
AppListPage(
title = stringResource(R.string.platform_compat_dashboard_title),
listModel = rememberContext(::PlatformCompatAppListModel),
noItemMessage = stringResource(R.string.platform_compat_dialog_text_no_apps),
)
}
}

View File

@@ -0,0 +1,72 @@
/*
* 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.development.compat
import android.app.settings.SettingsEnums
import android.content.Context
import android.content.pm.ApplicationInfo
import android.os.Build
import androidx.compose.runtime.Composable
import androidx.core.os.bundleOf
import com.android.settings.core.SubSettingLauncher
import com.android.settings.development.compat.PlatformCompatDashboard
import com.android.settingslib.spa.framework.compose.stateOf
import com.android.settingslib.spa.framework.util.filterItem
import com.android.settingslib.spa.framework.util.mapItem
import com.android.settingslib.spaprivileged.model.app.AppListModel
import com.android.settingslib.spaprivileged.model.app.AppRecord
import com.android.settingslib.spaprivileged.model.app.hasFlag
import com.android.settingslib.spaprivileged.model.app.userHandle
import com.android.settingslib.spaprivileged.template.app.AppListItem
import com.android.settingslib.spaprivileged.template.app.AppListItemModel
import kotlinx.coroutines.flow.Flow
data class PlatformCompatAppRecord(
override val app: ApplicationInfo,
) : AppRecord
class PlatformCompatAppListModel(
private val context: Context,
) : AppListModel<PlatformCompatAppRecord> {
override fun transform(userIdFlow: Flow<Int>, appListFlow: Flow<List<ApplicationInfo>>) =
appListFlow.mapItem(::PlatformCompatAppRecord)
override fun filter(
userIdFlow: Flow<Int>, option: Int, recordListFlow: Flow<List<PlatformCompatAppRecord>>,
) = recordListFlow.filterItem { record ->
Build.IS_DEBUGGABLE || record.app.hasFlag(ApplicationInfo.FLAG_DEBUGGABLE)
}
@Composable
override fun getSummary(option: Int, record: PlatformCompatAppRecord) =
stateOf(record.app.packageName)
@Composable
override fun AppListItemModel<PlatformCompatAppRecord>.AppItem() {
AppListItem { navigateToAppCompat(app = record.app) }
}
private fun navigateToAppCompat(app: ApplicationInfo) {
SubSettingLauncher(context)
.setDestination(PlatformCompatDashboard::class.qualifiedName)
.setSourceMetricsCategory(SettingsEnums.DEVELOPMENT)
.setArguments(bundleOf(PlatformCompatDashboard.COMPAT_APP to app.packageName))
.setUserHandle(app.userHandle)
.launch()
}
}

View File

@@ -0,0 +1,34 @@
/*
* 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.development.compat
import android.content.Context
import androidx.preference.Preference
import com.android.settings.core.BasePreferenceController
import com.android.settings.spa.SpaActivity.Companion.startSpaActivity
class PlatformCompatPreferenceController(context: Context, preferenceKey: String) :
BasePreferenceController(context, preferenceKey) {
override fun getAvailabilityStatus() = AVAILABLE
override fun handlePreferenceTreeClick(preference: Preference): Boolean {
if (preference.key == mPreferenceKey) {
mContext.startSpaActivity(PlatformCompatAppListPageProvider.name)
return true
}
return false
}
}