summaryrefslogtreecommitdiffstats
path: root/services/usage
diff options
context:
space:
mode:
authorXiaohui Chen <xiaohuic@google.com>2015-06-19 12:44:59 -0700
committerXiaohui Chen <xiaohuic@google.com>2015-06-22 15:35:19 -0700
commit8dca36dc8a5d17315775ce216689addc5bd9be00 (patch)
tree020e812cedd03afe06a6c783465ec85356c26b86 /services/usage
parent20fab81a09e1ca04e811c6c6d94acb08037739e7 (diff)
downloadframeworks_base-8dca36dc8a5d17315775ce216689addc5bd9be00.zip
frameworks_base-8dca36dc8a5d17315775ce216689addc5bd9be00.tar.gz
frameworks_base-8dca36dc8a5d17315775ce216689addc5bd9be00.tar.bz2
system_server: optimize app idle parole state change
Currently when app idle parole state changes, all idle apps' states are updated one by one including firewall modifications which are very expensive. This optimization gets rid of individual firewall rule changes and makes sure we only modify the firewall once at child chain level. BUG: 21446713 Change-Id: Iafc415fe0bc127826fe17894d4fedcf1755cb17d
Diffstat (limited to 'services/usage')
-rw-r--r--services/usage/java/com/android/server/usage/UsageStatsService.java42
1 files changed, 33 insertions, 9 deletions
diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java
index 490236e..c49a5f9 100644
--- a/services/usage/java/com/android/server/usage/UsageStatsService.java
+++ b/services/usage/java/com/android/server/usage/UsageStatsService.java
@@ -119,6 +119,7 @@ public class UsageStatsService extends SystemService implements
static final int MSG_CHECK_PAROLE_TIMEOUT = 6;
static final int MSG_PAROLE_END_TIMEOUT = 7;
static final int MSG_REPORT_CONTENT_PROVIDER_USAGE = 8;
+ static final int MSG_PAROLE_STATE_CHANGED = 9;
private final Object mLock = new Object();
Handler mHandler;
@@ -313,7 +314,7 @@ public class UsageStatsService extends SystemService implements
mLastAppIdleParoledTime = checkAndGetTimeLocked();
postNextParoleTimeout();
}
- postCheckIdleStates(UserHandle.USER_ALL);
+ postParoleStateChanged();
}
}
}
@@ -338,6 +339,12 @@ public class UsageStatsService extends SystemService implements
mHandler.sendEmptyMessageDelayed(MSG_PAROLE_END_TIMEOUT, mAppIdleParoleDurationMillis);
}
+ private void postParoleStateChanged() {
+ if (DEBUG) Slog.d(TAG, "Posting MSG_PAROLE_STATE_CHANGED");
+ mHandler.removeMessages(MSG_PAROLE_STATE_CHANGED);
+ mHandler.sendEmptyMessage(MSG_PAROLE_STATE_CHANGED);
+ }
+
void postCheckIdleStates(int userId) {
mHandler.sendMessage(mHandler.obtainMessage(MSG_CHECK_IDLE_STATES, userId, 0));
}
@@ -756,6 +763,13 @@ public class UsageStatsService extends SystemService implements
}
}
+ boolean isAppIdleFilteredOrParoled(String packageName, int userId, long timeNow) {
+ if (mAppIdleParoled) {
+ return false;
+ }
+ return isAppIdleFiltered(packageName, userId, timeNow);
+ }
+
boolean isAppIdleFiltered(String packageName, int userId, long timeNow) {
final UserUsageStatsService userService;
final long screenOnTime;
@@ -782,13 +796,6 @@ public class UsageStatsService extends SystemService implements
if (!mAppIdleEnabled) {
return false;
}
- synchronized (mLock) {
- // Temporary exemption, probably due to device charging or occasional allowance to
- // be allowed to sync, etc.
- if (mAppIdleParoled) {
- return false;
- }
- }
if (packageName.equals("android")) return false;
try {
if (mDeviceIdleController.isPowerSaveWhitelistApp(packageName)) {
@@ -846,6 +853,12 @@ public class UsageStatsService extends SystemService implements
}
}
+ void informParoleStateChanged() {
+ for (AppIdleStateChangeListener listener : mPackageAccessListeners) {
+ listener.onParoleStateChanged(mAppIdleParoled);
+ }
+ }
+
private static boolean validRange(long currentTime, long beginTime, long endTime) {
return beginTime <= currentTime && beginTime < endTime;
}
@@ -975,6 +988,11 @@ public class UsageStatsService extends SystemService implements
args.recycle();
break;
+ case MSG_PAROLE_STATE_CHANGED:
+ if (DEBUG) Slog.d(TAG, "Parole state changed: " + mAppIdleParoled);
+ informParoleStateChanged();
+ break;
+
default:
super.handleMessage(msg);
break;
@@ -1126,7 +1144,7 @@ public class UsageStatsService extends SystemService implements
}
final long token = Binder.clearCallingIdentity();
try {
- return UsageStatsService.this.isAppIdleFiltered(packageName, userId, -1);
+ return UsageStatsService.this.isAppIdleFilteredOrParoled(packageName, userId, -1);
} finally {
Binder.restoreCallingIdentity(token);
}
@@ -1251,6 +1269,11 @@ public class UsageStatsService extends SystemService implements
}
@Override
+ public boolean isAppIdleParoleOn() {
+ return mAppIdleParoled;
+ }
+
+ @Override
public void prepareShutdown() {
// This method *WILL* do IO work, but we must block until it is finished or else
// we might not shutdown cleanly. This is ok to do with the 'am' lock held, because
@@ -1261,6 +1284,7 @@ public class UsageStatsService extends SystemService implements
@Override
public void addAppIdleStateChangeListener(AppIdleStateChangeListener listener) {
UsageStatsService.this.addListener(listener);
+ listener.onParoleStateChanged(isAppIdleParoleOn());
}
@Override