Search in sources :

Example 1 with AccessPoint

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;
    }
}
Also used : AccessPointPreference(com.android.settingslib.wifi.AccessPointPreference) Preference(android.support.v7.preference.Preference) AccessPoint(com.android.settingslib.wifi.AccessPoint) PreferenceViewHolder(android.support.v7.preference.PreferenceViewHolder) AccessPoint(com.android.settingslib.wifi.AccessPoint)

Example 2 with AccessPoint

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);
}
Also used : AccessPoint(com.android.settingslib.wifi.AccessPoint)

Example 3 with AccessPoint

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);
}
Also used : AccessPoint(com.android.settingslib.wifi.AccessPoint)

Example 4 with AccessPoint

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();
}
Also used : WifiManager(android.net.wifi.WifiManager) Bundle(android.os.Bundle) AccessPoint(com.android.settingslib.wifi.AccessPoint) Intent(android.content.Intent)

Example 5 with AccessPoint

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();
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiConfiguration(android.net.wifi.WifiConfiguration) NetworkInfo(android.net.NetworkInfo) Bundle(android.os.Bundle) AccessPoint(com.android.settingslib.wifi.AccessPoint) Intent(android.content.Intent)

Aggregations

AccessPoint (com.android.settingslib.wifi.AccessPoint)130 WifiConfiguration (android.net.wifi.WifiConfiguration)36 Bundle (android.os.Bundle)29 AccessPointPreference (com.android.settingslib.wifi.AccessPointPreference)27 Test (org.junit.Test)26 Intent (android.content.Intent)22 NetworkInfo (android.net.NetworkInfo)18 WifiManager (android.net.wifi.WifiManager)18 WifiInfo (android.net.wifi.WifiInfo)16 Context (android.content.Context)13 Preference (android.support.v7.preference.Preference)13 PreferenceScreen (android.support.v7.preference.PreferenceScreen)7 TestAccessPointBuilder (com.android.settingslib.wifi.TestAccessPointBuilder)7 ArrayList (java.util.ArrayList)5 SubSettingLauncher (com.android.settings.core.SubSettingLauncher)4 View (android.view.View)3 VisibleForTesting (androidx.annotation.VisibleForTesting)3 ScanResult (android.net.wifi.ScanResult)2 Spinner (android.widget.Spinner)2 AlertDialog (androidx.appcompat.app.AlertDialog)2