use of com.android.settingslib.wifi.AccessPoint in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class WifiSettings method onAccessPointsChanged.
/**
* Shows the latest access points available with supplemental information like
* the strength of network and the security for it.
*/
@Override
public synchronized void onAccessPointsChanged() {
// Safeguard from some delayed event handling
if (getActivity() == null)
return;
if (isUiRestricted()) {
if (!isUiRestrictedByOnlyAdmin()) {
addMessagePreference(R.string.wifi_empty_list_user_restricted);
}
getPreferenceScreen().removeAll();
return;
}
final int wifiState = mWifiManager.getWifiState();
switch(wifiState) {
case WifiManager.WIFI_STATE_ENABLED:
// AccessPoints are automatically sorted with TreeSet.
final Collection<AccessPoint> accessPoints = mWifiTracker.getAccessPoints();
boolean hasAvailableAccessPoints = false;
int index = 0;
cacheRemoveAllPrefs(getPreferenceScreen());
for (AccessPoint accessPoint : accessPoints) {
// Ignore access points that are out of range.
if (accessPoint.getLevel() != -1) {
String key = accessPoint.getBssid();
if (TextUtils.isEmpty(key)) {
key = accessPoint.getSsidStr();
}
hasAvailableAccessPoints = true;
LongPressAccessPointPreference pref = (LongPressAccessPointPreference) getCachedPreference(key);
if (pref != null) {
pref.setOrder(index++);
continue;
}
LongPressAccessPointPreference preference = new LongPressAccessPointPreference(accessPoint, getPrefContext(), mUserBadgeCache, false, R.drawable.ic_wifi_signal_0, this);
preference.setKey(key);
preference.setOrder(index++);
if (mOpenSsid != null && mOpenSsid.equals(accessPoint.getSsidStr()) && !accessPoint.isSaved() && accessPoint.getSecurity() != AccessPoint.SECURITY_NONE) {
onPreferenceTreeClick(preference);
mOpenSsid = null;
}
getPreferenceScreen().addPreference(preference);
accessPoint.setListener(this);
preference.refresh();
}
}
removeCachedPrefs(getPreferenceScreen());
if (!hasAvailableAccessPoints) {
setProgressBarVisible(true);
Preference pref = new Preference(getContext()) {
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
// Show a line on each side of add network.
holder.setDividerAllowedBelow(true);
}
};
pref.setSelectable(false);
pref.setSummary(R.string.wifi_empty_list_wifi_on);
pref.setOrder(0);
pref.setKey(PREF_KEY_EMPTY_WIFI_LIST);
getPreferenceScreen().addPreference(pref);
mAddPreference.setOrder(1);
getPreferenceScreen().addPreference(mAddPreference);
} else {
mAddPreference.setOrder(index++);
getPreferenceScreen().addPreference(mAddPreference);
setProgressBarVisible(false);
}
if (mScanMenuItem != null) {
mScanMenuItem.setEnabled(true);
}
break;
case WifiManager.WIFI_STATE_ENABLING:
getPreferenceScreen().removeAll();
setProgressBarVisible(true);
break;
case WifiManager.WIFI_STATE_DISABLING:
addMessagePreference(R.string.wifi_stopping);
setProgressBarVisible(true);
break;
case WifiManager.WIFI_STATE_DISABLED:
setOffMessage();
setProgressBarVisible(false);
if (mScanMenuItem != null) {
mScanMenuItem.setEnabled(false);
}
break;
}
}
use of com.android.settingslib.wifi.AccessPoint in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SavedAccessPointsWifiSettings method onCreateDialog.
@Override
public Dialog onCreateDialog(int dialogId) {
switch(dialogId) {
case WifiSettings.WIFI_DIALOG_ID:
if (mDlgAccessPoint == null) {
// For re-launch from saved state
mDlgAccessPoint = new AccessPoint(getActivity(), mAccessPointSavedState);
// Reset the saved access point data
mAccessPointSavedState = null;
}
mSelectedAccessPoint = mDlgAccessPoint;
mDialog = new WifiDialog(getActivity(), this, mDlgAccessPoint, WifiConfigUiBase.MODE_VIEW, true);
return mDialog;
}
return super.onCreateDialog(dialogId);
}
use of com.android.settingslib.wifi.AccessPoint in project android_packages_apps_Settings by LineageOS.
the class SavedAccessPointsWifiSettings method onCreateDialog.
@Override
public Dialog onCreateDialog(int dialogId) {
switch(dialogId) {
case WifiSettings.WIFI_DIALOG_ID:
if (mDlgAccessPoint == null && mAccessPointSavedState == null) {
// Add new network
mDialog = WifiDialog.createFullscreen(getActivity(), this, null, WifiConfigUiBase.MODE_CONNECT);
} else {
// Modify network
if (mDlgAccessPoint == null) {
// Restore AP from save state
mDlgAccessPoint = new AccessPoint(getActivity(), mAccessPointSavedState);
// Reset the saved access point data
mAccessPointSavedState = null;
}
mDialog = WifiDialog.createModal(getActivity(), this, mDlgAccessPoint, WifiConfigUiBase.MODE_VIEW);
}
mSelectedAccessPoint = mDlgAccessPoint;
return mDialog;
}
return super.onCreateDialog(dialogId);
}
use of com.android.settingslib.wifi.AccessPoint in project android_packages_apps_Settings by LineageOS.
the class WifiDialogActivity method onForget.
@Override
public void onForget(WifiDialog dialog) {
final WifiManager wifiManager = getSystemService(WifiManager.class);
final AccessPoint accessPoint = dialog.getController().getAccessPoint();
if (accessPoint != null) {
if (!accessPoint.isSaved()) {
if (accessPoint.getNetworkInfo() != null && accessPoint.getNetworkInfo().getState() != NetworkInfo.State.DISCONNECTED) {
// Network is active but has no network ID - must be ephemeral.
wifiManager.disableEphemeralNetwork(AccessPoint.convertToQuotedString(accessPoint.getSsidStr()));
} else {
// Should not happen, but a monkey seems to trigger it
Log.e(TAG, "Failed to forget invalid network " + accessPoint.getConfig());
}
} else {
wifiManager.forget(accessPoint.getConfig().networkId, null);
}
}
Intent resultData = new Intent();
if (accessPoint != null) {
Bundle accessPointState = new Bundle();
accessPoint.saveWifiState(accessPointState);
resultData.putExtra(KEY_ACCESS_POINT_STATE, accessPointState);
}
setResult(RESULT_FORGET);
finish();
}
use of com.android.settingslib.wifi.AccessPoint in project android_packages_apps_Settings by LineageOS.
the class WifiDialogActivity method onSubmit.
@Override
public void onSubmit(WifiDialog dialog) {
final WifiConfiguration config = dialog.getController().getConfig();
final AccessPoint accessPoint = dialog.getController().getAccessPoint();
final WifiManager wifiManager = getSystemService(WifiManager.class);
if (config == null) {
if (accessPoint != null && accessPoint.isSaved()) {
wifiManager.connect(accessPoint.getConfig(), null);
}
} else {
wifiManager.save(config, null);
if (accessPoint != null) {
// accessPoint is null for "Add network"
NetworkInfo networkInfo = accessPoint.getNetworkInfo();
if (networkInfo == null || !networkInfo.isConnected()) {
wifiManager.connect(config, null);
}
}
}
Intent resultData = new Intent();
if (accessPoint != null) {
Bundle accessPointState = new Bundle();
accessPoint.saveWifiState(accessPointState);
resultData.putExtra(KEY_ACCESS_POINT_STATE, accessPointState);
}
if (config != null) {
resultData.putExtra(KEY_WIFI_CONFIGURATION, config);
}
setResult(RESULT_CONNECTED, resultData);
finish();
}
Aggregations