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

Commit cd23e5fc authored by Thomas Stuart's avatar Thomas Stuart
Browse files

replace hasBaseUserRestriction with getProfileParent

In support of the Telecom platform's mainline module cleanup, this
commit replaces a call to the hidden API `hasBaseUserRestriction`.

This approach provides full functional equivalence while aligning with
platform policy to eliminate dependencies on hidden APIs.

Flag: com.android.server.telecom.flags.resolve_hidden_dependencies_two
Fixes: 308491827
Test: existing unit tests + CTS
Change-Id: I87263f80a187996c3b4c53ca13b89fcad9bd0ca5
parent cab60804
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