• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

packages/apps/Settings


Commit MetaInfo

Revisão020af77825326cb24acbdc4aaf276a6976f06444 (tree)
Hora2021-03-22 18:43:57
AutorWeng Su <wengsu@goog...>
CommiterWeng Su

Mensagem de Log

Hide edit menu if network is uneditable

- Screenshot:

Bug: 161896161
Test: manual test
make RunSettingsRoboTests ROBOTEST_FILTER=WifiNetworkDetailsFragment2Test

Merged-In: I47ea2cf19e178eff48f23e56903d0daa4ef8fa28
Change-Id: I47ea2cf19e178eff48f23e56903d0daa4ef8fa28
(cherry picked from commit b7dbd3a911ecec24bb7779fa7a85f1a5d6681d07)

Mudança Sumário

Diff

--- a/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2.java
+++ b/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2.java
@@ -75,7 +75,8 @@ public class WifiNetworkDetailsFragment2 extends DashboardFragment implements
7575 // Interval between initiating SavedNetworkTracker scans
7676 private static final long SCAN_INTERVAL_MILLIS = 10_000;
7777
78- private NetworkDetailsTracker mNetworkDetailsTracker;
78+ @VisibleForTesting
79+ NetworkDetailsTracker mNetworkDetailsTracker;
7980 private HandlerThread mWorkerThread;
8081 private WifiDetailPreferenceController2 mWifiDetailPreferenceController2;
8182 private List<WifiDialog2.WifiDialog2Listener> mWifiDialogListeners = new ArrayList<>();
@@ -125,9 +126,11 @@ public class WifiNetworkDetailsFragment2 extends DashboardFragment implements
125126
126127 @Override
127128 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
128- MenuItem item = menu.add(0, Menu.FIRST, 0, R.string.wifi_modify);
129- item.setIcon(com.android.internal.R.drawable.ic_mode_edit);
130- item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
129+ if (isEditable()) {
130+ MenuItem item = menu.add(0, Menu.FIRST, 0, R.string.wifi_modify);
131+ item.setIcon(com.android.internal.R.drawable.ic_mode_edit);
132+ item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
133+ }
131134 super.onCreateOptionsMenu(menu, inflater);
132135 }
133136
@@ -253,6 +256,17 @@ public class WifiNetworkDetailsFragment2 extends DashboardFragment implements
253256 getArguments().getString(KEY_CHOSEN_WIFIENTRY_KEY));
254257 }
255258
259+ private boolean isEditable() {
260+ if (mNetworkDetailsTracker == null) {
261+ return false;
262+ }
263+ final WifiEntry wifiEntry = mNetworkDetailsTracker.getWifiEntry();
264+ if (wifiEntry == null) {
265+ return false;
266+ }
267+ return wifiEntry.isSaved();
268+ }
269+
256270 /**
257271 * API call for refreshing the preferences in this fragment.
258272 */
--- a/tests/robotests/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2Test.java
+++ b/tests/robotests/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2Test.java
@@ -24,9 +24,9 @@ import static org.mockito.ArgumentMatchers.anyInt;
2424 import static org.mockito.ArgumentMatchers.eq;
2525 import static org.mockito.Mockito.doReturn;
2626 import static org.mockito.Mockito.mock;
27+import static org.mockito.Mockito.never;
2728 import static org.mockito.Mockito.spy;
2829 import static org.mockito.Mockito.verify;
29-import static org.mockito.Mockito.when;
3030
3131 import android.app.settings.SettingsEnums;
3232 import android.view.Menu;
@@ -36,12 +36,17 @@ import android.view.MenuItem;
3636 import androidx.preference.Preference;
3737 import androidx.preference.PreferenceScreen;
3838
39+import com.android.settings.R;
3940 import com.android.settings.core.BasePreferenceController;
4041 import com.android.settingslib.core.AbstractPreferenceController;
42+import com.android.wifitrackerlib.NetworkDetailsTracker;
43+import com.android.wifitrackerlib.WifiEntry;
4144
4245 import org.junit.Before;
4346 import org.junit.Test;
4447 import org.junit.runner.RunWith;
48+import org.mockito.Mock;
49+import org.mockito.MockitoAnnotations;
4550 import org.robolectric.RobolectricTestRunner;
4651 import org.robolectric.RuntimeEnvironment;
4752
@@ -52,11 +57,22 @@ public class WifiNetworkDetailsFragment2Test {
5257
5358 final String TEST_PREFERENCE_KEY = "TEST_PREFERENCE_KEY";
5459
60+ @Mock
61+ WifiEntry mWifiEntry;
62+ @Mock
63+ NetworkDetailsTracker mNetworkDetailsTracker;
64+ @Mock
65+ Menu mMenu;
5566 private WifiNetworkDetailsFragment2 mFragment;
5667
5768 @Before
5869 public void setUp() {
70+ MockitoAnnotations.initMocks(this);
71+ doReturn(mWifiEntry).when(mNetworkDetailsTracker).getWifiEntry();
72+ doReturn(true).when(mWifiEntry).isSaved();
73+
5974 mFragment = new WifiNetworkDetailsFragment2();
75+ mFragment.mNetworkDetailsTracker = mNetworkDetailsTracker;
6076 }
6177
6278 @Test
@@ -77,16 +93,24 @@ public class WifiNetworkDetailsFragment2Test {
7793
7894 @Test
7995 public void onCreateOptionsMenu_shouldSetCorrectIcon() {
80- final Menu menu = mock(Menu.class);
8196 final MenuItem menuItem = mock(MenuItem.class);
82- doReturn(menuItem).when(menu).add(anyInt(), eq(Menu.FIRST), anyInt(), anyInt());
97+ doReturn(menuItem).when(mMenu).add(anyInt(), eq(Menu.FIRST), anyInt(), anyInt());
8398
84- mFragment.onCreateOptionsMenu(menu, mock(MenuInflater.class));
99+ mFragment.onCreateOptionsMenu(mMenu, mock(MenuInflater.class));
85100
86101 verify(menuItem).setIcon(com.android.internal.R.drawable.ic_mode_edit);
87102 }
88103
89104 @Test
105+ public void onCreateOptionsMenu_isNotSavedNetwork_shouldNotAddEditMenu() {
106+ doReturn(false).when(mWifiEntry).isSaved();
107+
108+ mFragment.onCreateOptionsMenu(mMenu, mock(MenuInflater.class));
109+
110+ verify(mMenu, never()).add(anyInt(), anyInt(), anyInt(), eq(R.string.wifi_modify));
111+ }
112+
113+ @Test
90114 public void refreshPreferences_controllerShouldUpdateStateAndDisplayPreference() {
91115 final FakeFragment fragment = spy(new FakeFragment());
92116 final PreferenceScreen screen = mock(PreferenceScreen.class);