blob: 7fe6743ddff25d6b4a3ffc2773426b36a968fd8b [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
19import android.content.Context;
Ken Shirriff1719a392009-12-07 15:57:35 -080020import android.net.TrafficStats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.os.INetStatService;
Dan Egnor621bc542010-03-25 16:20:14 -070022import android.os.SystemClock;
23
24import java.io.FileDescriptor;
25import java.io.PrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026
27public class NetStatService extends INetStatService.Stub {
Dan Egnor621bc542010-03-25 16:20:14 -070028 private final Context mContext;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029
30 public NetStatService(Context context) {
Dan Egnor621bc542010-03-25 16:20:14 -070031 mContext = context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032 }
33
34 public long getMobileTxPackets() {
Ken Shirriff5c19aec2010-02-04 13:33:45 -080035 return TrafficStats.getMobileTxPackets();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036 }
37
38 public long getMobileRxPackets() {
Ken Shirriff5c19aec2010-02-04 13:33:45 -080039 return TrafficStats.getMobileRxPackets();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040 }
41
42 public long getMobileTxBytes() {
Ken Shirriff1719a392009-12-07 15:57:35 -080043 return TrafficStats.getMobileTxBytes();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044 }
45
46 public long getMobileRxBytes() {
Ken Shirriff1719a392009-12-07 15:57:35 -080047 return TrafficStats.getMobileRxBytes();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048 }
49
50 public long getTotalTxPackets() {
Ken Shirriff5c19aec2010-02-04 13:33:45 -080051 return TrafficStats.getTotalTxPackets();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052 }
53
54 public long getTotalRxPackets() {
Ken Shirriff5c19aec2010-02-04 13:33:45 -080055 return TrafficStats.getTotalRxPackets();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 }
57
58 public long getTotalTxBytes() {
Ken Shirriff1719a392009-12-07 15:57:35 -080059 return TrafficStats.getTotalTxBytes();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060 }
61
62 public long getTotalRxBytes() {
Ken Shirriff1719a392009-12-07 15:57:35 -080063 return TrafficStats.getTotalRxBytes();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 }
Dan Egnor621bc542010-03-25 16:20:14 -070065
66 @Override
67 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
68 // This data is accessible to any app -- no permission check needed.
69
70 pw.print("Elapsed: total=");
71 pw.print(SystemClock.elapsedRealtime());
72 pw.print("ms awake=");
73 pw.print(SystemClock.uptimeMillis());
74 pw.println("ms");
75
76 pw.print("Mobile: Tx=");
77 pw.print(getMobileTxBytes());
78 pw.print("B/");
79 pw.print(getMobileTxPackets());
80 pw.print("Pkts Rx=");
81 pw.print(getMobileRxBytes());
82 pw.print("B/");
83 pw.print(getMobileRxPackets());
84 pw.println("Pkts");
85
86 pw.print("Total: Tx=");
87 pw.print(getTotalTxBytes());
88 pw.print("B/");
89 pw.print(getTotalTxPackets());
90 pw.print("Pkts Rx=");
91 pw.print(getTotalRxBytes());
92 pw.print("B/");
93 pw.print(getTotalRxPackets());
94 pw.println("Pkts");
95 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096}