forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Android: Integrates native and java SystemMonitor.
BUG=154293 Review URL: https://chromiumcodereview.appspot.com/11027024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162124 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
bulach@chromium.org
committed
Oct 16, 2012
1 parent
8a429d0
commit a614f15
Showing
8 changed files
with
130 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
base/android/java/src/org/chromium/base/PowerStatusReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// 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.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
|
||
|
||
/** | ||
* A BroadcastReceiver that listens to changes in power status and notifies | ||
* SystemMonitor. | ||
* It's instantiated by the framework via the application intent-filter | ||
* declared in its manifest. | ||
*/ | ||
public class PowerStatusReceiver extends BroadcastReceiver { | ||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
SystemMonitor.onBatteryChargingChanged(intent); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
base/android/java/src/org/chromium/base/SystemMonitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// 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 mIsBatteryPower; | ||
|
||
public static void createForTests(Context context) { | ||
// Applications will create this once the | ||
// JNI side has been fully wired up both sides. | ||
// For tests, we just need native -> java, that is, | ||
// we don't need to notify java -> native on creation. | ||
sInstance = new SystemMonitor(); | ||
} | ||
|
||
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 chargePlug = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); | ||
// If we're not plugged, assume we're running on battery power. | ||
sInstance.mIsBatteryPower = chargePlug != BatteryManager.BATTERY_PLUGGED_USB && | ||
chargePlug != BatteryManager.BATTERY_PLUGGED_AC; | ||
nativeOnBatteryChargingChanged(); | ||
} | ||
|
||
@CalledByNative | ||
private static boolean isBatteryPower() { | ||
return sInstance.mIsBatteryPower; | ||
} | ||
|
||
private static native void nativeOnBatteryChargingChanged(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 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. | ||
|
||
#ifndef BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_ANDROID_H_ | ||
#define BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_ANDROID_H_ | ||
|
||
#include <jni.h> | ||
|
||
namespace base { | ||
|
||
// Registers the JNI bindings for SystemMonitor. | ||
bool RegisterSystemMonitor(JNIEnv* env); | ||
|
||
} // namespace base | ||
|
||
#endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_ANDROID_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters