Merge "Test tethering log dump" am: 0e3371469e
Change-Id: I3218a3c600ffc4be33a660362cbb5dd001437171
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 static com.android.networkstack.tethering.TetheringNotificationUpdater.DOWNSTREAM_NONE;
|
||||||
|
|
||||||
import android.app.usage.NetworkStatsManager;
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothPan;
|
import android.bluetooth.BluetoothPan;
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
@@ -268,12 +267,9 @@ public class Tethering {
|
|||||||
mTetherMasterSM = new TetherMasterSM("TetherMaster", mLooper, deps);
|
mTetherMasterSM = new TetherMasterSM("TetherMaster", mLooper, deps);
|
||||||
mTetherMasterSM.start();
|
mTetherMasterSM.start();
|
||||||
|
|
||||||
final NetworkStatsManager statsManager =
|
|
||||||
(NetworkStatsManager) mContext.getSystemService(Context.NETWORK_STATS_SERVICE);
|
|
||||||
mHandler = mTetherMasterSM.getHandler();
|
mHandler = mTetherMasterSM.getHandler();
|
||||||
mOffloadController = new OffloadController(mHandler,
|
mOffloadController = mDeps.getOffloadController(mHandler, mLog,
|
||||||
mDeps.getOffloadHardwareInterface(mHandler, mLog), mContext.getContentResolver(),
|
new OffloadController.Dependencies() {
|
||||||
statsManager, mLog, new OffloadController.Dependencies() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TetheringConfiguration getTetherConfig() {
|
public TetheringConfiguration getTetherConfig() {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.networkstack.tethering;
|
package com.android.networkstack.tethering;
|
||||||
|
|
||||||
|
import android.app.usage.NetworkStatsManager;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.INetd;
|
import android.net.INetd;
|
||||||
@@ -46,6 +47,19 @@ public abstract class TetheringDependencies {
|
|||||||
return new OffloadHardwareInterface(h, log);
|
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.
|
* 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.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import java.io.FileDescriptor;
|
||||||
|
import java.io.PrintWriter;
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.net.Inet6Address;
|
import java.net.Inet6Address;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -212,6 +214,9 @@ public class TetheringTest {
|
|||||||
private Tethering mTethering;
|
private Tethering mTethering;
|
||||||
private PhoneStateListener mPhoneStateListener;
|
private PhoneStateListener mPhoneStateListener;
|
||||||
private InterfaceConfigurationParcel mInterfaceConfiguration;
|
private InterfaceConfigurationParcel mInterfaceConfiguration;
|
||||||
|
private TetheringConfiguration mConfig;
|
||||||
|
private EntitlementManager mEntitleMgr;
|
||||||
|
private OffloadController mOffloadCtrl;
|
||||||
|
|
||||||
private class TestContext extends BroadcastInterceptingContext {
|
private class TestContext extends BroadcastInterceptingContext {
|
||||||
TestContext(Context base) {
|
TestContext(Context base) {
|
||||||
@@ -297,8 +302,9 @@ public class TetheringTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MockTetheringConfiguration extends TetheringConfiguration {
|
// MyTetheringConfiguration is used to override static method for testing.
|
||||||
MockTetheringConfiguration(Context ctx, SharedLog log, int id) {
|
private class MyTetheringConfiguration extends TetheringConfiguration {
|
||||||
|
MyTetheringConfiguration(Context ctx, SharedLog log, int id) {
|
||||||
super(ctx, log, id);
|
super(ctx, log, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,6 +333,15 @@ public class TetheringTest {
|
|||||||
return mOffloadHardwareInterface;
|
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
|
@Override
|
||||||
public UpstreamNetworkMonitor getUpstreamNetworkMonitor(Context ctx,
|
public UpstreamNetworkMonitor getUpstreamNetworkMonitor(Context ctx,
|
||||||
StateMachine target, SharedLog log, int what) {
|
StateMachine target, SharedLog log, int what) {
|
||||||
@@ -351,6 +366,13 @@ public class TetheringTest {
|
|||||||
return mNetworkRequest;
|
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
|
@Override
|
||||||
public boolean isTetheringSupported() {
|
public boolean isTetheringSupported() {
|
||||||
return true;
|
return true;
|
||||||
@@ -359,7 +381,8 @@ public class TetheringTest {
|
|||||||
@Override
|
@Override
|
||||||
public TetheringConfiguration generateTetheringConfiguration(Context ctx, SharedLog log,
|
public TetheringConfiguration generateTetheringConfiguration(Context ctx, SharedLog log,
|
||||||
int subId) {
|
int subId) {
|
||||||
return new MockTetheringConfiguration(ctx, log, subId);
|
mConfig = spy(new MyTetheringConfiguration(ctx, log, subId));
|
||||||
|
return mConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1726,6 +1749,17 @@ public class TetheringTest {
|
|||||||
verify(mNotificationUpdater, never()).onUpstreamCapabilitiesChanged(any());
|
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
|
// TODO: Test that a request for hotspot mode doesn't interfere with an
|
||||||
// already operating tethering mode interface.
|
// already operating tethering mode interface.
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user