Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: net/android/cellular_signal_strength.cc

Issue 2763853002: Use Android callback API to obtain cellular signal strength (Closed)
Patch Set: pauljensen comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 {
14 14
15 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net 15 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net
16 enum CellularSignalStrengthError { 16 enum CellularSignalStrengthError {
17 // Value returned by CellularSignalStrength APIs when a valid value is 17 // Value returned by CellularSignalStrength APIs when a valid value is
18 // 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
19 // 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
20 // correctly. 20 // correctly.
21 ERROR_NOT_SUPPORTED = -2147483648, 21 ERROR_NOT_SUPPORTED = -2147483648,
22 }; 22 };
23 23
24 static_assert( 24 static_assert(
25 INT32_MIN == ERROR_NOT_SUPPORTED, 25 INT32_MIN == ERROR_NOT_SUPPORTED,
26 "CellularSignalStrengthError.ERROR_NOT_SUPPORTED has unexpected value"); 26 "CellularSignalStrengthError.ERROR_NOT_SUPPORTED has unexpected value");
27 27
28 bool GetSignalStrengthDbm(int32_t* signal_strength_dbm) { 28 } // 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 29
35 *signal_strength_dbm = signal_strength_dbm_tmp; 30 CellularSignalStrength::CellularSignalStrength() {
36 return true; 31 j_cellular_signal_strength_.Reset(Java_AndroidCellularSignalStrength_create(
32 base::android::AttachCurrentThread()));
37 } 33 }
38 34
39 bool GetSignalStrengthLevel(int32_t* signal_strength_level) { 35 CellularSignalStrength::~CellularSignalStrength() {
40 int32_t signal_strength_level_tmp = 36 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
41 Java_AndroidCellularSignalStrength_getSignalStrengthLevel(
42 base::android::AttachCurrentThread());
43 if (signal_strength_level_tmp == ERROR_NOT_SUPPORTED)
44 return false;
45
46 *signal_strength_level = signal_strength_level_tmp;
47 return true;
48 } 37 }
49 38
50 } // namespace cellular_signal_strength 39 base::Optional<int32_t> CellularSignalStrength::GetSignalStrengthLevel() const {
40 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
41
42 int32_t signal_strength_level =
43 Java_AndroidCellularSignalStrength_getSignalStrengthLevel(
44 base::android::AttachCurrentThread(), j_cellular_signal_strength_);
45 if (signal_strength_level == ERROR_NOT_SUPPORTED)
46 return base::Optional<int32_t>();
47
48 DCHECK_LE(0, signal_strength_level);
49 DCHECK_GE(4, signal_strength_level);
50
51 return signal_strength_level;
52 }
51 53
52 } // namespace android 54 } // namespace android
53 55
54 } // namespace net 56 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698