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