Merge "Enable multiple active Ethernet interfaces"
This commit is contained in:
@@ -18,9 +18,6 @@ package android.net;
|
||||
|
||||
import android.annotation.SystemService;
|
||||
import android.content.Context;
|
||||
import android.net.IEthernetManager;
|
||||
import android.net.IEthernetServiceListener;
|
||||
import android.net.IpConfiguration;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.RemoteException;
|
||||
@@ -45,18 +42,18 @@ public class EthernetManager {
|
||||
if (msg.what == MSG_AVAILABILITY_CHANGED) {
|
||||
boolean isAvailable = (msg.arg1 == 1);
|
||||
for (Listener listener : mListeners) {
|
||||
listener.onAvailabilityChanged(isAvailable);
|
||||
listener.onAvailabilityChanged((String) msg.obj, isAvailable);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
private final ArrayList<Listener> mListeners = new ArrayList<Listener>();
|
||||
private final ArrayList<Listener> mListeners = new ArrayList<>();
|
||||
private final IEthernetServiceListener.Stub mServiceListener =
|
||||
new IEthernetServiceListener.Stub() {
|
||||
@Override
|
||||
public void onAvailabilityChanged(boolean isAvailable) {
|
||||
public void onAvailabilityChanged(String iface, boolean isAvailable) {
|
||||
mHandler.obtainMessage(
|
||||
MSG_AVAILABILITY_CHANGED, isAvailable ? 1 : 0, 0, null).sendToTarget();
|
||||
MSG_AVAILABILITY_CHANGED, isAvailable ? 1 : 0, 0, iface).sendToTarget();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -66,9 +63,10 @@ public class EthernetManager {
|
||||
public interface Listener {
|
||||
/**
|
||||
* Called when Ethernet port's availability is changed.
|
||||
* @param isAvailable {@code true} if one or more Ethernet port exists.
|
||||
* @param iface Ethernet interface name
|
||||
* @param isAvailable {@code true} if Ethernet port exists.
|
||||
*/
|
||||
public void onAvailabilityChanged(boolean isAvailable);
|
||||
void onAvailabilityChanged(String iface, boolean isAvailable);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,9 +84,9 @@ public class EthernetManager {
|
||||
* Get Ethernet configuration.
|
||||
* @return the Ethernet Configuration, contained in {@link IpConfiguration}.
|
||||
*/
|
||||
public IpConfiguration getConfiguration() {
|
||||
public IpConfiguration getConfiguration(String iface) {
|
||||
try {
|
||||
return mService.getConfiguration();
|
||||
return mService.getConfiguration(iface);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -97,21 +95,29 @@ public class EthernetManager {
|
||||
/**
|
||||
* Set Ethernet configuration.
|
||||
*/
|
||||
public void setConfiguration(IpConfiguration config) {
|
||||
public void setConfiguration(String iface, IpConfiguration config) {
|
||||
try {
|
||||
mService.setConfiguration(config);
|
||||
mService.setConfiguration(iface, config);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the system currently has one or more
|
||||
* Ethernet interfaces.
|
||||
* Indicates whether the system currently has one or more Ethernet interfaces.
|
||||
*/
|
||||
public boolean isAvailable() {
|
||||
return getAvailableInterfaces().length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the system has given interface.
|
||||
*
|
||||
* @param iface Ethernet interface name
|
||||
*/
|
||||
public boolean isAvailable(String iface) {
|
||||
try {
|
||||
return mService.isAvailable();
|
||||
return mService.isAvailable(iface);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -136,6 +142,17 @@ public class EthernetManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of available Ethernet interface names.
|
||||
*/
|
||||
public String[] getAvailableInterfaces() {
|
||||
try {
|
||||
return mService.getAvailableInterfaces();
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowAsRuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a listener.
|
||||
* @param listener A {@link Listener} to remove.
|
||||
|
||||
@@ -26,9 +26,10 @@ import android.net.IEthernetServiceListener;
|
||||
/** {@hide} */
|
||||
interface IEthernetManager
|
||||
{
|
||||
IpConfiguration getConfiguration();
|
||||
void setConfiguration(in IpConfiguration config);
|
||||
boolean isAvailable();
|
||||
String[] getAvailableInterfaces();
|
||||
IpConfiguration getConfiguration(String iface);
|
||||
void setConfiguration(String iface, in IpConfiguration config);
|
||||
boolean isAvailable(String iface);
|
||||
void addListener(in IEthernetServiceListener listener);
|
||||
void removeListener(in IEthernetServiceListener listener);
|
||||
}
|
||||
|
||||
@@ -19,5 +19,5 @@ package android.net;
|
||||
/** @hide */
|
||||
oneway interface IEthernetServiceListener
|
||||
{
|
||||
void onAvailabilityChanged(boolean isAvailable);
|
||||
void onAvailabilityChanged(String iface, boolean isAvailable);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user