Search in sources :

Example 41 with AccessPoint

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

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)

Example 42 with AccessPoint

use of com.android.settingslib.wifi.AccessPoint in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiConfigController method initWifiConfigController.

private void initWifiConfigController(AccessPoint accessPoint, int mode) {
    mAccessPointSecurity = (accessPoint == null) ? AccessPoint.SECURITY_NONE : accessPoint.getSecurity();
    mMode = mode;
    final Resources res = mContext.getResources();
    mLevels = res.getStringArray(R.array.wifi_signal);
    if (Utils.isWifiOnly(mContext) || !mContext.getResources().getBoolean(com.android.internal.R.bool.config_eap_sim_based_auth_supported)) {
        mPhase2PeapAdapter = new ArrayAdapter<CharSequence>(mContext, android.R.layout.simple_spinner_item, res.getStringArray(R.array.wifi_peap_phase2_entries));
    } else {
        mPhase2PeapAdapter = new ArrayAdapter<CharSequence>(mContext, android.R.layout.simple_spinner_item, res.getStringArray(R.array.wifi_peap_phase2_entries_with_sim_auth));
    }
    mPhase2PeapAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mPhase2TtlsAdapter = new ArrayAdapter<CharSequence>(mContext, android.R.layout.simple_spinner_item, res.getStringArray(R.array.wifi_ttls_phase2_entries));
    mPhase2TtlsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mUnspecifiedCertString = mContext.getString(R.string.wifi_unspecified);
    mMultipleCertSetString = mContext.getString(R.string.wifi_multiple_cert_added);
    mUseSystemCertsString = mContext.getString(R.string.wifi_use_system_certs);
    mDoNotProvideEapUserCertString = mContext.getString(R.string.wifi_do_not_provide_eap_user_cert);
    mDoNotValidateEapServerString = mContext.getString(R.string.wifi_do_not_validate_eap_server);
    mSsidScanButton = (ImageButton) mView.findViewById(R.id.ssid_scanner_button);
    mPasswordScanButton = (ImageButton) mView.findViewById(R.id.password_scanner_button);
    mDialogContainer = mView.findViewById(R.id.dialog_scrollview);
    mIpSettingsSpinner = (Spinner) mView.findViewById(R.id.ip_settings);
    mIpSettingsSpinner.setOnItemSelectedListener(this);
    mProxySettingsSpinner = (Spinner) mView.findViewById(R.id.proxy_settings);
    mProxySettingsSpinner.setOnItemSelectedListener(this);
    mSharedCheckBox = (CheckBox) mView.findViewById(R.id.shared);
    mMeteredSettingsSpinner = mView.findViewById(R.id.metered_settings);
    mHiddenSettingsSpinner = mView.findViewById(R.id.hidden_settings);
    mPrivacySettingsSpinner = mView.findViewById(R.id.privacy_settings);
    if (mContext.getResources().getBoolean(com.android.internal.R.bool.config_wifi_connected_mac_randomization_supported)) {
        View privacySettingsLayout = mView.findViewById(R.id.privacy_settings_fields);
        privacySettingsLayout.setVisibility(View.VISIBLE);
    }
    mHiddenSettingsSpinner.setOnItemSelectedListener(this);
    mHiddenWarningView = mView.findViewById(R.id.hidden_settings_warning);
    mHiddenWarningView.setVisibility(mHiddenSettingsSpinner.getSelectedItemPosition() == NOT_HIDDEN_NETWORK ? View.GONE : View.VISIBLE);
    mSecurityInPosition = new Integer[AccessPoint.SECURITY_MAX_VAL];
    if (mAccessPoint == null) {
        // new network
        configureSecuritySpinner();
        mConfigUi.setSubmitButton(res.getString(R.string.wifi_save));
        mPasswordScanButton.setVisibility(View.GONE);
    } else {
        mConfigUi.setTitle(mAccessPoint.getTitle());
        ViewGroup group = (ViewGroup) mView.findViewById(R.id.info);
        boolean showAdvancedFields = false;
        if (mAccessPoint.isSaved()) {
            WifiConfiguration config = mAccessPoint.getConfig();
            mMeteredSettingsSpinner.setSelection(config.meteredOverride);
            mHiddenSettingsSpinner.setSelection(config.hiddenSSID ? HIDDEN_NETWORK : NOT_HIDDEN_NETWORK);
            final int prefMacValue = WifiPrivacyPreferenceController.translateMacRandomizedValueToPrefValue(config.macRandomizationSetting);
            mPrivacySettingsSpinner.setSelection(prefMacValue);
            if (config.getIpAssignment() == IpAssignment.STATIC) {
                mIpSettingsSpinner.setSelection(STATIC_IP);
                showAdvancedFields = true;
                // Display IP address.
                StaticIpConfiguration staticConfig = config.getStaticIpConfiguration();
                if (staticConfig != null && staticConfig.ipAddress != null) {
                    addRow(group, R.string.wifi_ip_address, staticConfig.ipAddress.getAddress().getHostAddress());
                }
            } else {
                mIpSettingsSpinner.setSelection(DHCP);
            }
            mSharedCheckBox.setEnabled(config.shared);
            if (!config.shared) {
                showAdvancedFields = true;
            }
            if (config.getProxySettings() == ProxySettings.STATIC) {
                mProxySettingsSpinner.setSelection(PROXY_STATIC);
                showAdvancedFields = true;
            } else if (config.getProxySettings() == ProxySettings.PAC) {
                mProxySettingsSpinner.setSelection(PROXY_PAC);
                showAdvancedFields = true;
            } else {
                mProxySettingsSpinner.setSelection(PROXY_NONE);
            }
            if (config != null && config.isPasspoint()) {
                addRow(group, R.string.passpoint_label, String.format(mContext.getString(R.string.passpoint_content), config.providerFriendlyName));
            }
        }
        if ((!mAccessPoint.isSaved() && !mAccessPoint.isActive() && !mAccessPoint.isPasspointConfig()) || mMode != WifiConfigUiBase.MODE_VIEW) {
            showSecurityFields(true, /* refreshEapMethods */
            true);
            showIpConfigFields();
            showProxyFields();
            final CheckBox advancedTogglebox = (CheckBox) mView.findViewById(R.id.wifi_advanced_togglebox);
            mView.findViewById(R.id.wifi_advanced_toggle).setVisibility(mAccessPoint.isCarrierAp() ? View.GONE : View.VISIBLE);
            advancedTogglebox.setOnCheckedChangeListener(this);
            advancedTogglebox.setChecked(showAdvancedFields);
            mView.findViewById(R.id.wifi_advanced_fields).setVisibility(showAdvancedFields ? View.VISIBLE : View.GONE);
            if (mAccessPoint.isCarrierAp()) {
                addRow(group, R.string.wifi_carrier_connect, String.format(mContext.getString(R.string.wifi_carrier_content), mAccessPoint.getCarrierName()));
            }
        }
        if (mMode == WifiConfigUiBase.MODE_MODIFY) {
            mConfigUi.setSubmitButton(res.getString(R.string.wifi_save));
        } else if (mMode == WifiConfigUiBase.MODE_CONNECT) {
            mConfigUi.setSubmitButton(res.getString(R.string.wifi_connect));
        } else {
            final DetailedState state = mAccessPoint.getDetailedState();
            final String signalLevel = getSignalString();
            if ((state == null || state == DetailedState.DISCONNECTED) && signalLevel != null) {
                mConfigUi.setSubmitButton(res.getString(R.string.wifi_connect));
            } else {
                if (state != null) {
                    boolean isEphemeral = mAccessPoint.isEphemeral();
                    WifiConfiguration config = mAccessPoint.getConfig();
                    String providerFriendlyName = null;
                    if (config != null && config.isPasspoint()) {
                        providerFriendlyName = config.providerFriendlyName;
                    }
                    String suggestionOrSpecifierPackageName = null;
                    if (config != null && (config.fromWifiNetworkSpecifier || config.fromWifiNetworkSuggestion)) {
                        suggestionOrSpecifierPackageName = config.creatorName;
                    }
                    String summary = AccessPoint.getSummary(mConfigUi.getContext(), /* ssid */
                    null, state, isEphemeral, suggestionOrSpecifierPackageName);
                    addRow(group, R.string.wifi_status, summary);
                }
                if (signalLevel != null) {
                    addRow(group, R.string.wifi_signal, signalLevel);
                }
                WifiInfo info = mAccessPoint.getInfo();
                if (info != null && info.getTxLinkSpeedMbps() != WifiInfo.LINK_SPEED_UNKNOWN) {
                    addRow(group, R.string.tx_wifi_speed, String.format(res.getString(R.string.tx_link_speed), info.getTxLinkSpeedMbps()));
                }
                if (info != null && info.getRxLinkSpeedMbps() != WifiInfo.LINK_SPEED_UNKNOWN) {
                    addRow(group, R.string.rx_wifi_speed, String.format(res.getString(R.string.rx_link_speed), info.getRxLinkSpeedMbps()));
                }
                if (info != null && info.getFrequency() != -1) {
                    final int frequency = info.getFrequency();
                    String band = null;
                    if (frequency >= AccessPoint.LOWER_FREQ_24GHZ && frequency < AccessPoint.HIGHER_FREQ_24GHZ) {
                        band = res.getString(R.string.wifi_band_24ghz);
                    } else if (frequency >= AccessPoint.LOWER_FREQ_5GHZ && frequency < AccessPoint.HIGHER_FREQ_5GHZ) {
                        band = res.getString(R.string.wifi_band_5ghz);
                    } else {
                        Log.e(TAG, "Unexpected frequency " + frequency);
                    }
                    if (band != null) {
                        addRow(group, R.string.wifi_frequency, band);
                    }
                }
                addRow(group, R.string.wifi_security, mAccessPoint.getSecurityString(false));
                mView.findViewById(R.id.ip_fields).setVisibility(View.GONE);
            }
            if (mAccessPoint.isSaved() || mAccessPoint.isActive() || mAccessPoint.isPasspointConfig()) {
                mConfigUi.setForgetButton(res.getString(R.string.wifi_forget));
            }
        }
        if (!WifiDppUtils.isSupportEnrolleeQrCodeScanner(mContext, mAccessPointSecurity)) {
            mPasswordScanButton.setVisibility(View.GONE);
        }
        mSsidScanButton.setVisibility(View.GONE);
    }
    if (!isSplitSystemUser()) {
        mSharedCheckBox.setVisibility(View.GONE);
    }
    mConfigUi.setCancelButton(res.getString(R.string.wifi_cancel));
    if (mConfigUi.getSubmitButton() != null) {
        enableSubmitIfAppropriate();
    }
    // After done view show and hide, request focus from parent view
    mView.findViewById(R.id.l_wifidialog).requestFocus();
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) ViewGroup(android.view.ViewGroup) DetailedState(android.net.NetworkInfo.DetailedState) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) AccessPoint(com.android.settingslib.wifi.AccessPoint) WifiInfo(android.net.wifi.WifiInfo) StaticIpConfiguration(android.net.StaticIpConfiguration) CheckBox(android.widget.CheckBox) Resources(android.content.res.Resources)

Example 43 with AccessPoint

use of com.android.settingslib.wifi.AccessPoint in project Resurrection_packages_apps_Settings by ResurrectionRemix.

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 (getIntent().getBooleanExtra(KEY_CONNECT_FOR_CALLER, true)) {
        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)

Example 44 with AccessPoint

use of com.android.settingslib.wifi.AccessPoint in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SavedAccessPointsWifiSettings method showWifiPage.

public void showWifiPage(@Nullable AccessPointPreference accessPoint) {
    removeDialog(WifiSettings.WIFI_DIALOG_ID);
    if (accessPoint != null) {
        // Save the access point and edit mode
        mSelectedAccessPoint = accessPoint.getAccessPoint();
    } else {
        // No access point is selected. Clear saved state.
        mSelectedAccessPoint = null;
        mAccessPointSavedState = null;
    }
    if (mSelectedAccessPoint == null) {
        mSelectedAccessPoint = new AccessPoint(getActivity(), mAccessPointSavedState);
    }
    final Bundle savedState = new Bundle();
    mSelectedAccessPoint.saveWifiState(savedState);
    new SubSettingLauncher(getContext()).setTitleText(mSelectedAccessPoint.getTitle()).setDestination(WifiNetworkDetailsFragment.class.getName()).setArguments(savedState).setSourceMetricsCategory(getMetricsCategory()).launch();
}
Also used : SubSettingLauncher(com.android.settings.core.SubSettingLauncher) Bundle(android.os.Bundle) AccessPoint(com.android.settingslib.wifi.AccessPoint)

Example 45 with AccessPoint

use of com.android.settingslib.wifi.AccessPoint in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiScanWorker method clone.

private AccessPoint clone(AccessPoint accessPoint) {
    final Bundle savedState = new Bundle();
    accessPoint.saveWifiState(savedState);
    return new AccessPoint(mContext, savedState);
}
Also used : Bundle(android.os.Bundle) AccessPoint(com.android.settingslib.wifi.AccessPoint)

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