summaryrefslogtreecommitdiffstats
path: root/core/java/com/android/internal
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/com/android/internal')
-rw-r--r--core/java/com/android/internal/app/IBatteryStats.aidl15
-rw-r--r--core/java/com/android/internal/os/BatteryStatsHelper.java89
-rw-r--r--core/java/com/android/internal/os/BatteryStatsImpl.java29
-rw-r--r--core/java/com/android/internal/os/DockBatteryStatsImpl.java56
4 files changed, 178 insertions, 11 deletions
diff --git a/core/java/com/android/internal/app/IBatteryStats.aidl b/core/java/com/android/internal/app/IBatteryStats.aidl
index 3cddbf6..ba92f48 100644
--- a/core/java/com/android/internal/app/IBatteryStats.aidl
+++ b/core/java/com/android/internal/app/IBatteryStats.aidl
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2016 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -121,4 +122,18 @@ interface IBatteryStats {
void setBatteryState(int status, int health, int plugType, int level, int temp, int volt);
long getAwakeTimeBattery();
long getAwakeTimePlugged();
+
+
+ /** @hide */
+ byte[] getDockStatistics();
+ /** @hide */
+ ParcelFileDescriptor getDockStatisticsStream();
+ /** @hide **/
+ void resetStatistics();
+ /** @hide **/
+ void setDockBatteryState(int status, int health, int plugType, int level, int temp, int volt);
+ /** @hide **/
+ long getAwakeTimeDockBattery();
+ /** @hide **/
+ long getAwakeTimeDockPlugged();
}
diff --git a/core/java/com/android/internal/os/BatteryStatsHelper.java b/core/java/com/android/internal/os/BatteryStatsHelper.java
index f178c8c..54a4e86 100644
--- a/core/java/com/android/internal/os/BatteryStatsHelper.java
+++ b/core/java/com/android/internal/os/BatteryStatsHelper.java
@@ -21,6 +21,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.SensorManager;
import android.net.ConnectivityManager;
+import android.os.BatteryManager;
import android.os.BatteryStats;
import android.os.BatteryStats.Uid;
import android.os.Bundle;
@@ -61,15 +62,18 @@ public final class BatteryStatsHelper {
private static final String TAG = BatteryStatsHelper.class.getSimpleName();
private static BatteryStats sStatsXfer;
+ private static BatteryStats sDockStatsXfer;
private static Intent sBatteryBroadcastXfer;
private static ArrayMap<File, BatteryStats> sFileXfer = new ArrayMap<>();
final private Context mContext;
+ final private BatteryManager mBatteryService;
final private boolean mCollectBatteryBroadcast;
final private boolean mWifiOnly;
private IBatteryStats mBatteryInfo;
private BatteryStats mStats;
+ private BatteryStats mDockStats;
private Intent mBatteryBroadcast;
private PowerProfile mPowerProfile;
@@ -160,19 +164,28 @@ public final class BatteryStatsHelper {
public BatteryStatsHelper(Context context, boolean collectBatteryBroadcast, boolean wifiOnly) {
mContext = context;
+ mBatteryService = ((BatteryManager) context.getSystemService(Context.BATTERY_SERVICE));
mCollectBatteryBroadcast = collectBatteryBroadcast;
mWifiOnly = wifiOnly;
}
public void storeStatsHistoryInFile(String fname) {
+ internalStoreStatsHistoryInFile(getStats(), fname);
+ }
+
+ public void storeDockStatsHistoryInFile(String fname) {
+ internalStoreStatsHistoryInFile(getDockStats(), fname);
+ }
+
+ public void internalStoreStatsHistoryInFile(BatteryStats stats, String fname) {
synchronized (sFileXfer) {
File path = makeFilePath(mContext, fname);
- sFileXfer.put(path, this.getStats());
+ sFileXfer.put(path, stats);
FileOutputStream fout = null;
try {
fout = new FileOutputStream(path);
Parcel hist = Parcel.obtain();
- getStats().writeToParcelWithoutUids(hist, 0);
+ stats.writeToParcelWithoutUids(hist, 0);
byte[] histData = hist.marshall();
fout.write(histData);
} catch (IOException e) {
@@ -229,18 +242,38 @@ public final class BatteryStatsHelper {
/** Clears the current stats and forces recreating for future use. */
public void clearStats() {
mStats = null;
+ mDockStats = null;
+ }
+
+ private void clearAllStats() {
+ clearStats();
+ sStatsXfer = null;
+ sDockStatsXfer = null;
+ sBatteryBroadcastXfer = null;
+ for (File f : sFileXfer.keySet()) {
+ f.delete();
+ }
+ sFileXfer.clear();
}
public BatteryStats getStats() {
if (mStats == null) {
- load();
+ loadStats();
}
return mStats;
}
+ public BatteryStats getDockStats() {
+ if (mDockStats == null) {
+ loadDockStats();
+ }
+ return mDockStats;
+ }
+
public Intent getBatteryBroadcast() {
if (mBatteryBroadcast == null && mCollectBatteryBroadcast) {
- load();
+ loadStats();
+ loadDockStats();
}
return mBatteryBroadcast;
}
@@ -257,6 +290,7 @@ public final class BatteryStatsHelper {
public void create(Bundle icicle) {
if (icicle != null) {
mStats = sStatsXfer;
+ mDockStats = sDockStatsXfer;
mBatteryBroadcast = sBatteryBroadcastXfer;
}
mBatteryInfo = IBatteryStats.Stub.asInterface(
@@ -266,6 +300,7 @@ public final class BatteryStatsHelper {
public void storeState() {
sStatsXfer = mStats;
+ sDockStatsXfer = mDockStats;
sBatteryBroadcastXfer = mBatteryBroadcast;
}
@@ -321,6 +356,7 @@ public final class BatteryStatsHelper {
long rawUptimeUs) {
// Initialize mStats if necessary.
getStats();
+ getDockStats();
mMaxPower = 0;
mMaxRealPower = 0;
@@ -739,7 +775,7 @@ public final class BatteryStatsHelper {
}
}
- private void load() {
+ private void loadStats() {
if (mBatteryInfo == null) {
return;
}
@@ -750,6 +786,26 @@ public final class BatteryStatsHelper {
}
}
+ private void loadDockStats() {
+ if (mBatteryInfo == null) {
+ return;
+ }
+ if (mBatteryService.isDockBatterySupported()) {
+ mDockStats = getDockStats(mBatteryInfo);
+ } else {
+ mDockStats = null;
+ }
+ }
+
+ public void resetStatistics() {
+ try {
+ clearAllStats();
+ mBatteryInfo.resetStatistics();
+ } catch (RemoteException e) {
+ Log.e(TAG, "RemoteException:", e);
+ }
+ }
+
private static BatteryStatsImpl getStats(IBatteryStats service) {
try {
ParcelFileDescriptor pfd = service.getStatisticsStream();
@@ -772,4 +828,27 @@ public final class BatteryStatsHelper {
}
return new BatteryStatsImpl();
}
+
+ private static BatteryStatsImpl getDockStats(IBatteryStats service) {
+ try {
+ ParcelFileDescriptor pfd = service.getDockStatisticsStream();
+ if (pfd != null) {
+ FileInputStream fis = new ParcelFileDescriptor.AutoCloseInputStream(pfd);
+ try {
+ byte[] data = readFully(fis, MemoryFile.getSize(pfd.getFileDescriptor()));
+ Parcel parcel = Parcel.obtain();
+ parcel.unmarshall(data, 0, data.length);
+ parcel.setDataPosition(0);
+ BatteryStatsImpl stats = com.android.internal.os.DockBatteryStatsImpl.CREATOR
+ .createFromParcel(parcel);
+ return stats;
+ } catch (IOException e) {
+ Log.w(TAG, "Unable to read statistics stream", e);
+ }
+ }
+ } catch (RemoteException e) {
+ Log.w(TAG, "RemoteException:", e);
+ }
+ return new BatteryStatsImpl();
+ }
}
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index 64b7768..28cc13f 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2006-2007 The Android Open Source Project
+ * Copyright (C) 2016 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -91,7 +92,7 @@ import java.util.concurrent.locks.ReentrantLock;
* battery life. All times are represented in microseconds except where indicated
* otherwise.
*/
-public final class BatteryStatsImpl extends BatteryStats {
+public class BatteryStatsImpl extends BatteryStats {
private static final String TAG = "BatteryStatsImpl";
private static final boolean DEBUG = false;
public static final boolean DEBUG_ENERGY = false;
@@ -6839,13 +6840,13 @@ public final class BatteryStatsImpl extends BatteryStats {
public BatteryStatsImpl(File systemDir, Handler handler, ExternalStatsSync externalSync) {
if (systemDir != null) {
- mFile = new JournaledFile(new File(systemDir, "batterystats.bin"),
- new File(systemDir, "batterystats.bin.tmp"));
+ mFile = new JournaledFile(new File(systemDir, getStatsName() + ".bin"),
+ new File(systemDir, getStatsName() + ".bin.tmp"));
} else {
mFile = null;
}
- mCheckinFile = new AtomicFile(new File(systemDir, "batterystats-checkin.bin"));
- mDailyFile = new AtomicFile(new File(systemDir, "batterystats-daily.xml"));
+ mCheckinFile = new AtomicFile(new File(systemDir, getStatsName() + "-checkin.bin"));
+ mDailyFile = new AtomicFile(new File(systemDir, getStatsName () + "-daily.xml"));
mExternalSync = externalSync;
mHandler = new MyHandler(handler.getLooper());
mStartCount++;
@@ -6921,6 +6922,16 @@ public final class BatteryStatsImpl extends BatteryStats {
readFromParcel(p);
}
+ /** @hide */
+ protected String getStatsName() {
+ return "batterystats";
+ }
+
+ /** @hide */
+ protected String getLogName() {
+ return "BatteryStats";
+ }
+
public void setPowerProfile(PowerProfile profile) {
synchronized (this) {
mPowerProfile = profile;
@@ -8434,7 +8445,13 @@ public final class BatteryStatsImpl extends BatteryStats {
public void setBatteryStateLocked(int status, int health, int plugType, int level,
int temp, int volt) {
- final boolean onBattery = plugType == BATTERY_PLUGGED_NONE;
+ // We need to add a extra check over the status because of dock batteries
+ // PlugType doesn't means that the dock battery is charging (some devices
+ // doesn't charge under dock usb)
+ boolean onBattery = plugType == BATTERY_PLUGGED_NONE &&
+ (status != BatteryManager.BATTERY_STATUS_CHARGING ||
+ status != BatteryManager.BATTERY_STATUS_FULL);
+
final long uptime = SystemClock.uptimeMillis();
final long elapsedRealtime = SystemClock.elapsedRealtime();
if (!mHaveBatteryLevel) {
diff --git a/core/java/com/android/internal/os/DockBatteryStatsImpl.java b/core/java/com/android/internal/os/DockBatteryStatsImpl.java
new file mode 100644
index 0000000..6099ad2
--- /dev/null
+++ b/core/java/com/android/internal/os/DockBatteryStatsImpl.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2016 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.os;
+
+import android.os.Handler;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.io.File;
+
+public final class DockBatteryStatsImpl extends BatteryStatsImpl {
+ public DockBatteryStatsImpl() {
+ super();
+ }
+
+ public DockBatteryStatsImpl(Parcel p) {
+ super(p);
+ }
+
+ public DockBatteryStatsImpl(File systemDir, Handler handler, ExternalStatsSync externalSync) {
+ super(systemDir, handler, externalSync);
+ }
+
+ protected String getStatsName() {
+ return "dockbatterystats";
+ }
+
+ protected String getLogName() {
+ return "DockBatteryStats";
+ }
+
+ public static final Parcelable.Creator<DockBatteryStatsImpl> CREATOR =
+ new Parcelable.Creator<DockBatteryStatsImpl>() {
+ public DockBatteryStatsImpl createFromParcel(Parcel in) {
+ return new DockBatteryStatsImpl(in);
+ }
+
+ public DockBatteryStatsImpl[] newArray(int size) {
+ return new DockBatteryStatsImpl[size];
+ }
+ };
+}