OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/android/cellular_signal_strength.h" |
| 6 |
| 7 #include "base/android/context_utils.h" |
| 8 #include "jni/AndroidCellularSignalStrength_jni.h" |
| 9 |
| 10 namespace net { |
| 11 |
| 12 namespace android { |
| 13 |
| 14 namespace cellular_signal_strength { |
| 15 |
| 16 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net |
| 17 enum CellularSignalStrengthError { |
| 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 |
| 20 // the explicit value of INT32_MIN so that the auto-generated Java enums work |
| 21 // correctly. |
| 22 ERROR_NOT_SUPPORTED = -2147483648, |
| 23 }; |
| 24 |
| 25 static_assert( |
| 26 INT32_MIN == ERROR_NOT_SUPPORTED, |
| 27 "CellularSignalStrengthError.ERROR_NOT_SUPPORTED has unexpected value"); |
| 28 |
| 29 bool GetSignalStrengthDbm(int32_t* signal_strength_dbm) { |
| 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 |
| 37 *signal_strength_dbm = signal_strength_dbm_tmp; |
| 38 return true; |
| 39 } |
| 40 |
| 41 bool GetSignalStrengthLevel(int32_t* signal_strength_level) { |
| 42 int32_t signal_strength_level_tmp = |
| 43 Java_AndroidCellularSignalStrength_getSignalStrengthLevel( |
| 44 base::android::AttachCurrentThread(), |
| 45 base::android::GetApplicationContext()); |
| 46 if (signal_strength_level_tmp == ERROR_NOT_SUPPORTED) |
| 47 return false; |
| 48 |
| 49 *signal_strength_level = signal_strength_level_tmp; |
| 50 return true; |
| 51 } |
| 52 |
| 53 bool Register(JNIEnv* env) { |
| 54 return RegisterNativesImpl(env); |
| 55 } |
| 56 |
| 57 } // namespace cellular_signal_strength |
| 58 |
| 59 } // namespace android |
| 60 |
| 61 } // namespace net |
OLD | NEW |