Merge commit 'f4740f2d370b6458126942156245b2d39ec223f9' into HEAD
This commit is contained in:
@@ -19,27 +19,25 @@ package com.android.server.ethernet;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.DhcpResults;
|
import android.net.DhcpResults;
|
||||||
|
import android.net.EthernetManager;
|
||||||
|
import android.net.IEthernetServiceListener;
|
||||||
import android.net.InterfaceConfiguration;
|
import android.net.InterfaceConfiguration;
|
||||||
import android.net.NetworkUtils;
|
|
||||||
import android.net.IpConfiguration;
|
import android.net.IpConfiguration;
|
||||||
import android.net.IpConfiguration.IpAssignment;
|
import android.net.IpConfiguration.IpAssignment;
|
||||||
import android.net.IpConfiguration.ProxySettings;
|
import android.net.IpConfiguration.ProxySettings;
|
||||||
import android.net.LinkAddress;
|
|
||||||
import android.net.LinkProperties;
|
import android.net.LinkProperties;
|
||||||
import android.net.NetworkAgent;
|
import android.net.NetworkAgent;
|
||||||
import android.net.NetworkCapabilities;
|
import android.net.NetworkCapabilities;
|
||||||
import android.net.NetworkFactory;
|
import android.net.NetworkFactory;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.NetworkInfo.DetailedState;
|
import android.net.NetworkInfo.DetailedState;
|
||||||
import android.net.NetworkRequest;
|
import android.net.NetworkUtils;
|
||||||
import android.net.EthernetManager;
|
|
||||||
import android.net.StaticIpConfiguration;
|
import android.net.StaticIpConfiguration;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.INetworkManagementService;
|
import android.os.INetworkManagementService;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.RemoteCallbackList;
|
||||||
import android.os.Messenger;
|
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -50,9 +48,6 @@ import com.android.server.net.BaseNetworkObserver;
|
|||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.net.Inet4Address;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -96,6 +91,9 @@ class EthernetNetworkFactory {
|
|||||||
/** Product-dependent regular expression of interface names we track. */
|
/** Product-dependent regular expression of interface names we track. */
|
||||||
private static String mIfaceMatch = "";
|
private static String mIfaceMatch = "";
|
||||||
|
|
||||||
|
/** To notify Ethernet status. */
|
||||||
|
private final RemoteCallbackList<IEthernetServiceListener> mListeners;
|
||||||
|
|
||||||
/** Data members. All accesses to these must be synchronized(this). */
|
/** Data members. All accesses to these must be synchronized(this). */
|
||||||
private static String mIface = "";
|
private static String mIface = "";
|
||||||
private String mHwAddr;
|
private String mHwAddr;
|
||||||
@@ -103,10 +101,11 @@ class EthernetNetworkFactory {
|
|||||||
private NetworkInfo mNetworkInfo;
|
private NetworkInfo mNetworkInfo;
|
||||||
private LinkProperties mLinkProperties;
|
private LinkProperties mLinkProperties;
|
||||||
|
|
||||||
EthernetNetworkFactory() {
|
EthernetNetworkFactory(RemoteCallbackList<IEthernetServiceListener> listeners) {
|
||||||
mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_ETHERNET, 0, NETWORK_TYPE, "");
|
mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_ETHERNET, 0, NETWORK_TYPE, "");
|
||||||
mLinkProperties = new LinkProperties();
|
mLinkProperties = new LinkProperties();
|
||||||
initNetworkCapabilities();
|
initNetworkCapabilities();
|
||||||
|
mListeners = listeners;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LocalNetworkFactory extends NetworkFactory {
|
private class LocalNetworkFactory extends NetworkFactory {
|
||||||
@@ -178,9 +177,8 @@ class EthernetNetworkFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (mIface.isEmpty()) {
|
if (!isTrackingInterface()) {
|
||||||
mIface = iface;
|
setInterfaceInfoLocked(iface, config.getHardwareAddress());
|
||||||
mHwAddr = config.getHardwareAddress();
|
|
||||||
mNetworkInfo.setIsAvailable(true);
|
mNetworkInfo.setIsAvailable(true);
|
||||||
mNetworkInfo.setExtraInfo(mHwAddr);
|
mNetworkInfo.setExtraInfo(mHwAddr);
|
||||||
} else {
|
} else {
|
||||||
@@ -196,7 +194,7 @@ class EthernetNetworkFactory {
|
|||||||
private boolean maybeTrackInterface(String iface) {
|
private boolean maybeTrackInterface(String iface) {
|
||||||
// If we don't already have an interface, and if this interface matches
|
// If we don't already have an interface, and if this interface matches
|
||||||
// our regex, start tracking it.
|
// our regex, start tracking it.
|
||||||
if (!iface.matches(mIfaceMatch) || !mIface.isEmpty())
|
if (!iface.matches(mIfaceMatch) || isTrackingInterface())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Log.d(TAG, "Started tracking interface " + iface);
|
Log.d(TAG, "Started tracking interface " + iface);
|
||||||
@@ -212,8 +210,7 @@ class EthernetNetworkFactory {
|
|||||||
// TODO: Unify this codepath with stop().
|
// TODO: Unify this codepath with stop().
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
NetworkUtils.stopDhcp(mIface);
|
NetworkUtils.stopDhcp(mIface);
|
||||||
mIface = "";
|
setInterfaceInfoLocked("", null);
|
||||||
mHwAddr = null;
|
|
||||||
mNetworkInfo.setExtraInfo(null);
|
mNetworkInfo.setExtraInfo(null);
|
||||||
mLinkUp = false;
|
mLinkUp = false;
|
||||||
mNetworkInfo.setDetailedState(DetailedState.DISCONNECTED, null, mHwAddr);
|
mNetworkInfo.setDetailedState(DetailedState.DISCONNECTED, null, mHwAddr);
|
||||||
@@ -414,8 +411,7 @@ class EthernetNetworkFactory {
|
|||||||
updateAgent();
|
updateAgent();
|
||||||
mLinkProperties = new LinkProperties();
|
mLinkProperties = new LinkProperties();
|
||||||
mNetworkAgent = null;
|
mNetworkAgent = null;
|
||||||
mIface = "";
|
setInterfaceInfoLocked("", null);
|
||||||
mHwAddr = null;
|
|
||||||
mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_ETHERNET, 0, NETWORK_TYPE, "");
|
mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_ETHERNET, 0, NETWORK_TYPE, "");
|
||||||
mFactory.unregister();
|
mFactory.unregister();
|
||||||
}
|
}
|
||||||
@@ -430,8 +426,35 @@ class EthernetNetworkFactory {
|
|||||||
mNetworkCapabilities.setLinkDownstreamBandwidthKbps(100 * 1000);
|
mNetworkCapabilities.setLinkDownstreamBandwidthKbps(100 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized boolean isTrackingInterface() {
|
||||||
|
return !TextUtils.isEmpty(mIface);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set interface information and notify listeners if availability is changed.
|
||||||
|
* This should be called with the lock held.
|
||||||
|
*/
|
||||||
|
private void setInterfaceInfoLocked(String iface, String hwAddr) {
|
||||||
|
boolean oldAvailable = isTrackingInterface();
|
||||||
|
mIface = iface;
|
||||||
|
mHwAddr = hwAddr;
|
||||||
|
boolean available = isTrackingInterface();
|
||||||
|
|
||||||
|
if (oldAvailable != available) {
|
||||||
|
int n = mListeners.beginBroadcast();
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
try {
|
||||||
|
mListeners.getBroadcastItem(i).onAvailabilityChanged(available);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
// Do nothing here.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mListeners.finishBroadcast();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
synchronized void dump(FileDescriptor fd, IndentingPrintWriter pw, String[] args) {
|
synchronized void dump(FileDescriptor fd, IndentingPrintWriter pw, String[] args) {
|
||||||
if (!TextUtils.isEmpty(mIface)) {
|
if (isTrackingInterface()) {
|
||||||
pw.println("Tracking interface: " + mIface);
|
pw.println("Tracking interface: " + mIface);
|
||||||
pw.increaseIndent();
|
pw.increaseIndent();
|
||||||
pw.println("MAC address: " + mHwAddr);
|
pw.println("MAC address: " + mHwAddr);
|
||||||
|
|||||||
@@ -18,37 +18,25 @@ package com.android.server.ethernet;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import com.android.internal.util.IndentingPrintWriter;
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.IEthernetManager;
|
import android.net.IEthernetManager;
|
||||||
|
import android.net.IEthernetServiceListener;
|
||||||
import android.net.IpConfiguration;
|
import android.net.IpConfiguration;
|
||||||
import android.net.IpConfiguration.IpAssignment;
|
import android.net.IpConfiguration.IpAssignment;
|
||||||
import android.net.IpConfiguration.ProxySettings;
|
import android.net.IpConfiguration.ProxySettings;
|
||||||
import android.net.LinkAddress;
|
|
||||||
import android.net.NetworkAgent;
|
|
||||||
import android.net.NetworkInfo;
|
|
||||||
import android.net.NetworkRequest;
|
|
||||||
import android.net.RouteInfo;
|
|
||||||
import android.net.StaticIpConfiguration;
|
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.IBinder;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
import android.os.Looper;
|
import android.os.RemoteCallbackList;
|
||||||
import android.os.Message;
|
|
||||||
import android.os.Messenger;
|
|
||||||
import android.os.INetworkManagementService;
|
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.PrintWriterPrinter;
|
import android.util.PrintWriterPrinter;
|
||||||
|
|
||||||
|
import com.android.internal.util.IndentingPrintWriter;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EthernetServiceImpl handles remote Ethernet operation requests by implementing
|
* EthernetServiceImpl handles remote Ethernet operation requests by implementing
|
||||||
* the IEthernetManager interface.
|
* the IEthernetManager interface.
|
||||||
@@ -60,14 +48,13 @@ public class EthernetServiceImpl extends IEthernetManager.Stub {
|
|||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final EthernetConfigStore mEthernetConfigStore;
|
private final EthernetConfigStore mEthernetConfigStore;
|
||||||
private final INetworkManagementService mNMService;
|
|
||||||
private final AtomicBoolean mStarted = new AtomicBoolean(false);
|
private final AtomicBoolean mStarted = new AtomicBoolean(false);
|
||||||
private IpConfiguration mIpConfiguration;
|
private IpConfiguration mIpConfiguration;
|
||||||
private ConnectivityManager mCM;
|
|
||||||
|
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
private NetworkInfo mNetworkInfo;
|
|
||||||
private final EthernetNetworkFactory mTracker;
|
private final EthernetNetworkFactory mTracker;
|
||||||
|
private final RemoteCallbackList<IEthernetServiceListener> mListeners =
|
||||||
|
new RemoteCallbackList<IEthernetServiceListener>();
|
||||||
|
|
||||||
public EthernetServiceImpl(Context context) {
|
public EthernetServiceImpl(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -77,10 +64,7 @@ public class EthernetServiceImpl extends IEthernetManager.Stub {
|
|||||||
|
|
||||||
Log.i(TAG, "Read stored IP configuration: " + mIpConfiguration);
|
Log.i(TAG, "Read stored IP configuration: " + mIpConfiguration);
|
||||||
|
|
||||||
IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
|
mTracker = new EthernetNetworkFactory(mListeners);
|
||||||
mNMService = INetworkManagementService.Stub.asInterface(b);
|
|
||||||
|
|
||||||
mTracker = new EthernetNetworkFactory();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enforceAccessPermission() {
|
private void enforceAccessPermission() {
|
||||||
@@ -103,7 +87,6 @@ public class EthernetServiceImpl extends IEthernetManager.Stub {
|
|||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
Log.i(TAG, "Starting Ethernet service");
|
Log.i(TAG, "Starting Ethernet service");
|
||||||
mCM = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
|
|
||||||
HandlerThread handlerThread = new HandlerThread("EthernetServiceThread");
|
HandlerThread handlerThread = new HandlerThread("EthernetServiceThread");
|
||||||
handlerThread.start();
|
handlerThread.start();
|
||||||
@@ -118,6 +101,7 @@ public class EthernetServiceImpl extends IEthernetManager.Stub {
|
|||||||
* Get Ethernet configuration
|
* Get Ethernet configuration
|
||||||
* @return the Ethernet Configuration, contained in {@link IpConfiguration}.
|
* @return the Ethernet Configuration, contained in {@link IpConfiguration}.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public IpConfiguration getConfiguration() {
|
public IpConfiguration getConfiguration() {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
|
|
||||||
@@ -129,6 +113,7 @@ public class EthernetServiceImpl extends IEthernetManager.Stub {
|
|||||||
/**
|
/**
|
||||||
* Set Ethernet configuration
|
* Set Ethernet configuration
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void setConfiguration(IpConfiguration config) {
|
public void setConfiguration(IpConfiguration config) {
|
||||||
if (!mStarted.get()) {
|
if (!mStarted.get()) {
|
||||||
Log.w(TAG, "System isn't ready enough to change ethernet configuration");
|
Log.w(TAG, "System isn't ready enough to change ethernet configuration");
|
||||||
@@ -150,6 +135,40 @@ public class EthernetServiceImpl extends IEthernetManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether the system currently has one or more
|
||||||
|
* Ethernet interfaces.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
enforceAccessPermission();
|
||||||
|
return mTracker.isTrackingInterface();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Addes a listener.
|
||||||
|
* @param listener A {@link IEthernetServiceListener} to add.
|
||||||
|
*/
|
||||||
|
public void addListener(IEthernetServiceListener listener) {
|
||||||
|
if (listener == null) {
|
||||||
|
throw new IllegalArgumentException("listener must not be null");
|
||||||
|
}
|
||||||
|
enforceAccessPermission();
|
||||||
|
mListeners.register(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a listener.
|
||||||
|
* @param listener A {@link IEthernetServiceListener} to remove.
|
||||||
|
*/
|
||||||
|
public void removeListener(IEthernetServiceListener listener) {
|
||||||
|
if (listener == null) {
|
||||||
|
throw new IllegalArgumentException("listener must not be null");
|
||||||
|
}
|
||||||
|
enforceAccessPermission();
|
||||||
|
mListeners.unregister(listener);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
|
protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
|
||||||
final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
|
final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
|
||||||
|
|||||||
Reference in New Issue
Block a user