1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/android/traffic_stats.h"
6 
7 #include "net/net_jni_headers/AndroidTrafficStats_jni.h"
8 
9 namespace net {
10 
11 namespace android {
12 
13 namespace traffic_stats {
14 
15 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net
16 enum TrafficStatsError {
17   // Value returned by AndroidTrafficStats APIs when a valid value is
18   // unavailable.
19   ERROR_NOT_SUPPORTED = 0,
20 };
21 
GetTotalTxBytes(int64_t * bytes)22 bool GetTotalTxBytes(int64_t* bytes) {
23   JNIEnv* env = base::android::AttachCurrentThread();
24   *bytes = Java_AndroidTrafficStats_getTotalTxBytes(env);
25   return *bytes != ERROR_NOT_SUPPORTED;
26 }
27 
GetTotalRxBytes(int64_t * bytes)28 bool GetTotalRxBytes(int64_t* bytes) {
29   JNIEnv* env = base::android::AttachCurrentThread();
30   *bytes = Java_AndroidTrafficStats_getTotalRxBytes(env);
31   return *bytes != ERROR_NOT_SUPPORTED;
32 }
33 
GetCurrentUidTxBytes(int64_t * bytes)34 bool GetCurrentUidTxBytes(int64_t* bytes) {
35   JNIEnv* env = base::android::AttachCurrentThread();
36   *bytes = Java_AndroidTrafficStats_getCurrentUidTxBytes(env);
37   return *bytes != ERROR_NOT_SUPPORTED;
38 }
39 
GetCurrentUidRxBytes(int64_t * bytes)40 bool GetCurrentUidRxBytes(int64_t* bytes) {
41   JNIEnv* env = base::android::AttachCurrentThread();
42   *bytes = Java_AndroidTrafficStats_getCurrentUidRxBytes(env);
43   return *bytes != ERROR_NOT_SUPPORTED;
44 }
45 
46 }  // namespace traffic_stats
47 
48 }  // namespace android
49 
50 }  // namespace net
51