Revert "Revert "Change network management listener to outcome re..."
Revert submission 2030087-revert-2028203-ethernet-outcomereceiver-WFKWDORBPY Reason for revert: Reinstate changes Reverted Changes: Ibd1d70ac3:Revert "Change Ethernet API to use OutcomeReceiver... I45af594f7:Revert "Change Ethernet API to use OutcomeReceiver... I45ba68452:Revert "Change network management listener to outc... Merged-In: Id8fadfed9fcfd22f04f6d7c3460b5956e571e01f Change-Id: If3854c1c3a39aa6de84807c6bde267cf88f3d277
This commit is contained in:
@@ -24,8 +24,8 @@ import android.net.ConnectivityManager;
|
|||||||
import android.net.ConnectivityResources;
|
import android.net.ConnectivityResources;
|
||||||
import android.net.EthernetManager;
|
import android.net.EthernetManager;
|
||||||
import android.net.EthernetNetworkSpecifier;
|
import android.net.EthernetNetworkSpecifier;
|
||||||
import android.net.IEthernetNetworkManagementListener;
|
|
||||||
import android.net.EthernetNetworkManagementException;
|
import android.net.EthernetNetworkManagementException;
|
||||||
|
import android.net.INetworkInterfaceOutcomeReceiver;
|
||||||
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;
|
||||||
@@ -239,14 +239,14 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
|||||||
* {@code null} is passed, then the network's current
|
* {@code null} is passed, then the network's current
|
||||||
* {@link NetworkCapabilities} will be used in support of existing APIs as
|
* {@link NetworkCapabilities} will be used in support of existing APIs as
|
||||||
* the public API does not allow this.
|
* the public API does not allow this.
|
||||||
* @param listener an optional {@link IEthernetNetworkManagementListener} to notify callers of
|
* @param listener an optional {@link INetworkInterfaceOutcomeReceiver} to notify callers of
|
||||||
* completion.
|
* completion.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
|
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
|
||||||
protected void updateInterface(@NonNull final String ifaceName,
|
protected void updateInterface(@NonNull final String ifaceName,
|
||||||
@Nullable final IpConfiguration ipConfig,
|
@Nullable final IpConfiguration ipConfig,
|
||||||
@Nullable final NetworkCapabilities capabilities,
|
@Nullable final NetworkCapabilities capabilities,
|
||||||
@Nullable final IEthernetNetworkManagementListener listener) {
|
@Nullable final INetworkInterfaceOutcomeReceiver listener) {
|
||||||
if (!hasInterface(ifaceName)) {
|
if (!hasInterface(ifaceName)) {
|
||||||
maybeSendNetworkManagementCallbackForUntracked(ifaceName, listener);
|
maybeSendNetworkManagementCallbackForUntracked(ifaceName, listener);
|
||||||
return;
|
return;
|
||||||
@@ -295,7 +295,7 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
|||||||
/** Returns true if state has been modified */
|
/** Returns true if state has been modified */
|
||||||
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
|
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
|
||||||
protected boolean updateInterfaceLinkState(@NonNull final String ifaceName, final boolean up,
|
protected boolean updateInterfaceLinkState(@NonNull final String ifaceName, final boolean up,
|
||||||
@Nullable final IEthernetNetworkManagementListener listener) {
|
@Nullable final INetworkInterfaceOutcomeReceiver listener) {
|
||||||
if (!hasInterface(ifaceName)) {
|
if (!hasInterface(ifaceName)) {
|
||||||
maybeSendNetworkManagementCallbackForUntracked(ifaceName, listener);
|
maybeSendNetworkManagementCallbackForUntracked(ifaceName, listener);
|
||||||
return false;
|
return false;
|
||||||
@@ -310,7 +310,7 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void maybeSendNetworkManagementCallbackForUntracked(
|
private void maybeSendNetworkManagementCallbackForUntracked(
|
||||||
String ifaceName, IEthernetNetworkManagementListener listener) {
|
String ifaceName, INetworkInterfaceOutcomeReceiver listener) {
|
||||||
maybeSendNetworkManagementCallback(listener, null,
|
maybeSendNetworkManagementCallback(listener, null,
|
||||||
new EthernetNetworkManagementException(
|
new EthernetNetworkManagementException(
|
||||||
ifaceName + " can't be updated as it is not available."));
|
ifaceName + " can't be updated as it is not available."));
|
||||||
@@ -353,15 +353,19 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void maybeSendNetworkManagementCallback(
|
private static void maybeSendNetworkManagementCallback(
|
||||||
@Nullable final IEthernetNetworkManagementListener listener,
|
@Nullable final INetworkInterfaceOutcomeReceiver listener,
|
||||||
@Nullable final Network network,
|
@Nullable final String iface,
|
||||||
@Nullable final EthernetNetworkManagementException e) {
|
@Nullable final EthernetNetworkManagementException e) {
|
||||||
if (null == listener) {
|
if (null == listener) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
listener.onComplete(network, e);
|
if (iface != null) {
|
||||||
|
listener.onResult(iface);
|
||||||
|
} else {
|
||||||
|
listener.onError(e);
|
||||||
|
}
|
||||||
} catch (RemoteException re) {
|
} catch (RemoteException re) {
|
||||||
Log.e(TAG, "Can't send onComplete for network management callback", re);
|
Log.e(TAG, "Can't send onComplete for network management callback", re);
|
||||||
}
|
}
|
||||||
@@ -415,9 +419,9 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
|||||||
private class EthernetIpClientCallback extends IpClientCallbacks {
|
private class EthernetIpClientCallback extends IpClientCallbacks {
|
||||||
private final ConditionVariable mIpClientStartCv = new ConditionVariable(false);
|
private final ConditionVariable mIpClientStartCv = new ConditionVariable(false);
|
||||||
private final ConditionVariable mIpClientShutdownCv = new ConditionVariable(false);
|
private final ConditionVariable mIpClientShutdownCv = new ConditionVariable(false);
|
||||||
@Nullable IEthernetNetworkManagementListener mNetworkManagementListener;
|
@Nullable INetworkInterfaceOutcomeReceiver mNetworkManagementListener;
|
||||||
|
|
||||||
EthernetIpClientCallback(@Nullable final IEthernetNetworkManagementListener listener) {
|
EthernetIpClientCallback(@Nullable final INetworkInterfaceOutcomeReceiver listener) {
|
||||||
mNetworkManagementListener = listener;
|
mNetworkManagementListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -502,7 +506,7 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
|||||||
|
|
||||||
void updateInterface(@Nullable final IpConfiguration ipConfig,
|
void updateInterface(@Nullable final IpConfiguration ipConfig,
|
||||||
@Nullable final NetworkCapabilities capabilities,
|
@Nullable final NetworkCapabilities capabilities,
|
||||||
@Nullable final IEthernetNetworkManagementListener listener) {
|
@Nullable final INetworkInterfaceOutcomeReceiver listener) {
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Log.d(TAG, "updateInterface, iface: " + name
|
Log.d(TAG, "updateInterface, iface: " + name
|
||||||
+ ", ipConfig: " + ipConfig + ", old ipConfig: " + mIpConfig
|
+ ", ipConfig: " + ipConfig + ", old ipConfig: " + mIpConfig
|
||||||
@@ -533,7 +537,7 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
|||||||
start(null);
|
start(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void start(@Nullable final IEthernetNetworkManagementListener listener) {
|
private void start(@Nullable final INetworkInterfaceOutcomeReceiver listener) {
|
||||||
if (mIpClient != null) {
|
if (mIpClient != null) {
|
||||||
if (DBG) Log.d(TAG, "IpClient already started");
|
if (DBG) Log.d(TAG, "IpClient already started");
|
||||||
return;
|
return;
|
||||||
@@ -553,7 +557,7 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onIpLayerStarted(@NonNull final LinkProperties linkProperties,
|
void onIpLayerStarted(@NonNull final LinkProperties linkProperties,
|
||||||
@Nullable final IEthernetNetworkManagementListener listener) {
|
@Nullable final INetworkInterfaceOutcomeReceiver listener) {
|
||||||
if(mIpClient == null) {
|
if(mIpClient == null) {
|
||||||
// This call comes from a message posted on the handler thread, but the IpClient has
|
// This call comes from a message posted on the handler thread, but the IpClient has
|
||||||
// since been stopped such as may be the case if updateInterfaceLinkState() is
|
// since been stopped such as may be the case if updateInterfaceLinkState() is
|
||||||
@@ -593,10 +597,10 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
|||||||
});
|
});
|
||||||
mNetworkAgent.register();
|
mNetworkAgent.register();
|
||||||
mNetworkAgent.markConnected();
|
mNetworkAgent.markConnected();
|
||||||
realizeNetworkManagementCallback(mNetworkAgent.getNetwork(), null);
|
realizeNetworkManagementCallback(name, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onIpLayerStopped(@Nullable final IEthernetNetworkManagementListener listener) {
|
void onIpLayerStopped(@Nullable final INetworkInterfaceOutcomeReceiver listener) {
|
||||||
// This cannot happen due to provisioning timeout, because our timeout is 0. It can
|
// This cannot happen due to provisioning timeout, because our timeout is 0. It can
|
||||||
// happen due to errors while provisioning or on provisioning loss.
|
// happen due to errors while provisioning or on provisioning loss.
|
||||||
if(mIpClient == null) {
|
if(mIpClient == null) {
|
||||||
@@ -622,7 +626,7 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Must be called on the handler thread
|
// Must be called on the handler thread
|
||||||
private void realizeNetworkManagementCallback(@Nullable final Network network,
|
private void realizeNetworkManagementCallback(@Nullable final String iface,
|
||||||
@Nullable final EthernetNetworkManagementException e) {
|
@Nullable final EthernetNetworkManagementException e) {
|
||||||
ensureRunningOnEthernetHandlerThread();
|
ensureRunningOnEthernetHandlerThread();
|
||||||
if (null == mIpClientCallback) {
|
if (null == mIpClientCallback) {
|
||||||
@@ -630,7 +634,7 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EthernetNetworkFactory.maybeSendNetworkManagementCallback(
|
EthernetNetworkFactory.maybeSendNetworkManagementCallback(
|
||||||
mIpClientCallback.mNetworkManagementListener, network, e);
|
mIpClientCallback.mNetworkManagementListener, iface, e);
|
||||||
// Only send a single callback per listener.
|
// Only send a single callback per listener.
|
||||||
mIpClientCallback.mNetworkManagementListener = null;
|
mIpClientCallback.mNetworkManagementListener = null;
|
||||||
}
|
}
|
||||||
@@ -671,7 +675,7 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
|||||||
|
|
||||||
/** Returns true if state has been modified */
|
/** Returns true if state has been modified */
|
||||||
boolean updateLinkState(final boolean up,
|
boolean updateLinkState(final boolean up,
|
||||||
@Nullable final IEthernetNetworkManagementListener listener) {
|
@Nullable final INetworkInterfaceOutcomeReceiver listener) {
|
||||||
if (mLinkUp == up) {
|
if (mLinkUp == up) {
|
||||||
EthernetNetworkFactory.maybeSendNetworkManagementCallback(listener, null,
|
EthernetNetworkFactory.maybeSendNetworkManagementCallback(listener, null,
|
||||||
new EthernetNetworkManagementException(
|
new EthernetNetworkManagementException(
|
||||||
@@ -681,13 +685,11 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
|||||||
mLinkUp = up;
|
mLinkUp = up;
|
||||||
|
|
||||||
if (!up) { // was up, goes down
|
if (!up) { // was up, goes down
|
||||||
// Save an instance of the current network to use with the callback before stop().
|
|
||||||
final Network network = mNetworkAgent != null ? mNetworkAgent.getNetwork() : null;
|
|
||||||
// Send an abort on a provisioning request callback if necessary before stopping.
|
// Send an abort on a provisioning request callback if necessary before stopping.
|
||||||
maybeSendNetworkManagementCallbackForAbort();
|
maybeSendNetworkManagementCallbackForAbort();
|
||||||
stop();
|
stop();
|
||||||
// If only setting the interface down, send a callback to signal completion.
|
// If only setting the interface down, send a callback to signal completion.
|
||||||
EthernetNetworkFactory.maybeSendNetworkManagementCallback(listener, network, null);
|
EthernetNetworkFactory.maybeSendNetworkManagementCallback(listener, name, null);
|
||||||
} else { // was down, goes up
|
} else { // was down, goes up
|
||||||
stop();
|
stop();
|
||||||
start(listener);
|
start(listener);
|
||||||
@@ -742,7 +744,7 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
|||||||
restart(null);
|
restart(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
void restart(@Nullable final IEthernetNetworkManagementListener listener){
|
void restart(@Nullable final INetworkInterfaceOutcomeReceiver listener) {
|
||||||
if (DBG) Log.d(TAG, "reconnecting Ethernet");
|
if (DBG) Log.d(TAG, "reconnecting Ethernet");
|
||||||
stop();
|
stop();
|
||||||
start(listener);
|
start(listener);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import android.content.Context;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.net.IEthernetManager;
|
import android.net.IEthernetManager;
|
||||||
import android.net.IEthernetServiceListener;
|
import android.net.IEthernetServiceListener;
|
||||||
import android.net.IEthernetNetworkManagementListener;
|
import android.net.INetworkInterfaceOutcomeReceiver;
|
||||||
import android.net.ITetheredInterfaceCallback;
|
import android.net.ITetheredInterfaceCallback;
|
||||||
import android.net.EthernetNetworkUpdateRequest;
|
import android.net.EthernetNetworkUpdateRequest;
|
||||||
import android.net.IpConfiguration;
|
import android.net.IpConfiguration;
|
||||||
@@ -243,7 +243,7 @@ public class EthernetServiceImpl extends IEthernetManager.Stub {
|
|||||||
@Override
|
@Override
|
||||||
public void updateConfiguration(@NonNull final String iface,
|
public void updateConfiguration(@NonNull final String iface,
|
||||||
@NonNull final EthernetNetworkUpdateRequest request,
|
@NonNull final EthernetNetworkUpdateRequest request,
|
||||||
@Nullable final IEthernetNetworkManagementListener listener) {
|
@Nullable final INetworkInterfaceOutcomeReceiver listener) {
|
||||||
Objects.requireNonNull(iface);
|
Objects.requireNonNull(iface);
|
||||||
Objects.requireNonNull(request);
|
Objects.requireNonNull(request);
|
||||||
throwIfEthernetNotStarted();
|
throwIfEthernetNotStarted();
|
||||||
@@ -260,7 +260,7 @@ public class EthernetServiceImpl extends IEthernetManager.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connectNetwork(@NonNull final String iface,
|
public void connectNetwork(@NonNull final String iface,
|
||||||
@Nullable final IEthernetNetworkManagementListener listener) {
|
@Nullable final INetworkInterfaceOutcomeReceiver listener) {
|
||||||
Log.i(TAG, "connectNetwork called with: iface=" + iface + ", listener=" + listener);
|
Log.i(TAG, "connectNetwork called with: iface=" + iface + ", listener=" + listener);
|
||||||
Objects.requireNonNull(iface);
|
Objects.requireNonNull(iface);
|
||||||
throwIfEthernetNotStarted();
|
throwIfEthernetNotStarted();
|
||||||
@@ -272,7 +272,7 @@ public class EthernetServiceImpl extends IEthernetManager.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnectNetwork(@NonNull final String iface,
|
public void disconnectNetwork(@NonNull final String iface,
|
||||||
@Nullable final IEthernetNetworkManagementListener listener) {
|
@Nullable final INetworkInterfaceOutcomeReceiver listener) {
|
||||||
Log.i(TAG, "disconnectNetwork called with: iface=" + iface + ", listener=" + listener);
|
Log.i(TAG, "disconnectNetwork called with: iface=" + iface + ", listener=" + listener);
|
||||||
Objects.requireNonNull(iface);
|
Objects.requireNonNull(iface);
|
||||||
throwIfEthernetNotStarted();
|
throwIfEthernetNotStarted();
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import android.content.res.Resources;
|
|||||||
import android.net.ConnectivityResources;
|
import android.net.ConnectivityResources;
|
||||||
import android.net.EthernetManager;
|
import android.net.EthernetManager;
|
||||||
import android.net.IEthernetServiceListener;
|
import android.net.IEthernetServiceListener;
|
||||||
import android.net.IEthernetNetworkManagementListener;
|
import android.net.INetworkInterfaceOutcomeReceiver;
|
||||||
import android.net.INetd;
|
import android.net.INetd;
|
||||||
import android.net.ITetheredInterfaceCallback;
|
import android.net.ITetheredInterfaceCallback;
|
||||||
import android.net.InterfaceConfigurationParcel;
|
import android.net.InterfaceConfigurationParcel;
|
||||||
@@ -291,7 +291,7 @@ public class EthernetTracker {
|
|||||||
protected void updateConfiguration(@NonNull final String iface,
|
protected void updateConfiguration(@NonNull final String iface,
|
||||||
@Nullable final IpConfiguration ipConfig,
|
@Nullable final IpConfiguration ipConfig,
|
||||||
@Nullable final NetworkCapabilities capabilities,
|
@Nullable final NetworkCapabilities capabilities,
|
||||||
@Nullable final IEthernetNetworkManagementListener listener) {
|
@Nullable final INetworkInterfaceOutcomeReceiver listener) {
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Log.i(TAG, "updateConfiguration, iface: " + iface + ", capabilities: " + capabilities
|
Log.i(TAG, "updateConfiguration, iface: " + iface + ", capabilities: " + capabilities
|
||||||
+ ", ipConfig: " + ipConfig);
|
+ ", ipConfig: " + ipConfig);
|
||||||
@@ -314,13 +314,13 @@ public class EthernetTracker {
|
|||||||
|
|
||||||
@VisibleForTesting(visibility = PACKAGE)
|
@VisibleForTesting(visibility = PACKAGE)
|
||||||
protected void connectNetwork(@NonNull final String iface,
|
protected void connectNetwork(@NonNull final String iface,
|
||||||
@Nullable final IEthernetNetworkManagementListener listener) {
|
@Nullable final INetworkInterfaceOutcomeReceiver listener) {
|
||||||
mHandler.post(() -> updateInterfaceState(iface, true, listener));
|
mHandler.post(() -> updateInterfaceState(iface, true, listener));
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting(visibility = PACKAGE)
|
@VisibleForTesting(visibility = PACKAGE)
|
||||||
protected void disconnectNetwork(@NonNull final String iface,
|
protected void disconnectNetwork(@NonNull final String iface,
|
||||||
@Nullable final IEthernetNetworkManagementListener listener) {
|
@Nullable final INetworkInterfaceOutcomeReceiver listener) {
|
||||||
mHandler.post(() -> updateInterfaceState(iface, false, listener));
|
mHandler.post(() -> updateInterfaceState(iface, false, listener));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -505,7 +505,7 @@ public class EthernetTracker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateInterfaceState(@NonNull final String iface, final boolean up,
|
private void updateInterfaceState(@NonNull final String iface, final boolean up,
|
||||||
@Nullable final IEthernetNetworkManagementListener listener) {
|
@Nullable final INetworkInterfaceOutcomeReceiver listener) {
|
||||||
final int mode = getInterfaceMode(iface);
|
final int mode = getInterfaceMode(iface);
|
||||||
final boolean factoryLinkStateUpdated = (mode == INTERFACE_MODE_CLIENT)
|
final boolean factoryLinkStateUpdated = (mode == INTERFACE_MODE_CLIENT)
|
||||||
&& mFactory.updateInterfaceLinkState(iface, up, listener);
|
&& mFactory.updateInterfaceLinkState(iface, up, listener);
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ import android.content.Context;
|
|||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.EthernetNetworkSpecifier;
|
import android.net.EthernetNetworkSpecifier;
|
||||||
import android.net.IEthernetNetworkManagementListener;
|
|
||||||
import android.net.EthernetNetworkManagementException;
|
import android.net.EthernetNetworkManagementException;
|
||||||
|
import android.net.INetworkInterfaceOutcomeReceiver;
|
||||||
import android.net.IpConfiguration;
|
import android.net.IpConfiguration;
|
||||||
import android.net.LinkAddress;
|
import android.net.LinkAddress;
|
||||||
import android.net.LinkProperties;
|
import android.net.LinkProperties;
|
||||||
@@ -85,7 +85,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
public class EthernetNetworkFactoryTest {
|
public class EthernetNetworkFactoryTest {
|
||||||
private static final int TIMEOUT_MS = 2_000;
|
private static final int TIMEOUT_MS = 2_000;
|
||||||
private static final String TEST_IFACE = "test123";
|
private static final String TEST_IFACE = "test123";
|
||||||
private static final IEthernetNetworkManagementListener NULL_LISTENER = null;
|
private static final INetworkInterfaceOutcomeReceiver NULL_LISTENER = null;
|
||||||
private static final String IP_ADDR = "192.0.2.2/25";
|
private static final String IP_ADDR = "192.0.2.2/25";
|
||||||
private static final LinkAddress LINK_ADDR = new LinkAddress(IP_ADDR);
|
private static final LinkAddress LINK_ADDR = new LinkAddress(IP_ADDR);
|
||||||
private static final String HW_ADDR = "01:02:03:04:05:06";
|
private static final String HW_ADDR = "01:02:03:04:05:06";
|
||||||
@@ -322,7 +322,7 @@ public class EthernetNetworkFactoryTest {
|
|||||||
|
|
||||||
assertTrue(ret);
|
assertTrue(ret);
|
||||||
verify(mIpClient).shutdown();
|
verify(mIpClient).shutdown();
|
||||||
assertSuccessfulListener(listener, null);
|
assertEquals(listener.expectOnResult(), TEST_IFACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -336,7 +336,7 @@ public class EthernetNetworkFactoryTest {
|
|||||||
|
|
||||||
assertTrue(ret);
|
assertTrue(ret);
|
||||||
verifyStop();
|
verifyStop();
|
||||||
assertSuccessfulListener(listener, mMockNetwork);
|
assertEquals(listener.expectOnResult(), TEST_IFACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -353,7 +353,7 @@ public class EthernetNetworkFactoryTest {
|
|||||||
verify(mDeps, never()).makeIpClient(any(), any(), any());
|
verify(mDeps, never()).makeIpClient(any(), any(), any());
|
||||||
verify(mDeps, never())
|
verify(mDeps, never())
|
||||||
.makeEthernetNetworkAgent(any(), any(), any(), any(), any(), any(), any());
|
.makeEthernetNetworkAgent(any(), any(), any(), any(), any(), any(), any());
|
||||||
assertSuccessfulListener(listener, null);
|
assertEquals(listener.expectOnResult(), TEST_IFACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -367,7 +367,7 @@ public class EthernetNetworkFactoryTest {
|
|||||||
|
|
||||||
assertFalse(ret);
|
assertFalse(ret);
|
||||||
verifyNoStopOrStart();
|
verifyNoStopOrStart();
|
||||||
assertFailedListener(listener, "can't be updated as it is not available");
|
listener.expectOnErrorWithMessage("can't be updated as it is not available");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -381,7 +381,7 @@ public class EthernetNetworkFactoryTest {
|
|||||||
|
|
||||||
assertFalse(ret);
|
assertFalse(ret);
|
||||||
verifyNoStopOrStart();
|
verifyNoStopOrStart();
|
||||||
assertFailedListener(listener, "No changes");
|
listener.expectOnErrorWithMessage("No changes");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -638,18 +638,31 @@ public class EthernetNetworkFactoryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final class TestNetworkManagementListener
|
private static final class TestNetworkManagementListener
|
||||||
implements IEthernetNetworkManagementListener {
|
implements INetworkInterfaceOutcomeReceiver {
|
||||||
private final CompletableFuture<Pair<Network, EthernetNetworkManagementException>> mDone
|
private final CompletableFuture<String> mResult = new CompletableFuture<>();
|
||||||
= new CompletableFuture<>();
|
private final CompletableFuture<EthernetNetworkManagementException> mError =
|
||||||
|
new CompletableFuture<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onComplete(final Network network,
|
public void onResult(@NonNull String iface) {
|
||||||
final EthernetNetworkManagementException exception) {
|
mResult.complete(iface);
|
||||||
mDone.complete(new Pair<>(network, exception));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Pair<Network, EthernetNetworkManagementException> expectOnComplete() throws Exception {
|
@Override
|
||||||
return mDone.get(TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
public void onError(@NonNull EthernetNetworkManagementException exception) {
|
||||||
|
mError.complete(exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
String expectOnResult() throws Exception {
|
||||||
|
return mResult.get(TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
EthernetNetworkManagementException expectOnError() throws Exception {
|
||||||
|
return mError.get(TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
void expectOnErrorWithMessage(String msg) throws Exception {
|
||||||
|
assertTrue(expectOnError().getMessage().contains(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -669,7 +682,7 @@ public class EthernetNetworkFactoryTest {
|
|||||||
mNetFactory.updateInterface(TEST_IFACE, ipConfiguration, capabilities, listener);
|
mNetFactory.updateInterface(TEST_IFACE, ipConfiguration, capabilities, listener);
|
||||||
triggerOnProvisioningSuccess();
|
triggerOnProvisioningSuccess();
|
||||||
|
|
||||||
assertSuccessfulListener(listener, mMockNetwork);
|
assertEquals(listener.expectOnResult(), TEST_IFACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DevSdkIgnoreRule.IgnoreUpTo(SC_V2) // TODO: Use to Build.VERSION_CODES.SC_V2 when available
|
@DevSdkIgnoreRule.IgnoreUpTo(SC_V2) // TODO: Use to Build.VERSION_CODES.SC_V2 when available
|
||||||
@@ -709,26 +722,7 @@ public class EthernetNetworkFactoryTest {
|
|||||||
triggerOnProvisioningSuccess();
|
triggerOnProvisioningSuccess();
|
||||||
});
|
});
|
||||||
|
|
||||||
assertSuccessfulListener(successfulListener, mMockNetwork);
|
assertEquals(successfulListener.expectOnResult(), TEST_IFACE);
|
||||||
}
|
|
||||||
|
|
||||||
private void assertSuccessfulListener(
|
|
||||||
@NonNull final TestNetworkManagementListener successfulListener,
|
|
||||||
@NonNull final Network expectedNetwork) throws Exception {
|
|
||||||
final Pair<Network, EthernetNetworkManagementException> successfulResult =
|
|
||||||
successfulListener.expectOnComplete();
|
|
||||||
assertEquals(expectedNetwork, successfulResult.first);
|
|
||||||
assertNull(successfulResult.second);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertFailedListener(@NonNull final TestNetworkManagementListener failedListener,
|
|
||||||
@NonNull final String errMsg)
|
|
||||||
throws Exception {
|
|
||||||
final Pair<Network, EthernetNetworkManagementException> failedResult =
|
|
||||||
failedListener.expectOnComplete();
|
|
||||||
assertNull(failedResult.first);
|
|
||||||
assertNotNull(failedResult.second);
|
|
||||||
assertTrue(failedResult.second.getMessage().contains(errMsg));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyNetworkManagementCallIsAbortedWhenInterrupted(
|
private void verifyNetworkManagementCallIsAbortedWhenInterrupted(
|
||||||
@@ -743,7 +737,7 @@ public class EthernetNetworkFactoryTest {
|
|||||||
mNetFactory.updateInterface(iface, ipConfiguration, capabilities, failedListener);
|
mNetFactory.updateInterface(iface, ipConfiguration, capabilities, failedListener);
|
||||||
interruptingRunnable.run();
|
interruptingRunnable.run();
|
||||||
|
|
||||||
assertFailedListener(failedListener, "aborted");
|
failedListener.expectOnErrorWithMessage("aborted");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -757,7 +751,7 @@ public class EthernetNetworkFactoryTest {
|
|||||||
mNetFactory.updateInterface(TEST_IFACE, ipConfiguration, capabilities, listener);
|
mNetFactory.updateInterface(TEST_IFACE, ipConfiguration, capabilities, listener);
|
||||||
triggerOnProvisioningSuccess();
|
triggerOnProvisioningSuccess();
|
||||||
|
|
||||||
listener.expectOnComplete();
|
assertEquals(listener.expectOnResult(), TEST_IFACE);
|
||||||
verify(mDeps).makeEthernetNetworkAgent(any(), any(),
|
verify(mDeps).makeEthernetNetworkAgent(any(), any(),
|
||||||
eq(capabilities), any(), any(), any(), any());
|
eq(capabilities), any(), any(), any(), any());
|
||||||
verifyRestart(ipConfiguration);
|
verifyRestart(ipConfiguration);
|
||||||
@@ -774,7 +768,7 @@ public class EthernetNetworkFactoryTest {
|
|||||||
mNetFactory.updateInterface(TEST_IFACE, ipConfiguration, capabilities, listener);
|
mNetFactory.updateInterface(TEST_IFACE, ipConfiguration, capabilities, listener);
|
||||||
|
|
||||||
verifyNoStopOrStart();
|
verifyNoStopOrStart();
|
||||||
assertFailedListener(listener, "can't be updated as it is not available");
|
listener.expectOnErrorWithMessage("can't be updated as it is not available");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import android.Manifest;
|
|||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.net.IEthernetNetworkManagementListener;
|
import android.net.INetworkInterfaceOutcomeReceiver;
|
||||||
import android.net.EthernetNetworkUpdateRequest;
|
import android.net.EthernetNetworkUpdateRequest;
|
||||||
import android.net.IpConfiguration;
|
import android.net.IpConfiguration;
|
||||||
import android.net.NetworkCapabilities;
|
import android.net.NetworkCapabilities;
|
||||||
@@ -64,7 +64,7 @@ public class EthernetServiceImplTest {
|
|||||||
new EthernetNetworkUpdateRequest.Builder()
|
new EthernetNetworkUpdateRequest.Builder()
|
||||||
.setNetworkCapabilities(new NetworkCapabilities.Builder().build())
|
.setNetworkCapabilities(new NetworkCapabilities.Builder().build())
|
||||||
.build();
|
.build();
|
||||||
private static final IEthernetNetworkManagementListener NULL_LISTENER = null;
|
private static final INetworkInterfaceOutcomeReceiver NULL_LISTENER = null;
|
||||||
private EthernetServiceImpl mEthernetServiceImpl;
|
private EthernetServiceImpl mEthernetServiceImpl;
|
||||||
@Mock private Context mContext;
|
@Mock private Context mContext;
|
||||||
@Mock private Handler mHandler;
|
@Mock private Handler mHandler;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import static org.mockito.Mockito.when;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.net.InetAddresses;
|
import android.net.InetAddresses;
|
||||||
import android.net.IEthernetNetworkManagementListener;
|
import android.net.INetworkInterfaceOutcomeReceiver;
|
||||||
import android.net.INetd;
|
import android.net.INetd;
|
||||||
import android.net.IpConfiguration;
|
import android.net.IpConfiguration;
|
||||||
import android.net.IpConfiguration.IpAssignment;
|
import android.net.IpConfiguration.IpAssignment;
|
||||||
@@ -66,7 +66,7 @@ public class EthernetTrackerTest {
|
|||||||
private static final String TEST_IFACE = "test123";
|
private static final String TEST_IFACE = "test123";
|
||||||
private static final int TIMEOUT_MS = 1_000;
|
private static final int TIMEOUT_MS = 1_000;
|
||||||
private static final String THREAD_NAME = "EthernetServiceThread";
|
private static final String THREAD_NAME = "EthernetServiceThread";
|
||||||
private static final IEthernetNetworkManagementListener NULL_LISTENER = null;
|
private static final INetworkInterfaceOutcomeReceiver NULL_LISTENER = null;
|
||||||
private EthernetTracker tracker;
|
private EthernetTracker tracker;
|
||||||
private HandlerThread mHandlerThread;
|
private HandlerThread mHandlerThread;
|
||||||
@Mock private Context mContext;
|
@Mock private Context mContext;
|
||||||
@@ -334,7 +334,7 @@ public class EthernetTrackerTest {
|
|||||||
new StaticIpConfiguration.Builder().setIpAddress(linkAddr).build();
|
new StaticIpConfiguration.Builder().setIpAddress(linkAddr).build();
|
||||||
final IpConfiguration ipConfig =
|
final IpConfiguration ipConfig =
|
||||||
new IpConfiguration.Builder().setStaticIpConfiguration(staticIpConfig).build();
|
new IpConfiguration.Builder().setStaticIpConfiguration(staticIpConfig).build();
|
||||||
final IEthernetNetworkManagementListener listener = null;
|
final INetworkInterfaceOutcomeReceiver listener = null;
|
||||||
|
|
||||||
tracker.updateConfiguration(TEST_IFACE, ipConfig, capabilities, listener);
|
tracker.updateConfiguration(TEST_IFACE, ipConfig, capabilities, listener);
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
|
|||||||
Reference in New Issue
Block a user