summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiao Ma <xiaom@google.com>2022-03-17 05:57:25 +0000
committerXiao Ma <xiaom@google.com>2022-03-23 15:20:58 +0000
commit260521db426c2d70cf713c122be085919be59df2 (patch)
tree96c427154dc269613ab46437e343a5976be99037
parent61566c7d1a8b511e58423b85c6fc1f1b454caaba (diff)
downloadethernet-260521db426c2d70cf713c122be085919be59df2.tar.gz
Add getInterfaceList API implementation in Ethernet service.
Bug: 171872016 Test: m Merged-In: I8eeb2cd211c6a2ec6bc997c5e18995b585c6118a Change-Id: Ic36d26be7dae5fd3f72abce3cea1ee845813a6e5
-rw-r--r--java/com/android/server/ethernet/EthernetServiceImpl.java7
-rw-r--r--java/com/android/server/ethernet/EthernetTracker.java19
2 files changed, 25 insertions, 1 deletions
diff --git a/java/com/android/server/ethernet/EthernetServiceImpl.java b/java/com/android/server/ethernet/EthernetServiceImpl.java
index afed01a..5e830ad 100644
--- a/java/com/android/server/ethernet/EthernetServiceImpl.java
+++ b/java/com/android/server/ethernet/EthernetServiceImpl.java
@@ -41,6 +41,7 @@ import com.android.net.module.util.PermissionUtils;
import java.io.FileDescriptor;
import java.io.PrintWriter;
+import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -289,4 +290,10 @@ public class EthernetServiceImpl extends IEthernetManager.Stub {
mTracker.setEthernetEnabled(enabled);
}
+
+ @Override
+ public List<String> getInterfaceList() {
+ PermissionUtils.enforceAccessNetworkStatePermission(mContext, TAG);
+ return mTracker.getInterfaceList();
+ }
}
diff --git a/java/com/android/server/ethernet/EthernetTracker.java b/java/com/android/server/ethernet/EthernetTracker.java
index c38c900..c291b3f 100644
--- a/java/com/android/server/ethernet/EthernetTracker.java
+++ b/java/com/android/server/ethernet/EthernetTracker.java
@@ -57,6 +57,7 @@ import com.android.net.module.util.PermissionUtils;
import java.io.FileDescriptor;
import java.net.InetAddress;
import java.util.ArrayList;
+import java.util.List;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
@@ -90,7 +91,7 @@ public class EthernetTracker {
* Interface names we track. This is a product-dependent regular expression, plus,
* if setIncludeTestInterfaces is true, any test interfaces.
*/
- private String mIfaceMatch;
+ private volatile String mIfaceMatch;
/**
* Track test interfaces if true, don't track otherwise.
*/
@@ -341,6 +342,22 @@ public class EthernetTracker {
return mFactory.getAvailableInterfaces(includeRestricted);
}
+ List<String> getInterfaceList() {
+ final List<String> interfaceList = new ArrayList<String>();
+ final String[] ifaces;
+ try {
+ ifaces = mNetd.interfaceGetList();
+ } catch (RemoteException e) {
+ Log.e(TAG, "Could not get list of interfaces " + e);
+ return interfaceList;
+ }
+ final String ifaceMatch = mIfaceMatch;
+ for (String iface : ifaces) {
+ if (iface.matches(ifaceMatch)) interfaceList.add(iface);
+ }
+ return interfaceList;
+ }
+
/**
* Returns true if given interface was configured as restricted (doesn't have
* NET_CAPABILITY_NOT_RESTRICTED) capability. Otherwise, returns false.