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

Commit 09a81e4d authored by Chenbo Feng's avatar Chenbo Feng Committed by android-build-merger
Browse files

Merge "Use NetworkStatsService to get stats for apps" am: 693d8a2a

am: fa7f4015

Change-Id: I14f614a86214bd4f006415c48b9a8323e06c737f
parents 7ad3eb8d fa7f4015
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -67,4 +67,13 @@ interface INetworkStatsService {
    /** Unregisters a callback on data usage. */
    void unregisterUsageRequest(in DataUsageRequest request);

    /** Get the uid stats information since boot */
    long getUidStats(int uid, int type);

    /** Get the iface stats information since boot */
    long getIfaceStats(String iface, int type);

    /** Get the total network stats information since boot */
    long getTotalStats(int type);

}
+92 −22
Original line number Diff line number Diff line
@@ -505,7 +505,12 @@ public class TrafficStats {
    public static long getMobileTcpRxPackets() {
        long total = 0;
        for (String iface : getMobileIfaces()) {
            final long stat = nativeGetIfaceStat(iface, TYPE_TCP_RX_PACKETS);
            long stat = UNSUPPORTED;
            try {
                stat = getStatsService().getIfaceStats(iface, TYPE_TCP_RX_PACKETS);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
            if (stat != UNSUPPORTED) {
                total += stat;
            }
@@ -517,7 +522,12 @@ public class TrafficStats {
    public static long getMobileTcpTxPackets() {
        long total = 0;
        for (String iface : getMobileIfaces()) {
            final long stat = nativeGetIfaceStat(iface, TYPE_TCP_TX_PACKETS);
            long stat = UNSUPPORTED;
            try {
                stat = getStatsService().getIfaceStats(iface, TYPE_TCP_TX_PACKETS);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
            if (stat != UNSUPPORTED) {
                total += stat;
            }
@@ -527,46 +537,78 @@ public class TrafficStats {

    /** {@hide} */
    public static long getTxPackets(String iface) {
        return nativeGetIfaceStat(iface, TYPE_TX_PACKETS);
        try {
            return getStatsService().getIfaceStats(iface, TYPE_TX_PACKETS);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /** {@hide} */
    public static long getRxPackets(String iface) {
        return nativeGetIfaceStat(iface, TYPE_RX_PACKETS);
        try {
            return getStatsService().getIfaceStats(iface, TYPE_RX_PACKETS);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /** {@hide} */
    public static long getTxBytes(String iface) {
        return nativeGetIfaceStat(iface, TYPE_TX_BYTES);
        try {
            return getStatsService().getIfaceStats(iface, TYPE_TX_BYTES);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /** {@hide} */
    public static long getRxBytes(String iface) {
        return nativeGetIfaceStat(iface, TYPE_RX_BYTES);
        try {
            return getStatsService().getIfaceStats(iface, TYPE_RX_BYTES);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /** {@hide} */
    @TestApi
    public static long getLoopbackTxPackets() {
        return nativeGetIfaceStat(LOOPBACK_IFACE, TYPE_TX_PACKETS);
        try {
            return getStatsService().getIfaceStats(LOOPBACK_IFACE, TYPE_TX_PACKETS);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /** {@hide} */
    @TestApi
    public static long getLoopbackRxPackets() {
        return nativeGetIfaceStat(LOOPBACK_IFACE, TYPE_RX_PACKETS);
        try {
            return getStatsService().getIfaceStats(LOOPBACK_IFACE, TYPE_RX_PACKETS);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /** {@hide} */
    @TestApi
    public static long getLoopbackTxBytes() {
        return nativeGetIfaceStat(LOOPBACK_IFACE, TYPE_TX_BYTES);
        try {
            return getStatsService().getIfaceStats(LOOPBACK_IFACE, TYPE_TX_BYTES);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /** {@hide} */
    @TestApi
    public static long getLoopbackRxBytes() {
        return nativeGetIfaceStat(LOOPBACK_IFACE, TYPE_RX_BYTES);
        try {
            return getStatsService().getIfaceStats(LOOPBACK_IFACE, TYPE_RX_BYTES);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
@@ -579,7 +621,11 @@ public class TrafficStats {
     * return {@link #UNSUPPORTED} on devices where statistics aren't available.
     */
    public static long getTotalTxPackets() {
        return nativeGetTotalStat(TYPE_TX_PACKETS);
        try {
            return getStatsService().getTotalStats(TYPE_TX_PACKETS);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
@@ -592,7 +638,11 @@ public class TrafficStats {
     * return {@link #UNSUPPORTED} on devices where statistics aren't available.
     */
    public static long getTotalRxPackets() {
        return nativeGetTotalStat(TYPE_RX_PACKETS);
        try {
            return getStatsService().getTotalStats(TYPE_RX_PACKETS);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
@@ -605,7 +655,11 @@ public class TrafficStats {
     * return {@link #UNSUPPORTED} on devices where statistics aren't available.
     */
    public static long getTotalTxBytes() {
        return nativeGetTotalStat(TYPE_TX_BYTES);
        try {
            return getStatsService().getTotalStats(TYPE_TX_BYTES);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
@@ -618,7 +672,11 @@ public class TrafficStats {
     * return {@link #UNSUPPORTED} on devices where statistics aren't available.
     */
    public static long getTotalRxBytes() {
        return nativeGetTotalStat(TYPE_RX_BYTES);
        try {
            return getStatsService().getTotalStats(TYPE_RX_BYTES);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
@@ -644,7 +702,11 @@ public class TrafficStats {
        // unsupported value. The real filtering is done at the kernel level.
        final int callingUid = android.os.Process.myUid();
        if (callingUid == android.os.Process.SYSTEM_UID || callingUid == uid) {
            return nativeGetUidStat(uid, TYPE_TX_BYTES);
            try {
                return getStatsService().getUidStats(uid, TYPE_TX_BYTES);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        } else {
            return UNSUPPORTED;
        }
@@ -673,7 +735,11 @@ public class TrafficStats {
        // unsupported value. The real filtering is done at the kernel level.
        final int callingUid = android.os.Process.myUid();
        if (callingUid == android.os.Process.SYSTEM_UID || callingUid == uid) {
            return nativeGetUidStat(uid, TYPE_RX_BYTES);
            try {
                return getStatsService().getUidStats(uid, TYPE_RX_BYTES);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        } else {
            return UNSUPPORTED;
        }
@@ -702,7 +768,11 @@ public class TrafficStats {
        // unsupported value. The real filtering is done at the kernel level.
        final int callingUid = android.os.Process.myUid();
        if (callingUid == android.os.Process.SYSTEM_UID || callingUid == uid) {
            return nativeGetUidStat(uid, TYPE_TX_PACKETS);
            try {
                return getStatsService().getUidStats(uid, TYPE_TX_PACKETS);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        } else {
            return UNSUPPORTED;
        }
@@ -731,7 +801,11 @@ public class TrafficStats {
        // unsupported value. The real filtering is done at the kernel level.
        final int callingUid = android.os.Process.myUid();
        if (callingUid == android.os.Process.SYSTEM_UID || callingUid == uid) {
            return nativeGetUidStat(uid, TYPE_RX_PACKETS);
            try {
                return getStatsService().getUidStats(uid, TYPE_RX_PACKETS);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        } else {
            return UNSUPPORTED;
        }
@@ -859,8 +933,4 @@ public class TrafficStats {
    private static final int TYPE_TX_PACKETS = 3;
    private static final int TYPE_TCP_RX_PACKETS = 4;
    private static final int TYPE_TCP_TX_PACKETS = 5;

    private static native long nativeGetTotalStat(int type);
    private static native long nativeGetIfaceStat(String iface, int type);
    private static native long nativeGetUidStat(int uid, int type);
}
+0 −1
Original line number Diff line number Diff line
@@ -96,7 +96,6 @@ cc_library_shared {
        "android_os_VintfRuntimeInfo.cpp",
        "android_net_LocalSocketImpl.cpp",
        "android_net_NetUtils.cpp",
        "android_net_TrafficStats.cpp",
        "android_nio_utils.cpp",
        "android_util_AssetManager.cpp",
        "android_util_Binder.cpp",
+0 −2
Original line number Diff line number Diff line
@@ -173,7 +173,6 @@ extern int register_android_os_MemoryFile(JNIEnv* env);
extern int register_android_os_SharedMemory(JNIEnv* env);
extern int register_android_net_LocalSocketImpl(JNIEnv* env);
extern int register_android_net_NetworkUtils(JNIEnv* env);
extern int register_android_net_TrafficStats(JNIEnv* env);
extern int register_android_text_AndroidCharacter(JNIEnv *env);
extern int register_android_text_StaticLayout(JNIEnv *env);
extern int register_android_text_AndroidBidi(JNIEnv *env);
@@ -1426,7 +1425,6 @@ static const RegJNIRec gRegJNI[] = {
    REG_JNI(register_android_os_UEventObserver),
    REG_JNI(register_android_net_LocalSocketImpl),
    REG_JNI(register_android_net_NetworkUtils),
    REG_JNI(register_android_net_TrafficStats),
    REG_JNI(register_android_os_MemoryFile),
    REG_JNI(register_android_os_SharedMemory),
    REG_JNI(register_com_android_internal_os_ClassLoaderFactory),
+26 −0
Original line number Diff line number Diff line
@@ -873,6 +873,21 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
        }
    }

    @Override
    public long getUidStats(int uid, int type) {
        return nativeGetUidStat(uid, type);
    }

    @Override
    public long getIfaceStats(String iface, int type) {
        return nativeGetIfaceStat(iface, type);
    }

    @Override
    public long getTotalStats(int type) {
        return nativeGetTotalStat(type);
    }

    /**
     * Update {@link NetworkStatsRecorder} and {@link #mGlobalAlertBytes} to
     * reflect current {@link #mPersistThreshold} value. Always defers to
@@ -1626,4 +1641,15 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
            return getGlobalLong(NETSTATS_UID_TAG_PERSIST_BYTES, def);
        }
    }

    private static int TYPE_RX_BYTES;
    private static int TYPE_RX_PACKETS;
    private static int TYPE_TX_BYTES;
    private static int TYPE_TX_PACKETS;
    private static int TYPE_TCP_RX_PACKETS;
    private static int TYPE_TCP_TX_PACKETS;

    private static native long nativeGetTotalStat(int type);
    private static native long nativeGetIfaceStat(String iface, int type);
    private static native long nativeGetUidStat(int uid, int type);
}
Loading