Merge "Small JS code cleanup." into sc-dev

This commit is contained in:
Kweku Adams
2021-03-05 16:47:40 +00:00
committed by Android (Google) Code Review
2 changed files with 18 additions and 18 deletions

View File

@@ -25,6 +25,7 @@ import android.app.ActivityManager;
import android.app.ActivityManagerInternal; import android.app.ActivityManagerInternal;
import android.app.UserSwitchObserver; import android.app.UserSwitchObserver;
import android.app.job.JobInfo; import android.app.job.JobInfo;
import android.app.job.JobParameters;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; 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. // 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 // Do this before the following loop to hopefully reduce the cost of
// shouldStopRunningJobLocked(). // shouldStopRunningJobLocked().
updateNonRunningPriorities(pendingJobs, true); updateNonRunningPrioritiesLocked(pendingJobs, true);
for (int i = 0; i < MAX_JOB_CONTEXTS_COUNT; i++) { for (int i = 0; i < MAX_JOB_CONTEXTS_COUNT; i++) {
final JobServiceContext js = activeServices.get(i); final JobServiceContext js = activeServices.get(i);
@@ -585,7 +586,8 @@ class JobConcurrencyManager {
+ activeServices.get(i).getRunningJobLocked()); + activeServices.get(i).getRunningJobLocked());
} }
// preferredUid will be set to uid of currently running job. // 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; preservePreferredUid = true;
} else { } else {
final JobStatus pendingJob = contextIdToJobMap[i]; final JobStatus pendingJob = contextIdToJobMap[i];
@@ -610,7 +612,8 @@ class JobConcurrencyManager {
mWorkCountTracker.getRunningJobCount(WORK_TYPE_TOP)); 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) { boolean updateCounter) {
for (int i = 0; i < pendingJobs.size(); i++) { for (int i = 0; i < pendingJobs.size(); i++) {
final JobStatus pending = pendingJobs.get(i); final JobStatus pending = pendingJobs.get(i);
@@ -628,6 +631,7 @@ class JobConcurrencyManager {
} }
} }
@GuardedBy("mLock")
private void startJobLocked(@NonNull JobServiceContext worker, @NonNull JobStatus jobStatus, private void startJobLocked(@NonNull JobServiceContext worker, @NonNull JobStatus jobStatus,
@WorkType final int workType) { @WorkType final int workType) {
final List<StateController> controllers = mService.mControllers; final List<StateController> controllers = mService.mControllers;
@@ -647,6 +651,7 @@ class JobConcurrencyManager {
} }
} }
@GuardedBy("mLock")
void onJobCompletedLocked(@NonNull JobServiceContext worker, @NonNull JobStatus jobStatus, void onJobCompletedLocked(@NonNull JobServiceContext worker, @NonNull JobStatus jobStatus,
@WorkType final int workType) { @WorkType final int workType) {
mWorkCountTracker.onJobFinished(workType); mWorkCountTracker.onJobFinished(workType);
@@ -655,7 +660,7 @@ class JobConcurrencyManager {
if (worker.getPreferredUid() != JobServiceContext.NO_PREFERRED_UID) { if (worker.getPreferredUid() != JobServiceContext.NO_PREFERRED_UID) {
updateCounterConfigLocked(); updateCounterConfigLocked();
// Preemption case needs special care. // Preemption case needs special care.
updateNonRunningPriorities(pendingJobs, false); updateNonRunningPrioritiesLocked(pendingJobs, false);
JobStatus highestPriorityJob = null; JobStatus highestPriorityJob = null;
int highPriWorkType = workType; int highPriWorkType = workType;
@@ -726,7 +731,7 @@ class JobConcurrencyManager {
} }
} else if (pendingJobs.size() > 0) { } else if (pendingJobs.size() > 0) {
updateCounterConfigLocked(); updateCounterConfigLocked();
updateNonRunningPriorities(pendingJobs, false); updateNonRunningPrioritiesLocked(pendingJobs, false);
// This slot is now free and we have pending jobs. Start the highest priority job we // This slot is now free and we have pending jobs. Start the highest priority job we
// find. // find.
@@ -775,6 +780,7 @@ class JobConcurrencyManager {
* another job to run, or if system state suggests the job should stop. * another job to run, or if system state suggests the job should stop.
*/ */
@Nullable @Nullable
@GuardedBy("mLock")
String shouldStopRunningJobLocked(@NonNull JobServiceContext context) { String shouldStopRunningJobLocked(@NonNull JobServiceContext context) {
final JobStatus js = context.getRunningJobLocked(); final JobStatus js = context.getRunningJobLocked();
if (js == null) { if (js == null) {
@@ -881,6 +887,7 @@ class JobConcurrencyManager {
return s.toString(); return s.toString();
} }
@GuardedBy("mLock")
void updateConfigLocked() { void updateConfigLocked() {
DeviceConfig.Properties properties = DeviceConfig.Properties properties =
DeviceConfig.getProperties(DeviceConfig.NAMESPACE_JOB_SCHEDULER); DeviceConfig.getProperties(DeviceConfig.NAMESPACE_JOB_SCHEDULER);

View File

@@ -269,8 +269,6 @@ public final class JobServiceContext implements ServiceConnection {
try { try {
final int bindFlags; final int bindFlags;
if (job.shouldTreatAsExpeditedJob()) { 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 bindFlags = Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND
| Context.BIND_ALMOST_PERCEPTIBLE | Context.BIND_ALMOST_PERCEPTIBLE
| Context.BIND_ALLOW_NETWORK_ACCESS | 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. */ /** Called externally when a job that was scheduled for execution should be cancelled. */
@GuardedBy("mLock") @GuardedBy("mLock")
void cancelExecutingJobLocked(int reason, String debugReason) { void cancelExecutingJobLocked(int reason, @NonNull String debugReason) {
doCancelLocked(reason, debugReason); doCancelLocked(reason, debugReason);
} }
@GuardedBy("mLock")
void preemptExecutingJobLocked(@NonNull String reason) {
doCancelLocked(JobParameters.REASON_PREEMPT, reason);
}
int getPreferredUid() { int getPreferredUid() {
return mPreferredUid; return mPreferredUid;
} }
@@ -620,7 +613,7 @@ public final class JobServiceContext implements ServiceConnection {
} }
@GuardedBy("mLock") @GuardedBy("mLock")
private void doCancelLocked(int stopReasonCode, String debugReason) { private void doCancelLocked(int stopReasonCode, @Nullable String debugReason) {
if (mVerb == VERB_FINISHED) { if (mVerb == VERB_FINISHED) {
if (DEBUG) { if (DEBUG) {
Slog.d(TAG, Slog.d(TAG,
@@ -733,7 +726,7 @@ public final class JobServiceContext implements ServiceConnection {
* _ENDING -> No point in doing anything here, so we ignore. * _ENDING -> No point in doing anything here, so we ignore.
*/ */
@GuardedBy("mLock") @GuardedBy("mLock")
private void handleCancelLocked(String reason) { private void handleCancelLocked(@Nullable String reason) {
if (JobSchedulerService.DEBUG) { if (JobSchedulerService.DEBUG) {
Slog.d(TAG, "Handling cancel for: " + mRunningJob.getJobId() + " " Slog.d(TAG, "Handling cancel for: " + mRunningJob.getJobId() + " "
+ VERB_STRINGS[mVerb]); + VERB_STRINGS[mVerb]);
@@ -817,7 +810,7 @@ public final class JobServiceContext implements ServiceConnection {
* VERB_STOPPING. * VERB_STOPPING.
*/ */
@GuardedBy("mLock") @GuardedBy("mLock")
private void sendStopMessageLocked(String reason) { private void sendStopMessageLocked(@Nullable String reason) {
removeOpTimeOutLocked(); removeOpTimeOutLocked();
if (mVerb != VERB_EXECUTING) { if (mVerb != VERB_EXECUTING) {
Slog.e(TAG, "Sending onStopJob for a job that isn't started. " + mRunningJob); 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. * we want to clean up internally.
*/ */
@GuardedBy("mLock") @GuardedBy("mLock")
private void closeAndCleanupJobLocked(boolean reschedule, String reason) { private void closeAndCleanupJobLocked(boolean reschedule, @Nullable String reason) {
final JobStatus completedJob; final JobStatus completedJob;
if (mVerb == VERB_FINISHED) { if (mVerb == VERB_FINISHED) {
return; return;
@@ -889,7 +882,7 @@ public final class JobServiceContext implements ServiceConnection {
mJobConcurrencyManager.onJobCompletedLocked(this, completedJob, workType); mJobConcurrencyManager.onJobCompletedLocked(this, completedJob, workType);
} }
private void applyStoppedReasonLocked(String reason) { private void applyStoppedReasonLocked(@Nullable String reason) {
if (reason != null && mStoppedReason == null) { if (reason != null && mStoppedReason == null) {
mStoppedReason = reason; mStoppedReason = reason;
mStoppedTime = sElapsedRealtimeClock.millis(); mStoppedTime = sElapsedRealtimeClock.millis();