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

Commit d3b0498f authored by Nikhil Nayunigari's avatar Nikhil Nayunigari
Browse files

Add ethernet dialog to edit IP Settings

Adds an edit icon to the ethernet details page and displays an edit
dialog with option to configure static IP.

Flag: com.android.settings.connectivity.ethernet_settings

Test: Manual testing on a Pixel tablet

Change-Id: If829946acf8b574c0963c583c17d8b5d40874d07
parent 1f99733b
Loading
Loading
Loading
Loading
+160 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    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.
-->

<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fadeScrollbars="false"
        android:scrollIndicators="top|bottom">

    <LinearLayout
        android:id="@+id/l_ethernetdialog"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingBottom="8dip">

        <LinearLayout android:id="@+id/ethernet_advanced_fields"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:orientation="vertical"
                      android:visibility="visible">

            <LinearLayout android:id="@+id/ip_fields"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          style="@style/ethernet_item"
                          android:visibility="visible">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    style="@style/ethernet_item_label"
                    android:text="@string/ethernet_ip_settings"/>

                <Spinner android:id="@+id/ip_settings"
                         android:layout_width="match_parent"
                         android:layout_height="wrap_content"
                         style="@style/ethernet_item_spinner"
                         android:prompt="@string/ethernet_ip_settings"
                         android:entries="@array/ethernet_ip_settings"/>

            </LinearLayout>

            <LinearLayout android:id="@+id/staticip"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          style="@style/ethernet_section"
                          android:visibility="gone">
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    style="@style/ethernet_item">
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        style="@style/ethernet_item_label"
                        android:text="@string/ethernet_ip_address"/>

                    <EditText android:id="@+id/ipaddress"
                              android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              style="@style/ethernet_item_edit_content"
                              android:singleLine="true"
                              android:hint="@string/ethernet_ip_address_hint"
                              android:inputType="textNoSuggestions"/>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    style="@style/ethernet_item">
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        style="@style/ethernet_item_label"
                        android:text="@string/ethernet_gateway"/>

                    <EditText android:id="@+id/gateway"
                              android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              style="@style/ethernet_item_edit_content"
                              android:singleLine="true"
                              android:hint="@string/ethernet_gateway_hint"
                              android:inputType="textNoSuggestions"/>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    style="@style/ethernet_item">
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        style="@style/ethernet_item_label"
                        android:text="@string/ethernet_network_prefix_length"/>

                    <EditText android:id="@+id/network_prefix_length"
                              android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              style="@style/ethernet_item_edit_content"
                              android:singleLine="true"
                              android:hint="@string/ethernet_network_prefix_length_hint"
                              android:inputType="number"/>
                </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    style="@style/ethernet_item">
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        style="@style/ethernet_item_label"
                        android:text="@string/ethernet_dns1"/>

                    <EditText android:id="@+id/dns1"
                              android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              style="@style/ethernet_item_edit_content"
                              android:singleLine="true"
                              android:hint="@string/ethernet_dns1_hint"
                              android:inputType="textNoSuggestions"/>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    style="@style/ethernet_item">
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        style="@style/ethernet_item_label"
                        android:text="@string/ethernet_dns2"/>

                    <EditText android:id="@+id/dns2"
                              android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              style="@style/ethernet_item_edit_content"
                              android:singleLine="true"
                              android:hint="@string/ethernet_dns2_hint"
                              android:inputType="textNoSuggestions"/>
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

</androidx.core.widget.NestedScrollView>
+9 −0
Original line number Diff line number Diff line
@@ -676,6 +676,15 @@
        <item>Long</item>
    </string-array>

    <!-- Ethernet IP settings. -->
    <!-- Note that adding/removing/moving the items will need ethernet settings code change. -->
    <string-array name="ethernet_ip_settings">
        <!-- Use DHCP (Dynamic Host Configuration Protocol) for obtaining IP settings [CHAR LIMIT=25] -->
        <item>DHCP</item>
        <!-- Use statically defined IP settings [CHAR LIMIT=25]-->
        <item>Static</item>
    </string-array>

    <!-- Values for the list of long press timeout options. -->
    <string-array name="long_press_timeout_selector_values" translatable="false">
        <item>400</item>
+29 −0
Original line number Diff line number Diff line
@@ -2695,6 +2695,32 @@
    <string name="hotspot_connection_category">Hotspot connection</string>
    <!-- Connection strength preference in Hotspot connection preference category [CHAR LIMIT=NONE]-->
    <string name="hotspot_connection_strength">Connection strength</string>
    <!-- Hint text for the IP address -->
    <string name="ethernet_ip_address_hint" translatable="false">192.168.1.128</string>
    <!-- Hint text for DNS -->
    <string name="ethernet_dns1_hint" translatable="false">8.8.8.8</string>
    <!-- Hint text for DNS -->
    <string name="ethernet_dns2_hint" translatable="false">8.8.4.4</string>
    <!-- Hint text for the gateway -->
    <string name="ethernet_gateway_hint" translatable="false">192.168.1.1</string>
    <!-- Hint text for network prefix length -->
    <string name="ethernet_network_prefix_length_hint" translatable="false">24</string>
    <!-- Label for the DNS (first one) -->
    <string name="ethernet_dns1">DNS 1 (unless overridden by private DNS)</string>
    <!-- Label for the DNS (second one)-->
    <string name="ethernet_dns2">DNS 2 (unless overridden by private DNS)</string>
    <!-- Label for the gateway of the network -->
    <string name="ethernet_gateway">Gateway</string>
    <!-- Label for the network prefix of the network [CHAR LIMIT=25]-->
    <string name="ethernet_network_prefix_length">Network prefix length</string>
    <!-- Label for the spinner to show ip settings [CHAR LIMIT=25] -->
    <string name="ethernet_ip_settings">IP settings</string>
    <!-- Label for the ethernet config dialog submit button [CHAR LIMIT=25] -->
    <string name="ethernet_config_submit">Submit</string>
    <!-- Label for the ethernet config dialog cancel button [CHAR LIMIT=25] -->
    <string name="ethernet_config_cancel">Cancel</string>
    <!-- Label for the ethernet config dialog title [CHAR LIMIT=25] -->
    <string name="ethernet_config_title">Ethernet Settings</string>
    <!-- Wifi saved access points.  Used as a label under the shortcut icon that goes to Wifi saved access points. [CHAR LIMIT=20] -->
    <string name="wifi_saved_access_points_label">Saved networks</string>
@@ -3961,6 +3987,9 @@
    <!-- Label for ethernet tether checkbox [CHAR LIMIT=NONE]-->
    <string name="ethernet_tether_checkbox_text">Ethernet tethering</string>
    <!-- Button label to modify a Ethernet network -->
    <string name="ethernet_modify">Modify</string>
    <!-- Tethering footer info [CHAR LIMIT=NONE]-->
    <string name="tethering_footer_info">Use hotspot and tethering to provide internet to other devices through your data connection. Apps can also create a hotspot to share content with nearby devices.</string>
    <!-- Tethering footer info for the device which supports Wi-Fi and Wi-Fi tethering enabled at the same time [CHAR LIMIT=NONE]-->
+51 −0
Original line number Diff line number Diff line
@@ -147,6 +147,57 @@
        <item name="android:orientation">vertical</item>
    </style>

    <style name="ethernet_item">
        <item name="android:layout_marginTop">8dip</item>
        <item name="android:layout_marginStart">8dip</item>
        <item name="android:layout_marginEnd">8dip</item>
        <item name="android:paddingStart">8dip</item>
        <item name="android:paddingEnd">8dip</item>
        <item name="android:orientation">vertical</item>
        <item name="android:gravity">start</item>
    </style>

    <style name="ethernet_item_label">
        <item name="android:paddingStart">8dip</item>
        <item name="android:textSize">14sp</item>
        <item name="android:textAlignment">viewStart</item>
        <item name="android:textAppearance">@*android:style/TextAppearance.DeviceDefault.Body1</item>
        <item name="android:textColor">?android:attr/textColorSecondary</item>
    </style>

    <style name="ethernet_item_content">
        <item name="android:textAlignment">viewStart</item>
        <item name="android:textAppearance">@*android:style/TextAppearance.DeviceDefault.Subhead</item>
        <item name="android:textColor">?android:attr/textColorPrimary</item>
        <item name="android:minHeight">@dimen/min_tap_target_size</item>
    </style>

    <style name="ethernet_item_spinner" parent="ethernet_item_content">
        <item name="android:minHeight">48dp</item>
    </style>

    <style name="ethernet_advanced_toggle" parent="ethernet_item_content">
        <item name="android:background">@null</item>
        <item name="android:button">@null</item>
        <item name="android:drawableEnd">@drawable/ic_expand</item>
        <item name="android:paddingStart">8dip</item>
        <item name="android:textSize">14sp</item>
    </style>

    <style name="ethernet_item_edit_content">
        <item name="android:paddingStart">4dip</item>
        <item name="android:layout_marginStart">4dip</item>
        <item name="android:textAlignment">viewStart</item>
        <item name="android:textAppearance">@android:style/TextAppearance.DeviceDefault.Medium</item>
        <item name="android:textColorHint">?android:attr/textColorSecondary</item>
        <item name="android:minHeight">@dimen/min_tap_target_size</item>
        <item name="android:maxLength">500</item>
    </style>

    <style name="ethernet_section">
        <item name="android:orientation">vertical</item>
    </style>

    <style name="adb_wireless_item">
        <item name="android:layout_marginTop">8dp</item>
        <item name="android:layout_marginStart">8dp</item>
+31 −0
Original line number Diff line number Diff line
/*
 * 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.network.ethernet

import android.widget.Button

interface EthernetDialog {
    interface EthernetDialogListener {
        fun onSubmit(dialog: EthernetDialog)
    }

    fun getController(): EthernetDialogController

    fun getSubmitButton(): Button?

    fun getCancelButton(): Button?
}
Loading