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

Commit fc138755 authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Ensure IMS dial uses the correct CLIR mode.

The IMS dial method was getting the shared pref CLIR_KEY to determine the
CLIR mode for an outgoing call.  Everywhere else in the code, the CLIR
mode is stored under key CLIR_KEY + phoneId, against the phoneId of the
Gsm/Cdma phone.
In ImsPhoneCallTracker, the default phone for the ImsPhone is the Gsm/Cdma
phone, and we need to use that id when accessing the key.
Also, added some more logging for oir mode sync/save.

Test: Manual
Bug: 64291602
Merged-In: I231f8fb74c29347da2085318b9ca42d5efec5271
Change-Id: I231f8fb74c29347da2085318b9ca42d5efec5271
parent 2c93941a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2028,6 +2028,7 @@ public class GsmCdmaPhone extends Phone {
    private void syncClirSetting() {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
        int clirSetting = sp.getInt(CLIR_KEY + getPhoneId(), -1);
        Rlog.i(LOG_TAG, "syncClirSetting: " + CLIR_KEY + getPhoneId() + "=" + clirSetting);
        if (clirSetting >= 0) {
            mCi.setCLIR(clirSetting, null);
        }
+2 −0
Original line number Diff line number Diff line
@@ -1328,6 +1328,8 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
        SharedPreferences.Editor editor = sp.edit();
        editor.putInt(CLIR_KEY + getPhoneId(), commandInterfaceCLIRMode);
        Rlog.i(LOG_TAG, "saveClirSetting: " + CLIR_KEY + getPhoneId() + "=" +
                commandInterfaceCLIRMode);

        // Commit and log the result.
        if (!editor.commit()) {
+31 −2
Original line number Diff line number Diff line
@@ -107,6 +107,10 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        void onPhoneStateChanged(PhoneConstants.State oldState, PhoneConstants.State newState);
    }

    public interface SharedPreferenceProxy {
        SharedPreferences getDefaultSharedPreferences(Context context);
    }

    private static final boolean DBG = true;

    // When true, dumps the state of ImsPhoneCallTracker after changes to foreground and background
@@ -585,6 +589,13 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
     */
    private boolean mShouldUpdateImsConfigOnDisconnect = false;

    /**
     * Default implementation for retrieving shared preferences; uses the actual PreferencesManager.
     */
    private SharedPreferenceProxy mSharedPreferenceProxy = (Context context) -> {
        return PreferenceManager.getDefaultSharedPreferences(context);
    };

    // Callback fires when ImsManager MMTel Feature changes state
    private ImsServiceProxy.INotifyStatusChanged mNotifyStatusChangedCallback = () -> {
        try {
@@ -654,6 +665,16 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        sendEmptyMessage(EVENT_GET_IMS_SERVICE);
    }

    /**
     * Test-only method used to mock out access to the shared preferences through the
     * {@link PreferenceManager}.
     * @param sharedPreferenceProxy
     */
    @VisibleForTesting
    public void setSharedPreferenceProxy(SharedPreferenceProxy sharedPreferenceProxy) {
        mSharedPreferenceProxy = sharedPreferenceProxy;
    }

    private PendingIntent createIncomingCallPendingIntent() {
        Intent intent = new Intent(ImsManager.ACTION_IMS_INCOMING_CALL);
        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
@@ -756,8 +777,16 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {

    public Connection dial(String dialString, int videoState, Bundle intentExtras) throws
            CallStateException {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
        int oirMode = sp.getInt(Phone.CLIR_KEY, CommandsInterface.CLIR_DEFAULT);
        int oirMode;
        if (mSharedPreferenceProxy != null && mPhone.getDefaultPhone() != null) {
            SharedPreferences sp = mSharedPreferenceProxy.getDefaultSharedPreferences(
                    mPhone.getContext());
            oirMode = sp.getInt(Phone.CLIR_KEY + mPhone.getDefaultPhone().getPhoneId(),
                    CommandsInterface.CLIR_DEFAULT);
        } else {
            loge("dial; could not get default CLIR mode.");
            oirMode = CommandsInterface.CLIR_DEFAULT;
        }
        return dial(dialString, oirMode, videoState, intentExtras);
    }

+32 −0
Original line number Diff line number Diff line
@@ -37,11 +37,13 @@ import static org.mockito.Mockito.verify;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.support.test.filters.FlakyTest;
import android.telecom.VideoProfile;
import android.telephony.PhoneNumberUtils;
import android.telephony.ims.feature.ImsFeature;
import android.test.suitebuilder.annotation.SmallTest;
@@ -56,6 +58,8 @@ import com.android.ims.ImsReasonInfo;
import com.android.ims.ImsServiceClass;
import com.android.ims.internal.ImsCallSession;
import com.android.internal.telephony.Call;
import com.android.internal.telephony.CallStateException;
import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.Connection;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyTest;
@@ -65,6 +69,7 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -80,6 +85,8 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest {
    private int mServiceId;
    @Mock
    private ImsCallSession mImsCallSession;
    @Mock
    private SharedPreferences mSharedPreferences;
    private Handler mCTHander;

    private class ImsCTHandlerThread extends HandlerThread {
@@ -347,6 +354,31 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest {
        assertEquals(Call.State.HOLDING, mCTUT.mBackgroundCall.getState());
    }

    /**
     * Ensures that the dial method will perform a shared preferences lookup using the correct
     * shared preference key to determine the CLIR mode.
     */
    @Test
    @SmallTest
    public void testDialClirMode() {
        mCTUT.setSharedPreferenceProxy((Context context) -> {
            return mSharedPreferences;
        });
        ArgumentCaptor<String> mStringCaptor = ArgumentCaptor.forClass(String.class);
        doReturn(CommandsInterface.CLIR_INVOCATION).when(mSharedPreferences).getInt(
                mStringCaptor.capture(), anyInt());

        try {
            mCTUT.dial("+17005554141", VideoProfile.STATE_AUDIO_ONLY, null);
        } catch (CallStateException cse) {
            cse.printStackTrace();
            Assert.fail("unexpected exception thrown" + cse.getMessage());
        }

        // Ensure that the correct key was queried from the shared prefs.
        assertEquals("clir_key0", mStringCaptor.getValue());
    }

    @FlakyTest
    @Test
    @SmallTest