From 280a64e793d081847c5dcea23ed9be38aa5332d2 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Mon, 13 Jul 2015 14:48:08 -0700 Subject: Improve tracking of screen on reasons. - New screen on app op to record the last time each app has caused the screen to be turned on. - New battery stats event that tells us the reason the screen has been asked to turn on. - Propagate out power manager API to specify the reason a caller is asking to have the screen turned on. Note that currently the window flag to turn the screen on bypasses much of this because it is being handled in the window manager by just directly telling the power manager to turn the screen on. To make this better we need a new API where it can specify who it is calling the API for. Change-Id: I667e56cb1f80508d054da004db667efbcc22e971 --- core/java/android/app/AppOpsManager.java | 28 +++++++++++++++------- core/java/android/os/BatteryStats.java | 10 +++++--- core/java/android/os/IPowerManager.aidl | 2 +- core/java/android/os/PowerManager.java | 12 +++++++++- core/java/android/service/dreams/Sandman.java | 3 ++- .../com/android/internal/app/IBatteryStats.aidl | 1 + .../com/android/internal/os/BatteryStatsImpl.java | 7 ++++++ 7 files changed, 48 insertions(+), 15 deletions(-) (limited to 'core/java') diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java index bf3bfae..849253b 100644 --- a/core/java/android/app/AppOpsManager.java +++ b/core/java/android/app/AppOpsManager.java @@ -233,8 +233,10 @@ public class AppOpsManager { public static final int OP_READ_EXTERNAL_STORAGE = 59; /** @hide Write external storage. */ public static final int OP_WRITE_EXTERNAL_STORAGE = 60; + /** @hide Turned on the screen. */ + public static final int OP_TURN_SCREEN_ON = 61; /** @hide */ - public static final int _NUM_OP = 61; + public static final int _NUM_OP = 62; /** Access to coarse location information. */ public static final String OPSTR_COARSE_LOCATION = "android:coarse_location"; @@ -393,7 +395,8 @@ public class AppOpsManager { OP_READ_CELL_BROADCASTS, OP_MOCK_LOCATION, OP_READ_EXTERNAL_STORAGE, - OP_WRITE_EXTERNAL_STORAGE + OP_WRITE_EXTERNAL_STORAGE, + OP_TURN_SCREEN_ON, }; /** @@ -461,7 +464,8 @@ public class AppOpsManager { OPSTR_READ_CELL_BROADCASTS, OPSTR_MOCK_LOCATION, OPSTR_READ_EXTERNAL_STORAGE, - OPSTR_WRITE_EXTERNAL_STORAGE + OPSTR_WRITE_EXTERNAL_STORAGE, + null, }; /** @@ -528,8 +532,9 @@ public class AppOpsManager { "BODY_SENSORS", "READ_CELL_BROADCASTS", "MOCK_LOCATION", - "OPSTR_READ_EXTERNAL_STORAGE", - "OPSTR_WRITE_EXTERNAL_STORAGE", + "READ_EXTERNAL_STORAGE", + "WRITE_EXTERNAL_STORAGE", + "TURN_ON_SCREEN", }; /** @@ -598,6 +603,7 @@ public class AppOpsManager { null, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, + null, // no permission for turning the screen on }; /** @@ -666,7 +672,8 @@ public class AppOpsManager { null, // READ_CELL_BROADCASTS null, // MOCK_LOCATION null, // READ_EXTERNAL_STORAGE - null // WRITE_EXTERNAL_STORAGE + null, // WRITE_EXTERNAL_STORAGE + null, // TURN_ON_SCREEN }; /** @@ -734,7 +741,8 @@ public class AppOpsManager { false, // READ_CELL_BROADCASTS false, // MOCK_LOCATION false, // READ_EXTERNAL_STORAGE - false // WRITE_EXTERNAL_STORAGE + false, // WRITE_EXTERNAL_STORAGE + false, // TURN_ON_SCREEN }; /** @@ -801,7 +809,8 @@ public class AppOpsManager { AppOpsManager.MODE_ALLOWED, AppOpsManager.MODE_ERRORED, // OP_MOCK_LOCATION AppOpsManager.MODE_ALLOWED, - AppOpsManager.MODE_ALLOWED + AppOpsManager.MODE_ALLOWED, + AppOpsManager.MODE_ALLOWED, // OP_TURN_ON_SCREEN }; /** @@ -872,7 +881,8 @@ public class AppOpsManager { false, false, false, - false + false, + false, }; /** diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java index 452e4d5..ecb7f5a 100644 --- a/core/java/android/os/BatteryStats.java +++ b/core/java/android/os/BatteryStats.java @@ -1195,9 +1195,11 @@ public abstract class BatteryStats implements Parcelable { public static final int EVENT_PACKAGE_ACTIVE = 0x0010; // Event for a package being on the temporary whitelist. public static final int EVENT_TEMP_WHITELIST = 0x0011; + // Event for the screen waking up. + public static final int EVENT_SCREEN_WAKE_UP = 0x0012; // Number of event types. - public static final int EVENT_COUNT = 0x0012; + public static final int EVENT_COUNT = 0x0013; // Mask to extract out only the type part of the event. public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH); @@ -1858,12 +1860,14 @@ public abstract class BatteryStats implements Parcelable { public static final String[] HISTORY_EVENT_NAMES = new String[] { "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", - "active", "pkginst", "pkgunin", "alarm", "stats", "inactive", "active", "tmpwhitelist" + "active", "pkginst", "pkgunin", "alarm", "stats", "inactive", "active", "tmpwhitelist", + "screenwake", }; public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", - "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw" + "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", + "Esw", }; /** diff --git a/core/java/android/os/IPowerManager.aidl b/core/java/android/os/IPowerManager.aidl index 804d3d0..0f37ac7 100644 --- a/core/java/android/os/IPowerManager.aidl +++ b/core/java/android/os/IPowerManager.aidl @@ -37,7 +37,7 @@ interface IPowerManager boolean isWakeLockLevelSupported(int level); void userActivity(long time, int event, int flags); - void wakeUp(long time); + void wakeUp(long time, String reason, String opPackageName); void goToSleep(long time, int reason, int flags); void nap(long time); boolean isInteractive(); diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index 6ef1cd0..9a1a03e 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -658,7 +658,17 @@ public final class PowerManager { */ public void wakeUp(long time) { try { - mService.wakeUp(time); + mService.wakeUp(time, "wakeUp", mContext.getOpPackageName()); + } catch (RemoteException e) { + } + } + + /** + * @hide + */ + public void wakeUp(long time, String reason) { + try { + mService.wakeUp(time, reason, mContext.getOpPackageName()); } catch (RemoteException e) { } } diff --git a/core/java/android/service/dreams/Sandman.java b/core/java/android/service/dreams/Sandman.java index 5f5b079..eeb340b 100644 --- a/core/java/android/service/dreams/Sandman.java +++ b/core/java/android/service/dreams/Sandman.java @@ -92,7 +92,8 @@ public final class Sandman { // be awake by the time this happens. Otherwise the dream may not start. PowerManager powerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); - powerManager.wakeUp(SystemClock.uptimeMillis()); + powerManager.wakeUp(SystemClock.uptimeMillis(), + "android.service.dreams:DREAM"); } else { Slog.i(TAG, "Activating dream by user request."); } diff --git a/core/java/com/android/internal/app/IBatteryStats.aidl b/core/java/com/android/internal/app/IBatteryStats.aidl index 6f0cec6..3cddbf6 100644 --- a/core/java/com/android/internal/app/IBatteryStats.aidl +++ b/core/java/com/android/internal/app/IBatteryStats.aidl @@ -83,6 +83,7 @@ interface IBatteryStats { void noteScreenState(int state); void noteScreenBrightness(int brightness); void noteUserActivity(int uid, int event); + void noteWakeUp(String reason, int reasonUid); void noteInteractive(boolean interactive); void noteConnectivityChanged(int type, String extra); void noteMobileRadioPowerState(int powerState, long timestampNs); diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java index ae2cbad..60f47d6 100644 --- a/core/java/com/android/internal/os/BatteryStatsImpl.java +++ b/core/java/com/android/internal/os/BatteryStatsImpl.java @@ -3122,6 +3122,13 @@ public final class BatteryStatsImpl extends BatteryStats { } } + public void noteWakeUpLocked(String reason, int reasonUid) { + final long elapsedRealtime = SystemClock.elapsedRealtime(); + final long uptime = SystemClock.uptimeMillis(); + addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SCREEN_WAKE_UP, + reason, reasonUid); + } + public void noteInteractiveLocked(boolean interactive) { if (mInteractive != interactive) { final long elapsedRealtime = SystemClock.elapsedRealtime(); -- cgit v1.1