Support phone number in Settings slices
- Let controller of phoner number extends BasePreferenceController, so it can be supported showing slice view by SettingsSliceProvider. Test: make RunSettingsRoboTests Bug: 74900516 Change-Id: Id98e6aac981025159a0530c6e0709ba0f2ebcd15
This commit is contained in:
@@ -16,8 +16,7 @@
|
||||
|
||||
package com.android.settings.deviceinfo;
|
||||
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
@@ -27,12 +26,14 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -41,7 +42,6 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class PhoneNumberPreferenceControllerTest {
|
||||
@@ -55,6 +55,8 @@ public class PhoneNumberPreferenceControllerTest {
|
||||
@Mock
|
||||
private SubscriptionInfo mSubscriptionInfo;
|
||||
@Mock
|
||||
private SubscriptionManager mSubscriptionManager;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
private Context mContext;
|
||||
@@ -63,9 +65,10 @@ public class PhoneNumberPreferenceControllerTest {
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = spy(new PhoneNumberPreferenceController(mContext));
|
||||
ReflectionHelpers.setField(mController, "mTelephonyManager", mTelephonyManager);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
||||
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
||||
mController = spy(new PhoneNumberPreferenceController(mContext, "phone_number"));
|
||||
final String prefKey = mController.getPreferenceKey();
|
||||
when(mScreen.findPreference(prefKey)).thenReturn(mPreference);
|
||||
when(mScreen.getContext()).thenReturn(mContext);
|
||||
@@ -75,17 +78,19 @@ public class PhoneNumberPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_shouldBeTrueIfCallCapable() {
|
||||
public void getAvailabilityStatus_isVoiceCapable_shouldBeAVAILABLE() {
|
||||
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
|
||||
|
||||
assertTrue(mController.isAvailable());
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_shouldBeFalseIfNotCallCapable() {
|
||||
public void getAvailabilityStatus_isNotVoiceCapable_shouldBeUNSUPPORTED_ON_DEVICE() {
|
||||
when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
|
||||
|
||||
assertFalse(mController.isAvailable());
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,4 +131,19 @@ public class PhoneNumberPreferenceControllerTest {
|
||||
mContext.getString(R.string.status_number_sim_slot, 2 /* sim slot */));
|
||||
verify(mSecondPreference).setSummary(phoneNumber);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_cannotGetActiveSubscriptionInfo_shouldShowUnknown() {
|
||||
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(null);
|
||||
|
||||
CharSequence primaryNumber = mController.getSummary();
|
||||
|
||||
assertThat(primaryNumber).isNotNull();
|
||||
assertThat(primaryNumber).isEqualTo(mContext.getString(R.string.device_info_default));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSliceable_shouldBeTrue() {
|
||||
assertThat(mController.isSliceable()).isTrue();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user