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

Commit 93383385 authored by Pranav Madapurmath's avatar Pranav Madapurmath
Browse files

Support notion of ECBM for work profiles.

When we have all sims assigned to the work profile and the profile is
paused, the admin would not be able to place or receive any calls going
through those sims. However, when the primary user needs to place a MO
emergency call, we allow them to use the work sim for this boundary
case.

Consequently, this enables ECBM for that sim where any MT non-emergency
calls during the 5 minute period should not be rejected. If the work
profile is disabled, the call needs to be accepted by the primary
profile. EmergencyCallHelper already defines a notion of determining if
we're in ECBM but it's also being tracked for MT emergency calls and is
simply passing it up into ConnectionRequest. Instead, I've added in
logic to keep track of the last MO emergency call while keeping the old
logic intact. This is being leveraged in
CallsManager#processIncomingCallIntent to determine if the phone account
for the incoming call is currrently in ECBM, which would allow the call
to go through to the primary user instead of failing. Note that MO
non-emergency calls should still be rejected.

The logic in InCallController where we determine the user to use in
binding to the ICS needs to be modified to ensure we bind to the
CURRENT_USER (aka primary user) when the work profile is disabled and we
are in ECBM mode. Note that that MO emergency calls will never reach
this line of logic as they would be rejected in the phone account
selection phase so we can ensure that this is scoped to MT calls.

Fixes: 279200068
Test: Manual with work profile enabled to ensure MT/MO emergency calls
        and non-emergency calls are routed to work profile dialer.
Test: Manual with work profile disabled to ensure MT non-emergency calls
	are rejected when ECBM isn't enabled and allowed when it is
	enabled for the 5 minute time period.
Test: Unit tests to ensure we reject the MT non-emergency calls when
	ECBM isn't enabled and accept when it is. Addded a test to
	ensure the binding to the ICS occurs on the CURRENT_USER.
Change-Id: I4bbcd6a70cbdc206b829af68139fb6a8e218dd43
parent f74bea62
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -414,6 +414,16 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,

    private boolean mIsEmergencyCall;

    /**
     * Flag indicating if ECBM is active for the target phone account. This only applies to MT calls
     * in the scenario of work profiles (when the profile is paused and the user has only registered
     * a work sim). Normally, MT calls made to the work sim should be rejected when the work apps
     * are paused. However, when the admin makes a MO ecall, ECBM should be enabled for that sim to
     * allow non-emergency MT calls. MO calls don't apply because the phone account would be
     * rejected from selection if the owner is not placing the call.
     */
    private boolean mIsInECBM;

    // The Call is considered an emergency call for testing, but will not actually connect to
    // emergency services.
    private boolean mIsTestEmergencyCall;
@@ -1591,6 +1601,21 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
        return mIsTestEmergencyCall;
    }

    /**
     * @return {@code true} if the target phone account is in ECBM.
     */
    public boolean isInECBM() {
        return mIsInECBM;
    }

    /**
     * Set if the target phone account is in ECBM.
     * @param isInEcbm {@code true} if target phone account is in ECBM, {@code false} otherwise.
     */
    public void setIsInECBM(boolean isInECBM) {
        mIsInECBM = isInECBM;
    }

    /**
     * @return {@code true} if the network has identified this call as an emergency call.
     */
@@ -1682,6 +1707,11 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
    public void setTargetPhoneAccount(PhoneAccountHandle accountHandle) {
        if (!Objects.equals(mTargetPhoneAccountHandle, accountHandle)) {
            mTargetPhoneAccountHandle = accountHandle;
            // Update the last MO emergency call in the helper, if applicable.
            if (isEmergencyCall() && !isIncoming()) {
                mCallsManager.getEmergencyCallHelper().setLastOutgoingEmergencyCallPAH(
                        accountHandle);
            }
            for (Listener l : mListeners) {
                l.onTargetPhoneAccountChanged(this);
            }
+19 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static android.provider.CallLog.Calls.SHORT_RING_THRESHOLD;
import static android.provider.CallLog.Calls.USER_MISSED_CALL_FILTERS_TIMEOUT;
import static android.provider.CallLog.Calls.USER_MISSED_CALL_SCREENING_SERVICE_SILENCED;
import static android.provider.CallLog.Calls.USER_MISSED_NEVER_RANG;
import static android.provider.CallLog.Calls.USER_MISSED_NOT_RUNNING;
import static android.provider.CallLog.Calls.USER_MISSED_NO_ANSWER;
import static android.provider.CallLog.Calls.USER_MISSED_SHORT_RING;
import static android.telecom.TelecomManager.ACTION_POST_CALL;
@@ -446,6 +447,7 @@ public class CallsManager extends Call.ListenerBase
    private final CallStreamingController mCallStreamingController;
    private final BlockedNumbersAdapter mBlockedNumbersAdapter;
    private final TransactionManager mTransactionManager;
    private final UserManager mUserManager;

    private final ConnectionServiceFocusManager.CallsManagerRequester mRequester =
            new ConnectionServiceFocusManager.CallsManagerRequester() {
@@ -685,6 +687,7 @@ public class CallsManager extends Call.ListenerBase

        mCallAnomalyWatchdog = callAnomalyWatchdog;
        mAsyncTaskExecutor = asyncTaskExecutor;
        mUserManager = mContext.getSystemService(UserManager.class);
    }

    public void setIncomingCallNotifier(IncomingCallNotifier incomingCallNotifier) {
@@ -1534,7 +1537,22 @@ public class CallsManager extends Call.ListenerBase

        CallFailureCause startFailCause =
                checkIncomingCallPermitted(call, call.getTargetPhoneAccount());
        if (!isHandoverAllowed ||
        // Check if the target phone account is possibly in ECBM.
        call.setIsInECBM(getEmergencyCallHelper()
                .isLastOutgoingEmergencyCallPAH(call.getTargetPhoneAccount()));
        if (mUserManager.isQuietModeEnabled(call.getUserHandleFromTargetPhoneAccount())
                && !call.isEmergencyCall() && !call.isInECBM()) {
            Log.d(TAG, "Rejecting non-emergency call because the owner %s is not running.",
                    phoneAccountHandle.getUserHandle());
            call.setMissedReason(USER_MISSED_NOT_RUNNING);
            call.setStartFailCause(CallFailureCause.INVALID_USE);
            if (isConference) {
                notifyCreateConferenceFailed(phoneAccountHandle, call);
            } else {
                notifyCreateConnectionFailed(phoneAccountHandle, call);
            }
        }
        else if (!isHandoverAllowed ||
                (call.isSelfManaged() && !startFailCause.isSuccess())) {
            if (isConference) {
                notifyCreateConferenceFailed(phoneAccountHandle, call);
+33 −6
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.content.Context;
import android.content.pm.PackageManager;
import android.os.UserHandle;
import android.telecom.Log;
import android.telecom.PhoneAccountHandle;

import com.android.internal.annotations.VisibleForTesting;

/**
@@ -34,6 +36,7 @@ public class EmergencyCallHelper {
    private final DefaultDialerCache mDefaultDialerCache;
    private final Timeouts.Adapter mTimeoutsAdapter;
    private UserHandle mLocationPermissionGrantedToUser;
    private PhoneAccountHandle mLastOutgoingEmergencyCallPAH;

    //stores the original state of permissions that dialer had
    private boolean mHadFineLocation = false;
@@ -46,6 +49,7 @@ public class EmergencyCallHelper {
    private boolean mBackgroundLocationGranted = false;

    private long mLastEmergencyCallTimestampMillis;
    private long mLastOutgoingEmergencyCallTimestampMillis;

    @VisibleForTesting
    public EmergencyCallHelper(
@@ -63,7 +67,7 @@ public class EmergencyCallHelper {
            grantLocationPermission(userHandle);
        }
        if (call != null && call.isEmergencyCall()) {
            recordEmergencyCallTime();
            recordEmergencyCall(call);
        }
    }

@@ -78,15 +82,37 @@ public class EmergencyCallHelper {
        return mLastEmergencyCallTimestampMillis;
    }

    private void recordEmergencyCallTime() {
        mLastEmergencyCallTimestampMillis = System.currentTimeMillis();
    void setLastOutgoingEmergencyCallPAH(PhoneAccountHandle accountHandle) {
        mLastOutgoingEmergencyCallPAH = accountHandle;
    }

    public boolean isLastOutgoingEmergencyCallPAH(PhoneAccountHandle currentCallHandle) {
        boolean ecbmActive = mLastOutgoingEmergencyCallPAH != null
                && isInEmergencyCallbackWindow(mLastOutgoingEmergencyCallTimestampMillis)
                && currentCallHandle != null
                && currentCallHandle.equals(mLastOutgoingEmergencyCallPAH);
        if (ecbmActive) {
            Log.i(this, "ECBM is enabled for %s. The last recorded call timestamp was at %s",
                    currentCallHandle, mLastOutgoingEmergencyCallTimestampMillis);
        }

        return ecbmActive;
    }

    private boolean isInEmergencyCallbackWindow() {
        return System.currentTimeMillis() - getLastEmergencyCallTimeMillis()
    boolean isInEmergencyCallbackWindow(long lastEmergencyCallTimestampMillis) {
        return System.currentTimeMillis() - lastEmergencyCallTimestampMillis
                < mTimeoutsAdapter.getEmergencyCallbackWindowMillis(mContext.getContentResolver());
    }

    private void recordEmergencyCall(Call call) {
        mLastEmergencyCallTimestampMillis = System.currentTimeMillis();
        if (!call.isIncoming()) {
            // ECBM is applicable to MO emergency calls
            mLastOutgoingEmergencyCallTimestampMillis = mLastEmergencyCallTimestampMillis;
            mLastOutgoingEmergencyCallPAH = call.getTargetPhoneAccount();
        }
    }

    private boolean shouldGrantTemporaryLocationPermission(Call call) {
        if (!mContext.getResources().getBoolean(R.bool.grant_location_permission_enabled)) {
            Log.i(this, "ShouldGrantTemporaryLocationPermission, disabled by config");
@@ -96,7 +122,8 @@ public class EmergencyCallHelper {
            Log.i(this, "ShouldGrantTemporaryLocationPermission, no call");
            return false;
        }
        if (!call.isEmergencyCall() && !isInEmergencyCallbackWindow()) {
        if (!call.isEmergencyCall() && !isInEmergencyCallbackWindow(
                getLastEmergencyCallTimeMillis())) {
            Log.i(this, "ShouldGrantTemporaryLocationPermission, not emergency");
            return false;
        }
+6 −2
Original line number Diff line number Diff line
@@ -338,7 +338,10 @@ public class InCallController extends CallsManagerListenerBase implements
            UserHandle userToBind = getUserFromCall(call);
            boolean isManagedProfile = UserUtil.isManagedProfile(mContext, userToBind);
            // 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.
            // 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
            // need to ensure that we bind to the CURRENT_USER in this case, as the work user would
            // not be running (handled in getUserFromCall).
            userToBind = isManagedProfile ? userToBind : UserHandle.CURRENT;
            if (!mContext.bindServiceAsUser(intent, mServiceConnection,
                    Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
@@ -2601,7 +2604,8 @@ public class InCallController extends CallsManagerListenerBase implements
            UserManager userManager = mContext.getSystemService(UserManager.class);
            // Emergency call should never be blocked, so if the user associated with call is in
            // quite mode, use the primary user for the emergency call.
            if (call.isEmergencyCall() && userManager.isQuietModeEnabled(userFromCall)) {
            if ((call.isEmergencyCall() || call.isInECBM())
                    && userManager.isQuietModeEnabled(userFromCall)) {
                return mCallsManager.getCurrentUserHandle();
            }
            return userFromCall;
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import android.os.Binder;
import android.os.Bundle;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.BlockedNumberContract;
import android.telecom.Call;
import android.telecom.CallAudioState;
Loading