diff options
4 files changed, 66 insertions, 2 deletions
diff --git a/src/java/com/android/internal/telephony/GsmCdmaPhone.java b/src/java/com/android/internal/telephony/GsmCdmaPhone.java index 861feb639b..237a726d4d 100644 --- a/src/java/com/android/internal/telephony/GsmCdmaPhone.java +++ b/src/java/com/android/internal/telephony/GsmCdmaPhone.java @@ -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); } diff --git a/src/java/com/android/internal/telephony/Phone.java b/src/java/com/android/internal/telephony/Phone.java index 30d1591ebe..f9da65be25 100644 --- a/src/java/com/android/internal/telephony/Phone.java +++ b/src/java/com/android/internal/telephony/Phone.java @@ -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()) { diff --git a/src/java/com/android/internal/telephony/imsphone/ImsPhoneCallTracker.java b/src/java/com/android/internal/telephony/imsphone/ImsPhoneCallTracker.java index e02457b722..34fe7ee8f4 100644 --- a/src/java/com/android/internal/telephony/imsphone/ImsPhoneCallTracker.java +++ b/src/java/com/android/internal/telephony/imsphone/ImsPhoneCallTracker.java @@ -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); } diff --git a/tests/telephonytests/src/com/android/internal/telephony/imsphone/ImsPhoneCallTrackerTest.java b/tests/telephonytests/src/com/android/internal/telephony/imsphone/ImsPhoneCallTrackerTest.java index db3f29fe2f..713467790e 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/imsphone/ImsPhoneCallTrackerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/imsphone/ImsPhoneCallTrackerTest.java @@ -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 |