Merge "Trace Doze states." into tm-qpr-dev

This commit is contained in:
Simon MacMullen
2022-07-29 09:19:25 +00:00
committed by Android (Google) Code Review

View File

@@ -73,6 +73,7 @@ import android.os.ServiceManager;
import android.os.ShellCallback; import android.os.ShellCallback;
import android.os.ShellCommand; import android.os.ShellCommand;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.Trace;
import android.os.UserHandle; import android.os.UserHandle;
import android.provider.DeviceConfig; import android.provider.DeviceConfig;
import android.util.ArrayMap; import android.util.ArrayMap;
@@ -2329,8 +2330,8 @@ public class DeviceIdleController extends SystemService
// a battery update the next time the level drops. // a battery update the next time the level drops.
mCharging = true; mCharging = true;
mActiveReason = ACTIVE_REASON_UNKNOWN; mActiveReason = ACTIVE_REASON_UNKNOWN;
mState = STATE_ACTIVE; moveToStateLocked(STATE_ACTIVE, "boot");
mLightState = LIGHT_STATE_ACTIVE; moveToLightStateLocked(LIGHT_STATE_ACTIVE, "boot");
mInactiveTimeout = mConstants.INACTIVE_TIMEOUT; mInactiveTimeout = mConstants.INACTIVE_TIMEOUT;
mPreIdleFactor = 1.0f; mPreIdleFactor = 1.0f;
mLastPreIdleFactor = 1.0f; mLastPreIdleFactor = 1.0f;
@@ -3173,8 +3174,7 @@ public class DeviceIdleController extends SystemService
+ ", changeLightIdle=" + changeLightIdle); + ", changeLightIdle=" + changeLightIdle);
} }
if (mState != STATE_ACTIVE || mLightState != STATE_ACTIVE) { if (mState != STATE_ACTIVE || mLightState != STATE_ACTIVE) {
EventLogTags.writeDeviceIdle(STATE_ACTIVE, activeReason); moveToStateLocked(STATE_ACTIVE, activeReason);
mState = STATE_ACTIVE;
mInactiveTimeout = newInactiveTimeout; mInactiveTimeout = newInactiveTimeout;
resetIdleManagementLocked(); resetIdleManagementLocked();
// Don't reset maintenance window start time if we're in a light idle maintenance window // Don't reset maintenance window start time if we're in a light idle maintenance window
@@ -3184,8 +3184,7 @@ public class DeviceIdleController extends SystemService
} }
if (changeLightIdle) { if (changeLightIdle) {
EventLogTags.writeDeviceIdleLight(LIGHT_STATE_ACTIVE, activeReason); moveToLightStateLocked(LIGHT_STATE_ACTIVE, activeReason);
mLightState = LIGHT_STATE_ACTIVE;
resetLightIdleManagementLocked(); resetLightIdleManagementLocked();
// Only report active if light is also ACTIVE. // Only report active if light is also ACTIVE.
scheduleReportActiveLocked(activeReason, activeUid); scheduleReportActiveLocked(activeReason, activeUid);
@@ -3258,11 +3257,7 @@ public class DeviceIdleController extends SystemService
// values, so returning here is safe. // values, so returning here is safe.
return; return;
} }
if (DEBUG) { moveToStateLocked(STATE_QUICK_DOZE_DELAY, "no activity");
Slog.d(TAG, "Moved from "
+ stateToString(mState) + " to STATE_QUICK_DOZE_DELAY");
}
mState = STATE_QUICK_DOZE_DELAY;
// Make sure any motion sensing or locating is stopped. // Make sure any motion sensing or locating is stopped.
resetIdleManagementLocked(); resetIdleManagementLocked();
if (isUpcomingAlarmClock()) { if (isUpcomingAlarmClock()) {
@@ -3277,10 +3272,8 @@ public class DeviceIdleController extends SystemService
// recently closed app) needs to finish running. // recently closed app) needs to finish running.
scheduleAlarmLocked(mConstants.QUICK_DOZE_DELAY_TIMEOUT, false); scheduleAlarmLocked(mConstants.QUICK_DOZE_DELAY_TIMEOUT, false);
} }
EventLogTags.writeDeviceIdle(mState, "no activity");
} else if (mState == STATE_ACTIVE) { } else if (mState == STATE_ACTIVE) {
mState = STATE_INACTIVE; moveToStateLocked(STATE_INACTIVE, "no activity");
if (DEBUG) Slog.d(TAG, "Moved from STATE_ACTIVE to STATE_INACTIVE");
resetIdleManagementLocked(); resetIdleManagementLocked();
long delay = mInactiveTimeout; long delay = mInactiveTimeout;
if (shouldUseIdleTimeoutFactorLocked()) { if (shouldUseIdleTimeoutFactorLocked()) {
@@ -3296,12 +3289,10 @@ public class DeviceIdleController extends SystemService
} else { } else {
scheduleAlarmLocked(delay, false); scheduleAlarmLocked(delay, false);
} }
EventLogTags.writeDeviceIdle(mState, "no activity");
} }
} }
if (mLightState == LIGHT_STATE_ACTIVE && mLightEnabled) { if (mLightState == LIGHT_STATE_ACTIVE && mLightEnabled) {
mLightState = LIGHT_STATE_INACTIVE; moveToLightStateLocked(LIGHT_STATE_INACTIVE, "no activity");
if (DEBUG) Slog.d(TAG, "Moved from LIGHT_STATE_ACTIVE to LIGHT_STATE_INACTIVE");
resetLightIdleManagementLocked(); resetLightIdleManagementLocked();
scheduleLightAlarmLocked(mConstants.LIGHT_IDLE_AFTER_INACTIVE_TIMEOUT, scheduleLightAlarmLocked(mConstants.LIGHT_IDLE_AFTER_INACTIVE_TIMEOUT,
mConstants.FLEX_TIME_SHORT); mConstants.FLEX_TIME_SHORT);
@@ -3309,7 +3300,6 @@ public class DeviceIdleController extends SystemService
// timeout and a single light idle period. // timeout and a single light idle period.
scheduleLightMaintenanceAlarmLocked( scheduleLightMaintenanceAlarmLocked(
mConstants.LIGHT_IDLE_AFTER_INACTIVE_TIMEOUT + mConstants.LIGHT_IDLE_TIMEOUT); mConstants.LIGHT_IDLE_AFTER_INACTIVE_TIMEOUT + mConstants.LIGHT_IDLE_TIMEOUT);
EventLogTags.writeDeviceIdleLight(mLightState, "no activity");
} }
} }
@@ -3429,12 +3419,7 @@ public class DeviceIdleController extends SystemService
// time from now. // time from now.
scheduleLightAlarmLocked(mCurLightIdleBudget, mConstants.FLEX_TIME_SHORT); scheduleLightAlarmLocked(mCurLightIdleBudget, mConstants.FLEX_TIME_SHORT);
scheduleLightMaintenanceAlarmLocked(mCurLightIdleBudget + mNextLightIdleDelay); scheduleLightMaintenanceAlarmLocked(mCurLightIdleBudget + mNextLightIdleDelay);
if (DEBUG) { moveToLightStateLocked(LIGHT_STATE_IDLE_MAINTENANCE, reason);
Slog.d(TAG, "Moved from " + lightStateToString(mLightState)
+ " to LIGHT_STATE_IDLE_MAINTENANCE");
}
mLightState = LIGHT_STATE_IDLE_MAINTENANCE;
EventLogTags.writeDeviceIdleLight(mLightState, reason);
addEvent(EVENT_LIGHT_MAINTENANCE, null); addEvent(EVENT_LIGHT_MAINTENANCE, null);
mHandler.sendEmptyMessage(MSG_REPORT_IDLE_OFF); mHandler.sendEmptyMessage(MSG_REPORT_IDLE_OFF);
} else { } else {
@@ -3443,9 +3428,7 @@ public class DeviceIdleController extends SystemService
// We'll only wait for another full idle period, however, and then give up. // We'll only wait for another full idle period, however, and then give up.
scheduleLightMaintenanceAlarmLocked(mNextLightIdleDelay); scheduleLightMaintenanceAlarmLocked(mNextLightIdleDelay);
cancelLightAlarmLocked(); cancelLightAlarmLocked();
if (DEBUG) Slog.d(TAG, "Moved to LIGHT_WAITING_FOR_NETWORK."); moveToLightStateLocked(LIGHT_STATE_WAITING_FOR_NETWORK, reason);
mLightState = LIGHT_STATE_WAITING_FOR_NETWORK;
EventLogTags.writeDeviceIdleLight(mLightState, reason);
} }
} else { } else {
if (mMaintenanceStartTime != 0) { if (mMaintenanceStartTime != 0) {
@@ -3469,9 +3452,7 @@ public class DeviceIdleController extends SystemService
// maintenance window, so reschedule the alarm starting from now. // maintenance window, so reschedule the alarm starting from now.
scheduleLightMaintenanceAlarmLocked(mNextLightIdleDelay); scheduleLightMaintenanceAlarmLocked(mNextLightIdleDelay);
cancelLightAlarmLocked(); cancelLightAlarmLocked();
if (DEBUG) Slog.d(TAG, "Moved to LIGHT_STATE_IDLE."); moveToLightStateLocked(LIGHT_STATE_IDLE, reason);
mLightState = LIGHT_STATE_IDLE;
EventLogTags.writeDeviceIdleLight(mLightState, reason);
addEvent(EVENT_LIGHT_IDLE, null); addEvent(EVENT_LIGHT_IDLE, null);
mGoingIdleWakeLock.acquire(); mGoingIdleWakeLock.acquire();
mHandler.sendEmptyMessage(MSG_REPORT_IDLE_ON_LIGHT); mHandler.sendEmptyMessage(MSG_REPORT_IDLE_ON_LIGHT);
@@ -3535,12 +3516,11 @@ public class DeviceIdleController extends SystemService
moveToStateLocked(STATE_IDLE_PENDING, reason); moveToStateLocked(STATE_IDLE_PENDING, reason);
break; break;
case STATE_IDLE_PENDING: case STATE_IDLE_PENDING:
moveToStateLocked(STATE_SENSING, reason);
cancelLocatingLocked(); cancelLocatingLocked();
mLocated = false; mLocated = false;
mLastGenericLocation = null; mLastGenericLocation = null;
mLastGpsLocation = null; mLastGpsLocation = null;
updateActiveConstraintsLocked(); moveToStateLocked(STATE_SENSING, reason);
// Wait for open constraints and an accelerometer reading before moving on. // Wait for open constraints and an accelerometer reading before moving on.
if (mUseMotionSensor && mAnyMotionDetector.hasSensor()) { if (mUseMotionSensor && mAnyMotionDetector.hasSensor()) {
@@ -3609,7 +3589,7 @@ public class DeviceIdleController extends SystemService
} }
moveToStateLocked(STATE_IDLE, reason); moveToStateLocked(STATE_IDLE, reason);
if (mLightState != LIGHT_STATE_OVERRIDE) { if (mLightState != LIGHT_STATE_OVERRIDE) {
mLightState = LIGHT_STATE_OVERRIDE; moveToLightStateLocked(LIGHT_STATE_OVERRIDE, "deep");
cancelAllLightAlarmsLocked(); cancelAllLightAlarmsLocked();
} }
addEvent(EVENT_DEEP_IDLE, null); addEvent(EVENT_DEEP_IDLE, null);
@@ -3636,15 +3616,28 @@ public class DeviceIdleController extends SystemService
} }
} }
@GuardedBy("this")
private void moveToLightStateLocked(int state, String reason) {
if (DEBUG) {
Slog.d(TAG, String.format("Moved from LIGHT_STATE_%s to LIGHT_STATE_%s.",
lightStateToString(mLightState), lightStateToString(state)));
}
mLightState = state;
EventLogTags.writeDeviceIdleLight(mLightState, reason);
// This is currently how to set the current state in a trace.
Trace.traceCounter(Trace.TRACE_TAG_SYSTEM_SERVER, "DozeLightState", state);
}
@GuardedBy("this") @GuardedBy("this")
private void moveToStateLocked(int state, String reason) { private void moveToStateLocked(int state, String reason) {
final int oldState = mState;
mState = state;
if (DEBUG) { if (DEBUG) {
Slog.d(TAG, String.format("Moved from STATE_%s to STATE_%s.", Slog.d(TAG, String.format("Moved from STATE_%s to STATE_%s.",
stateToString(oldState), stateToString(mState))); stateToString(mState), stateToString(state)));
} }
mState = state;
EventLogTags.writeDeviceIdle(mState, reason); EventLogTags.writeDeviceIdle(mState, reason);
// This is currently how to set the current state in a trace.
Trace.traceCounter(Trace.TRACE_TAG_SYSTEM_SERVER, "DozeDeepState", state);
updateActiveConstraintsLocked(); updateActiveConstraintsLocked();
} }