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

Commit 20b0af80 authored by Makoto Onuki's avatar Makoto Onuki Committed by Android (Google) Code Review
Browse files

Merge "Support protofied dumpsys for NetStats"

parents 2582b80a da65a52f
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -24,8 +24,10 @@ import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.service.NetworkIdentityProto;
import android.telephony.TelephonyManager;
import android.util.Slog;
import android.util.proto.ProtoOutputStream;

import java.util.Objects;

@@ -110,6 +112,23 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
        return builder.append("}").toString();
    }

    public void writeToProto(ProtoOutputStream proto, long tag) {
        final long start = proto.start(tag);

        proto.write(NetworkIdentityProto.TYPE, mType);

        // Not dumping mSubType, subtypes are no longer supported.

        if (mSubscriberId != null) {
            proto.write(NetworkIdentityProto.SUBSCRIBER_ID, scrubSubscriberId(mSubscriberId));
        }
        proto.write(NetworkIdentityProto.NETWORK_ID, mNetworkId);
        proto.write(NetworkIdentityProto.ROAMING, mRoaming);
        proto.write(NetworkIdentityProto.METERED, mMetered);

        proto.end(start);
    }

    public int getType() {
        return mType;
    }
+30 −0
Original line number Diff line number Diff line
@@ -31,7 +31,10 @@ import static com.android.internal.util.ArrayUtils.total;

import android.os.Parcel;
import android.os.Parcelable;
import android.service.NetworkStatsHistoryBucketProto;
import android.service.NetworkStatsHistoryProto;
import android.util.MathUtils;
import android.util.proto.ProtoOutputStream;

import com.android.internal.util.IndentingPrintWriter;

@@ -628,6 +631,33 @@ public class NetworkStatsHistory implements Parcelable {
        }
    }

    public void writeToProto(ProtoOutputStream proto, long tag) {
        final long start = proto.start(tag);

        proto.write(NetworkStatsHistoryProto.BUCKET_DURATION_MS, bucketDuration);

        for (int i = 0; i < bucketCount; i++) {
            final long startBucket = proto.start(NetworkStatsHistoryProto.BUCKETS);

            proto.write(NetworkStatsHistoryBucketProto.BUCKET_START_MS, bucketStart[i]);
            writeToProto(proto, NetworkStatsHistoryBucketProto.RX_BYTES, rxBytes, i);
            writeToProto(proto, NetworkStatsHistoryBucketProto.RX_PACKETS, rxPackets, i);
            writeToProto(proto, NetworkStatsHistoryBucketProto.TX_BYTES, txBytes, i);
            writeToProto(proto, NetworkStatsHistoryBucketProto.TX_PACKETS, txPackets, i);
            writeToProto(proto, NetworkStatsHistoryBucketProto.OPERATIONS, operations, i);

            proto.end(startBucket);
        }

        proto.end(start);
    }

    private static void writeToProto(ProtoOutputStream proto, long tag, long[] array, int index) {
        if (array != null) {
            proto.write(tag, array[index]);
        }
    }

    @Override
    public String toString() {
        final CharArrayWriter writer = new CharArrayWriter();
+2 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ option java_outer_classname = "IncidentProtoMetadata";

import "frameworks/base/libs/incident/proto/android/privacy.proto";
import "frameworks/base/core/proto/android/service/fingerprint.proto";
import "frameworks/base/core/proto/android/service/netstats.proto";

package android.os;

@@ -49,4 +50,5 @@ message IncidentProto {

    // System Services
    android.service.fingerprint.FingerprintServiceDumpProto fingerprint = 3000;
    android.service.NetworkStatsServiceDumpProto netstats = 3001;
}
+117 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.
 */

syntax = "proto3";

package android.service;

option java_multiple_files = true;
option java_outer_classname = "NetworkStatsServiceProto";

// Represents dumpsys from NetworkStatsService (netstats).
message NetworkStatsServiceDumpProto {
    repeated NetworkInterfaceProto active_interfaces = 1;

    repeated NetworkInterfaceProto active_uid_interfaces = 2;

    NetworkStatsRecorderProto dev_stats = 3;

    NetworkStatsRecorderProto xt_stats = 4;

    NetworkStatsRecorderProto uid_stats = 5;

    NetworkStatsRecorderProto uid_tag_stats = 6;
}

// Corresponds to NetworkStatsService.mActiveIfaces/mActiveUidIfaces.
message NetworkInterfaceProto {
    string interface = 1;

    NetworkIdentitySetProto identities = 2;
}

// Corresponds to NetworkIdentitySet.
message NetworkIdentitySetProto {
    repeated NetworkIdentityProto identities = 1;
}

// Corresponds to NetworkIdentity.
message NetworkIdentityProto {
    // Constats from ConnectivityManager.TYPE_*.
    int32 type = 1;

    string subscriber_id = 2;

    string network_id = 3;

    bool roaming = 4;

    bool metered = 5;
}

// Corresponds to NetworkStatsRecorder.
message NetworkStatsRecorderProto {
    int64 pending_total_bytes = 1;

    NetworkStatsCollectionProto complete_history = 2;
}

// Corresponds to NetworkStatsCollection.
message NetworkStatsCollectionProto {
    repeated NetworkStatsCollectionStatsProto stats = 1;
}

// Corresponds to NetworkStatsCollection.mStats.
message NetworkStatsCollectionStatsProto {
    NetworkStatsCollectionKeyProto key = 1;

    NetworkStatsHistoryProto history = 2;
}

// Corresponds to NetworkStatsCollection.Key.
message NetworkStatsCollectionKeyProto {
    NetworkIdentitySetProto identity = 1;

    int32 uid = 2;

    int32 set = 3;

    int32 tag = 4;
}

// Corresponds to NetworkStatsHistory.
message NetworkStatsHistoryProto {
    // Duration for this bucket in milliseconds.
    int64 bucket_duration_ms = 1;

    repeated NetworkStatsHistoryBucketProto buckets = 2;
}

// Corresponds to each bucket in NetworkStatsHistory.
message NetworkStatsHistoryBucketProto {
    // Bucket start time in milliseconds since epoch.
    int64 bucket_start_ms = 1;

    int64 rx_bytes = 2;

    int64 rx_packets = 3;

    int64 tx_bytes = 4;

    int64 tx_packets = 5;

    int64 operations = 6;
}
+12 −0
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
package com.android.server.net;

import android.net.NetworkIdentity;
import android.service.NetworkIdentitySetProto;
import android.util.proto.ProtoOutputStream;

import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -143,4 +145,14 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
        final NetworkIdentity anotherIdent = another.iterator().next();
        return ident.compareTo(anotherIdent);
    }

    public void writeToProto(ProtoOutputStream proto, long tag) {
        final long start = proto.start(tag);

        for (NetworkIdentity ident : this) {
            ident.writeToProto(proto, NetworkIdentitySetProto.IDENTITIES);
        }

        proto.end(start);
    }
}
Loading