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

Commit caf7b06d authored by Thomas Stuart's avatar Thomas Stuart Committed by Android (Google) Code Review
Browse files

Merge "replace hasBaseUserRestriction with getProfileParent" into main

parents 3b1ede05 cd23e5fc
Loading
Loading
Loading
Loading
+37 −2
Original line number Diff line number Diff line
@@ -117,8 +117,7 @@ public final class UserUtil {
                // Only emergency calls are allowed for users with the DISALLOW_OUTGOING_CALLS
                // restriction.
                if (!TelephonyUtil.shouldProcessAsEmergency(context, handle)) {
                    if (userManager.hasBaseUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS,
                            userHandle)) {
                    if (hasDisallowOutgoingCalls(context, userManager, userHandle, featureFlags)) {
                        String reason = "of DISALLOW_OUTGOING_CALLS restriction";
                        showErrorDialogForRestrictedOutgoingCall(context,
                                R.string.outgoing_call_not_allowed_user_restriction, tag, reason);
@@ -142,6 +141,42 @@ public final class UserUtil {
        return false;
    }

    /**
     * Checks if the {@link UserManager#DISALLOW_OUTGOING_CALLS} restriction is active for the given
     * user, correctly handling managed profiles by checking the restriction on the parent user.
     *
     * <p>This function determines the "base" user, which is the parent user for a profile or the
     * user itself otherwise. It then checks if the restriction is applied to that base user.
     *
     * @return {@code true} if outgoing calls are disallowed for the user, {@code false} otherwise.
     * Returns {@code false} if an error occurs during the check (e.g., missing permissions).
     */
    private static boolean hasDisallowOutgoingCalls(
            Context context,
            UserManager userManager,
            UserHandle user,
            FeatureFlags featureFlags){
        if(featureFlags.resolveHiddenDependenciesTwo()){
            UserHandle parent = userManager.getProfileParent(user);
            UserHandle baseUser = (parent != null) ? parent : user;
            try {
                Context baseUserContext = context.createContextAsUser(baseUser, 0);
                UserManager baseUserManager = baseUserContext.getSystemService(UserManager.class);
                if (baseUserManager != null) {
                    return baseUserManager.hasUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS);
                }
                return false;
            } catch (Exception e) {
                Log.e("UserUtil", e, "hasDisallowOutgoingCalls: caught exception");
                return false;
            }
        }
        else{
            return userManager.hasBaseUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS,
                    user);
        }
    }

    /**
     * Gets the associated user for the given call. Note: this is applicable to all calls except
     * outgoing calls as the associated user is already based off of the user placing the