Refine TetherSettings

- Move TetherSettings to network/tether folder

- Refine unit tests

Bug: 237273138
Test: manual test
make RunSettingsRoboTests ROBOTEST_FILTER=TetherSettingsTest

Change-Id: I1eb79780df824c575e79047bdeb3a9276f061fe9
This commit is contained in:
Weng Su
2022-12-22 20:24:34 +08:00
parent a7d5801d28
commit f077b83586
6 changed files with 23 additions and 17 deletions

View File

@@ -760,7 +760,7 @@
<category android:name="android.intent.category.VOICE_LAUNCH" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.TetherSettings" />
android:value="com.android.settings.network.tether.TetherSettings" />
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_network"/>
</activity>
@@ -792,7 +792,7 @@
android:exported="true"
android:targetActivity="Settings$TetherSettingsActivity">
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.TetherSettings" />
android:value="com.android.settings.network.tether.TetherSettings" />
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_network"/>
</activity-alias>

View File

@@ -72,7 +72,7 @@
settings:useAdminDisabledSummary="true" />
<com.android.settingslib.RestrictedPreference
android:fragment="com.android.settings.TetherSettings"
android:fragment="com.android.settings.network.tether.TetherSettings"
android:key="tether_settings"
android:title="@string/tether_settings_title_all"
android:icon="@drawable/ic_wifi_tethering"

View File

@@ -23,7 +23,6 @@ import com.android.settings.MainClear;
import com.android.settings.MainClearConfirm;
import com.android.settings.Settings;
import com.android.settings.TestingSettings;
import com.android.settings.TetherSettings;
import com.android.settings.TrustedCredentialsSettings;
import com.android.settings.accessibility.AccessibilityDetailsSettingsFragment;
import com.android.settings.accessibility.AccessibilitySettings;
@@ -138,6 +137,7 @@ import com.android.settings.network.apn.ApnEditor;
import com.android.settings.network.apn.ApnSettings;
import com.android.settings.network.telephony.MobileNetworkSettings;
import com.android.settings.network.telephony.NetworkSelectSettings;
import com.android.settings.network.tether.TetherSettings;
import com.android.settings.nfc.AndroidBeam;
import com.android.settings.nfc.PaymentSettings;
import com.android.settings.notification.ConfigureNotificationSettings;

View File

@@ -28,9 +28,9 @@ import android.os.UserHandle;
import android.os.UserManager;
import com.android.settings.R;
import com.android.settings.TetherSettings;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.homepage.contextualcards.ContextualCard;
import com.android.settings.network.tether.TetherSettings;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtilsInternal;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008 The Android Open Source Project
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings;
package com.android.settings.network.tether;
import static android.net.ConnectivityManager.TETHERING_BLUETOOTH;
import static android.net.ConnectivityManager.TETHERING_USB;
@@ -53,6 +53,9 @@ import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import com.android.settings.R;
import com.android.settings.RestrictedSettingsFragment;
import com.android.settings.Utils;
import com.android.settings.core.FeatureFlags;
import com.android.settings.datausage.DataSaverBackend;
import com.android.settings.search.BaseSearchIndexProvider;
@@ -69,7 +72,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
/*
/**
* Displays preferences for Tethering.
*/
@SearchIndexable
@@ -368,8 +371,9 @@ public class TetherSettings extends RestrictedSettingsFragment
registerReceiver();
mEthernetListener = new EthernetListener(this);
if (mEm != null)
if (mEm != null) {
mEm.addInterfaceStateListener(r -> mHandler.post(r), mEthernetListener);
}
updateUsbState();
updateBluetoothAndEthernetState();
@@ -384,8 +388,9 @@ public class TetherSettings extends RestrictedSettingsFragment
}
getActivity().unregisterReceiver(mTetherChangeReceiver);
mTm.unregisterTetheringEventCallback(mTetheringEventCallback);
if (mEm != null)
if (mEm != null) {
mEm.removeInterfaceStateListener(mEthernetListener);
}
mTetherChangeReceiver = null;
mStartTetheringCallback = null;
mTetheringEventCallback = null;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 The Android Open Source Project
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings;
package com.android.settings.network.tether;
import static android.content.Intent.ACTION_MEDIA_SHARED;
import static android.content.Intent.ACTION_MEDIA_UNSHARED;
@@ -53,6 +53,7 @@ import androidx.fragment.app.FragmentActivity;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import com.android.settings.R;
import com.android.settings.core.FeatureFlags;
import com.android.settingslib.RestrictedSwitchPreference;
@@ -141,7 +142,7 @@ public class TetherSettingsTest {
when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
final List<String> niks =
TetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
TetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
assertThat(niks).contains(TetherSettings.KEY_USB_TETHER_SETTINGS);
}
@@ -154,7 +155,7 @@ public class TetherSettingsTest {
when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[]{"fakeRegex"});
final List<String> niks =
TetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
TetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
assertThat(niks).doesNotContain(TetherSettings.KEY_USB_TETHER_SETTINGS);
}
@@ -164,7 +165,7 @@ public class TetherSettingsTest {
when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
final List<String> niks =
TetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
TetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
assertThat(niks).contains(TetherSettings.KEY_ENABLE_BLUETOOTH_TETHERING);
}
@@ -176,7 +177,7 @@ public class TetherSettingsTest {
.thenReturn(new String[]{"fakeRegex"});
final List<String> niks =
TetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
TetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
assertThat(niks).doesNotContain(TetherSettings.KEY_ENABLE_BLUETOOTH_TETHERING);
}
@@ -362,7 +363,7 @@ public class TetherSettingsTest {
}
private void updateOnlyBluetoothState(TetherSettings tetherSettings) {
doReturn(mTetheringManager).when(tetherSettings)
doReturn(mTetheringManager).when(mContext)
.getSystemService(Context.TETHERING_SERVICE);
when(mTetheringManager.getTetherableIfaces()).thenReturn(new String[0]);
when(mTetheringManager.getTetheredIfaces()).thenReturn(new String[0]);