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

Commit ccbf4e42 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android (Google) Code Review
Browse files

Merge "Initial implementation of light-weight idle mode."

parents e8301dda 08c47a5d
Loading
Loading
Loading
Loading
+99 −30
Original line number Diff line number Diff line
@@ -169,7 +169,7 @@ public abstract class BatteryStats implements Parcelable {
    /**
     * Current version of checkin data format.
     */
    static final String CHECKIN_VERSION = "15";
    static final String CHECKIN_VERSION = "16";

    /**
     * Old version, we hit 9 and ran out of room, need to remove.
@@ -468,8 +468,8 @@ public abstract class BatteryStats implements Parcelable {
         * @param cluster the index of the CPU cluster.
         * @param step the index of the CPU speed. This is not the actual speed of the CPU.
         * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
         * @see PowerProfile.getNumCpuClusters()
         * @see PowerProfile.getNumSpeedStepsInCpuCluster(int)
         * @see com.android.internal.os.PowerProfile#getNumCpuClusters()
         * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int)
         */
        public abstract long getTimeAtCpuSpeed(int cluster, int step, int which);

@@ -1135,14 +1135,15 @@ public abstract class BatteryStats implements Parcelable {
        public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
        public static final int STATE2_WIFI_ON_FLAG = 1<<28;
        public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
        public static final int STATE2_DEVICE_IDLE_FLAG = 1<<26;
        public static final int STATE2_CHARGING_FLAG = 1<<25;
        public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<24;
        public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<23;
        public static final int STATE2_CAMERA_FLAG = 1<<22;
        public static final int STATE2_DEVICE_IDLE_SHIFT = 25;
        public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT;
        public static final int STATE2_CHARGING_FLAG = 1<<24;
        public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23;
        public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
        public static final int STATE2_CAMERA_FLAG = 1<<21;

        public static final int MOST_INTERESTING_STATES2 =
            STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_FLAG
            STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
            | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;

        public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
@@ -1619,37 +1620,58 @@ public abstract class BatteryStats implements Parcelable {
     */
    public abstract int getPowerSaveModeEnabledCount(int which);

    /**
     * Constant for device idle mode: not active.
     */
    public static final int DEVICE_IDLE_MODE_OFF = 0;

    /**
     * Constant for device idle mode: active in lightweight mode.
     */
    public static final int DEVICE_IDLE_MODE_LIGHT = 1;

    /**
     * Constant for device idle mode: active in full mode.
     */
    public static final int DEVICE_IDLE_MODE_FULL = 2;

    /**
     * Returns the time in microseconds that device has been in idle mode while
     * running on battery.
     *
     * {@hide}
     */
    public abstract long getDeviceIdleModeEnabledTime(long elapsedRealtimeUs, int which);
    public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which);

    /**
     * Returns the number of times that the devie has gone in to idle mode.
     *
     * {@hide}
     */
    public abstract int getDeviceIdleModeEnabledCount(int which);
    public abstract int getDeviceIdleModeCount(int mode, int which);

    /**
     * Return the longest duration we spent in a particular device idle mode (fully in the
     * mode, not in idle maintenance etc).
     */
    public abstract long getLongestDeviceIdleModeTime(int mode);

    /**
     * Returns the time in microseconds that device has been in idling while on
     * battery.  This is broader than {@link #getDeviceIdleModeEnabledTime} -- it
     * battery.  This is broader than {@link #getDeviceIdleModeTime} -- it
     * counts all of the time that we consider the device to be idle, whether or not
     * it is currently in the actual device idle mode.
     *
     * {@hide}
     */
    public abstract long getDeviceIdlingTime(long elapsedRealtimeUs, int which);
    public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which);

    /**
     * Returns the number of times that the devie has started idling.
     *
     * {@hide}
     */
    public abstract int getDeviceIdlingCount(int which);
    public abstract int getDeviceIdlingCount(int mode, int which);

    /**
     * Returns the number of times that connectivity state changed.
@@ -1847,7 +1869,10 @@ public abstract class BatteryStats implements Parcelable {
        new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
        new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
        new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
        new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_FLAG, "device_idle", "di"),
        new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK,
                HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di",
                new String[] { "off", "light", "full", "???" },
                new String[] { "off", "light", "full", "???" }),
        new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
        new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
        new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
@@ -2529,8 +2554,14 @@ public abstract class BatteryStats implements Parcelable {
        final long screenOnTime = getScreenOnTime(rawRealtime, which);
        final long interactiveTime = getInteractiveTime(rawRealtime, which);
        final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
        final long deviceIdleModeEnabledTime = getDeviceIdleModeEnabledTime(rawRealtime, which);
        final long deviceIdlingTime = getDeviceIdlingTime(rawRealtime, which);
        final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
                rawRealtime, which);
        final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_FULL,
                rawRealtime, which);
        final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
                rawRealtime, which);
        final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_FULL,
                rawRealtime, which);
        final int connChanges = getNumConnectivityChange(which);
        final long phoneOnTime = getPhoneOnTime(rawRealtime, which);

@@ -2613,11 +2644,15 @@ public abstract class BatteryStats implements Parcelable {
                fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
                getMobileRadioActiveTime(rawRealtime, which) / 1000,
                getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
                powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeEnabledTime / 1000,
                getDeviceIdleModeEnabledCount(which), deviceIdlingTime / 1000,
                getDeviceIdlingCount(which),
                powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000,
                getDeviceIdleModeCount(DEVICE_IDLE_MODE_FULL, which), deviceIdlingTime / 1000,
                getDeviceIdlingCount(DEVICE_IDLE_MODE_FULL, which),
                getMobileRadioActiveCount(which),
                getMobileRadioActiveUnknownTime(which) / 1000);
                getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000,
                getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000,
                getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which),
                getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT),
                getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_FULL));
        
        // Dump screen brightness stats
        Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
@@ -3082,8 +3117,14 @@ public abstract class BatteryStats implements Parcelable {
        final long screenOnTime = getScreenOnTime(rawRealtime, which);
        final long interactiveTime = getInteractiveTime(rawRealtime, which);
        final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
        final long deviceIdleModeEnabledTime = getDeviceIdleModeEnabledTime(rawRealtime, which);
        final long deviceIdlingTime = getDeviceIdlingTime(rawRealtime, which);
        final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
                rawRealtime, which);
        final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_FULL,
                rawRealtime, which);
        final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
                rawRealtime, which);
        final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_FULL,
                rawRealtime, which);
        final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
        final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
        final long wifiOnTime = getWifiOnTime(rawRealtime, which);
@@ -3127,26 +3168,54 @@ public abstract class BatteryStats implements Parcelable {
                    sb.append(")");
            pw.println(sb.toString());
        }
        if (deviceLightIdlingTime != 0) {
            sb.setLength(0);
            sb.append(prefix);
                    sb.append("  Device light idling: ");
                    formatTimeMs(sb, deviceLightIdlingTime / 1000);
                    sb.append("(");
                    sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime));
                    sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
                    sb.append("x");
            pw.println(sb.toString());
        }
        if (deviceIdleModeLightTime != 0) {
            sb.setLength(0);
            sb.append(prefix);
                    sb.append("  Idle mode light time: ");
                    formatTimeMs(sb, deviceIdleModeLightTime / 1000);
                    sb.append("(");
                    sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime));
                    sb.append(") ");
                    sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
                    sb.append("x");
                    sb.append(" -- longest ");
                    formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
            pw.println(sb.toString());
        }
        if (deviceIdlingTime != 0) {
            sb.setLength(0);
            sb.append(prefix);
                    sb.append("  Device idling: ");
                    sb.append("  Device full idling: ");
                    formatTimeMs(sb, deviceIdlingTime / 1000);
                    sb.append("(");
                    sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
                    sb.append(") "); sb.append(getDeviceIdlingCount(which));
                    sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_FULL, which));
                    sb.append("x");
            pw.println(sb.toString());
        }
        if (deviceIdleModeEnabledTime != 0) {
        if (deviceIdleModeFullTime != 0) {
            sb.setLength(0);
            sb.append(prefix);
                    sb.append("  Idle mode time: ");
                    formatTimeMs(sb, deviceIdleModeEnabledTime / 1000);
                    sb.append("  Idle mode full time: ");
                    formatTimeMs(sb, deviceIdleModeFullTime / 1000);
                    sb.append("(");
                    sb.append(formatRatioLocked(deviceIdleModeEnabledTime, whichBatteryRealtime));
                    sb.append(") "); sb.append(getDeviceIdleModeEnabledCount(which));
                    sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime));
                    sb.append(") ");
                    sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_FULL, which));
                    sb.append("x");
                    sb.append(" -- longest ");
                    formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_FULL));
            pw.println(sb.toString());
        }
        if (phoneOnTime != 0) {
+1 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ interface IPowerManager
    boolean isPowerSaveMode();
    boolean setPowerSaveMode(boolean mode);
    boolean isDeviceIdleMode();
    boolean isLightDeviceIdleMode();

    void reboot(boolean confirm, String reason, boolean wait);
    void shutdown(boolean confirm, String reason, boolean wait);
+29 −0
Original line number Diff line number Diff line
@@ -909,6 +909,26 @@ public final class PowerManager {
        }
    }

    /**
     * Returns true if the device is currently in light idle mode.  This happens when a device
     * has had its screen off for a short time, switching it into a batching mode where we
     * execute jobs, syncs, networking on a batching schedule.  You can monitor for changes to
     * this state with {@link #ACTION_LIGHT_DEVICE_IDLE_MODE_CHANGED}.
     *
     * @return Returns true if currently in active light device idle mode, else false.  This is
     * when light idle mode restrictions are being actively applied; it will return false if the
     * device is in a long-term idle mode but currently running a maintenance window where
     * restrictions have been lifted.
     * @hide
     */
    public boolean isLightDeviceIdleMode() {
        try {
            return mService.isLightDeviceIdleMode();
        } catch (RemoteException e) {
            return false;
        }
    }

    /**
     * Return whether the given application package name is on the device's power whitelist.
     * Apps can be placed on the whitelist through the settings UI invoked by
@@ -960,6 +980,15 @@ public final class PowerManager {
    public static final String ACTION_DEVICE_IDLE_MODE_CHANGED
            = "android.os.action.DEVICE_IDLE_MODE_CHANGED";

    /**
     * Intent that is broadcast when the state of {@link #isLightDeviceIdleMode()} changes.
     * This broadcast is only sent to registered receivers.
     * @hide
     */
    @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_LIGHT_DEVICE_IDLE_MODE_CHANGED
            = "android.os.action.LIGHT_DEVICE_IDLE_MODE_CHANGED";

    /**
     * @hide Intent that is broadcast when the set of power save whitelist apps has changed.
     * This broadcast is only sent to registered receivers.
+3 −1
Original line number Diff line number Diff line
@@ -148,7 +148,9 @@ public abstract class PowerManagerInternal {
        public void onLowPowerModeChanged(boolean enabled);
    }

    public abstract void setDeviceIdleMode(boolean enabled);
    public abstract boolean setDeviceIdleMode(boolean enabled);

    public abstract boolean setLightDeviceIdleMode(boolean enabled);

    public abstract void setDeviceIdleWhitelist(int[] appids);

+1 −1
Original line number Diff line number Diff line
@@ -117,7 +117,7 @@ interface IBatteryStats {
    void noteWifiRadioPowerState(int powerState, long timestampNs);
    void noteNetworkInterfaceType(String iface, int type);
    void noteNetworkStatsEnabled();
    void noteDeviceIdleMode(boolean enabled, String activeReason, int activeUid);
    void noteDeviceIdleMode(int mode, String activeReason, int activeUid);
    void setBatteryState(int status, int health, int plugType, int level, int temp, int volt);
    long getAwakeTimeBattery();
    long getAwakeTimePlugged();
Loading