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

Commit 6ecd39c1 authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Allow system dialer to use phone call FGS.

The OEM dialer should be allowed to start a phone call FGS even if it
does not hold ROLE_DIALER role.  The user may have chosen another app
to be their dialer app, however when the user places an emergency call
we will always fall back to the OEM dialer.  The OEM dialer is also
used as a fallback in the case where a user's chosen dialer crashes during
a call as it is seen as a more stable alternative to provide call control.

Fixes: 425971621
Flag: android.app.system_dialer_phone_call_fgs_grant
Test: Added testForegroundServiceTypePhoneCallSystemDialer CTS test.
Change-Id: I444d9e233d355751282abc9da7650f7fe7c6e3a5
parent 230f3ad0
Loading
Loading
Loading
Loading
+36 −1
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ import android.os.UserHandle;
import android.permission.PermissionCheckerManager;
import android.permission.PermissionManager;
import android.provider.DeviceConfig;
import android.telecom.TelecomManager;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
@@ -350,8 +351,13 @@ public abstract class ForegroundServiceTypePolicy {
                new RegularPermission(Manifest.permission.FOREGROUND_SERVICE_PHONE_CALL)
            }, true),
            new ForegroundServiceTypePermissions(new ForegroundServiceTypePermission[] {
                // For VoIP applications using the Telecom APIs.
                new RegularPermission(Manifest.permission.MANAGE_OWN_CALLS),
                new RolePermission(RoleManager.ROLE_DIALER)
                // For the user's chosen dialer app.
                new RolePermission(RoleManager.ROLE_DIALER),
                // For the OEM's preloaded Dialer (used for emergency calls even when the user has
                // chosen a different dialer app as their default).
                new SystemDialerPermission()
            }, false),
            FGS_TYPE_PERM_ENFORCEMENT_FLAG_PHONE_CALL /* permissionEnforcementFlag */,
            true /* permissionEnforcementFlagDefaultValue */,
@@ -1304,6 +1310,35 @@ public abstract class ForegroundServiceTypePolicy {
        }
    }

    /**
     * Represents the pre-loaded system dialer which is preloaded on a device.  Used in the
     * {@link #FGS_TYPE_POLICY_PHONE_CALL} to also allow the system dialer to be allowed to use a
     * phone call FGS.
     * <p>
     * When the user places an emergency call, Telecom will always bind to the pre-loaded system
     * dialer instead of the one filling the {@link RoleManager#ROLE_DIALER} role.  If the user has
     * chosen a different app to fill that role, the system dialer will not be able to start its
     * phone call FGS.
     */
    static class SystemDialerPermission extends ForegroundServiceTypePermission {
        SystemDialerPermission() {
            super("System Dialer");
        }

        @Override
        @PackageManager.PermissionResult
        public int checkPermission(@NonNull Context context, int callerUid, int callerPid,
                @NonNull String packageName, boolean allowWhileInUse) {
            if (!android.app.Flags.systemDialerPhoneCallFgsGrant()) {
                return PERMISSION_DENIED;
            }
            final TelecomManager tm = context.getSystemService(TelecomManager.class);
            final String systemDialerPackage = tm.getSystemDialerPackage();
            return systemDialerPackage != null && systemDialerPackage.equals(packageName)
                    ? PERMISSION_GRANTED : PERMISSION_DENIED;
        }
    }

    /**
     * This represents a special Android permission to be required for accessing usb devices.
     */
+10 −0
Original line number Diff line number Diff line
@@ -161,3 +161,13 @@ flag {
         purpose: PURPOSE_BUGFIX
     }
}

flag {
    namespace: "telecom"
    name: "system_dialer_phone_call_fgs_grant"
    description: "Ensures that the system dialer app can use a phone call fgs."
    bug: "425971621"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}