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

Commit 92991c93 authored by Pranav Madapurmath's avatar Pranav Madapurmath
Browse files

Resolve Telecom UserManager/UserInfo references

As part of telecom mainline prep, ensure that the references to hidden
APIs in UserManager and UserInfo are resolved.

Bug: 308024293
Bug: 311773409
Test: atest TelecomUnitTests
Change-Id: I488b7d10cea083d405c9f6bd2890fe782790e720
parent f5094557
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2083,7 +2083,7 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
                userHandle = mTargetPhoneAccountHandle.getUserHandle();
            }
            if (userHandle != null) {
                isWorkCall = UserUtil.isManagedProfile(mContext, userHandle);
                isWorkCall = UserUtil.isManagedProfile(mContext, userHandle, mFlags);
            }

            isCallRecordingToneSupported = (phoneAccount.hasCapabilities(
+10 −7
Original line number Diff line number Diff line
@@ -168,7 +168,8 @@ public class CallIntentProcessor {

        if (!callsManager.isSelfManaged(phoneAccountHandle,
                (UserHandle) intent.getParcelableExtra(KEY_INITIATING_USER))) {
            boolean fixedInitiatingUser = fixInitiatingUserIfNecessary(context, intent);
            boolean fixedInitiatingUser = fixInitiatingUserIfNecessary(
                    context, intent, featureFlags);
            // Show the toast to warn user that it is a personal call though initiated in work
            // profile.
            if (fixedInitiatingUser) {
@@ -226,16 +227,18 @@ public class CallIntentProcessor {
     *
     * @return whether the initiating user is fixed.
     */
    static boolean fixInitiatingUserIfNecessary(Context context, Intent intent) {
    static boolean fixInitiatingUserIfNecessary(Context context, Intent intent,
            FeatureFlags featureFlags) {
        final UserHandle initiatingUser = intent.getParcelableExtra(KEY_INITIATING_USER);
        if (UserUtil.isManagedProfile(context, initiatingUser)) {
        if (UserUtil.isManagedProfile(context, initiatingUser, featureFlags)) {
            boolean noDialerInstalled = DefaultDialerManager.getInstalledDialerApplications(context,
                    initiatingUser.getIdentifier()).size() == 0;
            if (noDialerInstalled) {
                final UserManager userManager = UserManager.get(context);
                UserHandle parentUserHandle =
                        userManager.getProfileParent(
                                initiatingUser.getIdentifier()).getUserHandle();
                final UserManager userManager = context.getSystemService(UserManager.class);
                UserHandle parentUserHandle = featureFlags.telecomResolveHiddenDependencies()
                        ? userManager.getProfileParent(initiatingUser)
                        : userManager.getProfileParent(initiatingUser.getIdentifier())
                                .getUserHandle();
                intent.putExtra(KEY_INITIATING_USER, parentUserHandle);

                Log.i(CallIntentProcessor.class, "fixInitiatingUserIfNecessary: no dialer installed"
+5 −2
Original line number Diff line number Diff line
@@ -369,7 +369,7 @@ public final class CallLogManager extends CallsManagerListenerBase {
        if (phoneAccount != null &&
                phoneAccount.hasCapabilities(PhoneAccount.CAPABILITY_MULTI_USER)) {
            if (initiatingUser != null &&
                    UserUtil.isManagedProfile(mContext, initiatingUser)) {
                    UserUtil.isManagedProfile(mContext, initiatingUser, mFeatureFlags)) {
                paramBuilder.setUserToBeInsertedTo(initiatingUser);
                paramBuilder.setAddForAllUsers(false);
            } else {
@@ -693,7 +693,10 @@ public final class CallLogManager extends CallsManagerListenerBase {

            // Use shadow provider based on current user unlock state.
            Uri providerUri;
            if (userManager.isUserUnlocked(currentUserId)) {
            boolean isCurrentUserUnlocked = mFeatureFlags.telecomResolveHiddenDependencies()
                    ? userManager.isUserUnlocked(UserHandle.CURRENT)
                    : userManager.isUserUnlocked(currentUserId);
            if (isCurrentUserUnlocked) {
                providerUri = Calls.CONTENT_URI;
            } else {
                providerUri = Calls.SHADOW_CONTENT_URI;
+62 −23
Original line number Diff line number Diff line
@@ -675,7 +675,7 @@ public class CallsManager extends Call.ListenerBase
                () -> audioManager.getStreamVolume(AudioManager.STREAM_RING) > 0);

        SystemSettingsUtil systemSettingsUtil = new SystemSettingsUtil();
        RingtoneFactory ringtoneFactory = new RingtoneFactory(this, context);
        RingtoneFactory ringtoneFactory = new RingtoneFactory(this, context, featureFlags);
        SystemVibrator systemVibrator = new SystemVibrator(context);
        mInCallController = inCallControllerFactory.create(context, mLock, this,
                systemStateHelper, defaultDialerCache, mTimeoutsAdapter,
@@ -748,7 +748,7 @@ public class CallsManager extends Call.ListenerBase
        mVoipCallMonitor.startMonitor();

        // There is no USER_SWITCHED broadcast for user 0, handle it here explicitly.
        final UserManager userManager = UserManager.get(mContext);
        final UserManager userManager = mContext.getSystemService(UserManager.class);
        // Don't load missed call if it is run in split user model.
        if (userManager.isPrimaryUser()) {
            onUserSwitch(Process.myUserHandle());
@@ -1676,9 +1676,15 @@ public class CallsManager extends Call.ListenerBase
        boolean isCallHiddenFromProfile = !isCallVisibleForUser(call, mCurrentUserHandle);
        // For admins, we should check if the work profile is paused in order to reject
        // the call.
        if (mUserManager.isUserAdmin(mCurrentUserHandle.getIdentifier())) {
            isCallHiddenFromProfile &= mUserManager.isQuietModeEnabled(
                call.getAssociatedUser());
        UserManager currentUserManager = mContext.createContextAsUser(mCurrentUserHandle, 0)
                .getSystemService(UserManager.class);
        boolean isCurrentUserAdmin = mFeatureFlags.telecomResolveHiddenDependencies()
                ? currentUserManager.isAdminUser()
                : mUserManager.isUserAdmin(mCurrentUserHandle.getIdentifier());
        if (isCurrentUserAdmin) {
            isCallHiddenFromProfile &= mFeatureFlags.telecomResolveHiddenDependencies()
                    ? currentUserManager.isQuietModeEnabled(call.getAssociatedUser())
                    : mUserManager.isQuietModeEnabled(call.getAssociatedUser());
        }

        // We should always allow emergency calls and also allow non-emergency calls when ECBM
@@ -2135,7 +2141,7 @@ public class CallsManager extends Call.ListenerBase
                                Uri callUri = callToPlace.getHandle();
                                if (PhoneAccount.SCHEME_TEL.equals(callUri.getScheme())) {
                                    int managedProfileUserId = getManagedProfileUserId(mContext,
                                            initiatingUser.getIdentifier());
                                            initiatingUser.getIdentifier(), mFeatureFlags);
                                    if (managedProfileUserId != UserHandle.USER_NULL
                                            &&
                                            mPhoneAccountRegistrar.getCallCapablePhoneAccounts(
@@ -2310,10 +2316,29 @@ public class CallsManager extends Call.ListenerBase
        return mLatestPostSelectionProcessingFuture;
    }

    private static int getManagedProfileUserId(Context context, int userId) {
        UserManager um = context.getSystemService(UserManager.class);
        List<UserInfo> userProfiles = um.getProfiles(userId);
        for (UserInfo uInfo : userProfiles) {
    private static int getManagedProfileUserId(Context context, int userId,
            FeatureFlags featureFlags) {
        UserManager um;
        UserHandle userHandle = UserHandle.of(userId);
        um = featureFlags.telecomResolveHiddenDependencies()
                ? context.createContextAsUser(userHandle, 0).getSystemService(UserManager.class)
                : context.getSystemService(UserManager.class);

        if (featureFlags.telecomResolveHiddenDependencies()) {
            List<UserHandle> userProfiles = um.getAllProfiles();
            for (UserHandle userProfile : userProfiles) {
                UserManager profileUserManager = context.createContextAsUser(userProfile, 0)
                        .getSystemService(UserManager.class);
                if (userProfile.getIdentifier() == userId) {
                    continue;
                }
                if (profileUserManager.isManagedProfile()) {
                    return userProfile.getIdentifier();
                }
            }
        } else {
            List<UserInfo> userInfoProfiles = um.getProfiles(userId);
            for (UserInfo uInfo : userInfoProfiles) {
                if (uInfo.id == userId) {
                    continue;
                }
@@ -2321,6 +2346,7 @@ public class CallsManager extends Call.ListenerBase
                    return uInfo.id;
                }
            }
        }
        return UserHandle.USER_NULL;
    }

@@ -2431,8 +2457,8 @@ public class CallsManager extends Call.ListenerBase
         boolean isSelfManaged = account != null && account.isSelfManaged();
         // Enforce outgoing call restriction for conference calls. This is handled via
         // UserCallIntentProcessor for normal MO calls.
         if (UserUtil.hasOutgoingCallsUserRestriction(mContext, initiatingUser,
                 null, isSelfManaged, CallsManager.class.getCanonicalName())) {
         if (UserUtil.hasOutgoingCallsUserRestriction(mContext, initiatingUser, null,
                 isSelfManaged, CallsManager.class.getCanonicalName(), mFeatureFlags)) {
             return;
         }
         CompletableFuture<Call> callFuture = startOutgoingCall(participants, phoneAccountHandle,
@@ -5453,19 +5479,30 @@ public class CallsManager extends Call.ListenerBase
        mCurrentUserHandle = userHandle;
        mMissedCallNotifier.setCurrentUserHandle(userHandle);
        mRoleManagerAdapter.setCurrentUserHandle(userHandle);
        final UserManager userManager = UserManager.get(mContext);
        List<UserInfo> profiles = userManager.getEnabledProfiles(userHandle.getIdentifier());
        for (UserInfo profile : profiles) {
        final UserManager userManager = mFeatureFlags.telecomResolveHiddenDependencies()
                ? mContext.createContextAsUser(userHandle, 0).getSystemService(
                        UserManager.class)
                : mContext.getSystemService(UserManager.class);
        List<UserHandle> profiles = userManager.getUserProfiles();
        List<UserInfo> userInfoProfiles = userManager.getEnabledProfiles(
                userHandle.getIdentifier());
        if (mFeatureFlags.telecomResolveHiddenDependencies()) {
            for (UserHandle profileUser : profiles) {
                reloadMissedCallsOfUser(profileUser);
            }
        } else {
            for (UserInfo profile : userInfoProfiles) {
                reloadMissedCallsOfUser(profile.getUserHandle());
            }
        }
    }

    /**
     * Because there may be chances that profiles are not started yet though its parent user is
     * switched, we reload missed calls of profile that are just started here.
     */
    void onUserStarting(UserHandle userHandle) {
        if (UserUtil.isProfile(mContext, userHandle)) {
        if (UserUtil.isProfile(mContext, userHandle, mFeatureFlags)) {
            reloadMissedCallsOfUser(userHandle);
        }
    }
@@ -5574,8 +5611,10 @@ public class CallsManager extends Call.ListenerBase
        UserManager userManager = mContext.getSystemService(UserManager.class);
        KeyguardManager keyguardManager = mContext.getSystemService(KeyguardManager.class);

        boolean isUserRestricted = userManager != null
                && userManager.hasUserRestriction(UserManager.DISALLOW_SMS, callingUser);
        boolean hasUserRestriction = mFeatureFlags.telecomResolveHiddenDependencies()
                ? userManager.hasUserRestrictionForUser(UserManager.DISALLOW_SMS, callingUser)
                : userManager.hasUserRestriction(UserManager.DISALLOW_SMS, callingUser);
        boolean isUserRestricted = userManager != null && hasUserRestriction;
        boolean isLockscreenRestricted = keyguardManager != null
                && keyguardManager.isDeviceLocked();
        Log.d(this, "isReplyWithSmsAllowed: isUserRestricted: %s, isLockscreenRestricted: %s",
+10 −4
Original line number Diff line number Diff line
@@ -361,7 +361,8 @@ public class InCallController extends CallsManagerListenerBase implements
            Log.i(this, "Attempting to bind to InCall %s, with %s", mInCallServiceInfo, intent);
            mIsConnected = true;
            mInCallServiceInfo.setBindingStartTime(mClockProxy.elapsedRealtime());
            boolean isManagedProfile = UserUtil.isManagedProfile(mContext, userFromCall);
            boolean isManagedProfile = UserUtil.isManagedProfile(mContext,
                    userFromCall, mFeatureFlags);
            // Note that UserHandle.CURRENT fails to capture the work profile, so we need to handle
            // it separately to ensure that the ICS is bound to the appropriate user. If ECBM is
            // active, we know that a work sim was previously used to place a MO emergency call. We
@@ -3111,7 +3112,13 @@ public class InCallController extends CallsManagerListenerBase implements
            return mCallsManager.getCurrentUserHandle();
        } else {
            UserHandle userFromCall = call.getAssociatedUser();
            UserManager userManager = mContext.getSystemService(UserManager.class);
            UserManager userManager = mFeatureFlags.telecomResolveHiddenDependencies()
                    ? mContext.createContextAsUser(mCallsManager.getCurrentUserHandle(), 0)
                            .getSystemService(UserManager.class)
                    : mContext.getSystemService(UserManager.class);
            boolean isCurrentUserAdmin = mFeatureFlags.telecomResolveHiddenDependencies()
                    ? userManager.isAdminUser()
                    : userManager.isUserAdmin(mCallsManager.getCurrentUserHandle().getIdentifier());
            // Emergency call should never be blocked, so if the user associated with the target
            // phone account handle user is in quiet mode, use the current user for the ecall.
            // Note, that this only applies to incoming calls that are received on assigned
@@ -3121,8 +3128,7 @@ public class InCallController extends CallsManagerListenerBase implements
                    && (userManager.isQuietModeEnabled(userFromCall)
                    // We should also account for secondary/guest users where the profile may not
                    // necessarily be paused.
                    || !userManager.isUserAdmin(mCallsManager.getCurrentUserHandle()
                    .getIdentifier()))) {
                    || !isCurrentUserAdmin)) {
                return mCallsManager.getCurrentUserHandle();
            }
            return userFromCall;
Loading