Loading services/core/java/com/android/server/net/NetworkStatsService.java +5 −4 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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()); } /** Loading services/core/java/com/android/server/net/NetworkStatsSubscriptionsMonitor.java +4 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading tests/net/java/com/android/server/net/NetworkStatsServiceTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -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; Loading tests/net/java/com/android/server/net/NetworkStatsSubscriptionsMonitorTest.java +13 −13 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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))) Loading @@ -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 Loading Loading @@ -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)) { if (mTestSubList.contains(subId)) fail("The subscriber list already contains this ID"); mTestSubList.add(subId); } final int[] subList = convertArrayListToIntArray(mTestSubList); when(mSubscriptionManager.getActiveAndHiddenSubscriptionIdList()).thenReturn(subList); when(mTelephonyManager.getSubscriberId(subId)).thenReturn(subscriberId); Loading Loading
services/core/java/com/android/server/net/NetworkStatsService.java +5 −4 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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()); } /** Loading
services/core/java/com/android/server/net/NetworkStatsSubscriptionsMonitor.java +4 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading
tests/net/java/com/android/server/net/NetworkStatsServiceTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -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; Loading
tests/net/java/com/android/server/net/NetworkStatsSubscriptionsMonitorTest.java +13 −13 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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))) Loading @@ -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 Loading Loading @@ -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)) { if (mTestSubList.contains(subId)) fail("The subscriber list already contains this ID"); mTestSubList.add(subId); } final int[] subList = convertArrayListToIntArray(mTestSubList); when(mSubscriptionManager.getActiveAndHiddenSubscriptionIdList()).thenReturn(subList); when(mTelephonyManager.getSubscriberId(subId)).thenReturn(subscriberId); Loading