Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / base / power_monitor / power_monitor_device_source_android.cc
blob9671c30761ebb31584f1165e627f21933fc37baa
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.
5 #include "base/power_monitor/power_monitor_device_source_android.h"
7 #include "base/power_monitor/power_monitor.h"
8 #include "base/power_monitor/power_monitor_device_source.h"
9 #include "base/power_monitor/power_monitor_source.h"
10 #include "jni/PowerMonitor_jni.h"
12 namespace base {
14 // A helper function which is a friend of PowerMonitorSource.
15 void ProcessPowerEventHelper(PowerMonitorSource::PowerEvent event) {
16 PowerMonitorSource::ProcessPowerEvent(event);
19 namespace android {
21 // Native implementation of PowerMonitor.java.
22 void OnBatteryChargingChanged(JNIEnv* env, const JavaParamRef<jclass>& clazz) {
23 ProcessPowerEventHelper(PowerMonitorSource::POWER_STATE_EVENT);
26 void OnMainActivityResumed(JNIEnv* env, const JavaParamRef<jclass>& clazz) {
27 ProcessPowerEventHelper(PowerMonitorSource::RESUME_EVENT);
30 void OnMainActivitySuspended(JNIEnv* env, const JavaParamRef<jclass>& clazz) {
31 ProcessPowerEventHelper(PowerMonitorSource::SUSPEND_EVENT);
34 } // namespace android
36 bool PowerMonitorDeviceSource::IsOnBatteryPowerImpl() {
37 JNIEnv* env = base::android::AttachCurrentThread();
38 return base::android::Java_PowerMonitor_isBatteryPower(env);
41 bool RegisterPowerMonitor(JNIEnv* env) {
42 return base::android::RegisterNativesImpl(env);
45 } // namespace base