use of com.android.server.job.controllers.JobStatus in project platform_frameworks_base by android.
the class JobSchedulerService method stopJobOnServiceContextLocked.
private boolean stopJobOnServiceContextLocked(JobStatus job, int reason) {
for (int i = 0; i < mActiveServices.size(); i++) {
JobServiceContext jsc = mActiveServices.get(i);
final JobStatus executing = jsc.getRunningJob();
if (executing != null && executing.matches(job.getUid(), job.getJobId())) {
jsc.cancelExecutingJob(reason);
return true;
}
}
return false;
}
use of com.android.server.job.controllers.JobStatus in project platform_frameworks_base by android.
the class JobSchedulerService method cancelJobsForUser.
void cancelJobsForUser(int userHandle) {
List<JobStatus> jobsForUser;
synchronized (mLock) {
jobsForUser = mJobs.getJobsByUser(userHandle);
}
for (int i = 0; i < jobsForUser.size(); i++) {
JobStatus toRemove = jobsForUser.get(i);
cancelJobImpl(toRemove, null);
}
}
use of com.android.server.job.controllers.JobStatus in project platform_frameworks_base by android.
the class JobSchedulerService method dumpInternal.
void dumpInternal(final PrintWriter pw, String[] args) {
int filterUid = -1;
if (!ArrayUtils.isEmpty(args)) {
int opti = 0;
while (opti < args.length) {
String arg = args[opti];
if ("-h".equals(arg)) {
dumpHelp(pw);
return;
} else if ("-a".equals(arg)) {
// Ignore, we always dump all.
} else if (arg.length() > 0 && arg.charAt(0) == '-') {
pw.println("Unknown option: " + arg);
return;
} else {
break;
}
opti++;
}
if (opti < args.length) {
String pkg = args[opti];
try {
filterUid = getContext().getPackageManager().getPackageUid(pkg, PackageManager.MATCH_UNINSTALLED_PACKAGES);
} catch (NameNotFoundException ignored) {
pw.println("Invalid package: " + pkg);
return;
}
}
}
final int filterUidFinal = UserHandle.getAppId(filterUid);
final long now = SystemClock.elapsedRealtime();
synchronized (mLock) {
mConstants.dump(pw);
pw.println();
pw.println("Started users: " + Arrays.toString(mStartedUsers));
pw.print("Registered ");
pw.print(mJobs.size());
pw.println(" jobs:");
if (mJobs.size() > 0) {
final List<JobStatus> jobs = mJobs.mJobSet.getAllJobs();
Collections.sort(jobs, new Comparator<JobStatus>() {
@Override
public int compare(JobStatus o1, JobStatus o2) {
int uid1 = o1.getUid();
int uid2 = o2.getUid();
int id1 = o1.getJobId();
int id2 = o2.getJobId();
if (uid1 != uid2) {
return uid1 < uid2 ? -1 : 1;
}
return id1 < id2 ? -1 : (id1 > id2 ? 1 : 0);
}
});
for (JobStatus job : jobs) {
pw.print(" JOB #");
job.printUniqueId(pw);
pw.print(": ");
pw.println(job.toShortStringExceptUniqueId());
// Skip printing details if the caller requested a filter
if (!job.shouldDump(filterUidFinal)) {
continue;
}
job.dump(pw, " ", true);
pw.print(" Ready: ");
pw.print(mHandler.isReadyToBeExecutedLocked(job));
pw.print(" (job=");
pw.print(job.isReady());
pw.print(" pending=");
pw.print(mPendingJobs.contains(job));
pw.print(" active=");
pw.print(isCurrentlyActiveLocked(job));
pw.print(" user=");
pw.print(ArrayUtils.contains(mStartedUsers, job.getUserId()));
pw.println(")");
}
} else {
pw.println(" None.");
}
for (int i = 0; i < mControllers.size(); i++) {
pw.println();
mControllers.get(i).dumpControllerStateLocked(pw, filterUidFinal);
}
pw.println();
pw.println("Uid priority overrides:");
for (int i = 0; i < mUidPriorityOverride.size(); i++) {
int uid = mUidPriorityOverride.keyAt(i);
if (filterUidFinal == -1 || filterUidFinal == UserHandle.getAppId(uid)) {
pw.print(" ");
pw.print(UserHandle.formatUid(uid));
pw.print(": ");
pw.println(mUidPriorityOverride.valueAt(i));
}
}
pw.println();
mJobPackageTracker.dump(pw, "", filterUidFinal);
pw.println();
if (mJobPackageTracker.dumpHistory(pw, "", filterUidFinal)) {
pw.println();
}
pw.println("Pending queue:");
for (int i = 0; i < mPendingJobs.size(); i++) {
JobStatus job = mPendingJobs.get(i);
pw.print(" Pending #");
pw.print(i);
pw.print(": ");
pw.println(job.toShortString());
job.dump(pw, " ", false);
int priority = evaluateJobPriorityLocked(job);
if (priority != JobInfo.PRIORITY_DEFAULT) {
pw.print(" Evaluated priority: ");
pw.println(priority);
}
pw.print(" Tag: ");
pw.println(job.getTag());
}
pw.println();
pw.println("Active jobs:");
for (int i = 0; i < mActiveServices.size(); i++) {
JobServiceContext jsc = mActiveServices.get(i);
pw.print(" Slot #");
pw.print(i);
pw.print(": ");
if (jsc.getRunningJob() == null) {
pw.println("inactive");
continue;
} else {
pw.println(jsc.getRunningJob().toShortString());
pw.print(" Running for: ");
TimeUtils.formatDuration(now - jsc.getExecutionStartTimeElapsed(), pw);
pw.print(", timeout at: ");
TimeUtils.formatDuration(jsc.getTimeoutElapsed() - now, pw);
pw.println();
jsc.getRunningJob().dump(pw, " ", false);
int priority = evaluateJobPriorityLocked(jsc.getRunningJob());
if (priority != JobInfo.PRIORITY_DEFAULT) {
pw.print(" Evaluated priority: ");
pw.println(priority);
}
}
}
if (filterUid == -1) {
pw.println();
pw.print("mReadyToRock=");
pw.println(mReadyToRock);
pw.print("mReportedActive=");
pw.println(mReportedActive);
pw.print("mMaxActiveJobs=");
pw.println(mMaxActiveJobs);
}
}
pw.println();
}
use of com.android.server.job.controllers.JobStatus in project platform_frameworks_base by android.
the class JobSchedulerService method isCurrentlyActiveLocked.
/**
* @param job JobStatus we are querying against.
* @return Whether or not the job represented by the status object is currently being run or
* is pending.
*/
private boolean isCurrentlyActiveLocked(JobStatus job) {
for (int i = 0; i < mActiveServices.size(); i++) {
JobServiceContext serviceContext = mActiveServices.get(i);
// The 'unsafe' direct-internal-reference running-job inspector is okay to
// use here because we are already holding the necessary lock *and* we
// immediately discard the returned object reference, if any; we return
// only a boolean state indicator to the caller.
final JobStatus running = serviceContext.getRunningJobUnsafeLocked();
if (running != null && running.matches(job.getUid(), job.getJobId())) {
return true;
}
}
return false;
}
use of com.android.server.job.controllers.JobStatus in project platform_frameworks_base by android.
the class JobSchedulerService method executeRunCommand.
// Shell command infrastructure: run the given job immediately
int executeRunCommand(String pkgName, int userId, int jobId, boolean force) {
if (DEBUG) {
Slog.v(TAG, "executeRunCommand(): " + pkgName + "/" + userId + " " + jobId + " f=" + force);
}
try {
final int uid = AppGlobals.getPackageManager().getPackageUid(pkgName, 0, userId);
if (uid < 0) {
return JobSchedulerShellCommand.CMD_ERR_NO_PACKAGE;
}
synchronized (mLock) {
final JobStatus js = mJobs.getJobByUidAndJobId(uid, jobId);
if (js == null) {
return JobSchedulerShellCommand.CMD_ERR_NO_JOB;
}
js.overrideState = (force) ? JobStatus.OVERRIDE_FULL : JobStatus.OVERRIDE_SOFT;
if (!js.isConstraintsSatisfied()) {
js.overrideState = 0;
return JobSchedulerShellCommand.CMD_ERR_CONSTRAINTS;
}
mHandler.obtainMessage(MSG_CHECK_JOB_GREEDY).sendToTarget();
}
} catch (RemoteException e) {
// can't happen
}
return 0;
}
Aggregations