Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2927)

Unified Diff: base/android/java/src/org/chromium/base/SystemMonitor.java

Issue 11027024: Android: Integrates native and java SystemMonitor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..72a4fb870c7019a1ba041f37d55496a51ee7c762
--- /dev/null
+++ b/base/android/java/src/org/chromium/base/SystemMonitor.java
@@ -0,0 +1,51 @@
+// 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;
+
+ public static void create(Context context) {
+ // Can only be called on the UI thread.
+ assert Looper.myLooper() == Looper.getMainLooper();
+ 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);
+ boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
+ status == BatteryManager.BATTERY_STATUS_FULL;
+ nativeOnBatteryChargingChanged(isCharging);
+ }
+
+ private static native void nativeOnBatteryChargingChanged(boolean isCharging);
+
+}

Powered by Google App Engine
This is Rietveld 408576698