Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b9e62de1 authored by Aaron Huang's avatar Aaron Huang Committed by Automerger Merge Worker
Browse files

Merge "Address comments from aosp/1298476" am: 777fbbb9 am: eb276cb5 am: a12b3d36

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1340040

Change-Id: I8557b955af2d28122054df5236a38543523909f4
parents f85f638a a12b3d36
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -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());
        }

        /**
+4 −3
Original line number Diff line number Diff line
@@ -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);
+1 −1
Original line number Diff line number Diff line
@@ -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;
+13 −13
Original line number Diff line number Diff line
@@ -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)) {
        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);