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

Commit be0c4175 authored by Matthew Williams's avatar Matthew Williams Committed by Christopher Tate
Browse files

JobScheduler idle mode not being properly triggered

Issue with how the pending intent was being created -
the component name being explicitly set on the intent somehow
caused the intent to not be delivered.
Fix: no longer set the component name on the intent.
BUG: 16798118

Change-Id: I86b08b2a47067dc9b8da8b85450bc338e0826aca
parent 3f14df5c
Loading
Loading
Loading
Loading
+28 −4
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ public class JobSchedulerService extends com.android.server.SystemService
    static final boolean DEBUG = true;
    /** The number of concurrent jobs we run at one time. */
    private static final int MAX_JOB_CONTEXTS_COUNT = 3;
    static final String TAG = "JobManagerService";
    static final String TAG = "JobSchedulerService";
    /** Master list of jobs. */
    final JobStore mJobs;

@@ -87,6 +87,11 @@ public class JobSchedulerService extends com.android.server.SystemService
     * early.
     */
    static final int MIN_IDLE_COUNT = 1;
    /**
     * Minimum # of charging jobs that must be ready in order to force the JMS to schedule things
     * early.
     */
    static final int MIN_CHARGING_COUNT = 1;
    /**
     * Minimum # of connectivity jobs that must be ready in order to force the JMS to schedule
     * things early.
@@ -95,8 +100,9 @@ public class JobSchedulerService extends com.android.server.SystemService
    /**
     * Minimum # of jobs (with no particular constraints) for which the JMS will be happy running
     * some work early.
     * This is correlated with the amount of batching we'll be able to do.
     */
    static final int MIN_READY_JOBS_COUNT = 4;
    static final int MIN_READY_JOBS_COUNT = 2;

    /**
     * Track Services that have currently active or pending jobs. The index is provided by
@@ -546,6 +552,7 @@ public class JobSchedulerService extends com.android.server.SystemService
         */
        private void maybeQueueReadyJobsForExecutionH() {
            synchronized (mJobs) {
                int chargingCount = 0;
                int idleCount =  0;
                int backoffCount = 0;
                int connectivityCount = 0;
@@ -563,17 +570,34 @@ public class JobSchedulerService extends com.android.server.SystemService
                        if (job.hasConnectivityConstraint() || job.hasUnmeteredConstraint()) {
                            connectivityCount++;
                        }
                        if (job.hasChargingConstraint()) {
                            chargingCount++;
                        }
                        runnableJobs.add(job);
                    } else if (isReadyToBeCancelledLocked(job)) {
                        stopJobOnServiceContextLocked(job);
                    }
                }
                if (backoffCount > 0 || idleCount >= MIN_IDLE_COUNT ||
                if (backoffCount > 0 ||
                        idleCount >= MIN_IDLE_COUNT ||
                        connectivityCount >= MIN_CONNECTIVITY_COUNT ||
                        chargingCount >= MIN_CHARGING_COUNT ||
                        runnableJobs.size() >= MIN_READY_JOBS_COUNT) {
                    if (DEBUG) {
                        Slog.d(TAG, "maybeQueueReadyJobsForExecutionH: Running jobs.");
                    }
                    for (int i=0; i<runnableJobs.size(); i++) {
                        mPendingJobs.add(runnableJobs.get(i));
                    }
                } else {
                    if (DEBUG) {
                        Slog.d(TAG, "maybeQueueReadyJobsForExecutionH: Not running anything.");
                    }
                }
                if (DEBUG) {
                    Slog.d(TAG, "idle=" + idleCount + " connectivity=" +
                    connectivityCount + " charging=" + chargingCount + " tot=" +
                            runnableJobs.size());
                }
            }
        }
+9 −6
Original line number Diff line number Diff line
@@ -113,12 +113,13 @@ public class IdleController extends StateController {
        public IdlenessTracker() {
            mAlarm = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);

            Intent intent = new Intent(ACTION_TRIGGER_IDLE);
            intent.setComponent(new ComponentName(mContext, this.getClass()));
            Intent intent = new Intent(ACTION_TRIGGER_IDLE)
                    .setPackage("android")
                    .setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
            mIdleTriggerIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);

            // at boot we presume that the user has just "interacted" with the
            // device in some meaningful way
            // At boot we presume that the user has just "interacted" with the
            // device in some meaningful way.
            mIdle = false;
        }

@@ -163,9 +164,11 @@ public class IdleController extends StateController {
                // when the screen goes off or dreaming starts, we schedule the
                // alarm that will tell us when we have decided the device is
                // truly idle.
                long when = SystemClock.elapsedRealtime() + INACTIVITY_IDLE_THRESHOLD;
                final long nowElapsed = SystemClock.elapsedRealtime();
                final long when = nowElapsed + INACTIVITY_IDLE_THRESHOLD;
                if (DEBUG) {
                    Slog.v(TAG, "Scheduling idle : " + action + " when=" + when);
                    Slog.v(TAG, "Scheduling idle : " + action + " now:" + nowElapsed + " when="
                            + when);
                }
                mAlarm.setWindow(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                        when, IDLE_WINDOW_SLOP, mIdleTriggerIntent);