Adding allow edit toggle to the Wifi network details page
This CL adds the toggle and its associated controller. Controller reads and sets the toggle in the WifiEntry. Bug: 409845916 Flag: com.android.settings.connectivity.wifi_multiuser Test: Manual testing Change-Id: I39b2b991acd1e53acc5c9cf12329e08b3f900ea0
This commit is contained in:
@@ -2571,6 +2571,8 @@
|
||||
<string name="wifi_shared">Share with other device users</string>
|
||||
<!-- Hint for unchanged fields -->
|
||||
<string name="wifi_unchanged">(unchanged)</string>
|
||||
<!-- Label for the check box to allow other device users to edit network details -->
|
||||
<string name="wifi_allow_edit_configuration_title">Allow other users to edit network configuration</string>
|
||||
<!-- Hint for unspecified fields -->
|
||||
<string name="wifi_unspecified">Please select</string>
|
||||
<!-- Hint for multiple certificates being added to the configuration -->
|
||||
|
||||
@@ -102,10 +102,16 @@
|
||||
android:entries="@array/wifi_privacy_entries_ext"
|
||||
android:entryValues="@array/wifi_privacy_values_ext"/>
|
||||
|
||||
<com.android.settings.spa.preference.ComposePreference
|
||||
android:key="privacy_settings"
|
||||
android:title="@string/wifi_privacy_settings"
|
||||
settings:controller="com.android.settings.wifi.details2.WifiPrivacyPreferenceController"/>
|
||||
<SwitchPreferenceCompat
|
||||
android:key="edit_configuration"
|
||||
android:icon="@drawable/ic_edit_24dp"
|
||||
android:title="@string/wifi_allow_edit_configuration_title"
|
||||
settings:isPreferenceVisible="true"/>
|
||||
|
||||
<com.android.settings.spa.preference.ComposePreference
|
||||
android:key="privacy_settings"
|
||||
android:title="@string/wifi_privacy_settings"
|
||||
settings:controller="com.android.settings.wifi.details2.WifiPrivacyPreferenceController"/>
|
||||
|
||||
<Preference
|
||||
android:key="subscription_detail"
|
||||
|
||||
@@ -61,6 +61,7 @@ import com.android.settings.wifi.details2.CertificateDetailsPreferenceController
|
||||
import com.android.settings.wifi.details2.ServerNamePreferenceController;
|
||||
import com.android.settings.wifi.details2.WifiAutoConnectPreferenceController2;
|
||||
import com.android.settings.wifi.details2.WifiDetailPreferenceController2;
|
||||
import com.android.settings.wifi.details2.WifiEditConfigPreferenceController;
|
||||
import com.android.settings.wifi.details2.WifiMeteredPreferenceController2;
|
||||
import com.android.settings.wifi.details2.WifiPrivacyPreferenceController;
|
||||
import com.android.settings.wifi.details2.WifiPrivacyPreferenceController2;
|
||||
@@ -98,6 +99,7 @@ public class WifiNetworkDetailsFragment extends RestrictedDashboardFragment impl
|
||||
"hotspot_device_details_internet_source";
|
||||
public static final String KEY_HOTSPOT_DEVICE_BATTERY = "hotspot_device_details_battery";
|
||||
public static final String KEY_HOTSPOT_CONNECTION_CATEGORY = "hotspot_connection_category";
|
||||
public static final String KEY_EDIT_CONFIG_TOGGLE = "edit_configuration";
|
||||
|
||||
// Max age of tracked WifiEntries
|
||||
private static final long MAX_SCAN_AGE_MILLIS = 15_000;
|
||||
@@ -282,6 +284,11 @@ public class WifiNetworkDetailsFragment extends RestrictedDashboardFragment impl
|
||||
wifiAutoConnectPreferenceController2.setWifiEntry(wifiEntry);
|
||||
mControllers.add(wifiAutoConnectPreferenceController2);
|
||||
|
||||
final WifiEditConfigPreferenceController wifiEditConfigPreferenceController =
|
||||
new WifiEditConfigPreferenceController(
|
||||
context, KEY_EDIT_CONFIG_TOGGLE, wifiEntry);
|
||||
mControllers.add(wifiEditConfigPreferenceController);
|
||||
|
||||
final AddDevicePreferenceController2 addDevicePreferenceController2 =
|
||||
new AddDevicePreferenceController2(context);
|
||||
addDevicePreferenceController2.setWifiEntry(wifiEntry);
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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.R
|
||||
import com.android.settings.core.TogglePreferenceController
|
||||
import com.android.wifitrackerlib.WifiEntry
|
||||
|
||||
class WifiEditConfigPreferenceController(
|
||||
context: Context,
|
||||
preferenceKey: String,
|
||||
private val wifiEntry: WifiEntry,
|
||||
) : TogglePreferenceController(context, preferenceKey) {
|
||||
|
||||
override fun getAvailabilityStatus(): Int {
|
||||
return if (com.android.settings.connectivity.Flags.wifiMultiuser()) {
|
||||
AVAILABLE
|
||||
} else {
|
||||
CONDITIONALLY_UNAVAILABLE
|
||||
}
|
||||
}
|
||||
|
||||
override fun isChecked(): Boolean {
|
||||
return wifiEntry.isModifiableByOtherUsers()
|
||||
}
|
||||
|
||||
override fun setChecked(isChecked: Boolean): Boolean {
|
||||
wifiEntry.setModifiableByOtherUsers(isChecked)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun getSliceHighlightMenuRes(): Int {
|
||||
return R.string.menu_key_network
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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 android.platform.test.annotations.DisableFlags
|
||||
import android.platform.test.annotations.EnableFlags
|
||||
import android.platform.test.flag.junit.SetFlagsRule
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.android.settings.connectivity.Flags
|
||||
import com.android.settings.core.BasePreferenceController
|
||||
import com.android.wifitrackerlib.WifiEntry
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.kotlin.doReturn
|
||||
import org.mockito.kotlin.mock
|
||||
import org.mockito.kotlin.stub
|
||||
import org.mockito.kotlin.verify
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class WifiEditConfigPreferenceControllerTest {
|
||||
@get:Rule val setFlagsRule = SetFlagsRule()
|
||||
|
||||
private var mockWifiEntry = mock<WifiEntry>()
|
||||
|
||||
private val context: Context = mock<Context>()
|
||||
|
||||
private var controller = WifiEditConfigPreferenceController(context, "edit_configuration", mockWifiEntry)
|
||||
|
||||
@Test
|
||||
fun isChecked_returnsWifiEntry_allowEditConfig_Value() {
|
||||
mockWifiEntry.stub { on { isModifiableByOtherUsers() } doReturn false }
|
||||
|
||||
assertThat(controller.isChecked()).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun setChecked_setsWifiEntryValue() {
|
||||
controller.setChecked(true)
|
||||
|
||||
verify(mockWifiEntry).setModifiableByOtherUsers(true)
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags(Flags.FLAG_WIFI_MULTIUSER)
|
||||
fun getAvailabilityStatus_flagDisabled() {
|
||||
assertThat(controller.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE)
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_WIFI_MULTIUSER)
|
||||
fun getAvailabilityStatus_flagEnabled() {
|
||||
assertThat(controller.getAvailabilityStatus()).isEqualTo(BasePreferenceController.AVAILABLE)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user