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

Commit be9c0764 authored by Sunmeet Gill's avatar Sunmeet Gill Committed by Linux Build Service Account
Browse files

server: add network stat plugin framework

Enable custom network statistics plugin framework. Use platform
specific custom implementation to compute network stats
and enforce quota for user

Change-Id: Ie711ec0bbd58bf72c2b3450708768a02cfbba2f8
CRs-Fixed: 878013
parent f022fdcf
Loading
Loading
Loading
Loading
+93 −0
Original line number Diff line number Diff line
/*
 *Copyright (c) 2015, The Linux Foundation. All rights reserved.
 *
 *Redistribution and use in source and binary forms, with or without
 *modification, are permitted provided that the following conditions are
 *met:
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
 *   * Neither the name of The Linux Foundation nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 *THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
 *WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
 *ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
 *BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 *CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 *WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 *OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 *IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package com.android.server.net;

import dalvik.system.PathClassLoader;

import java.lang.reflect.Constructor;

import android.util.Slog;
import android.net.NetworkStats;
import android.util.Log;

class NetPluginDelegate {

    private static final String TAG = "ConnectivityExtension";
    private static final boolean LOGV = false;

    private static Class tetherExtensionClass = null;
    private static Object tetherExtensionObj = null;

    static void getTetherStats(NetworkStats uidStats, NetworkStats devStats,
            NetworkStats xtStats) {
        loadTetherExtJar();
        try {
            tetherExtensionClass.getMethod("getTetherStats", NetworkStats.class,
                    NetworkStats.class, NetworkStats.class).invoke(tetherExtensionObj, uidStats,
                    devStats, xtStats);
        } catch (Exception e) {
            e.printStackTrace();
            Log.w(TAG, "error in invoke method");
        }
    }

    static void setQuota(String iface, long quota) {
        loadTetherExtJar();
        try {
            tetherExtensionClass.getMethod("setQuota", String.class, long.class).invoke(
                    tetherExtensionObj, iface, quota);
        } catch (Exception ex) {
            Log.w(TAG, "Error calling setQuota Method on extension jar");
        }
    }



    private static void loadTetherExtJar() {
        final String realProvider = "com.qualcomm.qti.tetherstatsextension.TetherStatsReporting";
        final String realProviderPath = "/system/framework/ConnectivityExt.jar";
            if (tetherExtensionClass == null && tetherExtensionObj == null) {
                if (LOGV) Slog.v(TAG, "loading ConnectivityExt jar");
                try {

                    PathClassLoader classLoader = new PathClassLoader(realProviderPath,
                            ClassLoader.getSystemClassLoader());

                    tetherExtensionClass = classLoader.loadClass(realProvider);
                    tetherExtensionObj = tetherExtensionClass.newInstance();
                        if (LOGV)
                            Slog.v(TAG, "ConnectivityExt jar loaded");
                } catch (Exception e) {
                    e.printStackTrace();
                    Log.w(TAG, "unable to ConnectivityExt jar");
                }
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -2419,6 +2419,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
    private void setInterfaceQuota(String iface, long quotaBytes) {
        try {
            mNetworkManager.setInterfaceQuota(iface, quotaBytes);
            NetPluginDelegate.setQuota(iface, quotaBytes);
        } catch (IllegalStateException e) {
            Log.wtf(TAG, "problem setting interface quota", e);
        } catch (RemoteException e) {
+1 −1
Original line number Diff line number Diff line
@@ -971,7 +971,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
        final NetworkStats uidSnapshot = getNetworkStatsUidDetail();
        final NetworkStats xtSnapshot = mNetworkManager.getNetworkStatsSummaryXt();
        final NetworkStats devSnapshot = mNetworkManager.getNetworkStatsSummaryDev();

        NetPluginDelegate.getTetherStats(uidSnapshot, xtSnapshot, devSnapshot);
        VpnInfo[] vpnArray = mConnManager.getAllVpnInfo();
        mDevRecorder.recordSnapshotLocked(devSnapshot, mActiveIfaces, null, currentTime);
        mXtRecorder.recordSnapshotLocked(xtSnapshot, mActiveIfaces, null, currentTime);