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())); | |
pauljensen
2017/04/13 11:36:30
does this need to be called on the UI thread? if s
tbansal1
2017/06/07 21:39:20
No, it does not have to be called on UI thread.
An
| |
39 } | 35 } |
40 | 36 |
41 bool GetSignalStrengthLevel(int32_t* signal_strength_level) { | 37 CellularSignalStrength::~CellularSignalStrength() { |
42 int32_t signal_strength_level_tmp = | 38 DCHECK(thread_checker_.CalledOnValidThread()); |
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 } | 39 } |
52 | 40 |
53 } // namespace cellular_signal_strength | 41 base::Optional<int32_t> CellularSignalStrength::GetSignalStrengthLevel() const { |
42 DCHECK(thread_checker_.CalledOnValidThread()); | |
43 | |
44 int32_t signal_strength_level = | |
45 Java_AndroidCellularSignalStrength_getSignalStrengthLevel( | |
46 base::android::AttachCurrentThread(), j_cellular_signal_strength_); | |
47 if (signal_strength_level == ERROR_NOT_SUPPORTED) | |
48 return base::Optional<int32_t>(); | |
49 | |
50 return signal_strength_level; | |
51 } | |
54 | 52 |
55 } // namespace android | 53 } // namespace android |
56 | 54 |
57 } // namespace net | 55 } // namespace net |
OLD | NEW |