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