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

Commit db1c6752 authored by Kweku Adams's avatar Kweku Adams Committed by Android (Google) Code Review
Browse files

Merge "Remove network bypass flags for non-connectivity jobs." into main

parents 2694214b 539279fe
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