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
diff --git a/src/com/android/settings/wifi/LongPressWifiEntryPreference.java b/src/com/android/settings/wifi/LongPressWifiEntryPreference.java
index c509f1a..6343e06 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 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 5763abd..5187ee3 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.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 @@
         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 0f51ef3..a5d63db 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.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 e99b640..e78f1c1 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.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.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;