Remove Modify popup menu for non-admin
- Don't add the Modify ContextMenu if the user is not an admin.
Bug: 237672190
Test: manual test
make RunSettingsRoboTests ROBOTEST_FILTER=NetworkProviderSettingsTest
Change-Id: I62e0f5559fa2315450221fcb71e348af59af9549
diff --git a/src/com/android/settings/network/NetworkProviderSettings.java b/src/com/android/settings/network/NetworkProviderSettings.java
index 1c480e0..c5295e6 100644
--- a/src/com/android/settings/network/NetworkProviderSettings.java
+++ b/src/com/android/settings/network/NetworkProviderSettings.java
@@ -34,6 +34,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.PowerManager;
+import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.telephony.TelephonyManager;
@@ -598,10 +599,7 @@
return;
}
- if (mSelectedWifiEntry.isSaved() && mSelectedWifiEntry.getConnectedState()
- != WifiEntry.CONNECTED_STATE_CONNECTED) {
- menu.add(Menu.NONE, MENU_ID_MODIFY, 0 /* order */, R.string.wifi_modify);
- }
+ addModifyMenuIfSuitable(menu, mSelectedWifiEntry);
}
@VisibleForTesting
@@ -621,6 +619,14 @@
}
}
+ @VisibleForTesting
+ void addModifyMenuIfSuitable(ContextMenu menu, WifiEntry wifiEntry) {
+ if (mIsAdmin && wifiEntry.isSaved()
+ && wifiEntry.getConnectedState() != WifiEntry.CONNECTED_STATE_CONNECTED) {
+ menu.add(Menu.NONE, MENU_ID_MODIFY, 0 /* order */, R.string.wifi_modify);
+ }
+ }
+
private boolean canForgetNetwork() {
return mSelectedWifiEntry.canForget() && !WifiUtils.isNetworkLockedDown(getActivity(),
mSelectedWifiEntry.getWifiConfiguration());
@@ -643,6 +649,12 @@
() -> launchWifiDppConfiguratorActivity(mSelectedWifiEntry));
return true;
case MENU_ID_MODIFY:
+ if (!mIsAdmin) {
+ Log.e(TAG, "Can't modify Wi-Fi because the user isn't admin.");
+ EventLog.writeEvent(0x534e4554, "237672190", UserHandle.myUserId(),
+ "User isn't admin");
+ return true;
+ }
showDialog(mSelectedWifiEntry, WifiConfigUiBase2.MODE_MODIFY);
return true;
default:
diff --git a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
index 5122def..3589184 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
@@ -17,9 +17,11 @@
import static com.android.settings.network.NetworkProviderSettings.MENU_ID_DISCONNECT;
import static com.android.settings.network.NetworkProviderSettings.MENU_ID_FORGET;
+import static com.android.settings.network.NetworkProviderSettings.MENU_ID_MODIFY;
import static com.android.settings.network.NetworkProviderSettings.MENU_ID_SHARE;
import static com.android.settings.wifi.WifiConfigUiBase2.MODE_CONNECT;
import static com.android.settings.wifi.WifiConfigUiBase2.MODE_MODIFY;
+import static com.android.wifitrackerlib.WifiEntry.CONNECTED_STATE_DISCONNECTED;
import static com.google.common.truth.Truth.assertThat;
@@ -730,6 +732,28 @@
}
@Test
+ public void addModifyMenuIfSuitable_isAdmin_addMenu() {
+ mNetworkProviderSettings.mIsAdmin = true;
+ when(mWifiEntry.isSaved()).thenReturn(true);
+ when(mWifiEntry.getConnectedState()).thenReturn(CONNECTED_STATE_DISCONNECTED);
+
+ mNetworkProviderSettings.addModifyMenuIfSuitable(mContextMenu, mWifiEntry);
+
+ verify(mContextMenu).add(anyInt(), eq(MENU_ID_MODIFY), anyInt(), anyInt());
+ }
+
+ @Test
+ public void addModifyMenuIfSuitable_isNotAdmin_notAddMenu() {
+ mNetworkProviderSettings.mIsAdmin = false;
+ when(mWifiEntry.isSaved()).thenReturn(true);
+ when(mWifiEntry.getConnectedState()).thenReturn(CONNECTED_STATE_DISCONNECTED);
+
+ mNetworkProviderSettings.addModifyMenuIfSuitable(mContextMenu, mWifiEntry);
+
+ verify(mContextMenu, never()).add(anyInt(), eq(MENU_ID_MODIFY), anyInt(), anyInt());
+ }
+
+ @Test
public void getNonIndexableKeys_allowedChangeWifiState_keyNotReturned() {
when(mWifiRestriction.isChangeWifiStateAllowed(mContext)).thenReturn(true);
NetworkProviderSettings.SearchIndexProvider searchIndexProvider =