Make TetherSettings extend RestrictedDashboardFragment

RestrictedSettingsFragment is deprecated and no longer supported. To be
compatible with catalyst, change the super class to
RestrictedDashboardFragment.

Bug: 368359963
Test: atest TetherSettingsTest, manual test with the user restriction
Flag: EXEMPT N/A
Change-Id: If8c5af9d716c63fd33cb508394e7d13450c9d2e7
This commit is contained in:
Jason Chiu
2024-10-24 15:55:13 +08:00
parent b34562ef91
commit 8547d7ad96
2 changed files with 16 additions and 10 deletions

View File

@@ -54,8 +54,8 @@ import androidx.preference.Preference;
import androidx.preference.TwoStatePreference; import androidx.preference.TwoStatePreference;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.RestrictedSettingsFragment;
import com.android.settings.Utils; import com.android.settings.Utils;
import com.android.settings.dashboard.RestrictedDashboardFragment;
import com.android.settings.datausage.DataSaverBackend; import com.android.settings.datausage.DataSaverBackend;
import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.wifi.tether.WifiTetherPreferenceController; import com.android.settings.wifi.tether.WifiTetherPreferenceController;
@@ -75,7 +75,7 @@ import java.util.concurrent.atomic.AtomicReference;
* Displays preferences for Tethering. * Displays preferences for Tethering.
*/ */
@SearchIndexable @SearchIndexable
public class TetherSettings extends RestrictedSettingsFragment public class TetherSettings extends RestrictedDashboardFragment
implements DataSaverBackend.Listener { implements DataSaverBackend.Listener {
@VisibleForTesting @VisibleForTesting
@@ -143,11 +143,19 @@ public class TetherSettings extends RestrictedSettingsFragment
super(UserManager.DISALLOW_CONFIG_TETHERING); super(UserManager.DISALLOW_CONFIG_TETHERING);
} }
@Override
protected String getLogTag() {
return TAG;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.tether_prefs;
}
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
// Even when the UI is restricted, addPreferencesFromResource cannot be omitted.
addPreferencesFromResource(R.xml.tether_prefs);
setIfOnlyAvailableForAdmins(true); setIfOnlyAvailableForAdmins(true);
if (isUiRestricted()) { if (isUiRestricted()) {
return; return;

View File

@@ -54,7 +54,7 @@ import androidx.preference.Preference;
import androidx.preference.SwitchPreference; import androidx.preference.SwitchPreference;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.RestrictedSettingsFragment; import com.android.settings.dashboard.RestrictedDashboardFragment;
import com.android.settings.wifi.tether.WifiTetherPreferenceController; import com.android.settings.wifi.tether.WifiTetherPreferenceController;
import com.android.settingslib.RestrictedSwitchPreference; import com.android.settingslib.RestrictedSwitchPreference;
@@ -130,14 +130,12 @@ public class TetherSettingsTest {
} }
@Test @Test
@Config(shadows = ShadowRestrictedSettingsFragment.class) @Config(shadows = ShadowRestrictedDashboardFragment.class)
public void onCreate_isUiRestricted_doNotSetupViewModel() { public void onCreate_isUiRestricted_doNotSetupViewModel() {
doNothing().when(mTetherSettings).addPreferencesFromResource(anyInt());
when(mTetherSettings.isUiRestricted()).thenReturn(true); when(mTetherSettings.isUiRestricted()).thenReturn(true);
mTetherSettings.onCreate(null); mTetherSettings.onCreate(null);
verify(mTetherSettings).addPreferencesFromResource(anyInt());
verify(mTetherSettings, never()).setupViewModel(); verify(mTetherSettings, never()).setupViewModel();
} }
@@ -454,8 +452,8 @@ public class TetherSettingsTest {
} }
} }
@Implements(RestrictedSettingsFragment.class) @Implements(RestrictedDashboardFragment.class)
public static final class ShadowRestrictedSettingsFragment { public static final class ShadowRestrictedDashboardFragment {
@Implementation @Implementation
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
// do nothing // do nothing