Loading res/values/strings.xml +12 −0 Original line number Diff line number Diff line Loading @@ -3912,6 +3912,18 @@ <!-- Label for bluetooth tether checkbox [CHAR LIMIT=25]--> <string name="bluetooth_tether_checkbox_text">Bluetooth tethering</string> <!-- Ethernet settings--> <!-- Label for ethernet IP address [CHAR LIMIT=NONE]--> <string name="ethernet_ip_address">IP address</string> <!-- Label for ethernet MAC address [CHAR LIMIT=NONE]--> <string name="ethernet_mac_address_title">MAC address</string> <!-- Label for ethernet transfer speed [CHAR LIMIT=NONE]--> <string name="tx_ethernet_speed">Transit link speed</string> <!-- Label for ethernet receive speed [CHAR LIMIT=NONE]--> <string name="rx_ethernet_speed">Receive link speed</string> <!-- Label for ethernet network usage [CHAR LIMIT=NONE]--> <string name="ethernet_network_usage">Network usage</string> <!-- Ethernet Tethering settings--> <!-- Label for ethernet tether checkbox [CHAR LIMIT=NONE]--> <string name="ethernet_tether_checkbox_text">Ethernet tethering</string> res/xml/ethernet_interface_details.xml +32 −0 Original line number Diff line number Diff line Loading @@ -24,4 +24,36 @@ android:selectable="false" android:order="-10000"/> <ListPreference 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"/> <!-- Network Details --> <PreferenceCategory android:key="ip_details_category"> <Preference android:key="ethernet_ip_address" android:title="@string/ethernet_ip_address" android:selectable="false" settings:enableCopying="true"/> <Preference android:key="ethernet_mac_address" android:title="@string/ethernet_mac_address_title" android:selectable="false" settings:enableCopying="true"/> <Preference android:key="ethernet_tx_link_speed" android:title="@string/tx_ethernet_speed" android:selectable="false" settings:enableCopying="true"/> <Preference android:key="ethernet_rx_link_speed" android:title="@string/rx_ethernet_speed" android:selectable="false" settings:enableCopying="true"/> </PreferenceCategory> </PreferenceScreen> src/com/android/settings/network/ethernet/EthernetInterface.kt +54 −2 Original line number Diff line number Diff line Loading @@ -18,34 +18,68 @@ package com.android.settings.network.ethernet import android.content.Context import android.net.ConnectivityManager import android.net.ConnectivityManager.NetworkCallback import android.net.EthernetManager import android.net.EthernetManager.STATE_ABSENT import android.net.EthernetNetworkManagementException import android.net.EthernetNetworkUpdateRequest import android.net.IpConfiguration import android.net.LinkProperties import android.net.Network import android.net.NetworkCapabilities import android.net.NetworkRequest import android.os.OutcomeReceiver import android.util.Log import androidx.core.content.ContextCompat import com.google.common.annotations.VisibleForTesting class EthernetInterface(private val context: Context, private val id: String) : EthernetManager.InterfaceStateListener { interface EthernetInterfaceStateListener { fun interfaceUpdated() } private val ethernetManager: EthernetManager? = context.getSystemService(EthernetManager::class.java) private val connectivityManager: ConnectivityManager? = context.getSystemService(ConnectivityManager::class.java) private val executor = ContextCompat.getMainExecutor(context) private val interfaceListeners = mutableListOf<EthernetInterfaceStateListener>() private val TAG = "EthernetInterface" private val networkRequest: NetworkRequest = NetworkRequest.Builder() .clearCapabilities() .addTransportType(NetworkCapabilities.TRANSPORT_ETHERNET) .build() private var interfaceState = STATE_ABSENT private var ipConfiguration = IpConfiguration() private var linkProperties = LinkProperties() fun getInterfaceState() = interfaceState fun getId() = id fun getConfiguration(): IpConfiguration { return ipConfiguration fun getConfiguration() = ipConfiguration fun getLinkProperties() = linkProperties fun registerListener(listener: EthernetInterfaceStateListener) { if (interfaceListeners.isEmpty()) { ethernetManager?.addInterfaceStateListener(ContextCompat.getMainExecutor(context), this) connectivityManager?.registerNetworkCallback(networkRequest, networkCallback) } interfaceListeners.add(listener) } fun unregisterListener(listener: EthernetInterfaceStateListener) { interfaceListeners.remove(listener) if (interfaceListeners.isEmpty()) { connectivityManager?.unregisterNetworkCallback(networkCallback) ethernetManager?.removeInterfaceStateListener(this) } } fun setConfiguration(ipConfiguration: IpConfiguration) { Loading @@ -67,10 +101,28 @@ class EthernetInterface(private val context: Context, private val id: String) : ) } private fun notifyListeners() { for (listener in interfaceListeners) { listener.interfaceUpdated() } } override fun onInterfaceStateChanged(id: String, state: Int, role: Int, cfg: IpConfiguration?) { if (id == this.id) { ipConfiguration = cfg ?: IpConfiguration() interfaceState = state notifyListeners() } } @VisibleForTesting val networkCallback = object : NetworkCallback() { override fun onLinkPropertiesChanged(network: Network, lp: LinkProperties) { if (lp.getInterfaceName().equals(id)) { linkProperties = lp notifyListeners() } } } } src/com/android/settings/network/ethernet/EthernetInterfaceDetailsController.kt +79 −14 Original line number Diff line number Diff line Loading @@ -18,7 +18,14 @@ package com.android.settings.network.ethernet import android.content.Context import android.net.EthernetManager import android.net.IpConfiguration import android.net.LinkProperties import android.net.StaticIpConfiguration import android.widget.ImageView import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.LifecycleOwner import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceScreen import com.android.settings.R Loading @@ -30,13 +37,25 @@ class EthernetInterfaceDetailsController( context: Context, private val fragment: PreferenceFragmentCompat, private val preferenceId: String, ) : AbstractPreferenceController(context) { private val lifecycle: Lifecycle, ) : AbstractPreferenceController(context), EthernetInterface.EthernetInterfaceStateListener, LifecycleEventObserver { private val KEY_HEADER = "ethernet_details" private val ethernetManager = context.getSystemService(EthernetManager::class.java) private val ethernetInterface = EthernetTrackerImpl.getInstance(context).getInterface(preferenceId) private lateinit var entityHeaderController: EntityHeaderController private var ipAddressPref: Preference? = null init { lifecycle.addObserver(this) } override fun isAvailable(): Boolean { return true } Loading @@ -45,10 +64,24 @@ class EthernetInterfaceDetailsController( return KEY_HEADER } override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) { when (event) { Lifecycle.Event.ON_START -> { ethernetInterface?.registerListener(this) } Lifecycle.Event.ON_STOP -> { ethernetInterface?.unregisterListener(this) } else -> {} } } override fun displayPreference(screen: PreferenceScreen) { val headerPref: LayoutPreference? = screen.findPreference(KEY_HEADER) val mEntityHeaderController = entityHeaderController = EntityHeaderController.newInstance( fragment.getActivity(), fragment, Loading @@ -59,7 +92,8 @@ class EthernetInterfaceDetailsController( iconView?.setScaleType(ImageView.ScaleType.CENTER_INSIDE) mEntityHeaderController if (entityHeaderController != null) { entityHeaderController .setLabel("Ethernet") .setSummary( if (ethernetInterface?.getInterfaceState() == EthernetManager.STATE_LINK_UP) { Loading @@ -72,4 +106,35 @@ class EthernetInterfaceDetailsController( .setIcon(mContext.getDrawable(R.drawable.ic_settings_ethernet)) .done(true /* rebind */) } ipAddressPref = screen.findPreference<Preference>("ethernet_ip_address") if (ethernetInterface?.getInterfaceState() == EthernetManager.STATE_LINK_UP) { initializeIpDetails() } } override fun interfaceUpdated() { entityHeaderController?.setSummary( if (ethernetInterface?.getInterfaceState() == EthernetManager.STATE_LINK_UP) { mContext.getString(R.string.network_connected) } else { mContext.getString(R.string.network_disconnected) } ) initializeIpDetails() } private fun initializeIpDetails() { val ipConfiguration: IpConfiguration? = ethernetInterface?.getConfiguration() val linkProperties: LinkProperties? = ethernetInterface?.getLinkProperties() if (ipConfiguration?.getIpAssignment() == IpConfiguration.IpAssignment.STATIC) { val staticIp: StaticIpConfiguration? = ipConfiguration?.getStaticIpConfiguration() ipAddressPref?.setSummary(staticIp?.getIpAddress().toString()) } else { val addresses = linkProperties?.getAddresses() ipAddressPref?.setSummary(addresses?.first().toString()) } } } src/com/android/settings/network/ethernet/EthernetInterfaceDetailsFragment.kt +8 −1 Original line number Diff line number Diff line Loading @@ -50,6 +50,13 @@ class EthernetInterfaceDetailsFragment : DashboardFragment() { override public fun createPreferenceControllers( context: Context ): List<AbstractPreferenceController> { return listOf(EthernetInterfaceDetailsController(context, this, preferenceId ?: "")) return listOf( EthernetInterfaceDetailsController( context, this, preferenceId ?: "", getSettingsLifecycle(), ) ) } } Loading
res/values/strings.xml +12 −0 Original line number Diff line number Diff line Loading @@ -3912,6 +3912,18 @@ <!-- Label for bluetooth tether checkbox [CHAR LIMIT=25]--> <string name="bluetooth_tether_checkbox_text">Bluetooth tethering</string> <!-- Ethernet settings--> <!-- Label for ethernet IP address [CHAR LIMIT=NONE]--> <string name="ethernet_ip_address">IP address</string> <!-- Label for ethernet MAC address [CHAR LIMIT=NONE]--> <string name="ethernet_mac_address_title">MAC address</string> <!-- Label for ethernet transfer speed [CHAR LIMIT=NONE]--> <string name="tx_ethernet_speed">Transit link speed</string> <!-- Label for ethernet receive speed [CHAR LIMIT=NONE]--> <string name="rx_ethernet_speed">Receive link speed</string> <!-- Label for ethernet network usage [CHAR LIMIT=NONE]--> <string name="ethernet_network_usage">Network usage</string> <!-- Ethernet Tethering settings--> <!-- Label for ethernet tether checkbox [CHAR LIMIT=NONE]--> <string name="ethernet_tether_checkbox_text">Ethernet tethering</string>
res/xml/ethernet_interface_details.xml +32 −0 Original line number Diff line number Diff line Loading @@ -24,4 +24,36 @@ android:selectable="false" android:order="-10000"/> <ListPreference 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"/> <!-- Network Details --> <PreferenceCategory android:key="ip_details_category"> <Preference android:key="ethernet_ip_address" android:title="@string/ethernet_ip_address" android:selectable="false" settings:enableCopying="true"/> <Preference android:key="ethernet_mac_address" android:title="@string/ethernet_mac_address_title" android:selectable="false" settings:enableCopying="true"/> <Preference android:key="ethernet_tx_link_speed" android:title="@string/tx_ethernet_speed" android:selectable="false" settings:enableCopying="true"/> <Preference android:key="ethernet_rx_link_speed" android:title="@string/rx_ethernet_speed" android:selectable="false" settings:enableCopying="true"/> </PreferenceCategory> </PreferenceScreen>
src/com/android/settings/network/ethernet/EthernetInterface.kt +54 −2 Original line number Diff line number Diff line Loading @@ -18,34 +18,68 @@ package com.android.settings.network.ethernet import android.content.Context import android.net.ConnectivityManager import android.net.ConnectivityManager.NetworkCallback import android.net.EthernetManager import android.net.EthernetManager.STATE_ABSENT import android.net.EthernetNetworkManagementException import android.net.EthernetNetworkUpdateRequest import android.net.IpConfiguration import android.net.LinkProperties import android.net.Network import android.net.NetworkCapabilities import android.net.NetworkRequest import android.os.OutcomeReceiver import android.util.Log import androidx.core.content.ContextCompat import com.google.common.annotations.VisibleForTesting class EthernetInterface(private val context: Context, private val id: String) : EthernetManager.InterfaceStateListener { interface EthernetInterfaceStateListener { fun interfaceUpdated() } private val ethernetManager: EthernetManager? = context.getSystemService(EthernetManager::class.java) private val connectivityManager: ConnectivityManager? = context.getSystemService(ConnectivityManager::class.java) private val executor = ContextCompat.getMainExecutor(context) private val interfaceListeners = mutableListOf<EthernetInterfaceStateListener>() private val TAG = "EthernetInterface" private val networkRequest: NetworkRequest = NetworkRequest.Builder() .clearCapabilities() .addTransportType(NetworkCapabilities.TRANSPORT_ETHERNET) .build() private var interfaceState = STATE_ABSENT private var ipConfiguration = IpConfiguration() private var linkProperties = LinkProperties() fun getInterfaceState() = interfaceState fun getId() = id fun getConfiguration(): IpConfiguration { return ipConfiguration fun getConfiguration() = ipConfiguration fun getLinkProperties() = linkProperties fun registerListener(listener: EthernetInterfaceStateListener) { if (interfaceListeners.isEmpty()) { ethernetManager?.addInterfaceStateListener(ContextCompat.getMainExecutor(context), this) connectivityManager?.registerNetworkCallback(networkRequest, networkCallback) } interfaceListeners.add(listener) } fun unregisterListener(listener: EthernetInterfaceStateListener) { interfaceListeners.remove(listener) if (interfaceListeners.isEmpty()) { connectivityManager?.unregisterNetworkCallback(networkCallback) ethernetManager?.removeInterfaceStateListener(this) } } fun setConfiguration(ipConfiguration: IpConfiguration) { Loading @@ -67,10 +101,28 @@ class EthernetInterface(private val context: Context, private val id: String) : ) } private fun notifyListeners() { for (listener in interfaceListeners) { listener.interfaceUpdated() } } override fun onInterfaceStateChanged(id: String, state: Int, role: Int, cfg: IpConfiguration?) { if (id == this.id) { ipConfiguration = cfg ?: IpConfiguration() interfaceState = state notifyListeners() } } @VisibleForTesting val networkCallback = object : NetworkCallback() { override fun onLinkPropertiesChanged(network: Network, lp: LinkProperties) { if (lp.getInterfaceName().equals(id)) { linkProperties = lp notifyListeners() } } } }
src/com/android/settings/network/ethernet/EthernetInterfaceDetailsController.kt +79 −14 Original line number Diff line number Diff line Loading @@ -18,7 +18,14 @@ package com.android.settings.network.ethernet import android.content.Context import android.net.EthernetManager import android.net.IpConfiguration import android.net.LinkProperties import android.net.StaticIpConfiguration import android.widget.ImageView import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.LifecycleOwner import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceScreen import com.android.settings.R Loading @@ -30,13 +37,25 @@ class EthernetInterfaceDetailsController( context: Context, private val fragment: PreferenceFragmentCompat, private val preferenceId: String, ) : AbstractPreferenceController(context) { private val lifecycle: Lifecycle, ) : AbstractPreferenceController(context), EthernetInterface.EthernetInterfaceStateListener, LifecycleEventObserver { private val KEY_HEADER = "ethernet_details" private val ethernetManager = context.getSystemService(EthernetManager::class.java) private val ethernetInterface = EthernetTrackerImpl.getInstance(context).getInterface(preferenceId) private lateinit var entityHeaderController: EntityHeaderController private var ipAddressPref: Preference? = null init { lifecycle.addObserver(this) } override fun isAvailable(): Boolean { return true } Loading @@ -45,10 +64,24 @@ class EthernetInterfaceDetailsController( return KEY_HEADER } override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) { when (event) { Lifecycle.Event.ON_START -> { ethernetInterface?.registerListener(this) } Lifecycle.Event.ON_STOP -> { ethernetInterface?.unregisterListener(this) } else -> {} } } override fun displayPreference(screen: PreferenceScreen) { val headerPref: LayoutPreference? = screen.findPreference(KEY_HEADER) val mEntityHeaderController = entityHeaderController = EntityHeaderController.newInstance( fragment.getActivity(), fragment, Loading @@ -59,7 +92,8 @@ class EthernetInterfaceDetailsController( iconView?.setScaleType(ImageView.ScaleType.CENTER_INSIDE) mEntityHeaderController if (entityHeaderController != null) { entityHeaderController .setLabel("Ethernet") .setSummary( if (ethernetInterface?.getInterfaceState() == EthernetManager.STATE_LINK_UP) { Loading @@ -72,4 +106,35 @@ class EthernetInterfaceDetailsController( .setIcon(mContext.getDrawable(R.drawable.ic_settings_ethernet)) .done(true /* rebind */) } ipAddressPref = screen.findPreference<Preference>("ethernet_ip_address") if (ethernetInterface?.getInterfaceState() == EthernetManager.STATE_LINK_UP) { initializeIpDetails() } } override fun interfaceUpdated() { entityHeaderController?.setSummary( if (ethernetInterface?.getInterfaceState() == EthernetManager.STATE_LINK_UP) { mContext.getString(R.string.network_connected) } else { mContext.getString(R.string.network_disconnected) } ) initializeIpDetails() } private fun initializeIpDetails() { val ipConfiguration: IpConfiguration? = ethernetInterface?.getConfiguration() val linkProperties: LinkProperties? = ethernetInterface?.getLinkProperties() if (ipConfiguration?.getIpAssignment() == IpConfiguration.IpAssignment.STATIC) { val staticIp: StaticIpConfiguration? = ipConfiguration?.getStaticIpConfiguration() ipAddressPref?.setSummary(staticIp?.getIpAddress().toString()) } else { val addresses = linkProperties?.getAddresses() ipAddressPref?.setSummary(addresses?.first().toString()) } } }
src/com/android/settings/network/ethernet/EthernetInterfaceDetailsFragment.kt +8 −1 Original line number Diff line number Diff line Loading @@ -50,6 +50,13 @@ class EthernetInterfaceDetailsFragment : DashboardFragment() { override public fun createPreferenceControllers( context: Context ): List<AbstractPreferenceController> { return listOf(EthernetInterfaceDetailsController(context, this, preferenceId ?: "")) return listOf( EthernetInterfaceDetailsController( context, this, preferenceId ?: "", getSettingsLifecycle(), ) ) } }