From 10ef69316fea992525597a459515d2bbdc56b0ae Mon Sep 17 00:00:00 2001 From: Weng Su Date: Thu, 13 Oct 2022 03:52:08 +0800 Subject: [PATCH] Refine the check restriction function in WifiEntryPreference - Move checkRestrictionAndSetDisabled function from WifiEntryPreference to necessary child-classes to avoid impacting other child-classes such as SavedAccessPointsPreference. - Avoid adding ShadowRestrictedPreference to the unnecessary test class. Bug: 233871529 Test: manual test make RunSettingsRoboTests Change-Id: Ia2145401558b293b5f4eaa0860f83b7d3bbab548 --- .../android/settings/wifi/LongPressWifiEntryPreference.java | 2 ++ src/com/android/settings/wifi/WifiEntryPreference.java | 2 -- .../src/com/android/settings/wifi/WifiEntryPreferenceTest.java | 2 -- .../android/settings/wifi/dpp/WifiNetworkListFragmentTest.java | 3 --- 4 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/com/android/settings/wifi/LongPressWifiEntryPreference.java b/src/com/android/settings/wifi/LongPressWifiEntryPreference.java index c509f1ab929..6343e06e074 100644 --- a/src/com/android/settings/wifi/LongPressWifiEntryPreference.java +++ b/src/com/android/settings/wifi/LongPressWifiEntryPreference.java @@ -16,6 +16,7 @@ package com.android.settings.wifi; import android.content.Context; +import android.os.UserManager; import androidx.annotation.VisibleForTesting; import androidx.fragment.app.Fragment; @@ -33,6 +34,7 @@ public class LongPressWifiEntryPreference extends WifiEntryPreference { public LongPressWifiEntryPreference(Context context, WifiEntry wifiEntry, Fragment fragment) { super(context, wifiEntry); mFragment = fragment; + checkRestrictionAndSetDisabled(UserManager.DISALLOW_ADD_WIFI_CONFIG); } @Override diff --git a/src/com/android/settings/wifi/WifiEntryPreference.java b/src/com/android/settings/wifi/WifiEntryPreference.java index 5763abdbd81..5187ee3119c 100644 --- a/src/com/android/settings/wifi/WifiEntryPreference.java +++ b/src/com/android/settings/wifi/WifiEntryPreference.java @@ -21,7 +21,6 @@ import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.graphics.drawable.StateListDrawable; -import android.os.UserManager; import android.text.TextUtils; import android.view.View; import android.widget.ImageButton; @@ -88,7 +87,6 @@ public class WifiEntryPreference extends RestrictedPreference implements mWifiEntry = wifiEntry; mWifiEntry.setListener(this); mIconInjector = iconInjector; - checkRestrictionAndSetDisabled(UserManager.DISALLOW_ADD_WIFI_CONFIG); refresh(); } diff --git a/tests/robotests/src/com/android/settings/wifi/WifiEntryPreferenceTest.java b/tests/robotests/src/com/android/settings/wifi/WifiEntryPreferenceTest.java index 0f51ef3874a..a5d63dbd34d 100644 --- a/tests/robotests/src/com/android/settings/wifi/WifiEntryPreferenceTest.java +++ b/tests/robotests/src/com/android/settings/wifi/WifiEntryPreferenceTest.java @@ -40,13 +40,11 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; -import org.robolectric.annotation.Config; import java.util.ArrayList; import java.util.List; @RunWith(RobolectricTestRunner.class) -@Config(shadows = ShadowRestrictedPreference.class) public class WifiEntryPreferenceTest { private Context mContext; diff --git a/tests/robotests/src/com/android/settings/wifi/dpp/WifiNetworkListFragmentTest.java b/tests/robotests/src/com/android/settings/wifi/dpp/WifiNetworkListFragmentTest.java index e99b64003a2..e78f1c11348 100644 --- a/tests/robotests/src/com/android/settings/wifi/dpp/WifiNetworkListFragmentTest.java +++ b/tests/robotests/src/com/android/settings/wifi/dpp/WifiNetworkListFragmentTest.java @@ -36,7 +36,6 @@ import androidx.preference.Preference; import androidx.preference.PreferenceCategory; import androidx.test.InstrumentationRegistry; -import com.android.settings.wifi.ShadowRestrictedPreference; import com.android.settings.wifi.WifiEntryPreference; import com.android.wifitrackerlib.SavedNetworkTracker; import com.android.wifitrackerlib.WifiEntry; @@ -46,12 +45,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; -import org.robolectric.annotation.Config; import java.util.Arrays; @RunWith(RobolectricTestRunner.class) -@Config(shadows = ShadowRestrictedPreference.class) public class WifiNetworkListFragmentTest { private WifiNetworkListFragment mWifiNetworkListFragment; private Context mContext;