Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c3d14d17 authored by Kweku Adams's avatar Kweku Adams
Browse files

Modify wakelock tag.

1. Remove the job ID from the wakelock tag.
2. Lazily load the tag when needed to reduce memory usage of jobs
   waiting for constraints to be satisfied.
3. Remove redundant log line.

Bug: 273758274
Bug: 302348192
Bug: 307556230
Test: atest CtsJobSchedulerTestCases
Test: Manually remove output of `adb shell dumpsys jobscheduler`
Change-Id: If8547d23ced90b17225ab8efd758ac735655687e
parent 8943b729
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1518,8 +1518,8 @@ class JobConcurrencyManager {
            @WorkType final int workType) {
        final List<StateController> controllers = mService.mControllers;
        final int numControllers = controllers.size();
        final PowerManager.WakeLock wl =
                mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, jobStatus.getTag());
        final PowerManager.WakeLock wl = mPowerManager.newWakeLock(
                PowerManager.PARTIAL_WAKE_LOCK, jobStatus.getWakelockTag());
        wl.setWorkSource(mService.deriveWorkSource(
                jobStatus.getSourceUid(), jobStatus.getSourcePackageName()));
        wl.setReferenceCounted(false);
+0 −1
Original line number Diff line number Diff line
@@ -5512,7 +5512,6 @@ public class JobSchedulerService extends com.android.server.SystemService
                pw.print("Evaluated bias: ");
                pw.println(JobInfo.getBiasString(bias));

                pw.print("Tag: "); pw.println(job.getTag());
                pw.print("Enq: ");
                TimeUtils.formatDuration(job.madePending - nowUptime, pw);
                pw.decreaseIndent();
+2 −1
Original line number Diff line number Diff line
@@ -398,7 +398,8 @@ public final class JobServiceContext implements ServiceConnection {
            // it was inflated from disk with not-yet-coherent delay/deadline bounds.
            job.clearPersistedUtcTimes();

            mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, job.getTag());
            mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                    job.getWakelockTag());
            mWakeLock.setWorkSource(
                    mService.deriveWorkSource(job.getSourceUid(), job.getSourcePackageName()));
            mWakeLock.setReferenceCounted(false);
+15 −6
Original line number Diff line number Diff line
@@ -253,7 +253,12 @@ public final class JobStatus {
    /** An ID that can be used to uniquely identify the job when logging statsd metrics. */
    private final long mLoggingJobId;

    final String tag;
    /**
     * Tag to identify the wakelock held for this job. Lazily loaded in
     * {@link #getWakelockTag()} since it's not typically needed until the job is about to run.
     */
    @Nullable
    private String mWakelockTag;

    /** Whether this job was scheduled by one app on behalf of another. */
    final boolean mIsProxyJob;
@@ -627,7 +632,6 @@ public final class JobStatus {
        this.batteryName = this.sourceTag != null
                ? bnNamespace + this.sourceTag + ":" + job.getService().getPackageName()
                : bnNamespace + job.getService().flattenToShortString();
        this.tag = "*job*/" + this.batteryName + "#" + job.getId();

        final String componentPackage = job.getService().getPackageName();
        mIsProxyJob = !this.sourcePackageName.equals(componentPackage);
@@ -1321,8 +1325,13 @@ public final class JobStatus {
        return batteryName;
    }

    public String getTag() {
        return tag;
    /** Return the String to be used as the tag for the wakelock held for this job. */
    @NonNull
    public String getWakelockTag() {
        if (mWakelockTag == null) {
            mWakelockTag = "*job*/" + this.batteryName;
        }
        return mWakelockTag;
    }

    public int getBias() {
@@ -2639,7 +2648,7 @@ public final class JobStatus {
    @NeverCompile // Avoid size overhead of debugging code.
    public void dump(IndentingPrintWriter pw,  boolean full, long nowElapsed) {
        UserHandle.formatUid(pw, callingUid);
        pw.print(" tag="); pw.println(tag);
        pw.print(" tag="); pw.println(getWakelockTag());

        pw.print("Source: uid="); UserHandle.formatUid(pw, getSourceUid());
        pw.print(" user="); pw.print(getSourceUserId());
@@ -2955,7 +2964,7 @@ public final class JobStatus {
        final long token = proto.start(fieldId);

        proto.write(JobStatusDumpProto.CALLING_UID, callingUid);
        proto.write(JobStatusDumpProto.TAG, tag);
        proto.write(JobStatusDumpProto.TAG, getWakelockTag());
        proto.write(JobStatusDumpProto.SOURCE_UID, getSourceUid());
        proto.write(JobStatusDumpProto.SOURCE_USER_ID, getSourceUserId());
        proto.write(JobStatusDumpProto.SOURCE_PACKAGE_NAME, getSourcePackageName());