Merge changes from topic "settings-visibility-return-fixes" into main
* changes: Return DISABLED_FOR_USER in deviceinfo/simstatus availability if not admin user Return UNSUPPORTED_ON_DEVICE in deviceinfo/simstatus when no telephony Added unit tests for SimStatusPreferenceController visibility Return DISABLED_FOR_USER in IMEI availability if not admin user Return UNSUPPORTED_ON_DEVICE in network/imei when no telephony Added unit test for MobileNetworkImeiPreferenceController visibility Added unit tests for ImeiInfoPreferenceController visibility Return UNSUPPORTED_ON_DEVICE in network/phonenumber when no telephony
This commit is contained in:
committed by
Android (Google) Code Review
commit
c9aaa03d7b
@@ -20,7 +20,7 @@ import static android.telephony.TelephonyManager.PHONE_TYPE_CDMA;
|
||||
import static android.telephony.TelephonyManager.PHONE_TYPE_GSM;
|
||||
import static android.telephony.TelephonyManager.PHONE_TYPE_NONE;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.Mockito.anyInt;
|
||||
@@ -43,6 +43,7 @@ import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.deviceinfo.simstatus.SlotSimStatus;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -90,11 +91,15 @@ public class ImeiInfoPreferenceControllerTest {
|
||||
|
||||
mResources = spy(mContext.getResources());
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
when(mResources.getBoolean(R.bool.config_show_sim_info)).thenReturn(true);
|
||||
|
||||
mockService(Context.TELEPHONY_SERVICE, TelephonyManager.class, mTelephonyManager);
|
||||
mockService(Context.USER_SERVICE, UserManager.class, mUserManager);
|
||||
|
||||
// Availability defaults
|
||||
when(mResources.getBoolean(R.bool.config_show_sim_info)).thenReturn(true);
|
||||
when(mTelephonyManager.isDataCapable()).thenReturn(true);
|
||||
when(mUserManager.isAdminUser()).thenReturn(true);
|
||||
|
||||
when(mScreen.getContext()).thenReturn(mContext);
|
||||
final String categoryKey = "device_detail_category";
|
||||
when(mScreen.findPreference(categoryKey)).thenReturn(mCategory);
|
||||
@@ -109,7 +114,6 @@ public class ImeiInfoPreferenceControllerTest {
|
||||
}
|
||||
});
|
||||
controller.init(mFragment, slotSimStatus);
|
||||
doReturn(AVAILABLE).when(controller).getAvailabilityStatus();
|
||||
doReturn(preference).when(controller).createNewPreference(mContext);
|
||||
|
||||
when(mScreen.findPreference(key)).thenReturn(preference);
|
||||
@@ -228,6 +232,42 @@ public class ImeiInfoPreferenceControllerTest {
|
||||
verify(mFragment).getChildFragmentManager();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_showSimInfo_telephonyDataCapable_userAdmindisplayed() {
|
||||
setupPhoneCount(1, PHONE_TYPE_GSM, PHONE_TYPE_NONE);
|
||||
|
||||
// Use defaults
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_notShowSimInfo_telephonyDataCapable_userAdmin_notDisplayed() {
|
||||
setupPhoneCount(1, PHONE_TYPE_GSM, PHONE_TYPE_NONE);
|
||||
|
||||
when(mResources.getBoolean(R.bool.config_show_sim_info)).thenReturn(false);
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_showSimInfo_notTelephonyDataCapable_userAdmin_notDisplayed() {
|
||||
setupPhoneCount(1, PHONE_TYPE_GSM, PHONE_TYPE_NONE);
|
||||
|
||||
when(mTelephonyManager.isDataCapable()).thenReturn(false);
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_showSimInfo_telephonyDataCapable_notUserAdmin_notDisplayed() {
|
||||
setupPhoneCount(1, PHONE_TYPE_GSM, PHONE_TYPE_NONE);
|
||||
|
||||
when(mUserManager.isAdminUser()).thenReturn(false);
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.DISABLED_FOR_USER);
|
||||
}
|
||||
|
||||
private <T> void mockService(String serviceName, Class<T> serviceClass, T service) {
|
||||
when(mContext.getSystemServiceName(serviceClass)).thenReturn(serviceName);
|
||||
when(mContext.getSystemService(serviceName)).thenReturn(service);
|
||||
|
@@ -44,9 +44,6 @@ import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.search.SearchIndexableRaw;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
@@ -57,6 +54,9 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SimStatusPreferenceControllerTest {
|
||||
|
||||
@@ -93,7 +93,6 @@ public class SimStatusPreferenceControllerTest {
|
||||
|
||||
mResources = spy(mContext.getResources());
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
when(mResources.getBoolean(R.bool.config_show_sim_info)).thenReturn(true);
|
||||
|
||||
mockService(Context.TELEPHONY_SERVICE, TelephonyManager.class, mTelephonyManager);
|
||||
mockService(Context.TELEPHONY_SUBSCRIPTION_SERVICE, SubscriptionManager.class,
|
||||
@@ -114,7 +113,12 @@ public class SimStatusPreferenceControllerTest {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
doReturn(BasePreferenceController.AVAILABLE).when(mController).getAvailabilityStatus();
|
||||
|
||||
// Availability defaults
|
||||
when(mResources.getBoolean(R.bool.config_show_sim_info)).thenReturn(true);
|
||||
when(mTelephonyManager.isDataCapable()).thenReturn(true);
|
||||
when(mUserManager.isAdminUser()).thenReturn(true);
|
||||
|
||||
when(mScreen.getContext()).thenReturn(mContext);
|
||||
final String categoryKey = "device_detail_category";
|
||||
when(mScreen.findPreference(categoryKey)).thenReturn(mCategory);
|
||||
@@ -210,6 +214,46 @@ public class SimStatusPreferenceControllerTest {
|
||||
assertThat(rawData.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_showSimInfo_telephonyDataCapable_userAdmindisplayed() {
|
||||
SlotSimStatus slotSimStatus = new TestSlotSimStatus(mContext);
|
||||
mController.init(mFragment, slotSimStatus);
|
||||
|
||||
// Use defaults
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_notShowSimInfo_telephonyDataCapable_userAdmin_notDisplayed() {
|
||||
SlotSimStatus slotSimStatus = new TestSlotSimStatus(mContext);
|
||||
mController.init(mFragment, slotSimStatus);
|
||||
|
||||
when(mResources.getBoolean(R.bool.config_show_sim_info)).thenReturn(false);
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_showSimInfo_notTelephonyDataCapable_userAdmin_notDisplayed() {
|
||||
SlotSimStatus slotSimStatus = new TestSlotSimStatus(mContext);
|
||||
mController.init(mFragment, slotSimStatus);
|
||||
|
||||
when(mTelephonyManager.isDataCapable()).thenReturn(false);
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_showSimInfo_telephonyDataCapable_notUserAdmin_notDisplayed() {
|
||||
SlotSimStatus slotSimStatus = new TestSlotSimStatus(mContext);
|
||||
mController.init(mFragment, slotSimStatus);
|
||||
|
||||
when(mUserManager.isAdminUser()).thenReturn(false);
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.DISABLED_FOR_USER);
|
||||
}
|
||||
|
||||
private <T> void mockService(String serviceName, Class<T> serviceClass, T service) {
|
||||
when(mContext.getSystemServiceName(serviceClass)).thenReturn(serviceName);
|
||||
when(mContext.getSystemService(serviceName)).thenReturn(service);
|
||||
|
Reference in New Issue
Block a user