OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/android/cellular_signal_strength.h" | 5 #include "net/android/cellular_signal_strength.h" |
6 | 6 |
7 #include "base/android/context_utils.h" | 7 #include "base/android/context_utils.h" |
8 #include "jni/AndroidCellularSignalStrength_jni.h" | 8 #include "jni/AndroidCellularSignalStrength_jni.h" |
9 | 9 |
10 namespace net { | 10 namespace net { |
11 | 11 |
12 namespace android { | 12 namespace android { |
13 | 13 |
14 namespace cellular_signal_strength { | 14 namespace { |
15 | 15 |
16 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net | 16 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net |
17 enum CellularSignalStrengthError { | 17 enum CellularSignalStrengthError { |
18 // Value returned by CellularSignalStrength APIs when a valid value is | 18 // Value returned by CellularSignalStrength APIs when a valid value is |
19 // unavailable. This value is same as INT32_MIN, but the following code uses | 19 // unavailable. This value is same as INT32_MIN, but the following code uses |
20 // the explicit value of INT32_MIN so that the auto-generated Java enums work | 20 // the explicit value of INT32_MIN so that the auto-generated Java enums work |
21 // correctly. | 21 // correctly. |
22 ERROR_NOT_SUPPORTED = -2147483648, | 22 ERROR_NOT_SUPPORTED = -2147483648, |
23 }; | 23 }; |
24 | 24 |
25 static_assert( | 25 static_assert( |
26 INT32_MIN == ERROR_NOT_SUPPORTED, | 26 INT32_MIN == ERROR_NOT_SUPPORTED, |
27 "CellularSignalStrengthError.ERROR_NOT_SUPPORTED has unexpected value"); | 27 "CellularSignalStrengthError.ERROR_NOT_SUPPORTED has unexpected value"); |
28 | 28 |
29 bool GetSignalStrengthDbm(int32_t* signal_strength_dbm) { | 29 } // namespace |
30 int32_t signal_strength_dbm_tmp = | |
31 Java_AndroidCellularSignalStrength_getSignalStrengthDbm( | |
32 base::android::AttachCurrentThread(), | |
33 base::android::GetApplicationContext()); | |
34 if (signal_strength_dbm_tmp == ERROR_NOT_SUPPORTED) | |
35 return false; | |
36 | 30 |
37 *signal_strength_dbm = signal_strength_dbm_tmp; | 31 CellularSignalStrength::CellularSignalStrength() { |
38 return true; | 32 j_cellular_signal_strength_.Reset(Java_AndroidCellularSignalStrength_create( |
| 33 base::android::AttachCurrentThread(), |
| 34 base::android::GetApplicationContext())); |
39 } | 35 } |
40 | 36 |
41 bool GetSignalStrengthLevel(int32_t* signal_strength_level) { | 37 CellularSignalStrength::~CellularSignalStrength() { |
| 38 DCHECK(thread_checker_.CalledOnValidThread()); |
| 39 } |
| 40 |
| 41 bool CellularSignalStrength::GetSignalStrengthLevel( |
| 42 int32_t* signal_strength_level) const { |
| 43 DCHECK(thread_checker_.CalledOnValidThread()); |
| 44 |
42 int32_t signal_strength_level_tmp = | 45 int32_t signal_strength_level_tmp = |
43 Java_AndroidCellularSignalStrength_getSignalStrengthLevel( | 46 Java_AndroidCellularSignalStrength_getSignalStrengthLevel( |
44 base::android::AttachCurrentThread(), | 47 base::android::AttachCurrentThread(), j_cellular_signal_strength_); |
45 base::android::GetApplicationContext()); | |
46 if (signal_strength_level_tmp == ERROR_NOT_SUPPORTED) | 48 if (signal_strength_level_tmp == ERROR_NOT_SUPPORTED) |
47 return false; | 49 return false; |
48 | 50 |
49 *signal_strength_level = signal_strength_level_tmp; | 51 *signal_strength_level = signal_strength_level_tmp; |
50 return true; | 52 return true; |
51 } | 53 } |
52 | 54 |
53 } // namespace cellular_signal_strength | |
54 | |
55 } // namespace android | 55 } // namespace android |
56 | 56 |
57 } // namespace net | 57 } // namespace net |
OLD | NEW |