Use JS thread for idleness tracking.

Make sure to use the dedicated JobScheduler thread for all of the
idleness callbacks and state changes.

Bug: 172579710
Test: atest CtsJobSchedulerTestCases:IdleConstraintTest
Test: atest CtsJobSchedulerTestCases:JobThrottlingTest
Change-Id: I269d5927ba2c7b795f61ff73c46c8cd6f56c937c
This commit is contained in:
Kweku Adams
2023-02-25 00:15:46 +00:00
parent e4a37c494f
commit 0034b06258
2 changed files with 10 additions and 9 deletions

View File

@@ -24,6 +24,7 @@ import android.util.Log;
import android.util.Slog;
import android.util.proto.ProtoOutputStream;
import com.android.server.JobSchedulerBackgroundThread;
import com.android.server.am.ActivityManagerService;
import com.android.server.job.JobSchedulerService;
import com.android.server.job.StateControllerProto;
@@ -50,7 +51,7 @@ public final class CarIdlenessTracker extends BroadcastReceiver implements Idlen
public static final String ACTION_UNFORCE_IDLE = "com.android.server.jobscheduler.UNFORCE_IDLE";
// After construction, mutations of idle/screen-on state will only happen
// on the main looper thread, either in onReceive() or in an alarm callback.
// on the JobScheduler thread, either in onReceive() or in an alarm callback.
private boolean mIdle;
private boolean mGarageModeOn;
private boolean mForced;
@@ -90,7 +91,7 @@ public final class CarIdlenessTracker extends BroadcastReceiver implements Idlen
filter.addAction(ACTION_UNFORCE_IDLE);
filter.addAction(ActivityManagerService.ACTION_TRIGGER_IDLE);
context.registerReceiver(this, filter);
context.registerReceiver(this, filter, null, JobSchedulerBackgroundThread.getHandler());
}
@Override

View File

@@ -31,6 +31,7 @@ import android.util.Log;
import android.util.Slog;
import android.util.proto.ProtoOutputStream;
import com.android.server.JobSchedulerBackgroundThread;
import com.android.server.am.ActivityManagerService;
import com.android.server.job.JobSchedulerService;
import com.android.server.job.StateControllerProto;
@@ -47,8 +48,8 @@ public final class DeviceIdlenessTracker extends BroadcastReceiver implements Id
private AlarmManager mAlarm;
private PowerManager mPowerManager;
// After construction, mutations of idle/screen-on state will only happen
// on the main looper thread, either in onReceive() or in an alarm callback.
// After construction, mutations of idle/screen-on/projection states will only happen
// on the JobScheduler thread, either in onReceive(), in an alarm callback, or in on.*Changed.
private long mInactivityIdleThreshold;
private long mIdleWindowSlop;
private boolean mIdle;
@@ -101,12 +102,10 @@ public final class DeviceIdlenessTracker extends BroadcastReceiver implements Id
filter.addAction(Intent.ACTION_DOCK_IDLE);
filter.addAction(Intent.ACTION_DOCK_ACTIVE);
context.registerReceiver(this, filter);
context.registerReceiver(this, filter, null, JobSchedulerBackgroundThread.getHandler());
// TODO(b/172579710): Move the callbacks off the main executor and on to
// JobSchedulerBackgroundThread.getExecutor() once synchronization is fixed in this class.
context.getSystemService(UiModeManager.class).addOnProjectionStateChangedListener(
UiModeManager.PROJECTION_TYPE_ALL, context.getMainExecutor(),
UiModeManager.PROJECTION_TYPE_ALL, JobSchedulerBackgroundThread.getExecutor(),
mOnProjectionStateChangedListener);
}
@@ -226,7 +225,8 @@ public final class DeviceIdlenessTracker extends BroadcastReceiver implements Id
Slog.v(TAG, "Scheduling idle : " + reason + " now:" + nowElapsed + " when=" + when);
}
mAlarm.setWindow(AlarmManager.ELAPSED_REALTIME_WAKEUP,
when, mIdleWindowSlop, "JS idleness", mIdleAlarmListener, null);
when, mIdleWindowSlop, "JS idleness",
JobSchedulerBackgroundThread.getExecutor(), mIdleAlarmListener);
}
}