diff options
author | Matthew Williams <mjwilliams@google.com> | 2014-08-22 21:07:57 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-08-22 21:08:06 +0000 |
commit | 12eec2341db422ad5792e674a0b820da68b75f64 (patch) | |
tree | 3e3f743f347861cd00956e6604afdde331a1a7ab /services | |
parent | d9a218d499c47399ee185faa0eeca45eed1ca1a4 (diff) | |
parent | 9ae3dbeefcd6bc139c74bfe3d51de823e3be4b4b (diff) | |
download | frameworks_base-12eec2341db422ad5792e674a0b820da68b75f64.zip frameworks_base-12eec2341db422ad5792e674a0b820da68b75f64.tar.gz frameworks_base-12eec2341db422ad5792e674a0b820da68b75f64.tar.bz2 |
Merge "JobScheduler only run jobs for started users." into lmp-dev
Diffstat (limited to 'services')
-rw-r--r-- | services/core/java/com/android/server/job/JobSchedulerService.java | 32 | ||||
-rw-r--r-- | services/core/java/com/android/server/job/controllers/JobStatus.java | 31 |
2 files changed, 61 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/job/JobSchedulerService.java b/services/core/java/com/android/server/job/JobSchedulerService.java index 6771cce..60f880c 100644 --- a/services/core/java/com/android/server/job/JobSchedulerService.java +++ b/services/core/java/com/android/server/job/JobSchedulerService.java @@ -117,6 +117,8 @@ public class JobSchedulerService extends com.android.server.SystemService */ final ArrayList<JobStatus> mPendingJobs = new ArrayList<JobStatus>(); + final ArrayList<Integer> mStartedUsers = new ArrayList(); + final JobHandler mHandler; final JobSchedulerStub mJobSchedulerStub; @@ -151,6 +153,18 @@ public class JobSchedulerService extends com.android.server.SystemService } }; + @Override + public void onStartUser(int userHandle) { + mStartedUsers.add(userHandle); + // Let's kick any outstanding jobs for this user. + mHandler.obtainMessage(MSG_CHECK_JOB).sendToTarget(); + } + + @Override + public void onStopUser(int userHandle) { + mStartedUsers.remove(Integer.valueOf(userHandle)); + } + /** * Entry point from client to schedule the provided job. * This cancels the job if it's already been scheduled, and replaces it with the one provided. @@ -610,9 +624,20 @@ public class JobSchedulerService extends com.android.server.SystemService * - It's ready. * - It's not pending. * - It's not already running on a JSC. + * - The user that requested the job is running. */ private boolean isReadyToBeExecutedLocked(JobStatus job) { - return job.isReady() && !mPendingJobs.contains(job) && !isCurrentlyActiveLocked(job); + final boolean jobReady = job.isReady(); + final boolean jobPending = mPendingJobs.contains(job); + final boolean jobActive = isCurrentlyActiveLocked(job); + final boolean userRunning = mStartedUsers.contains(job.getUserId()); + + if (DEBUG) { + Slog.v(TAG, "isReadyToBeExecutedLocked: " + job.toShortString() + + " ready=" + jobReady + " pending=" + jobPending + + " active=" + jobActive + " userRunning=" + userRunning); + } + return userRunning && jobReady && !jobPending && !jobActive; } /** @@ -795,6 +820,11 @@ public class JobSchedulerService extends com.android.server.SystemService void dumpInternal(PrintWriter pw) { synchronized (mJobs) { + pw.print("Started users: "); + for (int i=0; i<mStartedUsers.size(); i++) { + pw.print("u" + mStartedUsers.get(i) + " "); + } + pw.println(); pw.println("Registered jobs:"); if (mJobs.size() > 0) { ArraySet<JobStatus> jobs = mJobs.getJobs(); diff --git a/services/core/java/com/android/server/job/controllers/JobStatus.java b/services/core/java/com/android/server/job/controllers/JobStatus.java index 652d8f8..a257ea0 100644 --- a/services/core/java/com/android/server/job/controllers/JobStatus.java +++ b/services/core/java/com/android/server/job/controllers/JobStatus.java @@ -21,6 +21,7 @@ import android.content.ComponentName; import android.os.PersistableBundle; import android.os.SystemClock; import android.os.UserHandle; +import android.text.format.DateUtils; import java.io.PrintWriter; import java.util.concurrent.atomic.AtomicBoolean; @@ -41,6 +42,7 @@ public class JobStatus { public static final long NO_EARLIEST_RUNTIME = 0L; final JobInfo job; + /** Uid of the package requesting this job. */ final int uId; final String name; final String tag; @@ -214,12 +216,39 @@ public class JobStatus { return String.valueOf(hashCode()).substring(0, 3) + ".." + ":[" + job.getService() + ",jId=" + job.getId() - + ",R=(" + earliestRunTimeElapsedMillis + "," + latestRunTimeElapsedMillis + ")" + + ",u" + getUserId() + + ",R=(" + formatRunTime(earliestRunTimeElapsedMillis, NO_EARLIEST_RUNTIME) + + "," + formatRunTime(latestRunTimeElapsedMillis, NO_LATEST_RUNTIME) + ")" + ",N=" + job.getNetworkCapabilities() + ",C=" + job.isRequireCharging() + ",I=" + job.isRequireDeviceIdle() + ",F=" + numFailures + + ",P=" + job.isPersisted() + (isReady() ? "(READY)" : "") + "]"; } + + private String formatRunTime(long runtime, long defaultValue) { + if (runtime == defaultValue) { + return "none"; + } else { + long elapsedNow = SystemClock.elapsedRealtime(); + long nextRuntime = runtime - elapsedNow; + if (nextRuntime > 0) { + return DateUtils.formatElapsedTime(nextRuntime / 1000); + } else { + return "-" + DateUtils.formatElapsedTime(nextRuntime / -1000); + } + } + } + + /** + * Convenience function to identify a job uniquely without pulling all the data that + * {@link #toString()} returns. + */ + public String toShortString() { + return job.getService().flattenToShortString() + " jId=" + job.getId() + + ", u" + getUserId(); + } + // Dumpsys infrastructure public void dump(PrintWriter pw, String prefix) { pw.println(this.toString()); |