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

Commit 1591b2ee authored by Nilesh Poddar's avatar Nilesh Poddar Committed by Steve Kondik
Browse files

Tether: add ipa tether stats to the existing design

Add ipa tether stats to the existing desing

Change-Id: If3406729aaf2e21f8d5d1e7b42723faf3962dabc
parent 350c9b8c
Loading
Loading
Loading
Loading
+59 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.Manifest.permission.CONNECTIVITY_INTERNAL;
import static android.Manifest.permission.DUMP;
import static android.Manifest.permission.SHUTDOWN;
import static android.net.NetworkStats.SET_DEFAULT;
import static android.net.NetworkStats.SET_ALL;
import static android.net.NetworkStats.TAG_ALL;
import static android.net.NetworkStats.TAG_NONE;
import static android.net.NetworkStats.UID_ALL;
@@ -1550,8 +1551,17 @@ public class NetworkManagementService extends INetworkManagementService.Stub
    @Override
    public NetworkStats getNetworkStatsSummaryDev() {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
        NetworkStats totalStats = null;
        NetworkStats ipaTetherStats = null;
        try {
            return mStatsFactory.readNetworkStatsSummaryDev();
            ipaTetherStats = getHardwareTetherStats();
        } catch (Exception e) {
        };
        try {
            totalStats = mStatsFactory.readNetworkStatsSummaryDev();
            if(ipaTetherStats != null)totalStats.combineAllValues(ipaTetherStats);
            Slog.d(TAG,"getNetworkStatsSummaryDev:"+totalStats);
            return totalStats;
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
@@ -1560,8 +1570,17 @@ public class NetworkManagementService extends INetworkManagementService.Stub
    @Override
    public NetworkStats getNetworkStatsSummaryXt() {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
        NetworkStats totalStats = null;
        NetworkStats ipaTetherStats = null;
        try {
            ipaTetherStats = getHardwareTetherStats();
        } catch (Exception e) {
        };
        try {
            return mStatsFactory.readNetworkStatsSummaryXt();
            totalStats = mStatsFactory.readNetworkStatsSummaryXt();
            if(ipaTetherStats != null) totalStats.combineAllValues(ipaTetherStats);
            Slog.d(TAG,"getNetworkStatsSummaryXt:"+totalStats);
            return totalStats;
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
@@ -1738,6 +1757,44 @@ public class NetworkManagementService extends INetworkManagementService.Stub
        }
    }

    private NetworkStats getHardwareTetherStats() {
        final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 1);
        try {
            final NativeDaemonEvent[] events = mConnector.executeForList(
                    "bandwidth", "gethardwaretetherstats");
            for (NativeDaemonEvent event : events) {
                if (event.getCode() != TetheringStatsListResult) continue;

                // 114 ifaceIn ifaceOut rx_bytes rx_packets tx_bytes tx_packets
                final StringTokenizer tok = new StringTokenizer(event.getMessage());
                try {
                    final String ifaceIn = tok.nextToken();
                    final String ifaceOut = tok.nextToken();

                    final NetworkStats.Entry entry = new NetworkStats.Entry();
                    entry.iface = ifaceOut;
                    entry.uid = UID_ALL;
                    entry.set = SET_ALL;
                    entry.tag = TAG_NONE;
                    entry.rxBytes = Long.parseLong(tok.nextToken());
                    entry.rxPackets = Long.parseLong(tok.nextToken());
                    entry.txBytes = Long.parseLong(tok.nextToken());
                    entry.txPackets = Long.parseLong(tok.nextToken());
                    stats.combineValues(entry);
                } catch (NoSuchElementException e) {
                    throw new IllegalStateException("problem parsing tethering stats: " + event);
                } catch (NumberFormatException e) {
                    throw new IllegalStateException("problem parsing tethering stats: " + event);
                }
            }
        } catch (NativeDaemonConnectorException e) {
            throw e.rethrowAsParcelableException();
        }
        Slog.d(TAG,"hardware tether stats:"+stats);
        return stats;
    }


    @Override
    public NetworkStats getNetworkStatsTethering() {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);