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

Commit 0afd3f64 authored by Nikhil Nayunigari's avatar Nikhil Nayunigari Committed by Android (Google) Code Review
Browse files

Merge "Display one row item per Ethernet interface" into main

parents 1a987d25 25c5971e
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -10993,6 +10993,9 @@
    <!-- Label for section about ethernet in data usage screen [CHAR LIMIT=60] -->
    <string name="ethernet">Ethernet</string>
    <!-- Label for ethernet interface sub rows -->
    <string name="ethernet_interface_title">Ethernet <xliff:g id="interfaceid">%1$s</xliff:g></string>
    <!-- Format string for amount of cellular data used [CHAR LIMIT=30] -->
    <string name="cell_data_template"><xliff:g id="amount" example="1 GB">^1</xliff:g> mobile data</string>
+4 −0
Original line number Diff line number Diff line
@@ -42,6 +42,10 @@
        settings:restrictedSwitchSummary="@string/not_allowed_by_ent"
        settings:allowDividerAbove="true"/>

    <PreferenceCategory
        android:key="ethernet_interfaces"
        android:layout="@layout/preference_category_no_label"/>

    <Preference
        android:key="connected_ethernet_network"
        android:title="@string/ethernet"
+51 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.LocationManager;
import android.net.EthernetManager;
import android.net.NetworkTemplate;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
@@ -69,7 +70,10 @@ import com.android.settings.dashboard.RestrictedDashboardFragment;
import com.android.settings.datausage.DataUsagePreference;
import com.android.settings.datausage.DataUsageUtils;
import com.android.settings.location.WifiScanningFragment;
import com.android.settings.network.ethernet.EthernetInterface;
import com.android.settings.network.ethernet.EthernetSwitchPreferenceController;
import com.android.settings.network.ethernet.EthernetTracker;
import com.android.settings.network.ethernet.EthernetTrackerImpl;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.wifi.AddNetworkFragment;
import com.android.settings.wifi.AddWifiNetworkPreference;
@@ -99,6 +103,7 @@ import com.android.wifitrackerlib.WifiEntry;
import com.android.wifitrackerlib.WifiEntry.ConnectCallback;
import com.android.wifitrackerlib.WifiPickerTracker;

import java.util.Collection;
import java.util.List;
import java.util.Optional;

@@ -147,6 +152,7 @@ public class NetworkProviderSettings extends RestrictedDashboardFragment
    static final String PREF_KEY_DATA_USAGE = "non_carrier_data_usage";
    private static final String PREF_KEY_RESET_INTERNET = "resetting_your_internet";
    private static final String PREF_KEY_WIFI_STATUS_MESSAGE = "wifi_status_message_footer";
    private static final String PREF_KEY_ETHERNET_INTERFACES = "ethernet_interfaces";

    private static final int REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER = 0;

@@ -252,6 +258,12 @@ public class NetworkProviderSettings extends RestrictedDashboardFragment
    @VisibleForTesting
    MenuProvider mMenuProvider;
    RestrictedSwitchPreference mEthernetSwitchPreference;
    @VisibleForTesting
    EthernetManager mEthernetManager;
    @VisibleForTesting
    EthernetTracker mEthernetTracker;
    @VisibleForTesting
    PreferenceCategory mEthernetPreferenceCategory;

    /**
     * Mobile networks list for provider model
@@ -390,6 +402,7 @@ public class NetworkProviderSettings extends RestrictedDashboardFragment
                        .build(), SubscriptionManager.INVALID_SUBSCRIPTION_ID);
        mResetInternetPreference = findPreference(PREF_KEY_RESET_INTERNET);
        mEthernetSwitchPreference = findPreference(PREF_KEY_ETHERNET_TOGGLE);
        mEthernetPreferenceCategory = findPreference(PREF_KEY_ETHERNET_INTERFACES);
        if (mResetInternetPreference != null) {
            mResetInternetPreference.setVisible(false);
        }
@@ -482,6 +495,11 @@ public class NetworkProviderSettings extends RestrictedDashboardFragment
            mWifiPickerTracker = mWifiPickerTrackerHelper.getWifiPickerTracker();
        }
        mInternetUpdater = new InternetUpdater(getContext(), getSettingsLifecycle(), this);
        if (com.android.settings.connectivity.Flags.ethernetSettings()) {
            mEthernetManager = getContext().getSystemService(EthernetManager.class);
            mEthernetTracker = EthernetTrackerImpl.getInstance(
                getContext());
        }

        mSaveListener = new WifiManager.ActionListener() {
            @Override
@@ -534,6 +552,9 @@ public class NetworkProviderSettings extends RestrictedDashboardFragment
            return;
        }
        mAirplaneModeEnabler.start();
        if (com.android.settings.connectivity.Flags.ethernetSettings()) {
            mEthernetTracker.registerInterfaceListener(this::onInterfaceListChanged);
        }
    }

    private void restrictUi() {
@@ -571,6 +592,9 @@ public class NetworkProviderSettings extends RestrictedDashboardFragment
        getView().removeCallbacks(mUpdateWifiEntryPreferencesRunnable);
        getView().removeCallbacks(mHideProgressBarRunnable);
        mAirplaneModeEnabler.stop();
        if (com.android.settings.connectivity.Flags.ethernetSettings()) {
            mEthernetTracker.unregisterInterfaceListener(this::onInterfaceListChanged);
        }
        super.onStop();
    }

@@ -644,6 +668,11 @@ public class NetworkProviderSettings extends RestrictedDashboardFragment
        }
    }

    /** Called when the list of ethernet interfaces has changed. */
    public void onInterfaceListChanged(List<EthernetInterface> ethernetInterfaces) {
        updateEthernetInterfaces(ethernetInterfaces);
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo info) {
        Preference preference = (Preference) view.getTag();
@@ -1081,6 +1110,28 @@ public class NetworkProviderSettings extends RestrictedDashboardFragment
        setAdditionalSettingsSummaries();
    }

    void updateEthernetInterfaces(Collection<EthernetInterface> interfaces) {
        int index = 0;
        mEthernetPreferenceCategory.removeAll();
        if (interfaces.size() > 0) {
            for (EthernetInterface ethernetInterface : interfaces) {
                Preference pref = new Preference(getPrefContext());
                pref.setSelectable(false);
                pref.setOrder(index++);
                pref.setKey(ethernetInterface.getId());
                pref.setTitle(getContext().getString(R.string.ethernet_interface_title, index));
                pref.setSummary(
                        (ethernetInterface.getInterfaceState() == EthernetManager.STATE_LINK_UP)
                            ? getContext().getString(R.string.network_connected) :
                              getContext().getString(R.string.network_disconnected));
                mEthernetPreferenceCategory.addPreference(pref);
            }
            mEthernetPreferenceCategory.setVisible(true);
        } else {
            mEthernetPreferenceCategory.setVisible(false);
        }
    }

    @VisibleForTesting
    PreferenceCategory getConnectedWifiPreferenceCategory() {
        if (mInternetUpdater.getInternetType() == InternetUpdater.INTERNET_WIFI) {
+5 −4
Original line number Diff line number Diff line
@@ -26,13 +26,12 @@ import android.net.IpConfiguration
import android.os.OutcomeReceiver
import android.util.Log
import androidx.core.content.ContextCompat
import java.util.concurrent.Executor

class EthernetInterface(private val context: Context, private val id: String) :
    EthernetManager.InterfaceStateListener {
    private val ethernetManager =
    private val ethernetManager: EthernetManager? =
        context.getSystemService(EthernetManager::class.java)
    private val connectivityManager =
    private val connectivityManager: ConnectivityManager? =
        context.getSystemService(ConnectivityManager::class.java)
    private val executor = ContextCompat.getMainExecutor(context)

@@ -43,6 +42,8 @@ class EthernetInterface(private val context: Context, private val id: String) :

    fun getInterfaceState() = interfaceState

    fun getId() = id

    fun getConfiguration(): IpConfiguration {
        return ipConfiguration
    }
@@ -50,7 +51,7 @@ class EthernetInterface(private val context: Context, private val id: String) :
    fun setConfiguration(ipConfiguration: IpConfiguration) {
        val request =
            EthernetNetworkUpdateRequest.Builder().setIpConfiguration(ipConfiguration).build()
        ethernetManager.updateConfiguration(
        ethernetManager?.updateConfiguration(
            id,
            request,
            executor,
+6 −5
Original line number Diff line number Diff line
@@ -33,13 +33,14 @@ import java.util.concurrent.Executor
class EthernetSwitchPreferenceController(context: Context, private val lifecycle: Lifecycle) :
    AbstractPreferenceController(context),
    LifecycleEventObserver,
    EthernetInterfaceTracker.EthernetInterfaceTrackerListener {
    EthernetTracker.EthernetInterfaceTrackerListener {

    private val ethernetManager: EthernetManager? =
        context.getSystemService(EthernetManager::class.java)
    private var preference: RestrictedSwitchPreference? = null
    private val executor = ContextCompat.getMainExecutor(context)
    private val ethernetInterfaceTracker = EthernetInterfaceTracker.getInstance(context)
    private val ethernetTracker =
        EthernetTrackerImpl.getInstance(context)

    init {
        lifecycle.addObserver(this)
@@ -50,7 +51,7 @@ class EthernetSwitchPreferenceController(context: Context, private val lifecycle
    }

    override fun isAvailable(): Boolean {
        return (Flags.ethernetSettings() && ethernetInterfaceTracker.availableInterfaces.size > 0)
        return (Flags.ethernetSettings() && ethernetTracker.availableInterfaces.size > 0)
    }

    override fun displayPreference(screen: PreferenceScreen) {
@@ -63,12 +64,12 @@ class EthernetSwitchPreferenceController(context: Context, private val lifecycle
        when (event) {
            Lifecycle.Event.ON_START -> {
                ethernetManager?.addEthernetStateListener(executor, this::onEthernetStateChanged)
                ethernetInterfaceTracker.registerInterfaceListener(this)
                ethernetTracker.registerInterfaceListener(this)
            }

            Lifecycle.Event.ON_STOP -> {
                ethernetManager?.removeEthernetStateListener(this::onEthernetStateChanged)
                ethernetInterfaceTracker.unregisterInterfaceListener(this)
                ethernetTracker.unregisterInterfaceListener(this)
            }

            else -> {}
Loading