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