Chromium Code Reviews| Index: net/android/cellular_signal_strength.cc |
| diff --git a/net/android/cellular_signal_strength.cc b/net/android/cellular_signal_strength.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b0d07fb6bffa42be403d44ee3ad4679fc4e60ccf |
| --- /dev/null |
| +++ b/net/android/cellular_signal_strength.cc |
| @@ -0,0 +1,58 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "net/android/cellular_signal_strength.h" |
| + |
| +#include <stdint.h> |
| + |
| +#include "base/android/context_utils.h" |
| +#include "jni/AndroidCellularSignalStrength_jni.h" |
| + |
| +namespace net { |
| + |
| +namespace android { |
| + |
| +namespace cellular_signal_strength { |
| + |
| +// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net |
| +enum CellularSignalStrengthError { |
| + // Value returned by CellularSignalStrength APIs when a valid value is |
| + // unavailable. |
| + ERROR_NOT_SUPPORTED = -2147483647 - 1, |
|
pauljensen
2016/05/23 12:25:10
why the subtraction?
tbansal1
2016/06/09 17:50:30
This is INT32_MIN. I just set it directly to -214
|
| +}; |
| + |
| +bool GetRssiDbm(int* rssi) { |
| + static_assert( |
| + INT32_MIN == ERROR_NOT_SUPPORTED, |
| + "CellularSignalStrengthError.ERROR_NOT_SUPPORTED has unexpected value"); |
|
pauljensen
2016/05/23 12:25:10
can we move this assert up a scope level to right
tbansal1
2016/06/09 17:50:30
Done.
|
| + int rssi_tmp = Java_AndroidCellularSignalStrength_getRssiDbm( |
| + base::android::AttachCurrentThread(), |
| + base::android::GetApplicationContext()); |
| + if (rssi_tmp == ERROR_NOT_SUPPORTED) |
| + return false; |
| + |
| + *rssi = rssi_tmp; |
| + return true; |
| +} |
| + |
| +bool GetSignalLevel(int* signal_level) { |
| + int signal_level_tmp = Java_AndroidCellularSignalStrength_getSignalLevel( |
| + base::android::AttachCurrentThread(), |
| + base::android::GetApplicationContext()); |
| + if (signal_level_tmp == ERROR_NOT_SUPPORTED) |
| + return false; |
| + |
| + *signal_level = signal_level_tmp; |
| + return true; |
| +} |
| + |
| +bool Register(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |
| + |
| +} // namespace cellular_signal_strength |
| + |
| +} // namespace android |
| + |
| +} // namespace net |