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

Commit 054fcdf7 authored by Kweku Adams's avatar Kweku Adams
Browse files

Properly set the NetworkRequest singleUid.

A job's NetworkRequest should have the source app's UID as the UID. The
previous code attempted to set the UID, but didn't modify the stored
job, leading to potentially unexpected behavior of proxied jobs.
Rearranging code to ensure we properly set the NetworkRequest UID.

Bug: 311727153
Test: N/A
Change-Id: I8fb49b74ff861ea82d89ab8d2791e4b917fd6ef2
parent 57ea0232
Loading
Loading
Loading
Loading
+16 −16
Original line number Original line Diff line number Diff line
@@ -598,7 +598,6 @@ public final class JobStatus {
            long lastSuccessfulRunTime, long lastFailedRunTime, long cumulativeExecutionTimeMs,
            long lastSuccessfulRunTime, long lastFailedRunTime, long cumulativeExecutionTimeMs,
            int internalFlags,
            int internalFlags,
            int dynamicConstraints) {
            int dynamicConstraints) {
        this.job = job;
        this.callingUid = callingUid;
        this.callingUid = callingUid;
        this.standbyBucket = standbyBucket;
        this.standbyBucket = standbyBucket;
        mNamespace = namespace;
        mNamespace = namespace;
@@ -626,6 +625,22 @@ public final class JobStatus {
            this.sourceTag = tag;
            this.sourceTag = tag;
        }
        }


        // This needs to be done before setting the field variable.
        if (job.getRequiredNetwork() != null) {
            // Later, when we check if a given network satisfies the required
            // network, we need to know the UID that is requesting it, so push
            // the source UID into place.
            final JobInfo.Builder builder = new JobInfo.Builder(job);
            builder.setRequiredNetwork(new NetworkRequest.Builder(job.getRequiredNetwork())
                    .setUids(Collections.singleton(new Range<>(this.sourceUid, this.sourceUid)))
                    .build());
            // Don't perform validation checks at this point since we've already passed the
            // initial validation check.
            job = builder.build(false, false);
        }

        this.job = job;

        final String bnNamespace = namespace == null ? "" :  "@" + namespace + "@";
        final String bnNamespace = namespace == null ? "" :  "@" + namespace + "@";
        this.batteryName = this.sourceTag != null
        this.batteryName = this.sourceTag != null
                ? bnNamespace + this.sourceTag + ":" + job.getService().getPackageName()
                ? bnNamespace + this.sourceTag + ":" + job.getService().getPackageName()
@@ -708,21 +723,6 @@ public final class JobStatus {


        updateNetworkBytesLocked();
        updateNetworkBytesLocked();


        if (job.getRequiredNetwork() != null) {
            // Later, when we check if a given network satisfies the required
            // network, we need to know the UID that is requesting it, so push
            // our source UID into place.
            final JobInfo.Builder builder = new JobInfo.Builder(job);
            final NetworkRequest.Builder requestBuilder =
                    new NetworkRequest.Builder(job.getRequiredNetwork());
            requestBuilder.setUids(
                    Collections.singleton(new Range<Integer>(this.sourceUid, this.sourceUid)));
            builder.setRequiredNetwork(requestBuilder.build());
            // Don't perform validation checks at this point since we've already passed the
            // initial validation check.
            job = builder.build(false, false);
        }

        updateMediaBackupExemptionStatus();
        updateMediaBackupExemptionStatus();
    }
    }