OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/power_monitor/power_monitor_device_source_android.h" | 5 #include "base/power_monitor/power_monitor_device_source_android.h" |
6 | 6 |
7 #include "base/power_monitor/power_monitor.h" | 7 #include "base/power_monitor/power_monitor.h" |
8 #include "base/power_monitor/power_monitor_device_source.h" | 8 #include "base/power_monitor/power_monitor_device_source.h" |
9 #include "base/power_monitor/power_monitor_source.h" | 9 #include "base/power_monitor/power_monitor_source.h" |
10 #include "jni/PowerMonitor_jni.h" | 10 #include "jni/PowerMonitor_jni.h" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 | 13 |
14 // A helper function which is a friend of PowerMonitorSource. | 14 // A helper function which is a friend of PowerMonitorSource. |
15 void ProcessPowerEventHelper(PowerMonitorSource::PowerEvent event) { | 15 void ProcessPowerEventHelper(PowerMonitorSource::PowerEvent event) { |
16 PowerMonitorSource::ProcessPowerEvent(event); | 16 PowerMonitorSource::ProcessPowerEvent(event); |
17 } | 17 } |
18 | 18 |
19 namespace android { | 19 namespace android { |
20 | 20 |
21 // Native implementation of PowerMonitor.java. | 21 // Native implementation of PowerMonitor.java. Note: This will be invoked by |
| 22 // PowerMonitor.java shortly after startup to set the correct initial value for |
| 23 // "is on battery power." |
22 void OnBatteryChargingChanged(JNIEnv* env, const JavaParamRef<jclass>& clazz) { | 24 void OnBatteryChargingChanged(JNIEnv* env, const JavaParamRef<jclass>& clazz) { |
23 ProcessPowerEventHelper(PowerMonitorSource::POWER_STATE_EVENT); | 25 ProcessPowerEventHelper(PowerMonitorSource::POWER_STATE_EVENT); |
24 } | 26 } |
25 | 27 |
26 // Note: Android does not have the concept of suspend / resume as it's known by | 28 // Note: Android does not have the concept of suspend / resume as it's known by |
27 // other platforms. Thus we do not send Suspend/Resume notifications. See | 29 // other platforms. Thus we do not send Suspend/Resume notifications. See |
28 // http://crbug.com/644515 | 30 // http://crbug.com/644515 |
29 | 31 |
30 } // namespace android | 32 } // namespace android |
31 | 33 |
32 bool PowerMonitorDeviceSource::IsOnBatteryPowerImpl() { | 34 bool PowerMonitorDeviceSource::IsOnBatteryPowerImpl() { |
33 JNIEnv* env = base::android::AttachCurrentThread(); | 35 JNIEnv* env = base::android::AttachCurrentThread(); |
34 return base::android::Java_PowerMonitor_isBatteryPower(env); | 36 return base::android::Java_PowerMonitor_isBatteryPower(env); |
35 } | 37 } |
36 | 38 |
37 bool RegisterPowerMonitor(JNIEnv* env) { | 39 bool RegisterPowerMonitor(JNIEnv* env) { |
38 return base::android::RegisterNativesImpl(env); | 40 return base::android::RegisterNativesImpl(env); |
39 } | 41 } |
40 | 42 |
41 } // namespace base | 43 } // namespace base |
OLD | NEW |