Skip Data usage in Settings Widgets
- Do not show data usage in Settings Widgets if the device does not support sim or there is the User Restricted of mobileMobileNetwork. Bug: 292998280 Test: Manual test [pass]make RunSettingsRoboTests ROBOTEST_FILTER=CreateShortcutPreferenceControllerTest Change-Id: I3984a43dc67e9efa92d06a4644b18d1799d56824
This commit is contained in:
committed by
SongFerngWang
parent
fdb53691b1
commit
8007efdbff
@@ -36,8 +36,11 @@ import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.content.pm.ShortcutManager;
|
||||
import android.content.res.Resources;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Settings;
|
||||
import com.android.settings.testutils.shadow.ShadowConnectivityManager;
|
||||
|
||||
@@ -69,6 +72,10 @@ public class CreateShortcutPreferenceControllerTest {
|
||||
private ShortcutManager mShortcutManager;
|
||||
@Mock
|
||||
private Activity mHost;
|
||||
@Mock
|
||||
private Resources mResources;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
|
||||
private Context mContext;
|
||||
private ShadowConnectivityManager mShadowConnectivityManager;
|
||||
@@ -188,6 +195,70 @@ public class CreateShortcutPreferenceControllerTest {
|
||||
assertThat(mController.queryShortcuts()).hasSize(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryShortcuts_configShowDataUsage_ShouldEnableShortcuts() {
|
||||
doReturn(true).when(mController).canShowDataUsage();
|
||||
setupActivityInfo(Settings.DataUsageSummaryActivity.class.getSimpleName());
|
||||
|
||||
assertThat(mController.queryShortcuts()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryShortcuts_configNotShowDataUsage_ShouldDisableShortcuts() {
|
||||
doReturn(false).when(mController).canShowDataUsage();
|
||||
setupActivityInfo(Settings.DataUsageSummaryActivity.class.getSimpleName());
|
||||
|
||||
assertThat(mController.queryShortcuts()).hasSize(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canShowDataUsage_configShowDataUsage_returnTrue() {
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
when(mResources.getBoolean(R.bool.config_show_sim_info)).thenReturn(true);
|
||||
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
|
||||
when(mUserManager.isGuestUser()).thenReturn(false);
|
||||
when(mUserManager.hasUserRestriction(
|
||||
UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)).thenReturn(false);
|
||||
|
||||
assertThat(mController.canShowDataUsage()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canShowDataUsage_noSimCapability_returnFalse() {
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
when(mResources.getBoolean(R.bool.config_show_sim_info)).thenReturn(false);
|
||||
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
|
||||
when(mUserManager.isGuestUser()).thenReturn(false);
|
||||
when(mUserManager.hasUserRestriction(
|
||||
UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)).thenReturn(false);
|
||||
|
||||
assertThat(mController.canShowDataUsage()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canShowDataUsage_isGuestUser_returnFalse() {
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
when(mResources.getBoolean(R.bool.config_show_sim_info)).thenReturn(true);
|
||||
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
|
||||
when(mUserManager.isGuestUser()).thenReturn(true);
|
||||
when(mUserManager.hasUserRestriction(
|
||||
UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)).thenReturn(false);
|
||||
|
||||
assertThat(mController.canShowDataUsage()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canShowDataUsage_isMobileNetworkUserRestricted_returnFalse() {
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
when(mResources.getBoolean(R.bool.config_show_sim_info)).thenReturn(true);
|
||||
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
|
||||
when(mUserManager.isGuestUser()).thenReturn(false);
|
||||
when(mUserManager.hasUserRestriction(
|
||||
UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)).thenReturn(true);
|
||||
|
||||
assertThat(mController.canShowDataUsage()).isFalse();
|
||||
}
|
||||
|
||||
private void setupActivityInfo(String name) {
|
||||
ResolveInfo ri = new ResolveInfo();
|
||||
ri.activityInfo = new ActivityInfo();
|
||||
|
Reference in New Issue
Block a user