Merge "Skip Data usage in Settings Widgets" into udc-qpr-dev am: 60afc1259f am: 33b6032bb2

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/24575008

Change-Id: I192fa19976ca932cabbf744915f6e4568ca391ac
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
SongFerng Wang
2023-09-05 03:44:34 +00:00
committed by Automerger Merge Worker
2 changed files with 86 additions and 0 deletions

View File

@@ -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;
@@ -192,6 +199,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();