OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/system_monitor/system_monitor.h" | 5 #include "base/power_monitor/power_monitor.h" |
6 #include "jni/SystemMonitor_jni.h" | 6 #include "jni/SystemMonitor_jni.h" |
7 | 7 |
8 namespace base { | 8 namespace base { |
9 | 9 |
10 namespace android { | 10 namespace android { |
11 | 11 |
| 12 namespace { |
| 13 |
| 14 static base::PowerMonitor::Notifier* g_power_notifier = NULL; |
| 15 |
| 16 } // namespace |
| 17 |
12 // Native implementation of SystemMonitor.java. | 18 // Native implementation of SystemMonitor.java. |
13 void OnBatteryChargingChanged(JNIEnv* env, | 19 void OnBatteryChargingChanged(JNIEnv* env, |
14 jclass clazz) { | 20 jclass clazz) { |
15 SystemMonitor::Get()->ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); | 21 if (g_power_notifier == NULL) |
| 22 g_power_notifier = base::PowerMonitor::GetInstance()->GetNotifierOnce(); |
| 23 if (g_power_notifier) |
| 24 g_power_notifier->ProcessPowerEvent(base::PowerMonitor::POWER_STATE_EVENT); |
16 } | 25 } |
17 | 26 |
18 } // namespace android | 27 } // namespace android |
19 | 28 |
20 bool SystemMonitor::IsBatteryPower() { | 29 bool PowerMonitor::IsBatteryPower() { |
21 JNIEnv* env = base::android::AttachCurrentThread(); | 30 JNIEnv* env = base::android::AttachCurrentThread(); |
22 return base::android::Java_SystemMonitor_isBatteryPower(env); | 31 return base::android::Java_SystemMonitor_isBatteryPower(env); |
23 } | 32 } |
24 | 33 |
25 bool RegisterSystemMonitor(JNIEnv* env) { | 34 bool RegisterSystemMonitor(JNIEnv* env) { |
26 return base::android::RegisterNativesImpl(env); | 35 return base::android::RegisterNativesImpl(env); |
27 } | 36 } |
28 | 37 |
29 } // namespace base | 38 } // namespace base |
OLD | NEW |