return getJobState(pw);
case "heartbeat":
return doHeartbeat(pw);
+ case "trigger-dock-state":
+ return triggerDockState(pw);
default:
return handleDefaultCommands(cmd);
}
}
}
+ private int triggerDockState(PrintWriter pw) throws Exception {
+ checkPermission("trigger wireless charging dock state");
+
+ final String opt = getNextArgRequired();
+ boolean idleState;
+ if ("idle".equals(opt)) {
+ idleState = true;
+ } else if ("active".equals(opt)) {
+ idleState = false;
+ } else {
+ getErrPrintWriter().println("Error: unknown option " + opt);
+ return 1;
+ }
+
+ final long ident = Binder.clearCallingIdentity();
+ try {
+ mInternal.triggerDockState(idleState);
+ } finally {
+ Binder.restoreCallingIdentity(ident);
+ }
+ return 0;
+ }
+
@Override
public void onHelp() {
final PrintWriter pw = getOutPrintWriter();
pw.println(" Options:");
pw.println(" -u or --user: specify which user's job is to be run; the default is");
pw.println(" the primary or system user");
+ pw.println(" trigger-dock-state [idle|active]");
+ pw.println(" Trigger wireless charging dock state. Active by default.");
pw.println();
}
|| Log.isLoggable(TAG, Log.DEBUG);
// Policy: we decide that we're "idle" if the device has been unused /
- // screen off or dreaming for at least this long
+ // screen off or dreaming or wireless charging dock idle for at least this long
private long mInactivityIdleThreshold;
private long mIdleWindowSlop;
final ArraySet<JobStatus> mTrackedTasks = new ArraySet<>();
// on the main looper thread, either in onReceive() or in an alarm callback.
private boolean mIdle;
private boolean mScreenOn;
+ private boolean mDockIdle;
private AlarmManager.OnAlarmListener mIdleAlarmListener = () -> {
handleIdleTrigger();
// device in some meaningful way.
mIdle = false;
mScreenOn = true;
+ mDockIdle = false;
}
public boolean isIdle() {
// Debugging/instrumentation
filter.addAction(ActivityManagerService.ACTION_TRIGGER_IDLE);
+ // Wireless charging dock state
+ filter.addAction(Intent.ACTION_DOCK_IDLE);
+ filter.addAction(Intent.ACTION_DOCK_ACTIVE);
+
mContext.registerReceiver(this, filter);
}
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action.equals(Intent.ACTION_SCREEN_ON)
- || action.equals(Intent.ACTION_DREAMING_STOPPED)) {
+ || action.equals(Intent.ACTION_DREAMING_STOPPED)
+ || action.equals(Intent.ACTION_DOCK_ACTIVE)) {
+ if (action.equals(Intent.ACTION_DOCK_ACTIVE)) {
+ if (!mScreenOn) {
+ // Ignore this intent during screen off
+ return;
+ } else {
+ mDockIdle = false;
+ }
+ } else {
+ mScreenOn = true;
+ mDockIdle = false;
+ }
if (DEBUG) {
Slog.v(TAG,"exiting idle : " + action);
}
- mScreenOn = true;
//cancel the alarm
mAlarm.cancel(mIdleAlarmListener);
if (mIdle) {
reportNewIdleState(mIdle);
}
} else if (action.equals(Intent.ACTION_SCREEN_OFF)
- || action.equals(Intent.ACTION_DREAMING_STARTED)) {
- // when the screen goes off or dreaming starts, we schedule the
- // alarm that will tell us when we have decided the device is
+ || action.equals(Intent.ACTION_DREAMING_STARTED)
+ || action.equals(Intent.ACTION_DOCK_IDLE)) {
+ // when the screen goes off or dreaming starts or wireless charging dock in idle,
+ // we schedule the alarm that will tell us when we have decided the device is
// truly idle.
+ if (action.equals(Intent.ACTION_DOCK_IDLE)) {
+ if (!mScreenOn) {
+ // Ignore this intent during screen off
+ return;
+ } else {
+ mDockIdle = true;
+ }
+ } else {
+ mScreenOn = false;
+ mDockIdle = false;
+ }
final long nowElapsed = sElapsedRealtimeClock.millis();
final long when = nowElapsed + mInactivityIdleThreshold;
if (DEBUG) {
Slog.v(TAG, "Scheduling idle : " + action + " now:" + nowElapsed + " when="
+ when);
}
- mScreenOn = false;
mAlarm.setWindow(AlarmManager.ELAPSED_REALTIME_WAKEUP,
when, mIdleWindowSlop, "JS idleness", mIdleAlarmListener, null);
} else if (action.equals(ActivityManagerService.ACTION_TRIGGER_IDLE)) {
private void handleIdleTrigger() {
// idle time starts now. Do not set mIdle if screen is on.
- if (!mIdle && !mScreenOn) {
+ if (!mIdle && (!mScreenOn || mDockIdle)) {
if (DEBUG) {
Slog.v(TAG, "Idle trigger fired @ " + sElapsedRealtimeClock.millis());
}