import android.view.View;
import androidx.annotation.DrawableRes;
+import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
/**
* An AP preference for the currently connected AP
*/
-public class ConnectedAccessPointPreference extends AccessPointPreference implements
+public class ConnectedAccessPointPreference extends LongPressAccessPointPreference implements
View.OnClickListener {
private OnGearClickListener mOnGearClickListener;
private boolean mIsCaptivePortal;
public ConnectedAccessPointPreference(AccessPoint accessPoint, Context context,
- UserBadgeCache cache, @DrawableRes int iconResId, boolean forSavedNetworks) {
- super(accessPoint, context, cache, iconResId, forSavedNetworks);
+ UserBadgeCache cache, @DrawableRes int iconResId, boolean forSavedNetworks,
+ Fragment fragment) {
+ super(accessPoint, context, cache, forSavedNetworks, iconResId, fragment);
}
@Override
import com.android.settings.widget.SwitchBarController;
import com.android.settings.wifi.details.WifiNetworkDetailsFragment;
import com.android.settings.wifi.dpp.WifiDppUtils;
-import com.android.settings.wifi.savedaccesspoints.SavedAccessPointsWifiSettings;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.search.SearchIndexable;
private static final String TAG = "WifiSettings";
private static final int MENU_ID_CONNECT = Menu.FIRST + 6;
- private static final int MENU_ID_FORGET = Menu.FIRST + 7;
+ @VisibleForTesting
+ static final int MENU_ID_FORGET = Menu.FIRST + 7;
private static final int MENU_ID_MODIFY = Menu.FIRST + 8;
public static final int WIFI_DIALOG_ID = 1;
((LongPressAccessPointPreference) preference).getAccessPoint();
menu.setHeaderTitle(mSelectedAccessPoint.getTitle());
if (mSelectedAccessPoint.isConnectable()) {
- menu.add(Menu.NONE, MENU_ID_CONNECT, 0, R.string.wifi_menu_connect);
+ menu.add(Menu.NONE, MENU_ID_CONNECT, 0 /* order */, R.string.wifi_connect);
}
WifiConfiguration config = mSelectedAccessPoint.getConfig();
return;
}
- if (mSelectedAccessPoint.isSaved() || mSelectedAccessPoint.isEphemeral()) {
- // Allow forgetting a network if either the network is saved or ephemerally
- // connected. (In the latter case, "forget" blacklists the network so it won't
- // be used again, ephemerally).
- menu.add(Menu.NONE, MENU_ID_FORGET, 0, R.string.wifi_menu_forget);
+ // "forget" for normal saved network. And "disconnect" for ephemeral network because we
+ // could only disconnect it and put it in blacklists so it won't be used again.
+ if (mSelectedAccessPoint.isEphemeral()) {
+ menu.add(Menu.NONE, MENU_ID_FORGET, 0 /* order */,
+ R.string.wifi_disconnect_button_text);
+ } else if (mSelectedAccessPoint.isSaved()) {
+ menu.add(Menu.NONE, MENU_ID_FORGET, 0 /* order */, R.string.forget);
}
- if (mSelectedAccessPoint.isSaved()) {
- menu.add(Menu.NONE, MENU_ID_MODIFY, 0, R.string.wifi_menu_modify);
+
+ if (mSelectedAccessPoint.isSaved() && !mSelectedAccessPoint.isActive()) {
+ menu.add(Menu.NONE, MENU_ID_MODIFY, 0 /* order */, R.string.wifi_modify);
}
}
}
}
@NonNull
- private ConnectedAccessPointPreference createConnectedAccessPointPreference(
- AccessPoint accessPoint) {
- return new ConnectedAccessPointPreference(accessPoint, getPrefContext(), mUserBadgeCache,
- R.drawable.ic_wifi_signal_0, false /* forSavedNetworks */);
+ @VisibleForTesting
+ ConnectedAccessPointPreference createConnectedAccessPointPreference(
+ AccessPoint accessPoint, Context context) {
+ return new ConnectedAccessPointPreference(accessPoint, context, mUserBadgeCache,
+ R.drawable.ic_wifi_signal_0, false /* forSavedNetworks */, this);
}
/**
*/
private void addConnectedAccessPointPreference(AccessPoint connectedAp) {
final ConnectedAccessPointPreference pref =
- createConnectedAccessPointPreference(connectedAp);
+ createConnectedAccessPointPreference(connectedAp, getPrefContext());
registerCaptivePortalNetworkCallback(getCurrentWifiNetwork(), pref);
// Launch details page or captive portal on click.
import android.os.UserManager;
import android.provider.Settings;
+import android.view.ContextMenu;
+import android.view.View;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.Preference;
import com.android.settings.datausage.DataUsagePreference;
import com.android.settings.search.SearchIndexableRaw;
import com.android.settings.testutils.shadow.ShadowDataUsageUtils;
+import com.android.settingslib.wifi.AccessPoint;
import com.android.settingslib.wifi.WifiTracker;
import org.junit.Before;
verify(mDataUsagePreference).setVisible(true);
verify(mDataUsagePreference).setTemplate(any(), eq(0) /*subId*/, eq(null) /*service*/);
}
+
+ @Test
+ public void onCreateContextMenu_shouldHaveForgetMenuForConnectedAccessPreference() {
+ final FragmentActivity mockActivity = mock(FragmentActivity.class);
+ when(mockActivity.getApplicationContext()).thenReturn(mContext);
+ when(mWifiSettings.getActivity()).thenReturn(mockActivity);
+
+ final AccessPoint accessPoint = mock(AccessPoint.class);
+ when(accessPoint.isConnectable()).thenReturn(false);
+ when(accessPoint.isSaved()).thenReturn(true);
+ when(accessPoint.isActive()).thenReturn(true);
+
+ final ConnectedAccessPointPreference connectedPreference =
+ mWifiSettings.createConnectedAccessPointPreference(accessPoint, mContext);
+ final View view = mock(View.class);
+ when(view.getTag()).thenReturn(connectedPreference);
+
+ final ContextMenu menu = mock(ContextMenu.class);
+ mWifiSettings.onCreateContextMenu(menu, view, null /* info */);
+
+ verify(menu).add(anyInt(), eq(WifiSettings.MENU_ID_FORGET), anyInt(), anyInt());
+ }
}