Merge "Allow the FGS with soft denied permission to start" into udc-dev am: 0b740a1388

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23156541

Change-Id: Id6e3ee7af069b8de476535c3a903b3e2a1deeeb7
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Jing Ji
2023-05-11 21:21:01 +00:00
committed by Automerger Merge Worker

View File

@@ -18,6 +18,7 @@ package android.app;
import static android.app.AppOpsManager.MODE_ALLOWED;
import static android.app.AppOpsManager.MODE_FOREGROUND;
import static android.app.AppOpsManager.MODE_IGNORED;
import static android.content.pm.PackageManager.PERMISSION_DENIED;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA;
@@ -1078,9 +1079,9 @@ 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.
@PackageManager.PermissionResult int result;
if ((result = PermissionChecker.checkPermissionForPreflight(context, name,
callerPid, callerUid, packageName)) == PERMISSION_GRANTED) {
@PermissionCheckerManager.PermissionResult int result;
if ((result = PermissionChecker.checkPermissionForPreflight(context, name, callerPid,
callerUid, packageName)) == PermissionCheckerManager.PERMISSION_GRANTED) {
return PERMISSION_GRANTED;
}
if (allowWhileInUse && result == PermissionCheckerManager.PERMISSION_SOFT_DENIED) {
@@ -1093,6 +1094,13 @@ public abstract class ForegroundServiceTypePolicy {
if (currentMode == MODE_FOREGROUND) {
// It's in foreground only mode and we're allowing while-in-use.
return PERMISSION_GRANTED;
} else if (currentMode == MODE_IGNORED) {
// If it's soft denied with the mode "ignore", semantically it's a silent
// failure and no exception should be thrown, we might not want to allow
// the FGS. However, since the user has agreed with this permission
// (otherwise it's going to be a hard denial), and we're allowing
// while-in-use here, it's safe to allow the FGS run here.
return PERMISSION_GRANTED;
}
}
}