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

Commit 539279fe authored by Kweku Adams's avatar Kweku Adams
Browse files

Remove network bypass flags for non-connectivity jobs.

If a job doesn't say that it needs network, then there's no reason to
ensure that the app has access to network while the job is running.
Currently, the network restriction bypass flags are only given to
expedited or user-initiated jobs. Don't include the flags when the job
doesn't require connectivity to avoid accidental network usage/leakage.

Bug: 297106511
Bug: 299329948
Bug: 299346198
Test: atest CtsJobSchedulerTestCases:ConnectivityConstraintTest
Test: atest CtsJobSchedulerTestCases:ExpeditedJobTest
Change-Id: I9c632595f27655a977d6b084760839ce02c8c07b
parent b1df6237
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -1791,7 +1791,10 @@ public class JobInfo implements Parcelable {
         * <ol>
         *     <li>Run as soon as possible</li>
         *     <li>Be less restricted during Doze and battery saver</li>
         *     <li>Bypass Doze, app standby, and battery saver network restrictions</li>
         *     <li>
         *         Bypass Doze, app standby, and battery saver network restrictions (if the job
         *         has a {@link #setRequiredNetwork(NetworkRequest) connectivity constraint})
         *     </li>
         *     <li>Be less likely to be killed than regular jobs</li>
         *     <li>Be subject to background location throttling</li>
         *     <li>Be exempt from delay to optimize job execution</li>
+15 −19
Original line number Diff line number Diff line
@@ -427,34 +427,30 @@ public final class JobServiceContext implements ServiceConnection {
            boolean binding = false;
            boolean startedWithForegroundFlag = false;
            try {
                final Context.BindServiceFlags bindFlags;
                long bindFlags = Context.BIND_AUTO_CREATE | Context.BIND_NOT_APP_COMPONENT_USAGE;
                if (job.shouldTreatAsUserInitiatedJob() && !job.isUserBgRestricted()) {
                    // If the user has bg restricted the app, don't give the job FG privileges
                    // such as bypassing data saver or getting the higher foreground proc state.
                    // If we've gotten to this point, the app is most likely in the foreground,
                    // so the job will run just fine while the user keeps the app in the foreground.
                    bindFlags = Context.BindServiceFlags.of(
                            Context.BIND_AUTO_CREATE
                                    | Context.BIND_ALMOST_PERCEPTIBLE
                                    | Context.BIND_BYPASS_POWER_NETWORK_RESTRICTIONS
                                    | Context.BIND_BYPASS_USER_NETWORK_RESTRICTIONS
                                    | Context.BIND_NOT_APP_COMPONENT_USAGE);
                    bindFlags |= Context.BIND_ALMOST_PERCEPTIBLE;
                    if (job.hasConnectivityConstraint()) {
                        // Only add network restriction bypass flags if the job requires network.
                        bindFlags |= Context.BIND_BYPASS_POWER_NETWORK_RESTRICTIONS
                                | Context.BIND_BYPASS_USER_NETWORK_RESTRICTIONS;
                    }
                    startedWithForegroundFlag = true;
                } else if (job.shouldTreatAsExpeditedJob() || job.shouldTreatAsUserInitiatedJob()) {
                    bindFlags = Context.BindServiceFlags.of(
                            Context.BIND_AUTO_CREATE
                                    | Context.BIND_NOT_FOREGROUND
                                    | Context.BIND_ALMOST_PERCEPTIBLE
                                    | Context.BIND_BYPASS_POWER_NETWORK_RESTRICTIONS
                                    | Context.BIND_NOT_APP_COMPONENT_USAGE);
                    bindFlags |= Context.BIND_NOT_FOREGROUND | Context.BIND_ALMOST_PERCEPTIBLE;
                    if (job.hasConnectivityConstraint()) {
                        // Only add network restriction bypass flags if the job requires network.
                        bindFlags |= Context.BIND_BYPASS_POWER_NETWORK_RESTRICTIONS;
                    }
                } else {
                    bindFlags = Context.BindServiceFlags.of(
                            Context.BIND_AUTO_CREATE
                                    | Context.BIND_NOT_FOREGROUND
                                    | Context.BIND_NOT_PERCEPTIBLE
                                    | Context.BIND_NOT_APP_COMPONENT_USAGE);
                    bindFlags |= Context.BIND_NOT_FOREGROUND | Context.BIND_NOT_PERCEPTIBLE;
                }
                binding = mContext.bindServiceAsUser(intent, this, bindFlags,
                binding = mContext.bindServiceAsUser(intent, this,
                        Context.BindServiceFlags.of(bindFlags),
                        UserHandle.of(job.getUserId()));
            } catch (SecurityException e) {
                // Some permission policy, for example INTERACT_ACROSS_USERS and