Show policy transparent of "Force stop" when no DO

PackageManager.isPackageStateProtected() is moving to permission based,
so force stop button can also be protected when no DeviceOwner.

The ActivityManger side has already handled correctly, no Settings UI
side need to show a device policy transparent dialog.

Fix: 319579347
Test: manual - Force stop on AppInfo
Test: unit test
Change-Id: I4432dcb798a0cfcbb6bfc8b30c9191dd91b980a2
This commit is contained in:
Chaohui Wang
2024-01-11 17:02:55 +08:00
parent 59d67c3dc2
commit 52ebf58566
2 changed files with 98 additions and 49 deletions

View File

@@ -19,6 +19,7 @@ package com.android.settings.spa.app.appinfo
import android.app.settings.SettingsEnums
import android.content.pm.ApplicationInfo
import android.os.UserManager
import androidx.annotation.VisibleForTesting
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Report
import androidx.compose.material3.Text
@@ -87,9 +88,10 @@ class AppForceStopButton(
dialogPresenter.open()
}
private fun getAdminRestriction(app: ApplicationInfo): EnforcedAdmin? = when {
@VisibleForTesting
fun getAdminRestriction(app: ApplicationInfo): EnforcedAdmin? = when {
packageManager.isPackageStateProtected(app.packageName, app.userId) -> {
RestrictedLockUtilsInternal.getDeviceOwner(context)
RestrictedLockUtilsInternal.getDeviceOwner(context) ?: EnforcedAdmin()
}
else -> RestrictedLockUtilsInternal.checkIfRestrictionEnforced(