Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 280a64e7 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

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
parent 18709f9a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ public class PowerCommand extends Svc.Command {
                        if (val != 0) {
                            // if the request is not to set it to false, wake up the screen so that
                            // it can stay on as requested
                            pm.wakeUp(SystemClock.uptimeMillis());
                            pm.wakeUp(SystemClock.uptimeMillis(), "PowerCommand", null);
                        }
                        pm.setStayOnSetting(val);
                    }
+19 −9
Original line number Diff line number Diff line
@@ -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,
    };

    /**
+7 −3
Original line number Diff line number Diff line
@@ -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",
    };

    /**
+1 −1
Original line number Diff line number Diff line
@@ -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();
+11 −1
Original line number Diff line number Diff line
@@ -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) {
        }
    }
Loading