Restrict WiFi network connection
- Use StandardWifiEntry#canConnect() to determine if the network should be disabled or not. - Use StandardWifiEntry#getSummary() to retrieve the restriction message. - Disabled WiFi network if it cannot connect. - If WiFi network is connected or saved network, leave it enabled to disconnect or configure. - See the result screenshot in b/203168943#comment11 Bug: 203168938 Bug: 203168943 Test: manual test make RunSettingsRoboTests ROBOTEST_FILTER=LongPressWifiEntryPreferenceTest make RunSettingsRoboTests ROBOTEST_FILTER=NetworkProviderSettingsTest Change-Id: I04aafaa5b383598a0f87eea15d06b38bbc662b9e
This commit is contained in:
@@ -17,6 +17,7 @@ package com.android.settings.wifi;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
@@ -43,4 +44,23 @@ public class LongPressWifiEntryPreference extends WifiEntryPreference {
|
||||
view.itemView.setLongClickable(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
super.refresh();
|
||||
setEnabled(shouldEnabled());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean shouldEnabled() {
|
||||
WifiEntry wifiEntry = getWifiEntry();
|
||||
if (wifiEntry == null) return false;
|
||||
|
||||
boolean enabled = wifiEntry.canConnect();
|
||||
// If Wi-Fi is connected or saved network, leave it enabled to disconnect or configure.
|
||||
if (!enabled && (wifiEntry.canDisconnect() || wifiEntry.isSaved())) {
|
||||
enabled = true;
|
||||
}
|
||||
return enabled;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user