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

Commit fc2c4e01 authored by Mahesh Telang's avatar Mahesh Telang Committed by Pranav Madapurmath
Browse files

Self-Managed calls are not permitted on secondary user

As per current design, Self-Managed calls are not permitted on
secondary user. Only outgoing Emergency calls are allowed for secondary user.

Bug: 157267643
Test: CTS
Change-Id: I3153ba3d4539afeacde9b7c38995a66c8b26b639
parent 257676d1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1813,7 +1813,7 @@ public class TelecomServiceImpl {
                        }
                        mUserCallIntentProcessorFactory.create(mContext, userHandle)
                                .processIntent(
                                        intent, callingPackage, isSelfManaged ||
                                        intent, callingPackage, isSelfManaged,
                                                (hasCallAppOp && hasCallPermission),
                                        true /* isLocalInvocation */);
                    } finally {
+2 −1
Original line number Diff line number Diff line
@@ -74,7 +74,8 @@ public class UserCallActivity extends Activity implements TelecomSystem.Componen
            // ActivityThread.ActivityClientRecord#intent directly.
            // Modifying directly may be a potential risk when relaunching this activity.
            new UserCallIntentProcessor(this, userHandle).processIntent(new Intent(intent),
                    getCallingPackage(), true /* hasCallAppOp*/, false /* isLocalInvocation */);
                    getCallingPackage(), false, true /* hasCallAppOp*/,
                    false /* isLocalInvocation */);
        } finally {
            Log.endSession();
            wakelock.release();
+36 −31
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ public class UserCallIntentProcessor {
     *
     * @param intent The intent.
     * @param callingPackageName The package name of the calling app.
     * @param isSelfManaged      {@code true} if SelfManaged profile enabled.
     * @param canCallNonEmergency {@code true} if the caller is permitted to call non-emergency
     *                            numbers.
     * @param isLocalInvocation {@code true} if the caller is within the system service (i.e. the
@@ -79,19 +80,21 @@ public class UserCallIntentProcessor {
     *                            service resides.
     */
    public void processIntent(Intent intent, String callingPackageName,
            boolean canCallNonEmergency, boolean isLocalInvocation) {
            boolean isSelfManaged, boolean canCallNonEmergency,
            boolean isLocalInvocation) {
        String action = intent.getAction();

        if (Intent.ACTION_CALL.equals(action) ||
                Intent.ACTION_CALL_PRIVILEGED.equals(action) ||
                Intent.ACTION_CALL_EMERGENCY.equals(action)) {
            processOutgoingCallIntent(intent, callingPackageName, canCallNonEmergency,
                    isLocalInvocation);
            processOutgoingCallIntent(intent, callingPackageName, isSelfManaged,
                    canCallNonEmergency, isLocalInvocation);
        }
    }

    private void processOutgoingCallIntent(Intent intent, String callingPackageName,
            boolean canCallNonEmergency, boolean isLocalInvocation) {
            boolean isSelfManaged, boolean canCallNonEmergency,
            boolean isLocalInvocation) {
        Uri handle = intent.getData();
        if (handle == null) return;
        String scheme = handle.getScheme();
@@ -102,21 +105,22 @@ public class UserCallIntentProcessor {
            handle = Uri.fromParts(PhoneAccount.SCHEME_SIP, uriString, null);
        }

        // Check DISALLOW_OUTGOING_CALLS restriction. Note: We are skipping this check in a managed
        // profile user because this check can always be bypassed by copying and pasting the phone
        // number into the personal dialer.
       if(!isSelfManaged && !isLocalInvocation) {
            // Check DISALLOW_OUTGOING_CALLS restriction. Note: We are skipping this
            // check in a managed profile user because this check can always be bypassed
            // by copying and pasting the phone number into the personal dialer.
            if (!UserUtil.isManagedProfile(mContext, mUserHandle)) {
                // Only emergency calls are allowed for users with the DISALLOW_OUTGOING_CALLS
                // restriction.
                if (!TelephonyUtil.shouldProcessAsEmergency(mContext, handle)) {
                final UserManager userManager = (UserManager) mContext.getSystemService(
                        Context.USER_SERVICE);
                    final UserManager userManager =
                            (UserManager) mContext.getSystemService(Context.USER_SERVICE);
                    if (userManager.hasBaseUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS,
                            mUserHandle)) {
                        showErrorDialogForRestrictedOutgoingCall(mContext,
                                R.string.outgoing_call_not_allowed_user_restriction);
                    Log.w(this, "Rejecting non-emergency phone call due to DISALLOW_OUTGOING_CALLS "
                            + "restriction");
                        Log.w(this, "Rejecting non-emergency phone call "
                                + "due to DISALLOW_OUTGOING_CALLS restriction");
                        return;
                    } else if (userManager.hasUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS,
                            mUserHandle)) {
@@ -134,6 +138,7 @@ public class UserCallIntentProcessor {
                    }
                }
            }
        }

        if (!canCallNonEmergency && !TelephonyUtil.shouldProcessAsEmergency(mContext, handle)) {
            showErrorDialogForRestrictedOutgoingCall(mContext,
+2 −2
Original line number Diff line number Diff line
@@ -1125,7 +1125,7 @@ public class TelecomServiceImplTest extends TelecomTestCase {
            boolean shouldNonEmergencyBeAllowed) {
        ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
        verify(mUserCallIntentProcessor).processIntent(intentCaptor.capture(), anyString(),
                eq(shouldNonEmergencyBeAllowed), eq(true));
                eq(false), eq(shouldNonEmergencyBeAllowed), eq(true));
        Intent capturedIntent = intentCaptor.getValue();
        assertEquals(Intent.ACTION_CALL, capturedIntent.getAction());
        assertEquals(expectedHandle, capturedIntent.getData());
@@ -1148,7 +1148,7 @@ public class TelecomServiceImplTest extends TelecomTestCase {
        }

        verify(mUserCallIntentProcessor, never())
                .processIntent(any(Intent.class), anyString(), anyBoolean(), eq(true));
                .processIntent(any(Intent.class), anyString(), eq(false), anyBoolean(), eq(true));
    }

    @SmallTest
+1 −1
Original line number Diff line number Diff line
@@ -761,7 +761,7 @@ public class TelecomSystemTest extends TelecomTestCase {
        final UserHandle userHandle = initiatingUser;
        Context localAppContext = mComponentContextFixture.getTestDouble().getApplicationContext();
        new UserCallIntentProcessor(localAppContext, userHandle).processIntent(
                actionCallIntent, null, true /* hasCallAppOp*/, false /* isLocal */);
                actionCallIntent, null, false, true /* hasCallAppOp*/, false /* isLocal */);
        // Wait for handler to start CallerInfo lookup.
        waitForHandlerAction(new Handler(Looper.getMainLooper()), TEST_TIMEOUT);
        // Send the CallerInfo lookup reply.