Index: base/android/java/src/org/chromium/base/SystemMonitor.java |
diff --git a/base/android/java/src/org/chromium/base/SystemMonitor.java b/base/android/java/src/org/chromium/base/SystemMonitor.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7297b52a16c0acb5f319c550b7328f5e0d457092 |
--- /dev/null |
+++ b/base/android/java/src/org/chromium/base/SystemMonitor.java |
@@ -0,0 +1,56 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.base; |
+ |
+import android.content.Context; |
+import android.content.Intent; |
+import android.content.IntentFilter; |
+import android.os.BatteryManager; |
+import android.os.Looper; |
+ |
+ |
+/** |
+ * Integrates native SystemMonitor with the java side. |
+ */ |
+@JNINamespace("base::android") |
+public class SystemMonitor { |
+ |
+ private static SystemMonitor sInstance; |
+ |
+ private boolean mIsCharging; |
+ |
+ public static void create(Context context) { |
+ if (sInstance == null) { |
+ sInstance = new SystemMonitor(); |
+ IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); |
+ Intent batteryStatusIntent = context.registerReceiver(null, ifilter); |
+ onBatteryChargingChanged(batteryStatusIntent); |
+ } |
+ } |
+ |
+ private SystemMonitor() { |
+ } |
+ |
+ public static void onBatteryChargingChanged(Intent intent) { |
+ if (sInstance == null) { |
+ // We may be called by the framework intent-filter before being |
+ // fully initialized. This is not a problem, since our constructor |
+ // will check for the state later on. |
+ return; |
+ } |
+ int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1); |
+ sInstance.mIsCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || |
+ status == BatteryManager.BATTERY_STATUS_FULL; |
vandebo (ex-Chrome)
2012/10/04 19:19:22
If the battery is full, then we're not charging, t
bulach
2012/10/05 13:12:30
oh, good point! using the "BATTERY_PLUGGED_" statu
|
+ nativeOnBatteryChargingChanged(); |
+ } |
+ |
+ @CalledByNative |
+ private static boolean isBatteryPower() { |
+ return sInstance.mIsCharging; |
+ } |
+ |
+ private static native void nativeOnBatteryChargingChanged(); |
+ |
+} |