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

Commit 206239fd authored by Junyu Lai's avatar Junyu Lai Committed by Automerger Merge Worker
Browse files

Merge changes from topics "sm14-puller", "sm16-per-sub" into rvc-dev am: 49d38d8b am: 84f68b3a

Change-Id: I2eb68612f6bdeab0625b5cfc0964a600df7502e9
parents 0f64ccb4 84f68b3a
Loading
Loading
Loading
Loading
+1 −43
Original line number Diff line number Diff line
@@ -160,6 +160,7 @@ import com.android.server.notification.NotificationManagerService;
import com.android.server.role.RoleManagerInternal;
import com.android.server.stats.pull.IonMemoryUtil.IonAllocations;
import com.android.server.stats.pull.ProcfsMemoryUtil.MemorySnapshot;
import com.android.server.stats.pull.netstats.NetworkStatsExt;
import com.android.server.stats.pull.netstats.SubInfo;
import com.android.server.storage.DiskStatsFileLogger;
import com.android.server.storage.DiskStatsLoggingService;
@@ -182,7 +183,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
@@ -817,48 +817,6 @@ public class StatsPullAtomService extends SystemService {
        );
    }

    /**
     * A data class to store a NetworkStats object with information associated to it.
     */
    private static class NetworkStatsExt {
        @NonNull
        public final NetworkStats stats;
        public final int[] transports;
        public final boolean slicedByFgbg;
        public final boolean slicedByTag;
        public final boolean slicedByMetered;
        public final int ratType;
        @Nullable
        public final SubInfo subInfo;

        NetworkStatsExt(@NonNull NetworkStats stats, int[] transports, boolean slicedByFgbg) {
            this(stats, transports, slicedByFgbg, /*slicedByTag=*/false, /*slicedByMetered=*/false,
                    TelephonyManager.NETWORK_TYPE_UNKNOWN, /*subInfo=*/null);
        }

        NetworkStatsExt(@NonNull NetworkStats stats, int[] transports, boolean slicedByFgbg,
                boolean slicedByTag, boolean slicedByMetered, int ratType,
                @Nullable SubInfo subInfo) {
            this.stats = stats;

            // Sort transports array so that we can test for equality without considering order.
            this.transports = Arrays.copyOf(transports, transports.length);
            Arrays.sort(this.transports);

            this.slicedByFgbg = slicedByFgbg;
            this.slicedByTag = slicedByTag;
            this.slicedByMetered = slicedByMetered;
            this.ratType = ratType;
            this.subInfo = subInfo;
        }

        public boolean hasSameSlicing(@NonNull NetworkStatsExt other) {
            return Arrays.equals(transports, other.transports) && slicedByFgbg == other.slicedByFgbg
                    && slicedByTag == other.slicedByTag && slicedByMetered == other.slicedByMetered
                    && ratType == other.ratType && Objects.equals(subInfo, other.subInfo);
        }
    }

    @NonNull
    private List<NetworkStatsExt> collectNetworkStatsSnapshotForAtom(int atomTag) {
        List<NetworkStatsExt> ret = new ArrayList<>();
+72 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.stats.pull.netstats;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.net.NetworkStats;
import android.telephony.TelephonyManager;

import java.util.Arrays;
import java.util.Objects;

/**
 * A data class to store a NetworkStats object with information associated to it.
 *
 * @hide
 */
public class NetworkStatsExt {
    @NonNull
    public final NetworkStats stats;
    public final int[] transports;
    public final boolean slicedByFgbg;
    public final boolean slicedByTag;
    public final boolean slicedByMetered;
    public final int ratType;
    @Nullable
    public final SubInfo subInfo;

    public NetworkStatsExt(@NonNull NetworkStats stats, int[] transports, boolean slicedByFgbg) {
        this(stats, transports, slicedByFgbg, /*slicedByTag=*/false, /*slicedByMetered=*/false,
                TelephonyManager.NETWORK_TYPE_UNKNOWN, /*subInfo=*/null);
    }

    public NetworkStatsExt(@NonNull NetworkStats stats, int[] transports, boolean slicedByFgbg,
            boolean slicedByTag, boolean slicedByMetered, int ratType,
            @Nullable SubInfo subInfo) {
        this.stats = stats;

        // Sort transports array so that we can test for equality without considering order.
        this.transports = Arrays.copyOf(transports, transports.length);
        Arrays.sort(this.transports);

        this.slicedByFgbg = slicedByFgbg;
        this.slicedByTag = slicedByTag;
        this.slicedByMetered = slicedByMetered;
        this.ratType = ratType;
        this.subInfo = subInfo;
    }

    /**
     * A helper function to compare if all fields except NetworkStats are the same.
     */
    public boolean hasSameSlicing(@NonNull NetworkStatsExt other) {
        return Arrays.equals(transports, other.transports) && slicedByFgbg == other.slicedByFgbg
                && slicedByTag == other.slicedByTag && slicedByMetered == other.slicedByMetered
                && ratType == other.ratType && Objects.equals(subInfo, other.subInfo);
    }
}