summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2014-05-14 11:42:00 -0700
committerDianne Hackborn <hackbod@google.com>2014-05-15 13:32:29 -0700
commitcbefd8dd2befcb768f911a63becc427ec4c13250 (patch)
tree083c53ca606811b4ccfbda8d013f29497b7efbd0 /services
parente7db83426e9979a0b6ecf124a013dc944dd3ccce (diff)
downloadframeworks_base-cbefd8dd2befcb768f911a63becc427ec4c13250.zip
frameworks_base-cbefd8dd2befcb768f911a63becc427ec4c13250.tar.gz
frameworks_base-cbefd8dd2befcb768f911a63becc427ec4c13250.tar.bz2
Battery stats more wake history, power save mode.
Add new option for battery stats to record the full wake lock history, and recording the current power save mode. Also add in some additional error constants when generating Binder error exceptions. And fix issue #14974572: Avoid repeating wakeup_reason at the beginning of history Change-Id: I7c1a2ab9569de216634f63d8ad69f1294ef1d235
Diffstat (limited to 'services')
-rw-r--r--services/core/java/com/android/server/am/BatteryStatsService.java70
-rw-r--r--services/core/java/com/android/server/power/Notifier.java13
-rw-r--r--services/core/java/com/android/server/power/PowerManagerService.java40
3 files changed, 103 insertions, 20 deletions
diff --git a/services/core/java/com/android/server/am/BatteryStatsService.java b/services/core/java/com/android/server/am/BatteryStatsService.java
index dd12a65..908bfbd 100644
--- a/services/core/java/com/android/server/am/BatteryStatsService.java
+++ b/services/core/java/com/android/server/am/BatteryStatsService.java
@@ -27,6 +27,7 @@ import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.os.Parcel;
+import android.os.PowerManagerInternal;
import android.os.Process;
import android.os.ServiceManager;
import android.os.SystemClock;
@@ -40,6 +41,7 @@ import android.util.Slog;
import com.android.internal.app.IBatteryStats;
import com.android.internal.os.BatteryStatsImpl;
import com.android.internal.os.PowerProfile;
+import com.android.server.LocalServices;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -49,7 +51,8 @@ import java.util.List;
* All information we are collecting about things that can happen that impact
* battery life.
*/
-public final class BatteryStatsService extends IBatteryStats.Stub {
+public final class BatteryStatsService extends IBatteryStats.Stub
+ implements PowerManagerInternal.LowPowerModeListener {
static final String TAG = "BatteryStatsService";
static IBatteryStats sService;
@@ -58,6 +61,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
Context mContext;
private boolean mBluetoothPendingStats;
private BluetoothHeadset mBluetoothHeadset;
+ PowerManagerInternal mPowerManagerInternal;
BatteryStatsService(String filename, Handler handler) {
mStats = new BatteryStatsImpl(filename, handler);
@@ -70,6 +74,9 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
mStats.setRadioScanningTimeout(mContext.getResources().getInteger(
com.android.internal.R.integer.config_radioScanningTimeout)
* 1000L);
+ mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
+ mPowerManagerInternal.registerLowPowerModeObserver(this);
+ mStats.noteLowPowerMode(mPowerManagerInternal.getLowPowerModeEnabled());
(new WakeupReasonThread()).start();
}
@@ -88,7 +95,14 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
sService = asInterface(b);
return sService;
}
-
+
+ @Override
+ public void onLowPowerModeChanged(boolean enabled) {
+ synchronized (mStats) {
+ mStats.noteLowPowerMode(enabled);
+ }
+ }
+
/**
* @return the current statistics object, which may be modified
* to reflect events that affect battery usage. You must lock the
@@ -154,11 +168,11 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
}
}
- public void noteStopWakelock(int uid, int pid, String name, int type) {
+ public void noteStopWakelock(int uid, int pid, String name, String historyName, int type) {
enforceCallingPermission();
synchronized (mStats) {
- mStats.noteStopWakeLocked(uid, pid, name, type, SystemClock.elapsedRealtime(),
- SystemClock.uptimeMillis());
+ mStats.noteStopWakeLocked(uid, pid, name, historyName, type,
+ SystemClock.elapsedRealtime(), SystemClock.uptimeMillis());
}
}
@@ -171,20 +185,21 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
}
}
- public void noteChangeWakelockFromSource(WorkSource ws, int pid, String name, int type,
- WorkSource newWs, int newPid, String newName,
+ public void noteChangeWakelockFromSource(WorkSource ws, int pid, String name,
+ String historyName, int type, WorkSource newWs, int newPid, String newName,
String newHistoryName, int newType, boolean newUnimportantForLogging) {
enforceCallingPermission();
synchronized (mStats) {
- mStats.noteChangeWakelockFromSourceLocked(ws, pid, name, type,
+ mStats.noteChangeWakelockFromSourceLocked(ws, pid, name, historyName, type,
newWs, newPid, newName, newHistoryName, newType, newUnimportantForLogging);
}
}
- public void noteStopWakelockFromSource(WorkSource ws, int pid, String name, int type) {
+ public void noteStopWakelockFromSource(WorkSource ws, int pid, String name, String historyName,
+ int type) {
enforceCallingPermission();
synchronized (mStats) {
- mStats.noteStopWakeFromSourceLocked(ws, pid, name, type);
+ mStats.noteStopWakeFromSourceLocked(ws, pid, name, historyName, type);
}
}
@@ -608,10 +623,31 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
pw.println(" --charged: only output data since last charged.");
pw.println(" --reset: reset the stats, clearing all current data.");
pw.println(" --write: force write current collected stats to disk.");
+ pw.println(" --enable: enable an option: full-wake-history.");
+ pw.println(" --disable: disable an option: full-wake-history.");
pw.println(" -h: print this help text.");
pw.println(" <package.name>: optional name of package to filter output by.");
}
+ private int doEnableOrDisable(PrintWriter pw, int i, String[] args, boolean enable) {
+ i++;
+ if (i >= args.length) {
+ pw.println("Missing option argument for " + (enable ? "--enable" : "--disable"));
+ dumpHelp(pw);
+ return -1;
+ }
+ if ("full-wake-history".equals(args[i])) {
+ synchronized (mStats) {
+ mStats.setRecordAllWakeLocksLocked(enable);
+ }
+ } else {
+ pw.println("Unknown enable/disable option: " + args[i]);
+ dumpHelp(pw);
+ return -1;
+ }
+ return i;
+ }
+
@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
@@ -662,6 +698,20 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
pw.println("Battery stats written.");
noOutput = true;
}
+ } else if ("--enable".equals(arg)) {
+ i = doEnableOrDisable(pw, i, args, true);
+ if (i < 0) {
+ return;
+ }
+ pw.println("Enabled: " + args[i]);
+ return;
+ } else if ("--disable".equals(arg)) {
+ i = doEnableOrDisable(pw, i, args, false);
+ if (i < 0) {
+ return;
+ }
+ pw.println("Disabled: " + args[i]);
+ return;
} else if ("-h".equals(arg)) {
dumpHelp(pw);
return;
diff --git a/services/core/java/com/android/server/power/Notifier.java b/services/core/java/com/android/server/power/Notifier.java
index 2d6cc7c..e244bde 100644
--- a/services/core/java/com/android/server/power/Notifier.java
+++ b/services/core/java/com/android/server/power/Notifier.java
@@ -190,14 +190,14 @@ final class Notifier {
+ ", workSource=" + newWorkSource);
}
try {
- mBatteryStats.noteChangeWakelockFromSource(workSource, ownerPid, tag, monitorType,
- newWorkSource, newOwnerPid, newTag, newHistoryTag,
+ mBatteryStats.noteChangeWakelockFromSource(workSource, ownerPid, tag, historyTag,
+ monitorType, newWorkSource, newOwnerPid, newTag, newHistoryTag,
newMonitorType, unimportantForLogging);
} catch (RemoteException ex) {
// Ignore
}
} else {
- onWakeLockReleased(flags, tag, packageName, ownerUid, ownerPid, workSource);
+ onWakeLockReleased(flags, tag, packageName, ownerUid, ownerPid, workSource, historyTag);
onWakeLockAcquired(newFlags, newTag, newPackageName, newOwnerUid, newOwnerPid,
newWorkSource, newHistoryTag);
}
@@ -207,7 +207,7 @@ final class Notifier {
* Called when a wake lock is released.
*/
public void onWakeLockReleased(int flags, String tag, String packageName,
- int ownerUid, int ownerPid, WorkSource workSource) {
+ int ownerUid, int ownerPid, WorkSource workSource, String historyTag) {
if (DEBUG) {
Slog.d(TAG, "onWakeLockReleased: flags=" + flags + ", tag=\"" + tag
+ "\", packageName=" + packageName
@@ -218,9 +218,10 @@ final class Notifier {
try {
final int monitorType = getBatteryStatsWakeLockMonitorType(flags);
if (workSource != null) {
- mBatteryStats.noteStopWakelockFromSource(workSource, ownerPid, tag, monitorType);
+ mBatteryStats.noteStopWakelockFromSource(workSource, ownerPid, tag, historyTag,
+ monitorType);
} else {
- mBatteryStats.noteStopWakelock(ownerUid, ownerPid, tag, monitorType);
+ mBatteryStats.noteStopWakelock(ownerUid, ownerPid, tag, historyTag, monitorType);
mAppOps.finishOperation(AppOpsManager.getToken(mAppOps),
AppOpsManager.OP_WAKE_LOCK, ownerUid, packageName);
}
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java
index 03941c6..f0b7861 100644
--- a/services/core/java/com/android/server/power/PowerManagerService.java
+++ b/services/core/java/com/android/server/power/PowerManagerService.java
@@ -18,6 +18,7 @@ package com.android.server.power;
import com.android.internal.app.IAppOpsService;
import com.android.internal.app.IBatteryStats;
+import com.android.internal.os.BackgroundThread;
import com.android.server.BatteryService;
import com.android.server.EventLogTags;
import com.android.server.LocalServices;
@@ -400,7 +401,10 @@ public final class PowerManagerService extends com.android.server.SystemService
private long mLastWarningAboutUserActivityPermission = Long.MIN_VALUE;
// If true, the device is in low power mode.
- private static boolean mLowPowerModeEnabled;
+ private boolean mLowPowerModeEnabled;
+
+ private final ArrayList<PowerManagerInternal.LowPowerModeListener> mLowPowerModeListeners
+ = new ArrayList<PowerManagerInternal.LowPowerModeListener>();
private native void nativeInit();
@@ -623,11 +627,24 @@ public final class PowerManagerService extends com.android.server.SystemService
Settings.System.SCREEN_BRIGHTNESS_MODE,
Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, UserHandle.USER_CURRENT);
- boolean lowPowerModeEnabled = Settings.Global.getInt(resolver,
+ final boolean lowPowerModeEnabled = Settings.Global.getInt(resolver,
Settings.Global.LOW_POWER_MODE, 0) != 0;
if (lowPowerModeEnabled != mLowPowerModeEnabled) {
powerHintInternal(POWER_HINT_LOW_POWER_MODE, lowPowerModeEnabled ? 1 : 0);
mLowPowerModeEnabled = lowPowerModeEnabled;
+ BackgroundThread.getHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ ArrayList<PowerManagerInternal.LowPowerModeListener> listeners;
+ synchronized (mLock) {
+ listeners = new ArrayList<PowerManagerInternal.LowPowerModeListener>(
+ mLowPowerModeListeners);
+ }
+ for (int i=0; i<listeners.size(); i++) {
+ listeners.get(i).onLowPowerModeChanged(lowPowerModeEnabled);
+ }
+ }
+ });
}
mDirty |= DIRTY_SETTINGS;
@@ -812,8 +829,9 @@ public final class PowerManagerService extends com.android.server.SystemService
private void notifyWakeLockReleasedLocked(WakeLock wakeLock) {
if (mSystemReady && wakeLock.mNotifiedAcquired) {
wakeLock.mNotifiedAcquired = false;
- mNotifier.onWakeLockReleased(wakeLock.mFlags, wakeLock.mTag, wakeLock.mPackageName,
- wakeLock.mOwnerUid, wakeLock.mOwnerPid, wakeLock.mWorkSource);
+ mNotifier.onWakeLockReleased(wakeLock.mFlags, wakeLock.mTag,
+ wakeLock.mPackageName, wakeLock.mOwnerUid, wakeLock.mOwnerPid,
+ wakeLock.mWorkSource, wakeLock.mHistoryTag);
}
}
@@ -2972,6 +2990,20 @@ public final class PowerManagerService extends com.android.server.SystemService
}
@Override
+ public boolean getLowPowerModeEnabled() {
+ synchronized (mLock) {
+ return mLowPowerModeEnabled;
+ }
+ }
+
+ @Override
+ public void registerLowPowerModeObserver(LowPowerModeListener listener) {
+ synchronized (mLock) {
+ mLowPowerModeListeners.add(listener);
+ }
+ }
+
+ @Override
public void setPolicy(WindowManagerPolicy policy) {
PowerManagerService.this.setPolicy(policy);
}