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

Commit d6e625de authored by Adam Bookatz's avatar Adam Bookatz
Browse files

SystemService post-completed user event: jobs

Use the new onUser completed event for JobSchedulerService.

This delays handling aspects of the user starting/unlock events
(which are important, but not urgent) until a little later.
In particular, it delays the intial job scheduling until a little after
the user has started, instead of immediately.

Test: manual
Bug: 197344658
Change-Id: I78ea7f7822ee466ce34dfc0b9f602fa1a4ceb7c3
parent 12091ce8
Loading
Loading
Loading
Loading
+7 −9
Original line number Diff line number Diff line
@@ -1209,19 +1209,17 @@ public class JobSchedulerService extends com.android.server.SystemService
        synchronized (mLock) {
            mStartedUsers = ArrayUtils.appendInt(mStartedUsers, user.getUserIdentifier());
        }
        // The user is starting but credential encrypted storage is still locked.
        // Only direct-boot-aware jobs can safely run.
        // Let's kick off any eligible jobs for this user.
        mHandler.obtainMessage(MSG_CHECK_JOB).sendToTarget();
    }

    /** Start jobs after user is available, delayed by a few seconds since non-urgent. */
    @Override
    public void onUserUnlocked(@NonNull TargetUser user) {
        // The user is fully unlocked and credential encrypted storage is now decrypted.
        // Direct-boot-UNaware jobs can now safely run.
        // Let's kick off any outstanding jobs for this user.
    public void onUserCompletedEvent(@NonNull TargetUser user, UserCompletedEventType eventType) {
        if (eventType.includesOnUserStarting() || eventType.includesOnUserUnlocked()) {
            // onUserStarting: direct-boot-aware jobs can safely run
            // onUserUnlocked: direct-boot-UNaware jobs can safely run.
            mHandler.obtainMessage(MSG_CHECK_JOB).sendToTarget();
        }
    }

    @Override
    public void onUserStopping(@NonNull TargetUser user) {