summaryrefslogtreecommitdiffstats
path: root/services/java/com/android/server/BatteryService.java
diff options
context:
space:
mode:
authorJorge Ruesga <jorge@ruesga.com>2013-01-27 05:03:48 +0100
committerJorge Ruesga <jorge@ruesga.com>2013-02-08 01:29:23 +0100
commit042159d9e9a129da3e290a5c6a2d4629acd56a65 (patch)
treec4bc85f8ed82ee0d66d3f304826e04d0e0525cc8 /services/java/com/android/server/BatteryService.java
parenteeb11165b6e5443be802b475017cb7aca9d6f213 (diff)
downloadframeworks_base-042159d9e9a129da3e290a5c6a2d4629acd56a65.zip
frameworks_base-042159d9e9a129da3e290a5c6a2d4629acd56a65.tar.gz
frameworks_base-042159d9e9a129da3e290a5c6a2d4629acd56a65.tar.bz2
SystemUI: Add dock battery icon styles
Support for dock battery icon styles. This changes does a refactor of DockBatteryController to extend BatteryController and create a new CircleDockBattery that extends CircleBattery (that listen for dock battery events) Patchset 2: Fully functional. Patchset 3: Fixed min icons. Rebased. Patchset 4: Create full device specific service in frameworks Move dock battery stuff from the framework to a device handler. Register/unregister DockBatteryController receivers Remove battery views if device doesn't support dock battery Refresh status on dock and screen on events Rebased Patchset 5: Transformers backwards compatibility Better main battery status detection (use status instead of plugged type) Fixed battery cluster space in status bar Rebased Patchset 6: Fix dock icons in ligths out mode Patchset 7: Fix code style Fix lockscreen status Fix lights out mode (typo) Fix images size Rebased Patchset 8: Fix icon images Fix status on full charge Rebased TF700T implementation: http://review.cyanogenmod.org/#/c/31298/ Change-Id: I9a576d1b279f1883f736ac3bcd2435c4b95a73de Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
Diffstat (limited to 'services/java/com/android/server/BatteryService.java')
-rw-r--r--services/java/com/android/server/BatteryService.java105
1 files changed, 62 insertions, 43 deletions
diff --git a/services/java/com/android/server/BatteryService.java b/services/java/com/android/server/BatteryService.java
index 5dbc2e4..08d9ffa 100644
--- a/services/java/com/android/server/BatteryService.java
+++ b/services/java/com/android/server/BatteryService.java
@@ -17,18 +17,23 @@
package com.android.server;
import com.android.internal.app.IBatteryStats;
+import com.android.internal.os.DeviceDockBatteryHandler;
+import com.android.internal.os.IDeviceHandler;
import com.android.server.am.BatteryStatsService;
import android.app.ActivityManagerNative;
+import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.graphics.Color;
import android.os.BatteryManager;
import android.os.Binder;
+import android.os.Bundle;
import android.os.FileUtils;
import android.os.Handler;
import android.os.IBinder;
@@ -65,7 +70,7 @@ import java.util.Calendar;
* <p>&quot;present&quot; - boolean, true if the battery is present<br />
* <p>&quot;icon-small&quot; - int, suggested small icon to use for this state</p>
* <p>&quot;plugged&quot; - int, 0 if the device is not plugged in; 1 if plugged
- * into an AC power adapter; 2 if plugged in via USB.</p>
+ * into an AC power adapter; 2 if plugged in via USB; 4 if plugged in via Wireless.</p>
* <p>&quot;voltage&quot; - int, current battery voltage in millivolts</p>
* <p>&quot;temperature&quot; - int, current battery temperature in tenths of
* a degree Centigrade</p>
@@ -129,15 +134,9 @@ public final class BatteryService extends Binder {
private boolean mLastBatteryLevelCritical;
private int mLastInvalidCharger;
+ // Device specific handler for extra dock battery
private boolean mHasDockBattery;
-
- private int mDockBatteryStatus;
- private int mDockBatteryLevel;
- private boolean mDockBatteryPresent;
-
- private int mLastDockBatteryStatus;
- private int mLastDockBatteryLevel;
- private boolean mLastDockBatteryPresent;
+ private DeviceDockBatteryHandler mDeviceDockBattery;
private int mLowBatteryWarningLevel;
private int mLowBatteryCloseWarningLevel;
@@ -168,7 +167,7 @@ public final class BatteryService extends Binder {
private int mQuietHoursEnd = 0;
private boolean mQuietHoursDim = true;
- public BatteryService(Context context, LightsService lights) {
+ public BatteryService(Context context, LightsService lights, IDeviceHandler deviceHandler) {
mContext = context;
mHandler = new Handler(true /*async*/);
mLed = new Led(context, lights);
@@ -183,8 +182,19 @@ public final class BatteryService extends Binder {
mShutdownBatteryTemperature = mContext.getResources().getInteger(
com.android.internal.R.integer.config_shutdownBatteryTemperature);
+ // Has Dock battery? and device specific handler?
mHasDockBattery = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_hasDockBattery);
+ if (mHasDockBattery) {
+ if (deviceHandler != null) {
+ mDeviceDockBattery = deviceHandler.getDeviceDockBatteryHandler();
+
+ // Force an update of the data when dock state change
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(Intent.ACTION_DOCK_EVENT);
+ context.registerReceiver(mDockReceiver, filter);
+ }
+ }
mPowerSupplyObserver.startObserving("SUBSYSTEM=power_supply");
@@ -226,6 +236,7 @@ public final class BatteryService extends Binder {
if (mBatteryStatus == BatteryManager.BATTERY_STATUS_UNKNOWN) {
return true;
}
+ // mAcOnline is used for main ac and dock battery ac
if ((plugTypeSet & BatteryManager.BATTERY_PLUGGED_AC) != 0 && mAcOnline) {
return true;
}
@@ -306,6 +317,9 @@ public final class BatteryService extends Binder {
if (!mUpdatesStopped) {
// Update the values of mAcOnline, et. all.
native_update();
+ if (mDeviceDockBattery != null) {
+ mDeviceDockBattery.update();
+ }
// Process the new values.
processValuesLocked();
@@ -316,8 +330,14 @@ public final class BatteryService extends Binder {
boolean logOutlier = false;
long dischargeDuration = 0;
+ // Process the dock battery values
+ if (mDeviceDockBattery != null) {
+ mDeviceDockBattery.process();
+ }
+
mBatteryLevelCritical = (mBatteryLevel <= mCriticalBatteryLevel);
- if (mAcOnline) {
+ if (mAcOnline ||
+ (mDeviceDockBattery != null && mDeviceDockBattery.isPlugged())) {
mPlugType = BatteryManager.BATTERY_PLUGGED_AC;
} else if (mUsbOnline) {
mPlugType = BatteryManager.BATTERY_PLUGGED_USB;
@@ -328,6 +348,7 @@ public final class BatteryService extends Binder {
}
if (DEBUG) {
+ String dockValues = String.valueOf(mDeviceDockBattery);
Slog.d(TAG, "Processing new values: "
+ "mAcOnline=" + mAcOnline
+ ", mUsbOnline=" + mUsbOnline
@@ -340,7 +361,9 @@ public final class BatteryService extends Binder {
+ ", mBatteryVoltage=" + mBatteryVoltage
+ ", mBatteryTemperature=" + mBatteryTemperature
+ ", mBatteryLevelCritical=" + mBatteryLevelCritical
- + ", mPlugType=" + mPlugType);
+ + ", mPlugType=" + mPlugType
+ + ", mHasDockBattery=" + mHasDockBattery
+ + ", mDeviceDockBattery=[" + dockValues + "]");
}
// Let the battery stats keep track of the current level.
@@ -355,12 +378,9 @@ public final class BatteryService extends Binder {
shutdownIfNoPowerLocked();
shutdownIfOverTempLocked();
- boolean dockBatteryChanged = false;
- if (mHasDockBattery &&
- (mDockBatteryLevel != mLastDockBatteryLevel ||
- mDockBatteryStatus != mLastDockBatteryStatus ||
- mDockBatteryPresent != mLastDockBatteryPresent)) {
- dockBatteryChanged = true;
+ boolean dockBatteryHasNewData = false;
+ if (mDeviceDockBattery != null) {
+ dockBatteryHasNewData = mDeviceDockBattery.hasNewData();
}
if (mBatteryStatus != mLastBatteryStatus ||
@@ -371,7 +391,7 @@ public final class BatteryService extends Binder {
mBatteryVoltage != mLastBatteryVoltage ||
mBatteryTemperature != mLastBatteryTemperature ||
mInvalidCharger != mLastInvalidCharger ||
- dockBatteryChanged) {
+ dockBatteryHasNewData) {
if (mPlugType != mLastPlugType) {
if (mLastPlugType == BATTERY_PLUGGED_NONE) {
@@ -494,12 +514,6 @@ public final class BatteryService extends Binder {
mLastBatteryTemperature = mBatteryTemperature;
mLastBatteryLevelCritical = mBatteryLevelCritical;
mLastInvalidCharger = mInvalidCharger;
-
- if (mHasDockBattery) {
- mLastDockBatteryLevel = mDockBatteryLevel;
- mLastDockBatteryStatus = mDockBatteryStatus;
- mLastDockBatteryPresent = mDockBatteryPresent;
- }
}
}
@@ -509,6 +523,11 @@ public final class BatteryService extends Binder {
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
| Intent.FLAG_RECEIVER_REPLACE_PENDING);
+ Bundle dockData = new Bundle();
+ if (mDeviceDockBattery != null) {
+ dockData = mDeviceDockBattery.getNotifyData();
+ }
+
int icon = getIconLocked(mBatteryLevel);
intent.putExtra(BatteryManager.EXTRA_STATUS, mBatteryStatus);
@@ -522,8 +541,13 @@ public final class BatteryService extends Binder {
intent.putExtra(BatteryManager.EXTRA_TEMPERATURE, mBatteryTemperature);
intent.putExtra(BatteryManager.EXTRA_TECHNOLOGY, mBatteryTechnology);
intent.putExtra(BatteryManager.EXTRA_INVALID_CHARGER, mInvalidCharger);
+ intent.putExtras(dockData);
if (DEBUG) {
+ String dockDebug = "";
+ for (String key : dockData.keySet()) {
+ dockDebug += ", " + key + ": " + String.valueOf(dockData.get(key));
+ }
Slog.d(TAG, "Sending ACTION_BATTERY_CHANGED. level:" + mBatteryLevel +
", scale:" + BATTERY_SCALE + ", status:" + mBatteryStatus +
", health:" + mBatteryHealth + ", present:" + mBatteryPresent +
@@ -532,24 +556,8 @@ public final class BatteryService extends Binder {
", technology: " + mBatteryTechnology +
", AC powered:" + mAcOnline + ", USB powered:" + mUsbOnline +
", Wireless powered:" + mWirelessOnline +
- ", icon:" + icon + ", invalid charger:" + mInvalidCharger);
- }
-
- if (mHasDockBattery){
- intent.putExtra(BatteryManager.EXTRA_DOCK_PRESENT, mDockBatteryPresent);
- intent.putExtra(BatteryManager.EXTRA_DOCK_STATUS, mDockBatteryStatus);
- intent.putExtra(BatteryManager.EXTRA_DOCK_LEVEL, mDockBatteryLevel);
- }
-
- if (false) {
- Slog.d(TAG, "level:" + mBatteryLevel +
- " scale:" + BATTERY_SCALE + " status:" + mBatteryStatus +
- " health:" + mBatteryHealth + " present:" + mBatteryPresent +
- " voltage: " + mBatteryVoltage +
- " temperature: " + mBatteryTemperature +
- " technology: " + mBatteryTechnology +
- " AC powered:" + mAcOnline + " USB powered:" + mUsbOnline +
- " icon:" + icon + " invalid charger:" + mInvalidCharger);
+ ", icon:" + icon + ", invalid charger:" + mInvalidCharger +
+ dockDebug);
}
mHandler.post(new Runnable() {
@@ -711,6 +719,17 @@ public final class BatteryService extends Binder {
}
}
+ private final BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
+ synchronized (mLock) {
+ updateLocked();
+ }
+ }
+ }
+ };
+
private final UEventObserver mPowerSupplyObserver = new UEventObserver() {
@Override
public void onUEvent(UEventObserver.UEvent event) {