Merge "Fix ConnectivityController running job counting." into sc-dev
This commit is contained in:
commit
410e46c277
@ -798,7 +798,8 @@ class JobConcurrencyManager {
|
||||
private void startJobLocked(@NonNull JobServiceContext worker, @NonNull JobStatus jobStatus,
|
||||
@WorkType final int workType) {
|
||||
final List<StateController> controllers = mService.mControllers;
|
||||
for (int ic = 0; ic < controllers.size(); ic++) {
|
||||
final int numControllers = controllers.size();
|
||||
for (int ic = 0; ic < numControllers; ic++) {
|
||||
controllers.get(ic).prepareForExecutionLocked(jobStatus);
|
||||
}
|
||||
final PackageStats packageStats =
|
||||
@ -807,6 +808,9 @@ class JobConcurrencyManager {
|
||||
if (!worker.executeRunnableJob(jobStatus, workType)) {
|
||||
Slog.e(TAG, "Error executing " + jobStatus);
|
||||
mWorkCountTracker.onStagedJobFailed(workType);
|
||||
for (int ic = 0; ic < numControllers; ic++) {
|
||||
controllers.get(ic).unprepareFromExecutionLocked(jobStatus);
|
||||
}
|
||||
} else {
|
||||
mRunningJobs.add(jobStatus);
|
||||
mWorkCountTracker.onJobStarted(workType);
|
||||
|
@ -148,7 +148,8 @@ public final class ConnectivityController extends RestrictingController implemen
|
||||
// 9. Enqueue time
|
||||
// TODO: maybe consider number of jobs
|
||||
// TODO: consider IMPORTANT_WHILE_FOREGROUND bit
|
||||
final int runningPriority = prioritizeExistenceOver(0, us1.numRunning, us2.numRunning);
|
||||
final int runningPriority = prioritizeExistenceOver(0,
|
||||
us1.runningJobs.size(), us2.runningJobs.size());
|
||||
if (runningPriority != 0) {
|
||||
return runningPriority;
|
||||
}
|
||||
@ -256,7 +257,18 @@ public final class ConnectivityController extends RestrictingController implemen
|
||||
if (jobStatus.hasConnectivityConstraint()) {
|
||||
final UidStats uidStats =
|
||||
getUidStats(jobStatus.getSourceUid(), jobStatus.getSourcePackageName(), true);
|
||||
uidStats.numRunning++;
|
||||
uidStats.runningJobs.add(jobStatus);
|
||||
}
|
||||
}
|
||||
|
||||
@GuardedBy("mLock")
|
||||
@Override
|
||||
public void unprepareFromExecutionLocked(JobStatus jobStatus) {
|
||||
if (jobStatus.hasConnectivityConstraint()) {
|
||||
final UidStats uidStats =
|
||||
getUidStats(jobStatus.getSourceUid(), jobStatus.getSourcePackageName(), true);
|
||||
uidStats.runningJobs.remove(jobStatus);
|
||||
postAdjustCallbacks();
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,12 +284,7 @@ public final class ConnectivityController extends RestrictingController implemen
|
||||
final UidStats uidStats =
|
||||
getUidStats(jobStatus.getSourceUid(), jobStatus.getSourcePackageName(), true);
|
||||
uidStats.numReadyWithConnectivity--;
|
||||
if (jobStatus.madeActive != 0) {
|
||||
// numRunning would be 0 if the UidStats object didn't exist before this method
|
||||
// was called. getUidStats() handles logging, so just make sure we don't save a
|
||||
// negative value.
|
||||
uidStats.numRunning = Math.max(0, uidStats.numRunning - 1);
|
||||
}
|
||||
uidStats.runningJobs.remove(jobStatus);
|
||||
maybeRevokeStandbyExceptionLocked(jobStatus);
|
||||
postAdjustCallbacks();
|
||||
}
|
||||
@ -1151,7 +1158,7 @@ public final class ConnectivityController extends RestrictingController implemen
|
||||
private static class UidStats {
|
||||
public final int uid;
|
||||
public int basePriority;
|
||||
public int numRunning;
|
||||
public final ArraySet<JobStatus> runningJobs = new ArraySet<>();
|
||||
public int numReadyWithConnectivity;
|
||||
public int numRequestedNetworkAvailable;
|
||||
public int numEJs;
|
||||
@ -1168,7 +1175,7 @@ public final class ConnectivityController extends RestrictingController implemen
|
||||
pw.print("UidStats{");
|
||||
pw.print("uid", uid);
|
||||
pw.print("pri", basePriority);
|
||||
pw.print("#run", numRunning);
|
||||
pw.print("#run", runningJobs.size());
|
||||
pw.print("#readyWithConn", numReadyWithConnectivity);
|
||||
pw.print("#netAvail", numRequestedNetworkAvailable);
|
||||
pw.print("#EJs", numEJs);
|
||||
|
@ -135,6 +135,29 @@ public final class ContentObserverController extends StateController {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unprepareFromExecutionLocked(JobStatus taskStatus) {
|
||||
if (taskStatus.hasContentTriggerConstraint()) {
|
||||
if (taskStatus.contentObserverJobInstance != null) {
|
||||
if (taskStatus.contentObserverJobInstance.mChangedUris == null) {
|
||||
taskStatus.contentObserverJobInstance.mChangedUris = taskStatus.changedUris;
|
||||
} else {
|
||||
taskStatus.contentObserverJobInstance.mChangedUris
|
||||
.addAll(taskStatus.changedUris);
|
||||
}
|
||||
if (taskStatus.contentObserverJobInstance.mChangedAuthorities == null) {
|
||||
taskStatus.contentObserverJobInstance.mChangedAuthorities =
|
||||
taskStatus.changedAuthorities;
|
||||
} else {
|
||||
taskStatus.contentObserverJobInstance.mChangedAuthorities
|
||||
.addAll(taskStatus.changedAuthorities);
|
||||
}
|
||||
taskStatus.changedUris = null;
|
||||
taskStatus.changedAuthorities = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void maybeStopTrackingJobLocked(JobStatus taskStatus, JobStatus incomingJob,
|
||||
boolean forUpdate) {
|
||||
|
@ -34,7 +34,6 @@ import android.annotation.Nullable;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.AppGlobals;
|
||||
import android.app.IUidObserver;
|
||||
import android.app.usage.UsageEvents;
|
||||
import android.app.usage.UsageStatsManagerInternal;
|
||||
@ -677,27 +676,30 @@ public final class QuotaController extends StateController {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void maybeStopTrackingJobLocked(JobStatus jobStatus, JobStatus incomingJob,
|
||||
boolean forUpdate) {
|
||||
if (jobStatus.clearTrackingController(JobStatus.TRACKING_QUOTA)) {
|
||||
Timer timer = mPkgTimers.get(jobStatus.getSourceUserId(),
|
||||
jobStatus.getSourcePackageName());
|
||||
public void unprepareFromExecutionLocked(JobStatus jobStatus) {
|
||||
Timer timer = mPkgTimers.get(jobStatus.getSourceUserId(), jobStatus.getSourcePackageName());
|
||||
if (timer != null) {
|
||||
timer.stopTrackingJob(jobStatus);
|
||||
}
|
||||
if (jobStatus.isRequestedExpeditedJob()) {
|
||||
timer = mEJPkgTimers.get(jobStatus.getSourceUserId(), jobStatus.getSourcePackageName());
|
||||
if (timer != null) {
|
||||
timer.stopTrackingJob(jobStatus);
|
||||
}
|
||||
if (jobStatus.isRequestedExpeditedJob()) {
|
||||
timer = mEJPkgTimers.get(jobStatus.getSourceUserId(),
|
||||
jobStatus.getSourcePackageName());
|
||||
if (timer != null) {
|
||||
timer.stopTrackingJob(jobStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
mTopStartedJobs.remove(jobStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void maybeStopTrackingJobLocked(JobStatus jobStatus, JobStatus incomingJob,
|
||||
boolean forUpdate) {
|
||||
if (jobStatus.clearTrackingController(JobStatus.TRACKING_QUOTA)) {
|
||||
unprepareFromExecutionLocked(jobStatus);
|
||||
ArraySet<JobStatus> jobs = mTrackedJobs.get(jobStatus.getSourceUserId(),
|
||||
jobStatus.getSourcePackageName());
|
||||
if (jobs != null) {
|
||||
jobs.remove(jobStatus);
|
||||
}
|
||||
mTopStartedJobs.remove(jobStatus);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,6 +75,12 @@ public abstract class StateController {
|
||||
public void prepareForExecutionLocked(JobStatus jobStatus) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionally implement logic here for when a job that was about to be executed failed to start.
|
||||
*/
|
||||
public void unprepareFromExecutionLocked(JobStatus jobStatus) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove task - this will happen if the task is cancelled, completed, etc.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user