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 "jni/AndroidCellularSignalStrength_jni.h" | 7 #include "jni/AndroidCellularSignalStrength_jni.h" |
8 | 8 |
9 namespace net { | 9 namespace net { |
10 | 10 |
11 namespace android { | 11 namespace android { |
12 | 12 |
13 namespace cellular_signal_strength { | 13 namespace cellular_signal_strength { |
14 | 14 |
| 15 namespace { |
| 16 |
15 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net | 17 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net |
16 enum CellularSignalStrengthError { | 18 enum CellularSignalStrengthError { |
17 // Value returned by CellularSignalStrength APIs when a valid value is | 19 // Value returned by CellularSignalStrength APIs when a valid value is |
18 // unavailable. This value is same as INT32_MIN, but the following code uses | 20 // unavailable. This value is same as INT32_MIN, but the following code uses |
19 // the explicit value of INT32_MIN so that the auto-generated Java enums work | 21 // the explicit value of INT32_MIN so that the auto-generated Java enums work |
20 // correctly. | 22 // correctly. |
21 ERROR_NOT_SUPPORTED = -2147483648, | 23 ERROR_NOT_SUPPORTED = -2147483648, |
22 }; | 24 }; |
23 | 25 |
24 static_assert( | 26 static_assert( |
25 INT32_MIN == ERROR_NOT_SUPPORTED, | 27 INT32_MIN == ERROR_NOT_SUPPORTED, |
26 "CellularSignalStrengthError.ERROR_NOT_SUPPORTED has unexpected value"); | 28 "CellularSignalStrengthError.ERROR_NOT_SUPPORTED has unexpected value"); |
27 | 29 |
28 bool GetSignalStrengthDbm(int32_t* signal_strength_dbm) { | 30 } // namespace |
29 int32_t signal_strength_dbm_tmp = | |
30 Java_AndroidCellularSignalStrength_getSignalStrengthDbm( | |
31 base::android::AttachCurrentThread()); | |
32 if (signal_strength_dbm_tmp == ERROR_NOT_SUPPORTED) | |
33 return false; | |
34 | 31 |
35 *signal_strength_dbm = signal_strength_dbm_tmp; | 32 base::Optional<int32_t> GetSignalStrengthLevel() { |
36 return true; | 33 int32_t signal_strength_level = |
37 } | |
38 | |
39 bool GetSignalStrengthLevel(int32_t* signal_strength_level) { | |
40 int32_t signal_strength_level_tmp = | |
41 Java_AndroidCellularSignalStrength_getSignalStrengthLevel( | 34 Java_AndroidCellularSignalStrength_getSignalStrengthLevel( |
42 base::android::AttachCurrentThread()); | 35 base::android::AttachCurrentThread()); |
43 if (signal_strength_level_tmp == ERROR_NOT_SUPPORTED) | 36 if (signal_strength_level == ERROR_NOT_SUPPORTED) |
44 return false; | 37 return base::Optional<int32_t>(); |
45 | 38 |
46 *signal_strength_level = signal_strength_level_tmp; | 39 DCHECK_LE(0, signal_strength_level); |
47 return true; | 40 DCHECK_GE(4, signal_strength_level); |
| 41 |
| 42 return signal_strength_level; |
48 } | 43 } |
49 | 44 |
50 } // namespace cellular_signal_strength | 45 } // namespace cellular_signal_strength |
51 | 46 |
52 } // namespace android | 47 } // namespace android |
53 | 48 |
54 } // namespace net | 49 } // namespace net |
OLD | NEW |