Loading services/usage/java/com/android/server/usage/UsageStatsService.java +35 −19 Original line number Diff line number Diff line Loading @@ -94,7 +94,7 @@ public class UsageStatsService extends SystemService implements static final String TAG = "UsageStatsService"; static final boolean DEBUG = false; static final boolean DEBUG = false; // Never submit with true static final boolean COMPRESS_TIME = false; private static final long TEN_SECONDS = 10 * 1000; Loading Loading @@ -139,8 +139,8 @@ public class UsageStatsService extends SystemService implements long mSystemTimeSnapshot; boolean mAppIdleEnabled; boolean mAppIdleParoled; private boolean mScreenOn; boolean mAppIdleTempParoled; boolean mCharging; private long mLastAppIdleParoledTime; private volatile boolean mPendingOneTimeCheckIdleStates; Loading Loading @@ -191,7 +191,7 @@ public class UsageStatsService extends SystemService implements mAppIdleEnabled = getContext().getResources().getBoolean( com.android.internal.R.bool.config_enableAutoPowerModes); if (mAppIdleEnabled) { IntentFilter deviceStates = new IntentFilter(BatteryManager.ACTION_CHARGING); IntentFilter deviceStates = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); deviceStates.addAction(BatteryManager.ACTION_DISCHARGING); deviceStates.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); getContext().registerReceiver(new DeviceStateReceiver(), deviceStates); Loading Loading @@ -237,7 +237,7 @@ public class UsageStatsService extends SystemService implements mSystemServicesReady = true; } else if (phase == PHASE_BOOT_COMPLETED) { setAppIdleParoled(getContext().getSystemService(BatteryManager.class).isCharging()); setChargingState(getContext().getSystemService(BatteryManager.class).isCharging()); } } Loading Loading @@ -284,9 +284,8 @@ public class UsageStatsService extends SystemService implements @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (BatteryManager.ACTION_CHARGING.equals(action) || BatteryManager.ACTION_DISCHARGING.equals(action)) { setAppIdleParoled(BatteryManager.ACTION_CHARGING.equals(action)); if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { setChargingState(intent.getIntExtra("plugged", 0) != 0); } else if (PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED.equals(action)) { onDeviceIdleModeChanged(); } Loading Loading @@ -376,12 +375,21 @@ public class UsageStatsService extends SystemService implements } } void setChargingState(boolean charging) { synchronized (mLock) { if (mCharging != charging) { mCharging = charging; postParoleStateChanged(); } } } /** Paroled here means temporary pardon from being inactive */ void setAppIdleParoled(boolean paroled) { synchronized (mLock) { if (mAppIdleParoled != paroled) { mAppIdleParoled = paroled; if (DEBUG) Slog.d(TAG, "Changing paroled to " + mAppIdleParoled); if (mAppIdleTempParoled != paroled) { mAppIdleTempParoled = paroled; if (DEBUG) Slog.d(TAG, "Changing paroled to " + mAppIdleTempParoled); if (paroled) { postParoleEndTimeout(); } else { Loading @@ -393,6 +401,12 @@ public class UsageStatsService extends SystemService implements } } boolean isParoledOrCharging() { synchronized (mLock) { return mAppIdleTempParoled || mCharging; } } private void postNextParoleTimeout() { if (DEBUG) Slog.d(TAG, "Posting MSG_CHECK_PAROLE_TIMEOUT"); mHandler.removeMessages(MSG_CHECK_PAROLE_TIMEOUT); Loading Loading @@ -495,7 +509,7 @@ public class UsageStatsService extends SystemService implements /** Check if it's been a while since last parole and let idle apps do some work */ void checkParoleTimeout() { synchronized (mLock) { if (!mAppIdleParoled) { if (!mAppIdleTempParoled) { final long timeSinceLastParole = checkAndGetTimeLocked() - mLastAppIdleParoledTime; if (timeSinceLastParole > mAppIdleParoleIntervalMillis) { if (DEBUG) Slog.d(TAG, "Crossed default parole interval"); Loading Loading @@ -786,7 +800,7 @@ public class UsageStatsService extends SystemService implements } boolean isAppIdleFilteredOrParoled(String packageName, int userId, long elapsedRealtime) { if (mAppIdleParoled) { if (isParoledOrCharging()) { return false; } return isAppIdleFiltered(packageName, getAppId(packageName), userId, elapsedRealtime); Loading Loading @@ -989,8 +1003,9 @@ public class UsageStatsService extends SystemService implements } void informParoleStateChanged() { final boolean paroled = isParoledOrCharging(); for (AppIdleStateChangeListener listener : mPackageAccessListeners) { listener.onParoleStateChanged(mAppIdleParoled); listener.onParoleStateChanged(paroled); } } Loading Loading @@ -1072,8 +1087,8 @@ public class UsageStatsService extends SystemService implements pw.println(); pw.print("mAppIdleEnabled="); pw.print(mAppIdleEnabled); pw.print(" mAppIdleParoled="); pw.print(mAppIdleParoled); pw.print(" mScreenOn="); pw.println(mScreenOn); pw.print(" mAppIdleTempParoled="); pw.print(mAppIdleTempParoled); pw.print(" mCharging="); pw.print(mCharging); pw.print(" mLastAppIdleParoledTime="); TimeUtils.formatDuration(mLastAppIdleParoledTime, pw); pw.println(); Loading Loading @@ -1139,7 +1154,8 @@ public class UsageStatsService extends SystemService implements break; case MSG_PAROLE_STATE_CHANGED: if (DEBUG) Slog.d(TAG, "Parole state changed: " + mAppIdleParoled); if (DEBUG) Slog.d(TAG, "Parole state: " + mAppIdleTempParoled + ", Charging state:" + mCharging); informParoleStateChanged(); break; Loading Loading @@ -1466,7 +1482,7 @@ public class UsageStatsService extends SystemService implements @Override public boolean isAppIdleParoleOn() { return mAppIdleParoled; return isParoledOrCharging(); } @Override Loading Loading
services/usage/java/com/android/server/usage/UsageStatsService.java +35 −19 Original line number Diff line number Diff line Loading @@ -94,7 +94,7 @@ public class UsageStatsService extends SystemService implements static final String TAG = "UsageStatsService"; static final boolean DEBUG = false; static final boolean DEBUG = false; // Never submit with true static final boolean COMPRESS_TIME = false; private static final long TEN_SECONDS = 10 * 1000; Loading Loading @@ -139,8 +139,8 @@ public class UsageStatsService extends SystemService implements long mSystemTimeSnapshot; boolean mAppIdleEnabled; boolean mAppIdleParoled; private boolean mScreenOn; boolean mAppIdleTempParoled; boolean mCharging; private long mLastAppIdleParoledTime; private volatile boolean mPendingOneTimeCheckIdleStates; Loading Loading @@ -191,7 +191,7 @@ public class UsageStatsService extends SystemService implements mAppIdleEnabled = getContext().getResources().getBoolean( com.android.internal.R.bool.config_enableAutoPowerModes); if (mAppIdleEnabled) { IntentFilter deviceStates = new IntentFilter(BatteryManager.ACTION_CHARGING); IntentFilter deviceStates = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); deviceStates.addAction(BatteryManager.ACTION_DISCHARGING); deviceStates.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); getContext().registerReceiver(new DeviceStateReceiver(), deviceStates); Loading Loading @@ -237,7 +237,7 @@ public class UsageStatsService extends SystemService implements mSystemServicesReady = true; } else if (phase == PHASE_BOOT_COMPLETED) { setAppIdleParoled(getContext().getSystemService(BatteryManager.class).isCharging()); setChargingState(getContext().getSystemService(BatteryManager.class).isCharging()); } } Loading Loading @@ -284,9 +284,8 @@ public class UsageStatsService extends SystemService implements @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (BatteryManager.ACTION_CHARGING.equals(action) || BatteryManager.ACTION_DISCHARGING.equals(action)) { setAppIdleParoled(BatteryManager.ACTION_CHARGING.equals(action)); if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { setChargingState(intent.getIntExtra("plugged", 0) != 0); } else if (PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED.equals(action)) { onDeviceIdleModeChanged(); } Loading Loading @@ -376,12 +375,21 @@ public class UsageStatsService extends SystemService implements } } void setChargingState(boolean charging) { synchronized (mLock) { if (mCharging != charging) { mCharging = charging; postParoleStateChanged(); } } } /** Paroled here means temporary pardon from being inactive */ void setAppIdleParoled(boolean paroled) { synchronized (mLock) { if (mAppIdleParoled != paroled) { mAppIdleParoled = paroled; if (DEBUG) Slog.d(TAG, "Changing paroled to " + mAppIdleParoled); if (mAppIdleTempParoled != paroled) { mAppIdleTempParoled = paroled; if (DEBUG) Slog.d(TAG, "Changing paroled to " + mAppIdleTempParoled); if (paroled) { postParoleEndTimeout(); } else { Loading @@ -393,6 +401,12 @@ public class UsageStatsService extends SystemService implements } } boolean isParoledOrCharging() { synchronized (mLock) { return mAppIdleTempParoled || mCharging; } } private void postNextParoleTimeout() { if (DEBUG) Slog.d(TAG, "Posting MSG_CHECK_PAROLE_TIMEOUT"); mHandler.removeMessages(MSG_CHECK_PAROLE_TIMEOUT); Loading Loading @@ -495,7 +509,7 @@ public class UsageStatsService extends SystemService implements /** Check if it's been a while since last parole and let idle apps do some work */ void checkParoleTimeout() { synchronized (mLock) { if (!mAppIdleParoled) { if (!mAppIdleTempParoled) { final long timeSinceLastParole = checkAndGetTimeLocked() - mLastAppIdleParoledTime; if (timeSinceLastParole > mAppIdleParoleIntervalMillis) { if (DEBUG) Slog.d(TAG, "Crossed default parole interval"); Loading Loading @@ -786,7 +800,7 @@ public class UsageStatsService extends SystemService implements } boolean isAppIdleFilteredOrParoled(String packageName, int userId, long elapsedRealtime) { if (mAppIdleParoled) { if (isParoledOrCharging()) { return false; } return isAppIdleFiltered(packageName, getAppId(packageName), userId, elapsedRealtime); Loading Loading @@ -989,8 +1003,9 @@ public class UsageStatsService extends SystemService implements } void informParoleStateChanged() { final boolean paroled = isParoledOrCharging(); for (AppIdleStateChangeListener listener : mPackageAccessListeners) { listener.onParoleStateChanged(mAppIdleParoled); listener.onParoleStateChanged(paroled); } } Loading Loading @@ -1072,8 +1087,8 @@ public class UsageStatsService extends SystemService implements pw.println(); pw.print("mAppIdleEnabled="); pw.print(mAppIdleEnabled); pw.print(" mAppIdleParoled="); pw.print(mAppIdleParoled); pw.print(" mScreenOn="); pw.println(mScreenOn); pw.print(" mAppIdleTempParoled="); pw.print(mAppIdleTempParoled); pw.print(" mCharging="); pw.print(mCharging); pw.print(" mLastAppIdleParoledTime="); TimeUtils.formatDuration(mLastAppIdleParoledTime, pw); pw.println(); Loading Loading @@ -1139,7 +1154,8 @@ public class UsageStatsService extends SystemService implements break; case MSG_PAROLE_STATE_CHANGED: if (DEBUG) Slog.d(TAG, "Parole state changed: " + mAppIdleParoled); if (DEBUG) Slog.d(TAG, "Parole state: " + mAppIdleTempParoled + ", Charging state:" + mCharging); informParoleStateChanged(); break; Loading Loading @@ -1466,7 +1482,7 @@ public class UsageStatsService extends SystemService implements @Override public boolean isAppIdleParoleOn() { return mAppIdleParoled; return isParoledOrCharging(); } @Override Loading