static final int MSG_CHECK_JOB = 1;
static final int MSG_STOP_JOB = 2;
static final int MSG_CHECK_JOB_GREEDY = 3;
+ static final int MSG_UID_STATE_CHANGED = 4;
+ static final int MSG_UID_GONE = 5;
+ static final int MSG_UID_ACTIVE = 6;
+ static final int MSG_UID_IDLE = 7;
/**
* Track Services that have currently active or pending jobs. The index is provided by
final private IUidObserver mUidObserver = new IUidObserver.Stub() {
@Override public void onUidStateChanged(int uid, int procState, long procStateSeq) {
- updateUidState(uid, procState);
+ mHandler.obtainMessage(MSG_UID_STATE_CHANGED, uid, procState).sendToTarget();
}
@Override public void onUidGone(int uid, boolean disabled) {
- updateUidState(uid, ActivityManager.PROCESS_STATE_CACHED_EMPTY);
- if (disabled) {
- cancelJobsForUid(uid, "uid gone");
- }
- synchronized (mLock) {
- mDeviceIdleJobsController.setUidActiveLocked(uid, false);
- }
+ mHandler.obtainMessage(MSG_UID_GONE, uid, disabled ? 1 : 0).sendToTarget();
}
@Override public void onUidActive(int uid) throws RemoteException {
- synchronized (mLock) {
- mDeviceIdleJobsController.setUidActiveLocked(uid, true);
- }
+ mHandler.obtainMessage(MSG_UID_ACTIVE, uid, 0).sendToTarget();
}
@Override public void onUidIdle(int uid, boolean disabled) {
- if (disabled) {
- cancelJobsForUid(uid, "app uid idle");
- }
- synchronized (mLock) {
- mDeviceIdleJobsController.setUidActiveLocked(uid, false);
- }
+ mHandler.obtainMessage(MSG_UID_IDLE, uid, disabled ? 1 : 0).sendToTarget();
}
@Override public void onUidCachedChanged(int uid, boolean cached) {
cancelJobImplLocked((JobStatus) message.obj, null,
"app no longer allowed to run");
break;
+
+ case MSG_UID_STATE_CHANGED: {
+ final int uid = message.arg1;
+ final int procState = message.arg2;
+ updateUidState(uid, procState);
+ break;
+ }
+ case MSG_UID_GONE: {
+ final int uid = message.arg1;
+ final boolean disabled = message.arg2 != 0;
+ updateUidState(uid, ActivityManager.PROCESS_STATE_CACHED_EMPTY);
+ if (disabled) {
+ cancelJobsForUid(uid, "uid gone");
+ }
+ synchronized (mLock) {
+ mDeviceIdleJobsController.setUidActiveLocked(uid, false);
+ }
+ break;
+ }
+ case MSG_UID_ACTIVE: {
+ final int uid = message.arg1;
+ synchronized (mLock) {
+ mDeviceIdleJobsController.setUidActiveLocked(uid, true);
+ }
+ break;
+ }
+ case MSG_UID_IDLE: {
+ final int uid = message.arg1;
+ final boolean disabled = message.arg2 != 0;
+ if (disabled) {
+ cancelJobsForUid(uid, "app uid idle");
+ }
+ synchronized (mLock) {
+ mDeviceIdleJobsController.setUidActiveLocked(uid, false);
+ }
+ break;
+ }
+
}
maybeRunPendingJobsLocked();
// Don't remove JOB_EXPIRED in case one came along while processing the queue.
static final int MSG_REPORT_EVENT = 0;
static final int MSG_FLUSH_TO_DISK = 1;
static final int MSG_REMOVE_USER = 2;
+ static final int MSG_UID_STATE_CHANGED = 3;
private final Object mLock = new Object();
Handler mHandler;
private final IUidObserver mUidObserver = new IUidObserver.Stub() {
@Override
public void onUidStateChanged(int uid, int procState, long procStateSeq) {
- final int newCounter = (procState <= ActivityManager.PROCESS_STATE_TOP) ? 0 : 1;
- synchronized (mUidToKernelCounter) {
- final int oldCounter = mUidToKernelCounter.get(uid, 0);
- if (newCounter != oldCounter) {
- mUidToKernelCounter.put(uid, newCounter);
- try {
- FileUtils.stringToFile(KERNEL_COUNTER_FILE, uid + " " + newCounter);
- } catch (IOException e) {
- Slog.w(TAG, "Failed to update counter set: " + e);
- }
- }
- }
+ mHandler.obtainMessage(MSG_UID_STATE_CHANGED, uid, procState).sendToTarget();
}
@Override
onUserRemoved(msg.arg1);
break;
+ case MSG_UID_STATE_CHANGED: {
+ final int uid = msg.arg1;
+ final int procState = msg.arg2;
+
+ final int newCounter = (procState <= ActivityManager.PROCESS_STATE_TOP) ? 0 : 1;
+ synchronized (mUidToKernelCounter) {
+ final int oldCounter = mUidToKernelCounter.get(uid, 0);
+ if (newCounter != oldCounter) {
+ mUidToKernelCounter.put(uid, newCounter);
+ try {
+ FileUtils.stringToFile(KERNEL_COUNTER_FILE, uid + " " + newCounter);
+ } catch (IOException e) {
+ Slog.w(TAG, "Failed to update counter set: " + e);
+ }
+ }
+ }
+ break;
+ }
+
default:
super.handleMessage(msg);
break;