Test tethering log dump
Bug: 145490751 Test: atest TetheringTests Merged-In: I01fc6969041711f7a15880144ee5eac591086ecd Change-Id: I01fc6969041711f7a15880144ee5eac591086ecd
This commit is contained in:
@@ -62,7 +62,6 @@ import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
|
||||
import static com.android.networkstack.tethering.TetheringNotificationUpdater.DOWNSTREAM_NONE;
|
||||
|
||||
import android.app.usage.NetworkStatsManager;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothPan;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
@@ -268,12 +267,9 @@ public class Tethering {
|
||||
mTetherMasterSM = new TetherMasterSM("TetherMaster", mLooper, deps);
|
||||
mTetherMasterSM.start();
|
||||
|
||||
final NetworkStatsManager statsManager =
|
||||
(NetworkStatsManager) mContext.getSystemService(Context.NETWORK_STATS_SERVICE);
|
||||
mHandler = mTetherMasterSM.getHandler();
|
||||
mOffloadController = new OffloadController(mHandler,
|
||||
mDeps.getOffloadHardwareInterface(mHandler, mLog), mContext.getContentResolver(),
|
||||
statsManager, mLog, new OffloadController.Dependencies() {
|
||||
mOffloadController = mDeps.getOffloadController(mHandler, mLog,
|
||||
new OffloadController.Dependencies() {
|
||||
|
||||
@Override
|
||||
public TetheringConfiguration getTetherConfig() {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.networkstack.tethering;
|
||||
|
||||
import android.app.usage.NetworkStatsManager;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.Context;
|
||||
import android.net.INetd;
|
||||
@@ -46,6 +47,19 @@ public abstract class TetheringDependencies {
|
||||
return new OffloadHardwareInterface(h, log);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a reference to the offload controller to be used by tethering.
|
||||
*/
|
||||
@NonNull
|
||||
public OffloadController getOffloadController(@NonNull Handler h,
|
||||
@NonNull SharedLog log, @NonNull OffloadController.Dependencies deps) {
|
||||
final NetworkStatsManager statsManager =
|
||||
(NetworkStatsManager) getContext().getSystemService(Context.NETWORK_STATS_SERVICE);
|
||||
return new OffloadController(h, getOffloadHardwareInterface(h, log),
|
||||
getContext().getContentResolver(), statsManager, log, deps);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a reference to the UpstreamNetworkMonitor to be used by tethering.
|
||||
*/
|
||||
|
||||
@@ -150,6 +150,8 @@ import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
import java.util.ArrayList;
|
||||
@@ -212,6 +214,9 @@ public class TetheringTest {
|
||||
private Tethering mTethering;
|
||||
private PhoneStateListener mPhoneStateListener;
|
||||
private InterfaceConfigurationParcel mInterfaceConfiguration;
|
||||
private TetheringConfiguration mConfig;
|
||||
private EntitlementManager mEntitleMgr;
|
||||
private OffloadController mOffloadCtrl;
|
||||
|
||||
private class TestContext extends BroadcastInterceptingContext {
|
||||
TestContext(Context base) {
|
||||
@@ -297,8 +302,9 @@ public class TetheringTest {
|
||||
}
|
||||
}
|
||||
|
||||
private class MockTetheringConfiguration extends TetheringConfiguration {
|
||||
MockTetheringConfiguration(Context ctx, SharedLog log, int id) {
|
||||
// MyTetheringConfiguration is used to override static method for testing.
|
||||
private class MyTetheringConfiguration extends TetheringConfiguration {
|
||||
MyTetheringConfiguration(Context ctx, SharedLog log, int id) {
|
||||
super(ctx, log, id);
|
||||
}
|
||||
|
||||
@@ -327,6 +333,15 @@ public class TetheringTest {
|
||||
return mOffloadHardwareInterface;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OffloadController getOffloadController(Handler h, SharedLog log,
|
||||
OffloadController.Dependencies deps) {
|
||||
mOffloadCtrl = spy(super.getOffloadController(h, log, deps));
|
||||
// Return real object here instead of mock because
|
||||
// testReportFailCallbackIfOffloadNotSupported depend on real OffloadController object.
|
||||
return mOffloadCtrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpstreamNetworkMonitor getUpstreamNetworkMonitor(Context ctx,
|
||||
StateMachine target, SharedLog log, int what) {
|
||||
@@ -351,6 +366,13 @@ public class TetheringTest {
|
||||
return mNetworkRequest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntitlementManager getEntitlementManager(Context ctx, StateMachine target,
|
||||
SharedLog log, int what) {
|
||||
mEntitleMgr = spy(super.getEntitlementManager(ctx, target, log, what));
|
||||
return mEntitleMgr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTetheringSupported() {
|
||||
return true;
|
||||
@@ -359,7 +381,8 @@ public class TetheringTest {
|
||||
@Override
|
||||
public TetheringConfiguration generateTetheringConfiguration(Context ctx, SharedLog log,
|
||||
int subId) {
|
||||
return new MockTetheringConfiguration(ctx, log, subId);
|
||||
mConfig = spy(new MyTetheringConfiguration(ctx, log, subId));
|
||||
return mConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1726,6 +1749,17 @@ public class TetheringTest {
|
||||
verify(mNotificationUpdater, never()).onUpstreamCapabilitiesChanged(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDumpTetheringLog() throws Exception {
|
||||
final FileDescriptor mockFd = mock(FileDescriptor.class);
|
||||
final PrintWriter mockPw = mock(PrintWriter.class);
|
||||
runUsbTethering(null);
|
||||
mTethering.dump(mockFd, mockPw, new String[0]);
|
||||
verify(mConfig).dump(any());
|
||||
verify(mEntitleMgr).dump(any());
|
||||
verify(mOffloadCtrl).dump(any());
|
||||
}
|
||||
|
||||
// TODO: Test that a request for hotspot mode doesn't interfere with an
|
||||
// already operating tethering mode interface.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user