Only evaluate the appops when the preflight check says soft denied

.. in the permission check of the foreground service type policy.

Bug: 254662522
Bug: 246792057
Test: atest CtsAppFgsTestCases
Change-Id: I83c6bd370481b1404ba12fa1c7b6d99d3daabca8
This commit is contained in:
Jing Ji
2022-12-01 21:52:11 -08:00
parent 8af9e2cddd
commit bf16066bfe

View File

@@ -58,6 +58,7 @@ import android.hardware.usb.UsbManager;
import android.healthconnect.HealthConnectManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.permission.PermissionCheckerManager;
import android.util.ArraySet;
import android.util.SparseArray;
@@ -880,11 +881,12 @@ public abstract class ForegroundServiceTypePolicy {
int checkPermission(@NonNull Context context, @NonNull String name, int callerUid,
int callerPid, String packageName, boolean allowWhileInUse) {
// Simple case, check if it's already granted.
if (PermissionChecker.checkPermissionForPreflight(context, name,
callerPid, callerUid, packageName) == PERMISSION_GRANTED) {
@PackageManager.PermissionResult int result;
if ((result = PermissionChecker.checkPermissionForPreflight(context, name,
callerPid, callerUid, packageName)) == PERMISSION_GRANTED) {
return PERMISSION_GRANTED;
}
if (allowWhileInUse) {
if (allowWhileInUse && result == PermissionCheckerManager.PERMISSION_SOFT_DENIED) {
// Check its appops
final int opCode = AppOpsManager.permissionToOpCode(name);
final AppOpsManager appOpsManager = context.getSystemService(AppOpsManager.class);