[MS39.2] Remove the looper from NetworkStatsSubscriptionMonitor

OnSubscriptionsChangedListenerHandler(Looper looper) is
hidden, there is no way to pass a looper to it in the test.
This change partially revert aosp/1340040 to fix hidden
API dependency. And will use a different approach to address
this problem in later stages.

Test: atest NetworkStatsSubscriptionMonitorTest
Bug: 204830222
Bug: 213280079
Change-Id: Ie17f04cd9f174f2895bde4607bbd7a9a92181a96
This commit is contained in:
Junyu Lai
2022-01-05 07:47:24 +00:00
parent 3cb8fe8c66
commit 0e9c51ca5c
2 changed files with 9 additions and 5 deletions

View File

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

View File

@@ -35,7 +35,7 @@ import android.annotation.Nullable;
import android.content.Context;
import android.net.NetworkTemplate;
import android.os.Build;
import android.os.test.TestLooper;
import android.os.Looper;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
@@ -79,19 +79,23 @@ public final class NetworkStatsSubscriptionsMonitorTest {
private final Executor mExecutor = Executors.newSingleThreadExecutor();
private NetworkStatsSubscriptionsMonitor mMonitor;
private TestLooper mTestLooper = new TestLooper();
@Before
public void setUp() {
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)))
.thenReturn(mSubscriptionManager);
when(mContext.getSystemService(eq(Context.TELEPHONY_SERVICE)))
.thenReturn(mTelephonyManager);
mMonitor = new NetworkStatsSubscriptionsMonitor(mContext, mTestLooper.getLooper(),
mExecutor, mDelegate);
mMonitor = new NetworkStatsSubscriptionsMonitor(mContext, mExecutor, mDelegate);
}
@Test