Search in sources :

Example 71 with AccessPoint

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

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)

Example 72 with AccessPoint

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

the class WifiNetworkDetailsFragment method onAttach.

@Override
public void onAttach(Context context) {
    mWifiDetailActionBarObserver = new WifiDetailActionBarObserver(context, this);
    getLifecycle().addObserver(mWifiDetailActionBarObserver);
    mAccessPoint = new AccessPoint(context, getArguments());
    super.onAttach(context);
}
Also used : AccessPoint(com.android.settingslib.wifi.AccessPoint)

Example 73 with AccessPoint

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

the class WifiSettingsUiTest method setupConnectedAccessPoint.

private void setupConnectedAccessPoint() {
    WifiConfiguration config = new WifiConfiguration();
    config.SSID = TEST_SSID;
    config.BSSID = TEST_BSSID;
    config.networkId = TEST_NETWORK_ID;
    WifiInfo wifiInfo = new WifiInfo();
    wifiInfo.setSSID(WifiSsid.createFromAsciiEncoded(TEST_UNQUOTED_SSID));
    wifiInfo.setBSSID(TEST_BSSID);
    wifiInfo.setRssi(TEST_RSSI);
    wifiInfo.setNetworkId(TEST_NETWORK_ID);
    NetworkInfo networkInfo = new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0, null, null);
    networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, null, null);
    AccessPoint accessPoint = new AccessPoint(mContext, config);
    accessPoint.update(config, wifiInfo, networkInfo);
    assertThat(accessPoint.getSsidStr()).isEqualTo(TEST_UNQUOTED_SSID);
    assertThat(accessPoint.getBssid()).isEqualTo(TEST_BSSID);
    assertThat(accessPoint.getNetworkInfo()).isNotNull();
    assertThat(accessPoint.isActive()).isTrue();
    assertThat(accessPoint.getSettingsSummary()).isEqualTo(resourceString(WIFI_DISPLAY_STATUS_CONNECTED));
    when(mWifiTracker.getAccessPoints()).thenReturn(Lists.asList(accessPoint, new AccessPoint[] {}));
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) NetworkInfo(android.net.NetworkInfo) AccessPoint(com.android.settingslib.wifi.AccessPoint) WifiInfo(android.net.wifi.WifiInfo)

Example 74 with AccessPoint

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

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

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

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)

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