Add getInterfaceList API implementation in Ethernet service.

Bug: 171872016
Test: m
Merged-In: I8eeb2cd211c6a2ec6bc997c5e18995b585c6118a
Change-Id: Ic36d26be7dae5fd3f72abce3cea1ee845813a6e5
This commit is contained in:
Xiao Ma
2022-03-17 05:57:25 +00:00
parent c0939b76f0
commit 846bbc9167
2 changed files with 25 additions and 1 deletions

View File

@@ -41,6 +41,7 @@ import com.android.net.module.util.PermissionUtils;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@@ -289,4 +290,10 @@ public class EthernetServiceImpl extends IEthernetManager.Stub {
mTracker.setEthernetEnabled(enabled); mTracker.setEthernetEnabled(enabled);
} }
@Override
public List<String> getInterfaceList() {
PermissionUtils.enforceAccessNetworkStatePermission(mContext, TAG);
return mTracker.getInterfaceList();
}
} }

View File

@@ -57,6 +57,7 @@ import com.android.net.module.util.PermissionUtils;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@@ -90,7 +91,7 @@ public class EthernetTracker {
* Interface names we track. This is a product-dependent regular expression, plus, * Interface names we track. This is a product-dependent regular expression, plus,
* if setIncludeTestInterfaces is true, any test interfaces. * if setIncludeTestInterfaces is true, any test interfaces.
*/ */
private String mIfaceMatch; private volatile String mIfaceMatch;
/** /**
* Track test interfaces if true, don't track otherwise. * Track test interfaces if true, don't track otherwise.
*/ */
@@ -341,6 +342,22 @@ public class EthernetTracker {
return mFactory.getAvailableInterfaces(includeRestricted); 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 * Returns true if given interface was configured as restricted (doesn't have
* NET_CAPABILITY_NOT_RESTRICTED) capability. Otherwise, returns false. * NET_CAPABILITY_NOT_RESTRICTED) capability. Otherwise, returns false.