Fix flicker of AppButtons
Also remove check for isSystemModule(), since it's also covered by AppUtils.isMainlineModule(). Bug: 236346018 Test: Unit test Test: Manually with Settings Change-Id: Icf8245145a2b2af98847db6040b9e5e930788d4f
This commit is contained in:
@@ -21,23 +21,21 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.remember
|
||||
import com.android.settingslib.applications.AppUtils
|
||||
import com.android.settingslib.spa.framework.compose.collectAsStateWithLifecycle
|
||||
import com.android.settingslib.spa.widget.button.ActionButton
|
||||
import com.android.settingslib.spa.widget.button.ActionButtons
|
||||
import com.android.settingslib.spaprivileged.model.app.isSystemModule
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@Composable
|
||||
fun AppButtons(packageInfoPresenter: PackageInfoPresenter) {
|
||||
if (remember(packageInfoPresenter) { packageInfoPresenter.isMainlineModule() }) return
|
||||
val presenter = remember { AppButtonsPresenter(packageInfoPresenter) }
|
||||
if (!presenter.isAvailableFlow.collectAsStateWithLifecycle(initialValue = false).value) return
|
||||
presenter.Dialogs()
|
||||
ActionButtons(actionButtons = presenter.rememberActionsButtons().value)
|
||||
}
|
||||
|
||||
private fun PackageInfoPresenter.isMainlineModule(): Boolean =
|
||||
AppUtils.isMainlineModule(userPackageManager, packageName)
|
||||
|
||||
private class AppButtonsPresenter(private val packageInfoPresenter: PackageInfoPresenter) {
|
||||
private val appLaunchButton = AppLaunchButton(packageInfoPresenter)
|
||||
private val appInstallButton = AppInstallButton(packageInfoPresenter)
|
||||
@@ -46,15 +44,6 @@ private class AppButtonsPresenter(private val packageInfoPresenter: PackageInfoP
|
||||
private val appClearButton = AppClearButton(packageInfoPresenter)
|
||||
private val appForceStopButton = AppForceStopButton(packageInfoPresenter)
|
||||
|
||||
val isAvailableFlow = flow { emit(isAvailable()) }
|
||||
|
||||
private suspend fun isAvailable(): Boolean = withContext(Dispatchers.IO) {
|
||||
!packageInfoPresenter.userPackageManager.isSystemModule(packageInfoPresenter.packageName) &&
|
||||
!AppUtils.isMainlineModule(
|
||||
packageInfoPresenter.userPackageManager, packageInfoPresenter.packageName
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun rememberActionsButtons() = remember {
|
||||
packageInfoPresenter.flow.map { packageInfo ->
|
||||
|
@@ -148,9 +148,7 @@ class PackageInfoPresenter(
|
||||
private fun getPackageInfo() =
|
||||
PackageManagers.getPackageInfoAsUser(
|
||||
packageName = packageName,
|
||||
flags = PackageManager.MATCH_DISABLED_COMPONENTS or
|
||||
PackageManager.GET_SIGNATURES or
|
||||
PackageManager.GET_PERMISSIONS,
|
||||
flags = PackageManager.MATCH_DISABLED_COMPONENTS or PackageManager.GET_PERMISSIONS,
|
||||
userId = userId,
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user