Remove Wi-Fi hotspot from settings search for non-admin users
- Don't use ViewModel if the settings UI is restricted Bug: 284931681 Test: manual test atest -c WifiTetherSettingsTest Change-Id: I3ae23b01b3be821c3560552b39cbd83ab51b2095
This commit is contained in:
@@ -91,7 +91,8 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
WifiTetherAutoOffPreferenceController mWifiTetherAutoOffPreferenceController;
|
WifiTetherAutoOffPreferenceController mWifiTetherAutoOffPreferenceController;
|
||||||
|
|
||||||
private boolean mUnavailable;
|
@VisibleForTesting
|
||||||
|
boolean mUnavailable;
|
||||||
private WifiRestriction mWifiRestriction;
|
private WifiRestriction mWifiRestriction;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
TetherChangeReceiver mTetherChangeReceiver;
|
TetherChangeReceiver mTetherChangeReceiver;
|
||||||
@@ -139,6 +140,9 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
|||||||
|
|
||||||
setIfOnlyAvailableForAdmins(true);
|
setIfOnlyAvailableForAdmins(true);
|
||||||
mUnavailable = isUiRestricted() || !mWifiRestriction.isHotspotAvailable(getContext());
|
mUnavailable = isUiRestricted() || !mWifiRestriction.isHotspotAvailable(getContext());
|
||||||
|
if (mUnavailable) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mWifiTetherViewModel = FeatureFactory.getFactory(getContext()).getWifiFeatureProvider()
|
mWifiTetherViewModel = FeatureFactory.getFactory(getContext()).getWifiFeatureProvider()
|
||||||
.getWifiTetherViewModel(this);
|
.getWifiTetherViewModel(this);
|
||||||
@@ -342,7 +346,16 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isPageSearchEnabled(Context context) {
|
protected boolean isPageSearchEnabled(Context context) {
|
||||||
if (context == null || !WifiUtils.canShowWifiHotspot(context)) return false;
|
if (context == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
UserManager userManager = context.getSystemService(UserManager.class);
|
||||||
|
if (userManager == null || !userManager.isAdminUser()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!WifiUtils.canShowWifiHotspot(context)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return !FeatureFlagUtils.isEnabled(context, FeatureFlags.TETHER_ALL_IN_ONE);
|
return !FeatureFlagUtils.isEnabled(context, FeatureFlags.TETHER_ALL_IN_ONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -146,6 +146,7 @@ public class WifiTetherSettingsTest {
|
|||||||
doReturn(mTetheringManager).when(mContext).getSystemService(Context.TETHERING_SERVICE);
|
doReturn(mTetheringManager).when(mContext).getSystemService(Context.TETHERING_SERVICE);
|
||||||
doReturn(WIFI_REGEXS).when(mTetheringManager).getTetherableWifiRegexs();
|
doReturn(WIFI_REGEXS).when(mTetheringManager).getTetherableWifiRegexs();
|
||||||
doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE);
|
doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE);
|
||||||
|
doReturn(true).when(mUserManager).isAdminUser();
|
||||||
when(mWifiRestriction.isTetherAvailable(mContext)).thenReturn(true);
|
when(mWifiRestriction.isTetherAvailable(mContext)).thenReturn(true);
|
||||||
when(mWifiRestriction.isHotspotAvailable(mContext)).thenReturn(true);
|
when(mWifiRestriction.isHotspotAvailable(mContext)).thenReturn(true);
|
||||||
|
|
||||||
@@ -184,10 +185,22 @@ public class WifiTetherSettingsTest {
|
|||||||
verify(mSettings).finish();
|
verify(mSettings).finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(shadows = ShadowRestrictedDashboardFragment.class)
|
||||||
|
public void onCreate_uiIsRestricted_shouldNotGetViewModel() {
|
||||||
|
mSettings.mWifiTetherViewModel = null;
|
||||||
|
when(mWifiRestriction.isHotspotAvailable(mContext)).thenReturn(false);
|
||||||
|
|
||||||
|
mSettings.onCreate(null);
|
||||||
|
|
||||||
|
assertThat(mSettings.mWifiTetherViewModel).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Config(shadows = ShadowFragment.class)
|
@Config(shadows = ShadowFragment.class)
|
||||||
public void onStart_uiIsRestricted_removeAllPreferences() {
|
public void onStart_uiIsRestricted_removeAllPreferences() {
|
||||||
spyWifiTetherSettings();
|
spyWifiTetherSettings();
|
||||||
|
mSettings.mUnavailable = true;
|
||||||
|
|
||||||
mSettings.onStart();
|
mSettings.onStart();
|
||||||
|
|
||||||
@@ -306,13 +319,21 @@ public class WifiTetherSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isPageSearchEnabled_canShowWifiHotspot_returnTrue() {
|
public void isPageSearchEnabled_allReady_returnTrue() {
|
||||||
setCanShowWifiHotspotCached(true);
|
setCanShowWifiHotspotCached(true);
|
||||||
|
|
||||||
assertThat(WifiTetherSettings.SEARCH_INDEX_DATA_PROVIDER.isPageSearchEnabled(mContext))
|
assertThat(WifiTetherSettings.SEARCH_INDEX_DATA_PROVIDER.isPageSearchEnabled(mContext))
|
||||||
.isTrue();
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isPageSearchEnabled_isNotAdminUser_returnFalse() {
|
||||||
|
doReturn(false).when(mUserManager).isAdminUser();
|
||||||
|
|
||||||
|
assertThat(WifiTetherSettings.SEARCH_INDEX_DATA_PROVIDER.isPageSearchEnabled(mContext))
|
||||||
|
.isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isPageSearchEnabled_canNotShowWifiHotspot_returnFalse() {
|
public void isPageSearchEnabled_canNotShowWifiHotspot_returnFalse() {
|
||||||
setCanShowWifiHotspotCached(false);
|
setCanShowWifiHotspotCached(false);
|
||||||
@@ -419,5 +440,10 @@ public class WifiTetherSettingsTest {
|
|||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
public boolean isUiRestricted() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user