Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c62c2ac8 authored by Jing Ji's avatar Jing Ji
Browse files

Allow default dialer app to use the "phoneCall" FGS type.

Bug: 280003654
Test: atest CtsAppFgsTestCases
Change-Id: Idc00fb6a04b133c8ba455bb029a4f13f1d8bc64c
parent abbe7c56
Loading
Loading
Loading
Loading
+28 −1
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.app.compat.CompatChanges;
import android.app.role.RoleManager;
import android.compat.Compatibility;
import android.compat.annotation.ChangeId;
import android.compat.annotation.Disabled;
@@ -58,6 +59,7 @@ import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.permission.PermissionCheckerManager;
import android.provider.DeviceConfig;
import android.text.TextUtils;
@@ -74,6 +76,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;

/**
@@ -333,7 +336,8 @@ public abstract class ForegroundServiceTypePolicy {
                new RegularPermission(Manifest.permission.FOREGROUND_SERVICE_PHONE_CALL)
            }, true),
            new ForegroundServiceTypePermissions(new ForegroundServiceTypePermission[] {
                new RegularPermission(Manifest.permission.MANAGE_OWN_CALLS)
                new RegularPermission(Manifest.permission.MANAGE_OWN_CALLS),
                new RolePermission(RoleManager.ROLE_DIALER)
            }, false),
            FGS_TYPE_PERM_ENFORCEMENT_FLAG_PHONE_CALL /* permissionEnforcementFlag */,
            true /* permissionEnforcementFlagDefaultValue */
@@ -1122,6 +1126,29 @@ public abstract class ForegroundServiceTypePolicy {
        }
    }

    /**
     * This represents a particular role an app needs to hold for a specific service type.
     */
    static class RolePermission extends ForegroundServiceTypePermission {
        final String mRole;

        RolePermission(@NonNull String role) {
            super(role);
            mRole = role;
        }

        @Override
        @PackageManager.PermissionResult
        public int checkPermission(@NonNull Context context, int callerUid, int callerPid,
                String packageName, boolean allowWhileInUse) {
            final RoleManager rm = context.getSystemService(RoleManager.class);
            final List<String> holders = rm.getRoleHoldersAsUser(mRole,
                    UserHandle.getUserHandleForUid(callerUid));
            return holders != null && holders.contains(packageName)
                    ? PERMISSION_GRANTED : PERMISSION_DENIED;
        }
    }

    /**
     * This represents a special Android permission to be required for accessing usb devices.
     */
+2 −1
Original line number Diff line number Diff line
@@ -168,7 +168,8 @@ public class ServiceInfo extends ComponentInfo
     * <p>Starting foreground service with this type from apps targeting API level
     * {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} and later, will require permission
     * {@link android.Manifest.permission#FOREGROUND_SERVICE_PHONE_CALL} and
     * {@link android.Manifest.permission#MANAGE_OWN_CALLS}.
     * {@link android.Manifest.permission#MANAGE_OWN_CALLS} or holding the default
     * {@link android.app.role.RoleManager#ROLE_DIALER dialer role}.
     */
    @RequiresPermission(
            allOf = {
+2 −1
Original line number Diff line number Diff line
@@ -1618,7 +1618,8 @@
            {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} and above, starting a foreground
            service with this type will require permission
            {@link android.Manifest.permission#FOREGROUND_SERVICE_PHONE_CALL} and
            {@link android.Manifest.permission#MANAGE_OWN_CALLS}.
            {@link android.Manifest.permission#MANAGE_OWN_CALLS} or holding the default
            {@link android.app.role.RoleManager#ROLE_DIALER dialer role}.
        -->
        <flag name="phoneCall" value="0x04" />
        <!-- GPS, map, navigation location update.