Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bc7c4262 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Wi-Fi] Remove the files which use SettingsLib Wi-Fi objects"

parents 6934c022 fef7216e
Loading
Loading
Loading
Loading
+0 −135
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    settings:initialExpandedChildrenCount="5">

    <com.android.settingslib.widget.LayoutPreference
        android:key="connection_header"
        android:layout="@layout/settings_entity_header"
        android:selectable="false"
        android:order="-10000"
        settings:allowDividerBelow="true"/>

    <com.android.settings.datausage.DataUsageSummaryPreference
        android:key="status_header"
        android:selectable="false"
        settings:isPreferenceVisible="false"/>

    <!-- Buttons -->
    <com.android.settingslib.widget.ActionButtonsPreference
        android:key="buttons"
        android:selectable="false" />

    <!-- General Details Preferences -->
    <Preference
        android:key="signal_strength"
        android:title="@string/wifi_signal"
        android:selectable="false"
        settings:allowDividerAbove="true"/>

    <Preference
        android:key="frequency"
        android:icon="@drawable/ic_frequency_antenna"
        android:title="@string/wifi_frequency"
        android:selectable="false"/>

    <Preference
        android:key="security"
        android:icon="@drawable/ic_security_lock_24dp"
        android:title="@string/wifi_security"
        android:selectable="false"/>

    <DropDownPreference
        android:key="metered"
        android:icon="@drawable/ic_attach_money_black_24dp"
        android:title="@string/wifi_metered_title"
        android:entries="@array/wifi_metered_entries"
        android:entryValues="@array/wifi_metered_values"/>

    <DropDownPreference
        android:key="privacy"
        android:icon="@drawable/ic_wifi_privacy_24dp"
        android:title="@string/wifi_privacy_settings"
        android:entries="@array/wifi_privacy_entries"
        android:entryValues="@array/wifi_privacy_values"/>

    <!-- Add device Preference -->
    <Preference
        android:key="add_device_to_network"
        android:title="@string/wifi_dpp_add_device"
        android:summary="@string/wifi_dpp_connect_network_using_qr_code"
        settings:allowDividerAbove="true"/>

    <!-- Network Details -->
    <PreferenceCategory
            android:key="ip_details_category"
            android:title="@string/wifi_setup_detail">
        <Preference
                android:key="ssid"
                android:title="@string/wifi_advanced_ssid_title"
                android:selectable="false"
                settings:enableCopying="true"/>
        <Preference
                android:key="mac_address"
                android:title="@string/wifi_advanced_randomized_mac_address_title"
                android:selectable="false"
                settings:enableCopying="true"/>
        <Preference
                android:key="ip_address"
                android:title="@string/wifi_ip_address"
                android:selectable="false"
                settings:enableCopying="true"/>
        <Preference
                android:key="gateway"
                android:title="@string/wifi_gateway"
                android:selectable="false"
                settings:enableCopying="true"/>
        <Preference
                android:key="subnet_mask"
                android:title="@string/wifi_details_subnet_mask"
                android:selectable="false"
                settings:enableCopying="true"/>
        <Preference
                android:key="dns"
                android:title="@string/wifi_details_dns"
                android:selectable="false"
                settings:enableCopying="true"/>
        <Preference
                android:key="tx_link_speed"
                android:title="@string/tx_wifi_speed"
                android:selectable="false"
                settings:enableCopying="true"/>
        <Preference
                android:key="rx_link_speed"
                android:title="@string/rx_wifi_speed"
                android:selectable="false"
                settings:enableCopying="true"/>
    </PreferenceCategory>

    <!-- IPv6 Details -->
    <PreferenceCategory
            android:key="ipv6_category"
            android:title="@string/wifi_details_ipv6_address_header"
            android:selectable="false">
        <Preference
                android:key="ipv6_addresses"
                android:selectable="false"
                settings:enableCopying="true"/>
    </PreferenceCategory>
</PreferenceScreen>
+1 −1
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ public class AddNetworkFragment extends InstrumentedFragment implements WifiConf

    @Override
    public int getMode() {
        return WifiConfigUiBase.MODE_CONNECT;
        return WifiConfigUiBase2.MODE_CONNECT;
    }

    @Override
+5 −19
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ import android.text.InputType;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.FeatureFlagUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
@@ -67,7 +66,6 @@ import androidx.annotation.VisibleForTesting;

import com.android.settings.ProxySelector;
import com.android.settings.R;
import com.android.settings.wifi.details.WifiPrivacyPreferenceController;
import com.android.settings.wifi.details2.WifiPrivacyPreferenceController2;
import com.android.settings.wifi.dpp.WifiDppUtils;
import com.android.settingslib.Utils;
@@ -294,14 +292,8 @@ public class WifiConfigController2 implements TextWatcher,
                        ? HIDDEN_NETWORK
                        : NOT_HIDDEN_NETWORK);

                int prefMacValue;
                if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
                    prefMacValue = WifiPrivacyPreferenceController2
                final int prefMacValue = WifiPrivacyPreferenceController2
                        .translateMacRandomizedValueToPrefValue(config.macRandomizationSetting);
                } else {
                    prefMacValue = WifiPrivacyPreferenceController
                            .translateMacRandomizedValueToPrefValue(config.macRandomizationSetting);
                }
                mPrivacySettingsSpinner.setSelection(prefMacValue);

                if (config.getIpConfiguration().getIpAssignment() == IpAssignment.STATIC) {
@@ -814,15 +806,9 @@ public class WifiConfigController2 implements TextWatcher,
        }

        if (mPrivacySettingsSpinner != null) {
            int macValue;
            if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
                macValue = WifiPrivacyPreferenceController2.translatePrefValueToMacRandomizedValue(
                        mPrivacySettingsSpinner.getSelectedItemPosition());
            } else {
                macValue = WifiPrivacyPreferenceController.translatePrefValueToMacRandomizedValue(
                        mPrivacySettingsSpinner.getSelectedItemPosition());
            }
            config.macRandomizationSetting = macValue;
            config.macRandomizationSetting = WifiPrivacyPreferenceController2
                    .translatePrefValueToMacRandomizedValue(mPrivacySettingsSpinner
                            .getSelectedItemPosition());
        }

        return config;
+0 −87
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.wifi.details;

import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.util.Log;

import androidx.preference.Preference;

import com.android.settings.core.BasePreferenceController;
import com.android.settings.wifi.dpp.WifiDppUtils;
import com.android.settingslib.wifi.AccessPoint;

/**
 * {@link BasePreferenceController} that launches Wi-Fi Easy Connect configurator flow.
 *
 * Migrating from Wi-Fi SettingsLib to to WifiTrackerLib, this object will be removed in the near
 * future, please develop in
 * {@link com.android.settings.wifi.details2.AddDevicePreferenceController2}.
 */
public class AddDevicePreferenceController extends BasePreferenceController {

    private static final String TAG = "AddDevicePreferenceController";

    private static final String KEY_ADD_DEVICE = "add_device_to_network";

    private AccessPoint mAccessPoint;
    private WifiManager mWifiManager;

    public AddDevicePreferenceController(Context context) {
        super(context, KEY_ADD_DEVICE);

        mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    }

    public AddDevicePreferenceController init(AccessPoint accessPoint) {
        mAccessPoint = accessPoint;

        return this;
    }

    @Override
    public int getAvailabilityStatus() {
        if (WifiDppUtils.isSupportConfiguratorQrCodeScanner(mContext, mAccessPoint)) {
            return AVAILABLE;
        } else {
            return CONDITIONALLY_UNAVAILABLE;
        }
    }

    @Override
    public boolean handlePreferenceTreeClick(Preference preference) {
        if (KEY_ADD_DEVICE.equals(preference.getKey())) {
            WifiDppUtils.showLockScreen(mContext, () -> launchWifiDppConfiguratorQrCodeScanner());
            return true; /* click is handled */
        }

        return false; /* click is not handled */
    }

    private void launchWifiDppConfiguratorQrCodeScanner() {
        final Intent intent = WifiDppUtils.getConfiguratorQrCodeScannerIntentOrNull(mContext,
                mWifiManager, mAccessPoint);

        if (intent == null) {
            Log.e(TAG, "Launch Wi-Fi QR code scanner with a wrong Wi-Fi network!");
        } else {
            mContext.startActivity(intent);
        }
    }
}
+0 −112
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.wifi.details;

import android.app.backup.BackupManager;
import android.content.Context;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;

import androidx.annotation.VisibleForTesting;
import androidx.preference.DropDownPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;

import com.android.settings.core.BasePreferenceController;
import com.android.settings.wifi.WifiDialog;
import com.android.settingslib.core.AbstractPreferenceController;

/**
 * {@link AbstractPreferenceController} that controls whether the wifi network is metered or not.
 *
 * Migrating from Wi-Fi SettingsLib to to WifiTrackerLib, this object will be removed in the near
 * future, please develop in
 * {@link com.android.settings.wifi.details2.WifiMeteredPreferenceControlle2}.
 */
public class WifiMeteredPreferenceController extends BasePreferenceController implements
        Preference.OnPreferenceChangeListener, WifiDialog.WifiDialogListener {

    private static final String KEY_WIFI_METERED = "metered";
    private WifiConfiguration mWifiConfiguration;
    private WifiManager mWifiManager;
    private Preference mPreference;

    public WifiMeteredPreferenceController(Context context, WifiConfiguration wifiConfiguration) {
        super(context, KEY_WIFI_METERED);
        mWifiConfiguration = wifiConfiguration;
        mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    }

    @Override
    public void updateState(Preference preference) {
        final DropDownPreference dropDownPreference = (DropDownPreference) preference;
        final int meteredOverride = getMeteredOverride();
        dropDownPreference.setValue(Integer.toString(meteredOverride));
        updateSummary(dropDownPreference, meteredOverride);
    }

    @Override
    public int getAvailabilityStatus() {
        return AVAILABLE;
    }

    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        if (mWifiConfiguration != null) {
            mWifiConfiguration.meteredOverride = Integer.parseInt((String) newValue);
        }
        mWifiManager.updateNetwork(mWifiConfiguration);
        // Stage the backup of the SettingsProvider package which backs this up
        BackupManager.dataChanged("com.android.providers.settings");
        updateSummary((DropDownPreference) preference, getMeteredOverride());
        return true;
    }

    @VisibleForTesting
    int getMeteredOverride() {
        if (mWifiConfiguration != null) {
            // Wrap the meteredOverride since robolectric cannot recognize it
            return mWifiConfiguration.meteredOverride;
        }
        return WifiConfiguration.METERED_OVERRIDE_NONE;
    }

    private void updateSummary(DropDownPreference preference, int meteredOverride) {
        preference.setSummary(preference.getEntries()[meteredOverride]);
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        mPreference = screen.findPreference(getPreferenceKey());
    }

    @Override
    public void onSubmit(WifiDialog dialog) {
        if (dialog.getController() != null) {
            final WifiConfiguration newConfig = dialog.getController().getConfig();
            if (newConfig == null || mWifiConfiguration == null) {
                return;
            }

            if (newConfig.meteredOverride != mWifiConfiguration.meteredOverride) {
                mWifiConfiguration = newConfig;
                onPreferenceChange(mPreference, String.valueOf(newConfig.meteredOverride));
            }
        }
    }
}
Loading