OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 package org.chromium.base; | |
6 | |
7 import android.content.Context; | |
8 import android.content.Intent; | |
9 import android.content.IntentFilter; | |
10 import android.os.BatteryManager; | |
11 import android.os.Looper; | |
12 | |
13 | |
14 /** | |
15 * Integrates native SystemMonitor with the java side. | |
16 */ | |
17 @JNINamespace("base::android") | |
18 public class SystemMonitor { | |
19 | |
20 private static SystemMonitor sInstance; | |
21 | |
22 private boolean mIsBatteryPower; | |
23 | |
24 public static void create(Context context) { | |
25 if (sInstance == null) { | |
26 sInstance = new SystemMonitor(); | |
27 IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGE D); | |
jar (doing other things)
2012/10/05 17:39:51
Although the style guide allows for either 80 or 1
bulach
2012/10/05 18:23:52
depends on what you call "newer" :)
for java, we f
| |
28 Intent batteryStatusIntent = context.registerReceiver(null, ifilter) ; | |
29 onBatteryChargingChanged(batteryStatusIntent); | |
30 } | |
31 } | |
32 | |
33 private SystemMonitor() { | |
34 } | |
35 | |
36 public static void onBatteryChargingChanged(Intent intent) { | |
37 if (sInstance == null) { | |
38 // We may be called by the framework intent-filter before being | |
39 // fully initialized. This is not a problem, since our constructor | |
40 // will check for the state later on. | |
41 return; | |
42 } | |
43 int chargePlug = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); | |
44 // If we're not plugged, assume we're running on battery power. | |
45 sInstance.mIsBatteryPower = chargePlug != BatteryManager.BATTERY_PLUGGED _USB && | |
46 chargePlug != BatteryManager.BATTERY_PLUGGED _AC; | |
47 nativeOnBatteryChargingChanged(); | |
48 } | |
49 | |
50 @CalledByNative | |
51 private static boolean isBatteryPower() { | |
52 return sInstance.mIsBatteryPower; | |
53 } | |
54 | |
55 private static native void nativeOnBatteryChargingChanged(); | |
56 | |
57 } | |
OLD | NEW |