diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/app/IBatteryService.aidl | 26 | ||||
-rw-r--r-- | core/java/android/app/SystemServiceRegistry.java | 4 | ||||
-rw-r--r-- | core/java/android/os/BatteryManager.java | 160 | ||||
-rw-r--r-- | core/java/android/os/BatteryManagerInternal.java | 21 | ||||
-rw-r--r-- | core/java/android/os/BatteryProperties.java | 54 | ||||
-rw-r--r-- | core/java/android/os/IBatteryPropertiesRegistrar.aidl | 2 | ||||
-rw-r--r-- | core/java/com/android/internal/app/IBatteryStats.aidl | 15 | ||||
-rw-r--r-- | core/java/com/android/internal/os/BatteryStatsHelper.java | 89 | ||||
-rw-r--r-- | core/java/com/android/internal/os/BatteryStatsImpl.java | 29 | ||||
-rw-r--r-- | core/java/com/android/internal/os/DockBatteryStatsImpl.java | 56 | ||||
-rw-r--r-- | core/res/AndroidManifest.xml | 9 | ||||
-rw-r--r-- | core/res/res/values/cm_strings.xml | 7 |
12 files changed, 456 insertions, 16 deletions
diff --git a/core/java/android/app/IBatteryService.aidl b/core/java/android/app/IBatteryService.aidl new file mode 100644 index 0000000..196159b --- /dev/null +++ b/core/java/android/app/IBatteryService.aidl @@ -0,0 +1,26 @@ +/** + * 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 android.app; + +/** + * System private API for talking with the battery service. + * + * {@hide} + */ +interface IBatteryService { + boolean isDockBatterySupported(); +} diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index 3d264c6..34c967f 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -254,7 +254,9 @@ final class SystemServiceRegistry { new StaticServiceFetcher<BatteryManager>() { @Override public BatteryManager createService() { - return new BatteryManager(); + IBinder b = ServiceManager.getService(Context.BATTERY_SERVICE); + IBatteryService service = IBatteryService.Stub.asInterface(b); + return new BatteryManager(service); }}); registerService(Context.NFC_SERVICE, NfcManager.class, diff --git a/core/java/android/os/BatteryManager.java b/core/java/android/os/BatteryManager.java index 1f3e9a7..050820c 100644 --- a/core/java/android/os/BatteryManager.java +++ b/core/java/android/os/BatteryManager.java @@ -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. @@ -16,6 +17,7 @@ package android.os; +import android.app.IBatteryService; import android.content.Context; import android.os.BatteryProperty; import android.os.IBatteryPropertiesRegistrar; @@ -95,6 +97,79 @@ public class BatteryManager { /** * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: + * integer containing the current dock status constant. + * @hide + */ + public static final String EXTRA_DOCK_STATUS = "dock_status"; + + /** + * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: + * integer containing the current dock health constant. + * @hide + */ + public static final String EXTRA_DOCK_HEALTH = "dock_health"; + + /** + * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: + * boolean indicating whether a dock battery is present. + * @hide + */ + public static final String EXTRA_DOCK_PRESENT = "dock_present"; + + /** + * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: + * integer field containing the current dock battery level, from 0 to + * {@link #EXTRA_SCALE}. + * @hide + */ + public static final String EXTRA_DOCK_LEVEL = "dock_level"; + + /** + * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: + * integer containing the maximum dock battery level. + * @hide + */ + public static final String EXTRA_DOCK_SCALE = "dock_scale"; + + /** + * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: + * integer containing the resource ID of a small status bar icon + * indicating the current dock battery state. + * @hide + */ + public static final String EXTRA_DOCK_ICON_SMALL = "dock_icon-small"; + + /** + * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: + * integer indicating whether the device is plugged in to a dock power + * source. + * @hide + */ + public static final String EXTRA_DOCK_PLUGGED = "dock_plugged"; + + /** + * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: + * integer containing the current dock battery voltage level. + * @hide + */ + public static final String EXTRA_DOCK_VOLTAGE = "dock_voltage"; + + /** + * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: + * integer containing the current dock battery temperature. + * @hide + */ + public static final String EXTRA_DOCK_TEMPERATURE = "dock_temperature"; + + /** + * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: + * String describing the technology of the current dock battery. + * @hide + */ + public static final String EXTRA_DOCK_TECHNOLOGY = "dock_technology"; + + /** + * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: * Int value set to nonzero if an unsupported charger is attached * to the device. * {@hide} @@ -133,10 +208,23 @@ public class BatteryManager { /** Power source is wireless. */ public static final int BATTERY_PLUGGED_WIRELESS = 4; + // values of the "dock_plugged" field in the ACTION_BATTERY_CHANGED intent. + // These must be powers of 2. + /** Power source is an DockAC charger. + * @hide*/ + public static final int BATTERY_DOCK_PLUGGED_AC = 1; + /** Power source is an DockUSB charger. + * @hide*/ + public static final int BATTERY_DOCK_PLUGGED_USB = 2; + /** @hide */ public static final int BATTERY_PLUGGED_ANY = BATTERY_PLUGGED_AC | BATTERY_PLUGGED_USB | BATTERY_PLUGGED_WIRELESS; + /** @hide */ + public static final int BATTERY_DOCK_PLUGGED_ANY = + BATTERY_DOCK_PLUGGED_AC | BATTERY_DOCK_PLUGGED_USB; + /** * Sent when the device's battery has started charging (or has reached full charge * and the device is on power). This is a good time to do work that you would like to @@ -191,6 +279,7 @@ public class BatteryManager { */ public static final int BATTERY_PROPERTY_ENERGY_COUNTER = 5; + private final IBatteryService mBatteryService; private final IBatteryStats mBatteryStats; private final IBatteryPropertiesRegistrar mBatteryPropertiesRegistrar; @@ -202,6 +291,27 @@ public class BatteryManager { ServiceManager.getService(BatteryStats.SERVICE_NAME)); mBatteryPropertiesRegistrar = IBatteryPropertiesRegistrar.Stub.asInterface( ServiceManager.getService("batteryproperties")); + mBatteryService = null; + } + + /** @hide */ + public BatteryManager(IBatteryService service) { + super(); + mBatteryStats = IBatteryStats.Stub.asInterface( + ServiceManager.getService(BatteryStats.SERVICE_NAME)); + mBatteryPropertiesRegistrar = IBatteryPropertiesRegistrar.Stub.asInterface( + ServiceManager.getService("batteryproperties")); + mBatteryService = service; + } + + /** @hide */ + public boolean isDockBatterySupported() { + try { + return mBatteryService != null && mBatteryService.isDockBatterySupported(); + } catch (RemoteException ex) { + // Ignore + } + return false; } /** @@ -223,8 +333,10 @@ public class BatteryManager { * * Returns the requested value, or Long.MIN_VALUE if property not * supported on this system or on other error. + * fromDock determines if the property is query from the normal battery + * or the dock battery. */ - private long queryProperty(int id) { + private long queryProperty(int id, boolean fromDock) { long ret; if (mBatteryPropertiesRegistrar == null) { @@ -234,7 +346,13 @@ public class BatteryManager { try { BatteryProperty prop = new BatteryProperty(); - if (mBatteryPropertiesRegistrar.getProperty(id, prop) == 0) + final int callResult; + if (!fromDock) { + callResult = mBatteryPropertiesRegistrar.getProperty(id, prop); + } else { + callResult = mBatteryPropertiesRegistrar.getDockProperty(id, prop); + } + if (callResult == 0) ret = prop.getLong(); else ret = Long.MIN_VALUE; @@ -255,7 +373,7 @@ public class BatteryManager { * @return the property value, or Integer.MIN_VALUE if not supported. */ public int getIntProperty(int id) { - return (int)queryProperty(id); + return (int)queryProperty(id, false); } /** @@ -268,6 +386,40 @@ public class BatteryManager { * @return the property value, or Long.MIN_VALUE if not supported. */ public long getLongProperty(int id) { - return queryProperty(id); + return queryProperty(id, false); + } + + /** + * Return the value of a dock battery property of integer type. If the + * platform does not provide the property queried, this value will + * be Integer.MIN_VALUE. + * + * @param id identifier of the requested property + * + * @return the property value, or Integer.MIN_VALUE if not supported. + * @hide + */ + public int getIntDockProperty(int id) { + if (!isDockBatterySupported()) { + return Integer.MIN_VALUE; + } + return (int)queryProperty(id, true); + } + + /** + * Return the value of a dock battery property of long type If the + * platform does not provide the property queried, this value will + * be Long.MIN_VALUE. + * + * @param id identifier of the requested property + * + * @return the property value, or Long.MIN_VALUE if not supported. + * @hide + */ + public long getLongDockProperty(int id) { + if (!isDockBatterySupported()) { + return Long.MIN_VALUE; + } + return queryProperty(id, true); } } diff --git a/core/java/android/os/BatteryManagerInternal.java b/core/java/android/os/BatteryManagerInternal.java index f3a95b9..1abb3d5 100644 --- a/core/java/android/os/BatteryManagerInternal.java +++ b/core/java/android/os/BatteryManagerInternal.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2014 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. @@ -43,6 +44,26 @@ public abstract class BatteryManagerInternal { public abstract boolean getBatteryLevelLow(); /** + * Returns whether dock batteries is supported + */ + public abstract boolean isDockBatterySupported(); + + /** + * Returns the current dock plug type. + */ + public abstract int getDockPlugType(); + + /** + * Returns dock battery level as a percentage. + */ + public abstract int getDockBatteryLevel(); + + /** + * Returns whether we currently consider the dock battery level to be low. + */ + public abstract boolean getDockBatteryLevelLow(); + + /** * Returns a non-zero value if an unsupported charger is attached. */ public abstract int getInvalidCharger(); diff --git a/core/java/android/os/BatteryProperties.java b/core/java/android/os/BatteryProperties.java index 29e868c..cad741a 100644 --- a/core/java/android/os/BatteryProperties.java +++ b/core/java/android/os/BatteryProperties.java @@ -1,4 +1,5 @@ /* Copyright 2013, The Android Open Source Project + * Copyright 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. @@ -31,6 +32,16 @@ public class BatteryProperties implements Parcelable { public int batteryTemperature; public String batteryTechnology; + public boolean dockBatterySupported; + public boolean chargerDockAcOnline; + public int dockBatteryStatus; + public int dockBatteryHealth; + public boolean dockBatteryPresent; + public int dockBatteryLevel; + public int dockBatteryVoltage; + public int dockBatteryTemperature; + public String dockBatteryTechnology; + public BatteryProperties() { } @@ -46,6 +57,16 @@ public class BatteryProperties implements Parcelable { batteryVoltage = other.batteryVoltage; batteryTemperature = other.batteryTemperature; batteryTechnology = other.batteryTechnology; + + dockBatterySupported = other.dockBatterySupported; + chargerDockAcOnline = other.chargerDockAcOnline; + dockBatteryStatus = other.dockBatteryStatus; + dockBatteryHealth = other.dockBatteryHealth; + dockBatteryPresent = other.dockBatteryPresent; + dockBatteryLevel = other.dockBatteryLevel; + dockBatteryVoltage = other.dockBatteryVoltage; + dockBatteryTemperature = other.dockBatteryTemperature; + dockBatteryTechnology = other.dockBatteryTechnology; } /* @@ -65,6 +86,27 @@ public class BatteryProperties implements Parcelable { batteryVoltage = p.readInt(); batteryTemperature = p.readInt(); batteryTechnology = p.readString(); + + dockBatterySupported = p.readInt() == 1 ? true : false; + if (dockBatterySupported) { + chargerDockAcOnline = p.readInt() == 1 ? true : false; + dockBatteryStatus = p.readInt(); + dockBatteryHealth = p.readInt(); + dockBatteryPresent = p.readInt() == 1 ? true : false; + dockBatteryLevel = p.readInt(); + dockBatteryVoltage = p.readInt(); + dockBatteryTemperature = p.readInt(); + dockBatteryTechnology = p.readString(); + } else { + chargerDockAcOnline = false; + dockBatteryStatus = BatteryManager.BATTERY_STATUS_UNKNOWN; + dockBatteryHealth = BatteryManager.BATTERY_HEALTH_UNKNOWN; + dockBatteryPresent = false; + dockBatteryLevel = 0; + dockBatteryVoltage = 0; + dockBatteryTemperature = 0; + dockBatteryTechnology = ""; + } } public void writeToParcel(Parcel p, int flags) { @@ -79,6 +121,18 @@ public class BatteryProperties implements Parcelable { p.writeInt(batteryVoltage); p.writeInt(batteryTemperature); p.writeString(batteryTechnology); + + p.writeInt(dockBatterySupported ? 1 : 0); + if (dockBatterySupported) { + p.writeInt(chargerDockAcOnline ? 1 : 0); + p.writeInt(dockBatteryStatus); + p.writeInt(dockBatteryHealth); + p.writeInt(dockBatteryPresent ? 1 : 0); + p.writeInt(dockBatteryLevel); + p.writeInt(dockBatteryVoltage); + p.writeInt(dockBatteryTemperature); + p.writeString(dockBatteryTechnology); + } } public static final Parcelable.Creator<BatteryProperties> CREATOR diff --git a/core/java/android/os/IBatteryPropertiesRegistrar.aidl b/core/java/android/os/IBatteryPropertiesRegistrar.aidl index fd01802..43b9650 100644 --- a/core/java/android/os/IBatteryPropertiesRegistrar.aidl +++ b/core/java/android/os/IBatteryPropertiesRegistrar.aidl @@ -1,5 +1,6 @@ /* ** Copyright 2013, The Android Open Source Project +** Copyright 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. @@ -27,4 +28,5 @@ interface IBatteryPropertiesRegistrar { void registerListener(IBatteryPropertiesListener listener); void unregisterListener(IBatteryPropertiesListener listener); int getProperty(in int id, out BatteryProperty prop); + int getDockProperty(in int id, out BatteryProperty prop); } 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]; + } + }; +} diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 6ef5bde..7b3738f 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -2377,6 +2377,15 @@ <permission android:name="android.permission.BATTERY_STATS" android:protectionLevel="signature|privileged|development" /> + <!-- Allows an application to reset the device battery statistics. + <p>Not for use by third-party applications. + @hide --> + <permission android:name="android.permission.RESET_BATTERY_STATS" + android:permissionGroup="android.permission-group.SYSTEM_TOOLS" + android:label="@string/permlab_resetBatteryStats" + android:description="@string/permdesc_resetBatteryStats" + android:protectionLevel="signature|system|development" /> + <!-- @SystemApi Allows an application to control the backup and restore process. <p>Not for use by third-party applications. @hide pending API council --> diff --git a/core/res/res/values/cm_strings.xml b/core/res/res/values/cm_strings.xml index 688b2f9..9b03793 100644 --- a/core/res/res/values/cm_strings.xml +++ b/core/res/res/values/cm_strings.xml @@ -225,4 +225,11 @@ <!-- Battery fully charged notification --> <string name="notify_battery_fully_charged_title">Battery fully charged</string> <string name="notify_battery_fully_charged_text">Disconnect your device from the charger to improve battery longevity.</string> + + <!-- [CHAR LIMIT=NONE] Title of an application permission, listed so the user can choose + whether they want to allow the application to do this. --> + <string name="permlab_resetBatteryStats">reset battery statistics</string> + <!-- [CHAR LIMIT=NONE] Description of an application permission, listed so the user can choose + whether they want to allow the application to do this. --> + <string name="permdesc_resetBatteryStats">Allows an application to reset the current low-level battery usage data.</string> </resources> |