Merge "Small JS code cleanup." into sc-dev
This commit is contained in:
@@ -25,6 +25,7 @@ import android.app.ActivityManager;
|
||||
import android.app.ActivityManagerInternal;
|
||||
import android.app.UserSwitchObserver;
|
||||
import android.app.job.JobInfo;
|
||||
import android.app.job.JobParameters;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -469,7 +470,7 @@ class JobConcurrencyManager {
|
||||
// Update the priorities of jobs that aren't running, and also count the pending work types.
|
||||
// Do this before the following loop to hopefully reduce the cost of
|
||||
// shouldStopRunningJobLocked().
|
||||
updateNonRunningPriorities(pendingJobs, true);
|
||||
updateNonRunningPrioritiesLocked(pendingJobs, true);
|
||||
|
||||
for (int i = 0; i < MAX_JOB_CONTEXTS_COUNT; i++) {
|
||||
final JobServiceContext js = activeServices.get(i);
|
||||
@@ -585,7 +586,8 @@ class JobConcurrencyManager {
|
||||
+ activeServices.get(i).getRunningJobLocked());
|
||||
}
|
||||
// preferredUid will be set to uid of currently running job.
|
||||
activeServices.get(i).preemptExecutingJobLocked(preemptReasonForContext[i]);
|
||||
activeServices.get(i).cancelExecutingJobLocked(
|
||||
JobParameters.REASON_PREEMPT, preemptReasonForContext[i]);
|
||||
preservePreferredUid = true;
|
||||
} else {
|
||||
final JobStatus pendingJob = contextIdToJobMap[i];
|
||||
@@ -610,7 +612,8 @@ class JobConcurrencyManager {
|
||||
mWorkCountTracker.getRunningJobCount(WORK_TYPE_TOP));
|
||||
}
|
||||
|
||||
private void updateNonRunningPriorities(@NonNull final List<JobStatus> pendingJobs,
|
||||
@GuardedBy("mLock")
|
||||
private void updateNonRunningPrioritiesLocked(@NonNull final List<JobStatus> pendingJobs,
|
||||
boolean updateCounter) {
|
||||
for (int i = 0; i < pendingJobs.size(); i++) {
|
||||
final JobStatus pending = pendingJobs.get(i);
|
||||
@@ -628,6 +631,7 @@ class JobConcurrencyManager {
|
||||
}
|
||||
}
|
||||
|
||||
@GuardedBy("mLock")
|
||||
private void startJobLocked(@NonNull JobServiceContext worker, @NonNull JobStatus jobStatus,
|
||||
@WorkType final int workType) {
|
||||
final List<StateController> controllers = mService.mControllers;
|
||||
@@ -647,6 +651,7 @@ class JobConcurrencyManager {
|
||||
}
|
||||
}
|
||||
|
||||
@GuardedBy("mLock")
|
||||
void onJobCompletedLocked(@NonNull JobServiceContext worker, @NonNull JobStatus jobStatus,
|
||||
@WorkType final int workType) {
|
||||
mWorkCountTracker.onJobFinished(workType);
|
||||
@@ -655,7 +660,7 @@ class JobConcurrencyManager {
|
||||
if (worker.getPreferredUid() != JobServiceContext.NO_PREFERRED_UID) {
|
||||
updateCounterConfigLocked();
|
||||
// Preemption case needs special care.
|
||||
updateNonRunningPriorities(pendingJobs, false);
|
||||
updateNonRunningPrioritiesLocked(pendingJobs, false);
|
||||
|
||||
JobStatus highestPriorityJob = null;
|
||||
int highPriWorkType = workType;
|
||||
@@ -726,7 +731,7 @@ class JobConcurrencyManager {
|
||||
}
|
||||
} else if (pendingJobs.size() > 0) {
|
||||
updateCounterConfigLocked();
|
||||
updateNonRunningPriorities(pendingJobs, false);
|
||||
updateNonRunningPrioritiesLocked(pendingJobs, false);
|
||||
|
||||
// This slot is now free and we have pending jobs. Start the highest priority job we
|
||||
// find.
|
||||
@@ -775,6 +780,7 @@ class JobConcurrencyManager {
|
||||
* another job to run, or if system state suggests the job should stop.
|
||||
*/
|
||||
@Nullable
|
||||
@GuardedBy("mLock")
|
||||
String shouldStopRunningJobLocked(@NonNull JobServiceContext context) {
|
||||
final JobStatus js = context.getRunningJobLocked();
|
||||
if (js == null) {
|
||||
@@ -881,6 +887,7 @@ class JobConcurrencyManager {
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
@GuardedBy("mLock")
|
||||
void updateConfigLocked() {
|
||||
DeviceConfig.Properties properties =
|
||||
DeviceConfig.getProperties(DeviceConfig.NAMESPACE_JOB_SCHEDULER);
|
||||
|
||||
@@ -269,8 +269,6 @@ public final class JobServiceContext implements ServiceConnection {
|
||||
try {
|
||||
final int bindFlags;
|
||||
if (job.shouldTreatAsExpeditedJob()) {
|
||||
// TODO(171305774): The job should run on the little cores. We'll probably need
|
||||
// another binding flag for that.
|
||||
bindFlags = Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND
|
||||
| Context.BIND_ALMOST_PERCEPTIBLE
|
||||
| Context.BIND_ALLOW_NETWORK_ACCESS
|
||||
@@ -355,15 +353,10 @@ public final class JobServiceContext implements ServiceConnection {
|
||||
|
||||
/** Called externally when a job that was scheduled for execution should be cancelled. */
|
||||
@GuardedBy("mLock")
|
||||
void cancelExecutingJobLocked(int reason, String debugReason) {
|
||||
void cancelExecutingJobLocked(int reason, @NonNull String debugReason) {
|
||||
doCancelLocked(reason, debugReason);
|
||||
}
|
||||
|
||||
@GuardedBy("mLock")
|
||||
void preemptExecutingJobLocked(@NonNull String reason) {
|
||||
doCancelLocked(JobParameters.REASON_PREEMPT, reason);
|
||||
}
|
||||
|
||||
int getPreferredUid() {
|
||||
return mPreferredUid;
|
||||
}
|
||||
@@ -620,7 +613,7 @@ public final class JobServiceContext implements ServiceConnection {
|
||||
}
|
||||
|
||||
@GuardedBy("mLock")
|
||||
private void doCancelLocked(int stopReasonCode, String debugReason) {
|
||||
private void doCancelLocked(int stopReasonCode, @Nullable String debugReason) {
|
||||
if (mVerb == VERB_FINISHED) {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG,
|
||||
@@ -733,7 +726,7 @@ public final class JobServiceContext implements ServiceConnection {
|
||||
* _ENDING -> No point in doing anything here, so we ignore.
|
||||
*/
|
||||
@GuardedBy("mLock")
|
||||
private void handleCancelLocked(String reason) {
|
||||
private void handleCancelLocked(@Nullable String reason) {
|
||||
if (JobSchedulerService.DEBUG) {
|
||||
Slog.d(TAG, "Handling cancel for: " + mRunningJob.getJobId() + " "
|
||||
+ VERB_STRINGS[mVerb]);
|
||||
@@ -817,7 +810,7 @@ public final class JobServiceContext implements ServiceConnection {
|
||||
* VERB_STOPPING.
|
||||
*/
|
||||
@GuardedBy("mLock")
|
||||
private void sendStopMessageLocked(String reason) {
|
||||
private void sendStopMessageLocked(@Nullable String reason) {
|
||||
removeOpTimeOutLocked();
|
||||
if (mVerb != VERB_EXECUTING) {
|
||||
Slog.e(TAG, "Sending onStopJob for a job that isn't started. " + mRunningJob);
|
||||
@@ -843,7 +836,7 @@ public final class JobServiceContext implements ServiceConnection {
|
||||
* we want to clean up internally.
|
||||
*/
|
||||
@GuardedBy("mLock")
|
||||
private void closeAndCleanupJobLocked(boolean reschedule, String reason) {
|
||||
private void closeAndCleanupJobLocked(boolean reschedule, @Nullable String reason) {
|
||||
final JobStatus completedJob;
|
||||
if (mVerb == VERB_FINISHED) {
|
||||
return;
|
||||
@@ -889,7 +882,7 @@ public final class JobServiceContext implements ServiceConnection {
|
||||
mJobConcurrencyManager.onJobCompletedLocked(this, completedJob, workType);
|
||||
}
|
||||
|
||||
private void applyStoppedReasonLocked(String reason) {
|
||||
private void applyStoppedReasonLocked(@Nullable String reason) {
|
||||
if (reason != null && mStoppedReason == null) {
|
||||
mStoppedReason = reason;
|
||||
mStoppedTime = sElapsedRealtimeClock.millis();
|
||||
|
||||
Reference in New Issue
Block a user