Search in sources :

Example 16 with SoftApConfiguration

use of android.net.wifi.SoftApConfiguration in project android_packages_apps_Settings by omnirom.

the class WifiTetherAutoOffPreferenceController method onPreferenceChange.

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    final boolean settingsOn = (Boolean) newValue;
    SoftApConfiguration softApConfiguration = mWifiManager.getSoftApConfiguration();
    SoftApConfiguration newSoftApConfiguration = new SoftApConfiguration.Builder(softApConfiguration).setAutoShutdownEnabled(settingsOn).build();
    return mWifiManager.setSoftApConfiguration(newSoftApConfiguration);
}
Also used : SoftApConfiguration(android.net.wifi.SoftApConfiguration)

Example 17 with SoftApConfiguration

use of android.net.wifi.SoftApConfiguration in project android_packages_apps_Settings by omnirom.

the class WifiTetherPasswordPreferenceController method updateDisplay.

@Override
public void updateDisplay() {
    final SoftApConfiguration config = mWifiManager.getSoftApConfiguration();
    if (config.getSecurityType() != SoftApConfiguration.SECURITY_TYPE_OPEN && TextUtils.isEmpty(config.getPassphrase())) {
        mPassword = generateRandomPassword();
    } else {
        mPassword = config.getPassphrase();
    }
    mSecurityType = config.getSecurityType();
    ((ValidatedEditTextPreference) mPreference).setValidator(this);
    ((ValidatedEditTextPreference) mPreference).setIsPassword(true);
    ((ValidatedEditTextPreference) mPreference).setIsSummaryPassword(true);
    updatePasswordDisplay((EditTextPreference) mPreference);
}
Also used : ValidatedEditTextPreference(com.android.settings.widget.ValidatedEditTextPreference) SoftApConfiguration(android.net.wifi.SoftApConfiguration)

Example 18 with SoftApConfiguration

use of android.net.wifi.SoftApConfiguration in project android_packages_apps_Settings by omnirom.

the class WifiTetherSSIDPreferenceController method updateDisplay.

@Override
public void updateDisplay() {
    final SoftApConfiguration config = mWifiManager.getSoftApConfiguration();
    if (config != null) {
        mSSID = config.getSsid();
    } else {
        mSSID = DEFAULT_SSID;
    }
    ((ValidatedEditTextPreference) mPreference).setValidator(this);
    if (mWifiManager.isWifiApEnabled() && config != null) {
        final Intent intent = WifiDppUtils.getHotspotConfiguratorIntentOrNull(mContext, mWifiManager, config);
        if (intent == null) {
            Log.e(TAG, "Invalid security to share hotspot");
            ((WifiTetherSsidPreference) mPreference).setButtonVisible(false);
        } else {
            ((WifiTetherSsidPreference) mPreference).setButtonOnClickListener(view -> shareHotspotNetwork(intent));
            ((WifiTetherSsidPreference) mPreference).setButtonVisible(true);
        }
    } else {
        ((WifiTetherSsidPreference) mPreference).setButtonVisible(false);
    }
    updateSsidDisplay((EditTextPreference) mPreference);
}
Also used : ValidatedEditTextPreference(com.android.settings.widget.ValidatedEditTextPreference) Intent(android.content.Intent) SoftApConfiguration(android.net.wifi.SoftApConfiguration)

Example 19 with SoftApConfiguration

use of android.net.wifi.SoftApConfiguration in project android_packages_apps_Settings by omnirom.

the class WifiTetherSettings method onTetherConfigUpdated.

@Override
public void onTetherConfigUpdated(AbstractPreferenceController context) {
    final SoftApConfiguration config = buildNewConfig();
    mPasswordPreferenceController.setSecurityType(config.getSecurityType());
    /**
     * if soft AP is stopped, bring up
     * else restart with new config
     * TODO: update config on a running access point when framework support is added
     */
    if (mWifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_ENABLED) {
        Log.d("TetheringSettings", "Wifi AP config changed while enabled, stop and restart");
        mRestartWifiApAfterConfigChange = true;
        mSwitchBarController.stopTether();
    }
    mWifiManager.setSoftApConfiguration(config);
    if (context instanceof WifiTetherSecurityPreferenceController) {
        reConfigInitialExpandedChildCount();
    }
}
Also used : SoftApConfiguration(android.net.wifi.SoftApConfiguration)

Example 20 with SoftApConfiguration

use of android.net.wifi.SoftApConfiguration in project android_packages_apps_Settings by omnirom.

the class WifiTetherPreferenceController method handleWifiApStateChanged.

@VisibleForTesting
void handleWifiApStateChanged(int state, int reason) {
    switch(state) {
        case WifiManager.WIFI_AP_STATE_ENABLING:
            mPreference.setSummary(R.string.wifi_tether_starting);
            break;
        case WifiManager.WIFI_AP_STATE_ENABLED:
            final SoftApConfiguration softApConfig = mWifiManager.getSoftApConfiguration();
            updateConfigSummary(softApConfig);
            break;
        case WifiManager.WIFI_AP_STATE_DISABLING:
            mPreference.setSummary(R.string.wifi_tether_stopping);
            break;
        case WifiManager.WIFI_AP_STATE_DISABLED:
            mPreference.setSummary(R.string.wifi_hotspot_off_subtext);
            break;
        default:
            if (reason == WifiManager.SAP_START_FAILURE_NO_CHANNEL) {
                mPreference.setSummary(R.string.wifi_sap_no_channel_error);
            } else {
                mPreference.setSummary(R.string.wifi_error);
            }
    }
}
Also used : SoftApConfiguration(android.net.wifi.SoftApConfiguration) VisibleForTesting(androidx.annotation.VisibleForTesting)

Aggregations

SoftApConfiguration (android.net.wifi.SoftApConfiguration)28 Test (org.junit.Test)16 ValidatedEditTextPreference (com.android.settings.widget.ValidatedEditTextPreference)3 VisibleForTesting (androidx.annotation.VisibleForTesting)2 Intent (android.content.Intent)1 WifiManager (android.net.wifi.WifiManager)1 ListPreference (androidx.preference.ListPreference)1 PreferenceManager (androidx.preference.PreferenceManager)1 SwitchPreference (androidx.preference.SwitchPreference)1 ShadowWifiManager (com.android.settings.testutils.shadow.ShadowWifiManager)1 Before (org.junit.Before)1