Merge changes I4719b4dc,I0308cdf4,I38db1bb7
am: e5090f2547
Change-Id: I3b222afc77b121769cc18d52e5c3d8bcec9db886
This commit is contained in:
@@ -278,6 +278,10 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
|
|||||||
return mHandler;
|
return mHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Network network() {
|
||||||
|
return network;
|
||||||
|
}
|
||||||
|
|
||||||
// Functions for manipulating the requests satisfied by this network.
|
// Functions for manipulating the requests satisfied by this network.
|
||||||
//
|
//
|
||||||
// These functions must only called on ConnectivityService's main thread.
|
// These functions must only called on ConnectivityService's main thread.
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class NsdManagerTest {
|
|||||||
|
|
||||||
NsdManager mManager;
|
NsdManager mManager;
|
||||||
|
|
||||||
long mTimeoutMs = 100; // non-final so that tests can adjust the value.
|
long mTimeoutMs = 200; // non-final so that tests can adjust the value.
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
@@ -74,7 +74,7 @@ public class NsdManagerTest {
|
|||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
waitForIdleHandler(mServiceHandler, mTimeoutMs);
|
mServiceHandler.waitForIdle(mTimeoutMs);
|
||||||
mServiceHandler.chan.disconnect();
|
mServiceHandler.chan.disconnect();
|
||||||
mServiceHandler.stop();
|
mServiceHandler.stop();
|
||||||
if (mManager != null) {
|
if (mManager != null) {
|
||||||
@@ -334,9 +334,10 @@ public class NsdManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int verifyRequest(int expectedMessageType) {
|
int verifyRequest(int expectedMessageType) {
|
||||||
|
mServiceHandler.waitForIdle(mTimeoutMs);
|
||||||
verify(mServiceHandler, timeout(mTimeoutMs)).handleMessage(any());
|
verify(mServiceHandler, timeout(mTimeoutMs)).handleMessage(any());
|
||||||
reset(mServiceHandler);
|
reset(mServiceHandler);
|
||||||
Message received = mServiceHandler.lastMessage;
|
Message received = mServiceHandler.getLastMessage();
|
||||||
assertEquals(NsdManager.nameOf(expectedMessageType), NsdManager.nameOf(received.what));
|
assertEquals(NsdManager.nameOf(expectedMessageType), NsdManager.nameOf(received.what));
|
||||||
return received.arg2;
|
return received.arg2;
|
||||||
}
|
}
|
||||||
@@ -347,31 +348,43 @@ public class NsdManagerTest {
|
|||||||
|
|
||||||
// Implements the server side of AsyncChannel connection protocol
|
// Implements the server side of AsyncChannel connection protocol
|
||||||
public static class MockServiceHandler extends Handler {
|
public static class MockServiceHandler extends Handler {
|
||||||
public Context mContext;
|
public final Context context;
|
||||||
public AsyncChannel chan;
|
public AsyncChannel chan;
|
||||||
public volatile Message lastMessage;
|
public Message lastMessage;
|
||||||
|
|
||||||
MockServiceHandler(Looper looper, Context context) {
|
MockServiceHandler(Looper l, Context c) {
|
||||||
super(looper);
|
super(l);
|
||||||
mContext = context;
|
context = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized Message getLastMessage() {
|
||||||
|
return lastMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized void setLastMessage(Message msg) {
|
||||||
|
lastMessage = obtainMessage();
|
||||||
|
lastMessage.copyFrom(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void waitForIdle(long timeoutMs) {
|
||||||
|
waitForIdleHandler(this, timeoutMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
lastMessage = obtainMessage();
|
setLastMessage(msg);
|
||||||
lastMessage.copyFrom(msg);
|
|
||||||
if (msg.what == AsyncChannel.CMD_CHANNEL_FULL_CONNECTION) {
|
if (msg.what == AsyncChannel.CMD_CHANNEL_FULL_CONNECTION) {
|
||||||
chan = new AsyncChannel();
|
chan = new AsyncChannel();
|
||||||
chan.connect(mContext, this, msg.replyTo);
|
chan.connect(context, this, msg.replyTo);
|
||||||
chan.sendMessage(AsyncChannel.CMD_CHANNEL_FULLY_CONNECTED);
|
chan.sendMessage(AsyncChannel.CMD_CHANNEL_FULLY_CONNECTED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
void stop() {
|
||||||
getLooper().quitSafely();
|
getLooper().quitSafely();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MockServiceHandler create(Context context) {
|
static MockServiceHandler create(Context context) {
|
||||||
HandlerThread t = new HandlerThread("mock-service-handler");
|
HandlerThread t = new HandlerThread("mock-service-handler");
|
||||||
t.start();
|
t.start();
|
||||||
return new MockServiceHandler(t.getLooper(), context);
|
return new MockServiceHandler(t.getLooper(), context);
|
||||||
|
|||||||
@@ -683,7 +683,8 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
|||||||
public WrappedNetworkMonitor(Context context, Handler handler,
|
public WrappedNetworkMonitor(Context context, Handler handler,
|
||||||
NetworkAgentInfo networkAgentInfo, NetworkRequest defaultRequest,
|
NetworkAgentInfo networkAgentInfo, NetworkRequest defaultRequest,
|
||||||
IpConnectivityLog log) {
|
IpConnectivityLog log) {
|
||||||
super(context, handler, networkAgentInfo, defaultRequest, log);
|
super(context, handler, networkAgentInfo, defaultRequest, log,
|
||||||
|
NetworkMonitor.NetworkMonitorSettings.DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user