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
This commit is contained in:
Weng Su
2022-10-26 16:31:00 +08:00
parent a7b9107027
commit dcfbccbfbc
2 changed files with 40 additions and 4 deletions

View File

@@ -17,9 +17,11 @@ package com.android.settings.network;
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;
@@ -729,6 +731,28 @@ public class NetworkProviderSettingsTest {
verify(mContextMenu, never()).add(anyInt(), eq(MENU_ID_FORGET), anyInt(), anyInt());
}
@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);