Merge "[Wi-Fi] Implement Wi-Fi Auto-connect feature"
This commit is contained in:
committed by
Android (Google) Code Review
commit
1772ec0040
@@ -2091,6 +2091,10 @@
|
||||
<string name="wifi_dpp_wifi_password">Wi\u2011Fi password: <xliff:g id="password" example="my password">%1$s</xliff:g></string>
|
||||
<!-- Hint for Wi-Fi hotspot password [CHAR LIMIT=50] -->
|
||||
<string name="wifi_dpp_hotspot_password">Hotspot password: <xliff:g id="password" example="my password">%1$s</xliff:g></string>
|
||||
<!-- Label for specifying if a Wi-Fi network supports auto connection [CHAR LIMIT=50] -->
|
||||
<string name="wifi_auto_connect_title">Auto\u2011connect</string>
|
||||
<!-- Hint for Wi-Fi Auto-connect [CHAR LIMIT=NONE] -->
|
||||
<string name="wifi_auto_connect_summary">Allow connection to this network when in range</string>
|
||||
<!-- Label for "Use a QR code to add a device to this network" [CHAR LIMIT=50] -->
|
||||
<string name="wifi_dpp_add_device">Add device</string>
|
||||
<!-- Hint for "Add device" [CHAR LIMIT=NONE] -->
|
||||
|
141
res/xml/wifi_network_details_fragment2.xml
Normal file
141
res/xml/wifi_network_details_fragment2.xml
Normal file
@@ -0,0 +1,141 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2020 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"/>
|
||||
|
||||
<SwitchPreference
|
||||
android:key="auto_connect"
|
||||
android:title="@string/wifi_auto_connect_title"
|
||||
android:summary="@string/wifi_auto_connect_summary"
|
||||
settings:allowDividerAbove="true"/>
|
||||
|
||||
<!-- 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>
|
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.details2;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.wifitrackerlib.WifiEntry;
|
||||
|
||||
/**
|
||||
* {@link TogglePreferenceController} that controls whether the Wi-Fi Auto-connect feature should be
|
||||
* enabled.
|
||||
*/
|
||||
public class WifiAutoConnectPreferenceController2 extends TogglePreferenceController {
|
||||
|
||||
private static final String KEY_AUTO_CONNECT = "auto_connect";
|
||||
|
||||
private WifiEntry mWifiEntry;
|
||||
|
||||
public WifiAutoConnectPreferenceController2(Context context) {
|
||||
super(context, KEY_AUTO_CONNECT);
|
||||
}
|
||||
|
||||
public void setWifiEntry(WifiEntry wifiEntry) {
|
||||
mWifiEntry = wifiEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mWifiEntry.canSetAutoJoinEnabled() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return mWifiEntry.isAutoJoinEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
mWifiEntry.setAutoJoinEnabled(isChecked);
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -91,7 +91,7 @@ public class WifiNetworkDetailsFragment2 extends DashboardFragment implements
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.wifi_network_details_fragment;
|
||||
return R.xml.wifi_network_details_fragment2;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -155,6 +155,11 @@ public class WifiNetworkDetailsFragment2 extends DashboardFragment implements
|
||||
mMetricsFeatureProvider);
|
||||
controllers.add(mWifiDetailPreferenceController2);
|
||||
|
||||
final WifiAutoConnectPreferenceController2 wifiAutoConnectPreferenceController2 =
|
||||
new WifiAutoConnectPreferenceController2(context);
|
||||
wifiAutoConnectPreferenceController2.setWifiEntry(wifiEntry);
|
||||
controllers.add(wifiAutoConnectPreferenceController2);
|
||||
|
||||
final AddDevicePreferenceController2 addDevicePreferenceController2 =
|
||||
new AddDevicePreferenceController2(context);
|
||||
addDevicePreferenceController2.setWifiEntry(wifiEntry);
|
||||
|
@@ -7,4 +7,5 @@ com.android.settings.network.telephony.Enhanced4gBasePreferenceController
|
||||
com.android.settings.testutils.FakeToggleController
|
||||
com.android.settings.testutils.FakeSliderController
|
||||
com.android.settings.testutils.FakeInvalidSliderController
|
||||
com.android.settings.wifi.details2.WifiAutoConnectPreferenceController2
|
||||
|
||||
|
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.details2;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.android.wifitrackerlib.WifiEntry;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class WifiAutoConnectPreferenceController2Test {
|
||||
|
||||
private WifiAutoConnectPreferenceController2 mController;
|
||||
@Mock
|
||||
private WifiEntry mWifiEntry;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mController = new WifiAutoConnectPreferenceController2(RuntimeEnvironment.application);
|
||||
mController.setWifiEntry(mWifiEntry);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_shouldFollowCanSetAutoJoinEnabled() {
|
||||
// Test able to set auto join.
|
||||
when(mWifiEntry.canSetAutoJoinEnabled()).thenReturn(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
|
||||
// Test not able to set auto join.
|
||||
when(mWifiEntry.canSetAutoJoinEnabled()).thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_shouldFollowIsAutoJoinEnabled() {
|
||||
// Test auto join enabled.
|
||||
when(mWifiEntry.isAutoJoinEnabled()).thenReturn(true);
|
||||
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
|
||||
// Test auto join disabled.
|
||||
when(mWifiEntry.isAutoJoinEnabled()).thenReturn(false);
|
||||
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_shouldSetAutoJoinEnabled() {
|
||||
// Test checked.
|
||||
mController.setChecked(true);
|
||||
|
||||
verify(mWifiEntry).setAutoJoinEnabled(true);
|
||||
|
||||
// Test unchecked.
|
||||
mController.setChecked(false);
|
||||
|
||||
verify(mWifiEntry).setAutoJoinEnabled(false);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user