Move NetworkStatsExt to a standalone file

This is a no-op refactoring.

Test: atest UidAtomTests#testMobileBytesTransfer \
      UidAtomTests#testMobileBytesTransferByFgBg \
      UidAtomTests#testDataUsageBytesTransfer
Bug: 129082217
Change-Id: I52d3418c1f46acfd38bc281d87fa1d1abf6ff469
This commit is contained in:
junyulai
2020-05-22 11:44:03 +08:00
parent aa31d3cb11
commit c2d3a68873
2 changed files with 73 additions and 43 deletions

View File

@@ -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<>();

View File

@@ -0,0 +1,72 @@
/*
* 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);
}
}