Merge "Address comments from aosp/1298476" am: 777fbbb954 am: eb276cb5b3 am: a12b3d3626 am: b9e62de14f
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1340040 Change-Id: I067965de3d884bfe8f2832e5116daadd5bda1ae5
This commit is contained in:
@@ -442,7 +442,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
handlerThread.start();
|
||||
mHandler = new NetworkStatsHandler(handlerThread.getLooper());
|
||||
mNetworkStatsSubscriptionsMonitor = deps.makeSubscriptionsMonitor(mContext,
|
||||
new HandlerExecutor(mHandler), this);
|
||||
mHandler.getLooper(), new HandlerExecutor(mHandler), this);
|
||||
mContentResolver = mContext.getContentResolver();
|
||||
mContentObserver = mDeps.makeContentObserver(mHandler, mSettings,
|
||||
mNetworkStatsSubscriptionsMonitor);
|
||||
@@ -468,11 +468,12 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
*/
|
||||
@NonNull
|
||||
public NetworkStatsSubscriptionsMonitor makeSubscriptionsMonitor(@NonNull Context context,
|
||||
@NonNull Executor executor, @NonNull NetworkStatsService service) {
|
||||
@NonNull Looper looper, @NonNull Executor executor,
|
||||
@NonNull NetworkStatsService service) {
|
||||
// TODO: Update RatType passively in NSS, instead of querying into the monitor
|
||||
// when forceUpdateIface.
|
||||
return new NetworkStatsSubscriptionsMonitor(context, executor, (subscriberId, type) ->
|
||||
service.handleOnCollapsedRatTypeChanged());
|
||||
return new NetworkStatsSubscriptionsMonitor(context, looper, executor,
|
||||
(subscriberId, type) -> service.handleOnCollapsedRatTypeChanged());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,6 +20,7 @@ import static android.net.NetworkTemplate.getCollapsedRatType;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.content.Context;
|
||||
import android.os.Looper;
|
||||
import android.telephony.Annotation;
|
||||
import android.telephony.PhoneStateListener;
|
||||
import android.telephony.ServiceState;
|
||||
@@ -75,9 +76,9 @@ public class NetworkStatsSubscriptionsMonitor extends
|
||||
@NonNull
|
||||
private final Executor mExecutor;
|
||||
|
||||
NetworkStatsSubscriptionsMonitor(@NonNull Context context, @NonNull Executor executor,
|
||||
@NonNull Delegate delegate) {
|
||||
super();
|
||||
NetworkStatsSubscriptionsMonitor(@NonNull Context context, @NonNull Looper looper,
|
||||
@NonNull Executor executor, @NonNull Delegate delegate) {
|
||||
super(looper);
|
||||
mSubscriptionManager = (SubscriptionManager) context.getSystemService(
|
||||
Context.TELEPHONY_SUBSCRIPTION_SERVICE);
|
||||
mTeleManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
|
||||
@@ -245,7 +245,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
||||
|
||||
@Override
|
||||
public NetworkStatsSubscriptionsMonitor makeSubscriptionsMonitor(
|
||||
@NonNull Context context, @NonNull Executor executor,
|
||||
@NonNull Context context, @NonNull Looper looper, @NonNull Executor executor,
|
||||
@NonNull NetworkStatsService service) {
|
||||
|
||||
return mNetworkStatsSubscriptionsMonitor;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.android.server.net;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.anyInt;
|
||||
import static org.mockito.Mockito.eq;
|
||||
@@ -29,14 +30,13 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.content.Context;
|
||||
import android.os.Looper;
|
||||
import android.os.test.TestLooper;
|
||||
import android.telephony.PhoneStateListener;
|
||||
import android.telephony.ServiceState;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import com.android.internal.util.CollectionUtils;
|
||||
import com.android.server.net.NetworkStatsSubscriptionsMonitor.Delegate;
|
||||
import com.android.server.net.NetworkStatsSubscriptionsMonitor.RatTypeListener;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -64,20 +64,17 @@ public final class NetworkStatsSubscriptionsMonitorTest {
|
||||
@Mock private PhoneStateListener mPhoneStateListener;
|
||||
@Mock private SubscriptionManager mSubscriptionManager;
|
||||
@Mock private TelephonyManager mTelephonyManager;
|
||||
@Mock private Delegate mDelegate;
|
||||
@Mock private NetworkStatsSubscriptionsMonitor.Delegate mDelegate;
|
||||
private final List<Integer> mTestSubList = new ArrayList<>();
|
||||
|
||||
private final Executor mExecutor = Executors.newSingleThreadExecutor();
|
||||
private NetworkStatsSubscriptionsMonitor mMonitor;
|
||||
private TestLooper mTestLooper = new TestLooper();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
if (Looper.myLooper() == null) {
|
||||
Looper.prepare();
|
||||
}
|
||||
|
||||
when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager);
|
||||
|
||||
when(mContext.getSystemService(eq(Context.TELEPHONY_SUBSCRIPTION_SERVICE)))
|
||||
@@ -85,7 +82,8 @@ public final class NetworkStatsSubscriptionsMonitorTest {
|
||||
when(mContext.getSystemService(eq(Context.TELEPHONY_SERVICE)))
|
||||
.thenReturn(mTelephonyManager);
|
||||
|
||||
mMonitor = new NetworkStatsSubscriptionsMonitor(mContext, mExecutor, mDelegate);
|
||||
mMonitor = new NetworkStatsSubscriptionsMonitor(mContext, mTestLooper.getLooper(),
|
||||
mExecutor, mDelegate);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,16 +115,18 @@ public final class NetworkStatsSubscriptionsMonitorTest {
|
||||
when(serviceState.getDataNetworkType()).thenReturn(type);
|
||||
final RatTypeListener match = CollectionUtils
|
||||
.find(listeners, it -> it.getSubId() == subId);
|
||||
if (match != null) {
|
||||
match.onServiceStateChanged(serviceState);
|
||||
if (match == null) {
|
||||
fail("Could not find listener with subId: " + subId);
|
||||
}
|
||||
match.onServiceStateChanged(serviceState);
|
||||
}
|
||||
|
||||
private void addTestSub(int subId, String subscriberId) {
|
||||
// add SubId to TestSubList.
|
||||
if (!mTestSubList.contains(subId)) {
|
||||
mTestSubList.add(subId);
|
||||
}
|
||||
if (mTestSubList.contains(subId)) fail("The subscriber list already contains this ID");
|
||||
|
||||
mTestSubList.add(subId);
|
||||
|
||||
final int[] subList = convertArrayListToIntArray(mTestSubList);
|
||||
when(mSubscriptionManager.getCompleteActiveSubscriptionIdList()).thenReturn(subList);
|
||||
when(mTelephonyManager.getSubscriberId(subId)).thenReturn(subscriberId);
|
||||
|
||||
Reference in New Issue
Block a user