Search in sources :

Example 31 with AccessPoint

use of com.android.settingslib.wifi.AccessPoint in project android_packages_apps_Settings by crdroidandroid.

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 32 with AccessPoint

use of com.android.settingslib.wifi.AccessPoint in project platform_packages_apps_Settings by BlissRoms.

the class WifiSettings method updateAccessPointPreferences.

private void updateAccessPointPreferences() {
    // in case state has changed
    if (!mWifiManager.isWifiEnabled()) {
        return;
    }
    // AccessPoints are sorted by the WifiTracker
    final List<AccessPoint> accessPoints = mWifiTracker.getAccessPoints();
    if (WifiTracker.sVerboseLogging) {
        Log.i(TAG, "updateAccessPoints called for: " + accessPoints);
    }
    boolean hasAvailableAccessPoints = false;
    mAccessPointsPreferenceCategory.removePreference(mStatusMessagePreference);
    cacheRemoveAllPrefs(mAccessPointsPreferenceCategory);
    int index = configureConnectedAccessPointPreferenceCategory(accessPoints) ? 1 : 0;
    int numAccessPoints = accessPoints.size();
    for (; index < numAccessPoints; index++) {
        AccessPoint accessPoint = accessPoints.get(index);
        // Ignore access points that are out of range.
        if (accessPoint.isReachable()) {
            String key = AccessPointPreference.generatePreferenceKey(accessPoint);
            hasAvailableAccessPoints = true;
            LongPressAccessPointPreference pref = (LongPressAccessPointPreference) getCachedPreference(key);
            if (pref != null) {
                pref.setOrder(index);
                continue;
            }
            LongPressAccessPointPreference preference = createLongPressActionPointPreference(accessPoint);
            preference.setKey(key);
            preference.setOrder(index);
            if (mOpenSsid != null && mOpenSsid.equals(accessPoint.getSsidStr()) && accessPoint.getSecurity() != AccessPoint.SECURITY_NONE) {
                if (!accessPoint.isSaved() || isDisabledByWrongPassword(accessPoint)) {
                    onPreferenceTreeClick(preference);
                    mOpenSsid = null;
                }
            }
            mAccessPointsPreferenceCategory.addPreference(preference);
            accessPoint.setListener(WifiSettings.this);
            preference.refresh();
        }
    }
    removeCachedPrefs(mAccessPointsPreferenceCategory);
    mAddPreference.setOrder(index);
    mAccessPointsPreferenceCategory.addPreference(mAddPreference);
    setAdditionalSettingsSummaries();
    if (!hasAvailableAccessPoints) {
        setProgressBarVisible(true);
        Preference pref = new Preference(getPrefContext());
        pref.setSelectable(false);
        pref.setSummary(R.string.wifi_empty_list_wifi_on);
        pref.setOrder(index++);
        pref.setKey(PREF_KEY_EMPTY_WIFI_LIST);
        mAccessPointsPreferenceCategory.addPreference(pref);
    } else {
        // Continuing showing progress bar for an additional delay to overlap with animation
        getView().postDelayed(mHideProgressBarRunnable, 1700);
    }
}
Also used : AccessPointPreference(com.android.settingslib.wifi.AccessPointPreference) Preference(android.support.v7.preference.Preference) AccessPoint(com.android.settingslib.wifi.AccessPoint) AccessPoint(com.android.settingslib.wifi.AccessPoint)

Example 33 with AccessPoint

use of com.android.settingslib.wifi.AccessPoint in project platform_packages_apps_Settings by BlissRoms.

the class WifiSettings method onCreateDialog.

@Override
public Dialog onCreateDialog(int dialogId) {
    switch(dialogId) {
        case WIFI_DIALOG_ID:
            if (mDlgAccessPoint == null && mAccessPointSavedState == null) {
                // add new network
                mDialog = WifiDialog.createFullscreen(getActivity(), this, mDlgAccessPoint, mDialogMode);
            } 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, mDialogMode);
            }
            mSelectedAccessPoint = mDlgAccessPoint;
            return mDialog;
        case WPS_PBC_DIALOG_ID:
            return new WpsDialog(getActivity(), WpsInfo.PBC);
        case WPS_PIN_DIALOG_ID:
            return new WpsDialog(getActivity(), WpsInfo.DISPLAY);
        case WRITE_NFC_DIALOG_ID:
            if (mSelectedAccessPoint != null) {
                mWifiToNfcDialog = new WriteWifiConfigToNfcDialog(getActivity(), mSelectedAccessPoint.getSecurity(), new WifiManagerWrapper(mWifiManager));
            } else if (mWifiNfcDialogSavedState != null) {
                mWifiToNfcDialog = new WriteWifiConfigToNfcDialog(getActivity(), mWifiNfcDialogSavedState, new WifiManagerWrapper(mWifiManager));
            }
            return mWifiToNfcDialog;
    }
    return super.onCreateDialog(dialogId);
}
Also used : AccessPoint(com.android.settingslib.wifi.AccessPoint)

Example 34 with AccessPoint

use of com.android.settingslib.wifi.AccessPoint in project platform_packages_apps_Settings by BlissRoms.

the class WifiSettings method isDisabledByWrongPassword.

/**
 * Helper method to return whether an AccessPoint is disabled due to a wrong password
 */
private static boolean isDisabledByWrongPassword(AccessPoint accessPoint) {
    WifiConfiguration config = accessPoint.getConfig();
    if (config == null) {
        return false;
    }
    WifiConfiguration.NetworkSelectionStatus networkStatus = config.getNetworkSelectionStatus();
    if (networkStatus == null || networkStatus.isNetworkEnabled()) {
        return false;
    }
    int reason = networkStatus.getNetworkSelectionDisableReason();
    return WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD == reason;
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) AccessPoint(com.android.settingslib.wifi.AccessPoint)

Example 35 with AccessPoint

use of com.android.settingslib.wifi.AccessPoint in project platform_packages_apps_Settings by BlissRoms.

the class WifiSettingsUiTest method wrongPasswordSavedNetwork.

@Test
public void wrongPasswordSavedNetwork() {
    setWifiState(WifiManager.WIFI_STATE_ENABLED);
    // Set up an AccessPoint that is disabled due to incorrect password.
    WifiConfiguration config = new WifiConfiguration();
    config.SSID = TEST_SSID;
    config.BSSID = TEST_BSSID;
    config.networkId = TEST_NETWORK_ID;
    config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
    WifiConfiguration.NetworkSelectionStatus selectionStatus = new WifiConfiguration.NetworkSelectionStatus();
    selectionStatus.setNetworkSelectionDisableReason(WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD);
    selectionStatus.setNetworkSelectionStatus(WifiConfiguration.NetworkSelectionStatus.NETWORK_SELECTION_TEMPORARY_DISABLED);
    config.setNetworkSelectionStatus(selectionStatus);
    WifiInfo wifiInfo = new WifiInfo();
    wifiInfo.setSSID(WifiSsid.createFromAsciiEncoded(TEST_UNQUOTED_SSID));
    wifiInfo.setBSSID(TEST_BSSID);
    wifiInfo.setRssi(TEST_RSSI);
    wifiInfo.setNetworkId(TEST_NETWORK_ID);
    AccessPoint accessPoint = new AccessPoint(mContext, config);
    accessPoint.update(config, wifiInfo, null);
    // Make sure we've set up our access point correctly.
    assertThat(accessPoint.getSsidStr()).isEqualTo(TEST_UNQUOTED_SSID);
    assertThat(accessPoint.getBssid()).isEqualTo(TEST_BSSID);
    assertThat(accessPoint.isActive()).isFalse();
    assertThat(accessPoint.getConfig()).isNotNull();
    WifiConfiguration.NetworkSelectionStatus networkStatus = accessPoint.getConfig().getNetworkSelectionStatus();
    assertThat(networkStatus).isNotNull();
    assertThat(networkStatus.isNetworkEnabled()).isFalse();
    assertThat(networkStatus.getNetworkSelectionDisableReason()).isEqualTo(WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD);
    when(mWifiTracker.getAccessPoints()).thenReturn(Lists.newArrayList(accessPoint));
    launchActivity(WifiSettings.EXTRA_START_CONNECT_SSID, accessPoint.getSsidStr());
    // Make sure that the password dialog is visible.
    onView(withText(resourceId(STRING, WIFI_PASSWORD))).check(matches(isDisplayed()));
    onView(withText(resourceId(STRING, WIFI_SHOW_PASSWORD))).check(matches(isDisplayed()));
    onView(withId(resourceId(ID, PASSWORD_LAYOUT))).check(matches(isDisplayed()));
    onView(withId(resourceId(ID, PASSWORD))).check(matches(isDisplayed()));
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) AccessPoint(com.android.settingslib.wifi.AccessPoint) WifiInfo(android.net.wifi.WifiInfo) Test(org.junit.Test)

Aggregations

AccessPoint (com.android.settingslib.wifi.AccessPoint)132 WifiConfiguration (android.net.wifi.WifiConfiguration)36 Bundle (android.os.Bundle)29 AccessPointPreference (com.android.settingslib.wifi.AccessPointPreference)27 Test (org.junit.Test)27 Intent (android.content.Intent)21 WifiManager (android.net.wifi.WifiManager)20 NetworkInfo (android.net.NetworkInfo)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 Spinner (android.widget.Spinner)4 SubSettingLauncher (com.android.settings.core.SubSettingLauncher)4 ArrayList (java.util.ArrayList)4 View (android.view.View)3 VisibleForTesting (androidx.annotation.VisibleForTesting)3 ScanResult (android.net.wifi.ScanResult)2 ArrayAdapter (android.widget.ArrayAdapter)2