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

Commit 677c6ae1 authored by Kweku Adams's avatar Kweku Adams
Browse files

Update response to Task Manager stops.

1. Don't inform the job it's about to be stopped.
2. Don't reschedule user-visible jobs if they were stopped by the user
   via Task Manager.
3. Kill the app process immediately instead of waiting for the onStopJob
   flow/timeout.

Bug: 261999509
Test: atest FrameworksMockingServicesTests:JobSchedulerServiceTest
Test: atest FrameworksMockingServicesTests:JobStatusTest
Test: atest SystemUITests:FgsManagerControllerTest
Test: Manually stop test app in Task Manager and check JobScheduler logs
Change-Id: I29cecfc4b0988685e78387943154837cd4b72cea
parent 022f67e2
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -230,9 +230,10 @@ public class JobSchedulerImpl extends JobScheduler {
            android.Manifest.permission.MANAGE_ACTIVITY_TASKS,
            android.Manifest.permission.INTERACT_ACROSS_USERS_FULL})
    @Override
    public void stopUserVisibleJobsForUser(@NonNull String packageName, int userId) {
    public void notePendingUserRequestedAppStop(@NonNull String packageName, int userId,
            @Nullable String debugReason) {
        try {
            mBinder.stopUserVisibleJobsForUser(packageName, userId);
            mBinder.notePendingUserRequestedAppStop(packageName, userId, debugReason);
        } catch (RemoteException e) {
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -48,5 +48,5 @@ interface IJobScheduler {
    @EnforcePermission(allOf={"MANAGE_ACTIVITY_TASKS", "INTERACT_ACROSS_USERS_FULL"})
    void unregisterUserVisibleJobObserver(in IUserVisibleJobObserver observer);
    @EnforcePermission(allOf={"MANAGE_ACTIVITY_TASKS", "INTERACT_ACROSS_USERS_FULL"})
    void stopUserVisibleJobsForUser(String packageName, int userId);
    void notePendingUserRequestedAppStop(String packageName, int userId, String debugReason);
}
+5 −1
Original line number Diff line number Diff line
@@ -1897,7 +1897,11 @@ public class JobInfo implements Parcelable {
         * <p>
         * All user-initiated jobs must have an associated notification, set via
         * {@link JobService#setNotification(JobParameters, int, Notification, int)}, and will be
         * shown in the Task Manager when running.
         * shown in the Task Manager when running. These jobs cannot be rescheduled by the app
         * if the user stops the job via system provided affordance (such as the Task Manager).
         * Thus, it is best practice and recommended to provide action buttons in the
         * associated notification to allow the user to stop the job gracefully
         * and allow for rescheduling.
         *
         * <p>
         * If the app doesn't hold the {@link android.Manifest.permission#RUN_LONG_JOBS} permission
+2 −1
Original line number Diff line number Diff line
@@ -515,5 +515,6 @@ public abstract class JobScheduler {
            android.Manifest.permission.MANAGE_ACTIVITY_TASKS,
            android.Manifest.permission.INTERACT_ACROSS_USERS_FULL})
    @SuppressWarnings("HiddenAbstractMethod")
    public abstract void stopUserVisibleJobsForUser(@NonNull String packageName, int userId);
    public abstract void notePendingUserRequestedAppStop(@NonNull String packageName, int userId,
            @Nullable String debugReason);
}
+12 −0
Original line number Diff line number Diff line
@@ -156,6 +156,12 @@ public abstract class JobService extends Service {
     * a future idle maintenance window.
     * </p>
     *
     * <p class="note">
     * Any {@link JobInfo.Builder#setUserInitiated(boolean) user-initiated job}
     * cannot be rescheduled when the user has asked to stop the app
     * via a system provided affordance (such as the Task Manager).
     * In such situations, the value of {@code wantsReschedule} is always treated as {@code false}.
     *
     * @param params The parameters identifying this job, as supplied to
     *               the job in the {@link #onStartJob(JobParameters)} callback.
     * @param wantsReschedule {@code true} if this job should be rescheduled according
@@ -220,6 +226,12 @@ public abstract class JobService extends Service {
     * Once this method returns (or times out), the system releases the wakelock that it is holding
     * on behalf of the job.</p>
     *
     * <p class="note">
     * Any {@link JobInfo.Builder#setUserInitiated(boolean) user-initiated job}
     * cannot be rescheduled when stopped by the user via a system provided affordance (such as
     * the Task Manager). In such situations, the returned value from this method call is always
     * treated as {@code false}.
     *
     * <p class="caution"><strong>Note:</strong> When a job is stopped and rescheduled via this
     * method call, the deadline constraint is excluded from the rescheduled job's constraint set.
     * The rescheduled job will run again once all remaining constraints are satisfied.
Loading