Merge "[MS39.2] Remove the looper from NetworkStatsSubscriptionMonitor"

This commit is contained in:
Treehugger Robot
2022-01-07 14:42:52 +00:00
committed by Gerrit Code Review
2 changed files with 9 additions and 5 deletions

View File

@@ -307,7 +307,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
@Override @Override
public NetworkStatsSubscriptionsMonitor makeSubscriptionsMonitor( public NetworkStatsSubscriptionsMonitor makeSubscriptionsMonitor(
@NonNull Context context, @NonNull Looper looper, @NonNull Executor executor, @NonNull Context context, @NonNull Executor executor,
@NonNull NetworkStatsService service) { @NonNull NetworkStatsService service) {
return mNetworkStatsSubscriptionsMonitor; return mNetworkStatsSubscriptionsMonitor;

View File

@@ -35,7 +35,7 @@ import android.annotation.Nullable;
import android.content.Context; import android.content.Context;
import android.net.NetworkTemplate; import android.net.NetworkTemplate;
import android.os.Build; import android.os.Build;
import android.os.test.TestLooper; import android.os.Looper;
import android.telephony.NetworkRegistrationInfo; import android.telephony.NetworkRegistrationInfo;
import android.telephony.PhoneStateListener; import android.telephony.PhoneStateListener;
import android.telephony.ServiceState; import android.telephony.ServiceState;
@@ -79,19 +79,23 @@ public final class NetworkStatsSubscriptionsMonitorTest {
private final Executor mExecutor = Executors.newSingleThreadExecutor(); private final Executor mExecutor = Executors.newSingleThreadExecutor();
private NetworkStatsSubscriptionsMonitor mMonitor; private NetworkStatsSubscriptionsMonitor mMonitor;
private TestLooper mTestLooper = new TestLooper();
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
// TODO(b/213280079): Start a different thread and prepare the looper, create the monitor
// on that thread instead of using the test main thread looper.
if (Looper.myLooper() == null) {
Looper.prepare();
}
when(mContext.getSystemService(eq(Context.TELEPHONY_SUBSCRIPTION_SERVICE))) when(mContext.getSystemService(eq(Context.TELEPHONY_SUBSCRIPTION_SERVICE)))
.thenReturn(mSubscriptionManager); .thenReturn(mSubscriptionManager);
when(mContext.getSystemService(eq(Context.TELEPHONY_SERVICE))) when(mContext.getSystemService(eq(Context.TELEPHONY_SERVICE)))
.thenReturn(mTelephonyManager); .thenReturn(mTelephonyManager);
mMonitor = new NetworkStatsSubscriptionsMonitor(mContext, mTestLooper.getLooper(), mMonitor = new NetworkStatsSubscriptionsMonitor(mContext, mExecutor, mDelegate);
mExecutor, mDelegate);
} }
@Test @Test