privatelong mNextWakeup; // 下一个包含 wakeup 的 batch 的开始时间 privatelong mNextNonWakeup; // 下一个包含 no wake up 的 batch 的开始时间 privatelong mLastWakeupSet; privatelong mLastWakeup;
boolean mInteractive = true; // 熄屏亮屏状态,亮屏为 true
long mNonInteractiveStartTime; // 熄灭屏幕的开始时间; long mNonInteractiveTime; // 熄灭屏幕的最长时间间隔;
long mLastAlarmDeliveryTime; // 上一个 alarm 的分发时间! long mStartCurrentDelayTime; // 需要延迟执行的非 wake up 类型的 alarm 开始延迟的时间! long mNextNonWakeupDeliveryTime; // 下一次非 wake up 类型的 alarm 分发时间!
long mLastTimeChangeClockTime; // 上一次时间发生改变的时间点,取值为 System.currentTimeMillis(); long mLastTimeChangeRealtime; // 上一次时间发生改变的时间点,取值为 SystemClock.elapsedRealtime();
long mAllowWhileIdleMinTime; // 可以开始执行 flag 为 ALLOW_WHILE_IDLE 的 alarm 的最小时间间隔!
long mTotalDelayTime = 0; long mMaxDelayTime = 0; //
int mNumTimeChanged; // 时间改变的次数! int mNumDelayedAlarms = 0;
// 延迟执行的 no wake up 类型的 alarm 列表! ArrayList<Alarm> mPendingNonWakeupAlarms = new ArrayList<>();
// 正在执行中的 alarm 列表! ArrayList<InFlight> mInFlight = new ArrayList<>();
/** * For each uid, this is the last time we dispatched an "allow while idle" alarm, * used to determine the earliest we can dispatch the next such alarm. */ final SparseLongArray mLastAllowWhileIdleDispatch = new SparseLongArray();
final ArrayList<IdleDispatchEntry> mAllowWhileIdleDispatches = new ArrayList();
privatefinal SparseArray<AlarmManager.AlarmClockInfo> mNextAlarmClockForUser = new SparseArray<>(); privatefinal SparseArray<AlarmManager.AlarmClockInfo> mTmpSparseAlarmClockArray = new SparseArray<>(); privatefinal SparseBooleanArray mPendingSendNextAlarmClockChangedForUser = new SparseBooleanArray(); /** * The current set of user whitelisted apps for device idle mode, meaning these are allowed * to freely schedule alarms. */ int[] mDeviceIdleUserWhitelist = newint[0];
ArrayList<Alarm> mPendingWhileIdleAlarms = new ArrayList<>();
final SparseArray<ArrayMap<String, BroadcastStats>> mBroadcastStats = new SparseArray<ArrayMap<String, BroadcastStats>>(); // May only use on mHandler's thread, locking not required. privatefinal SparseArray<AlarmManager.AlarmClockInfo> mHandlerSparseAlarmClockArray = new SparseArray<>(); final LinkedList<WakeupEvent> mRecentWakeups = new LinkedList<WakeupEvent>();
final HashMap<String, PriorityClass> mPriorities = new HashMap<>();
// // alarm批处理对象列表 final ArrayList<Batch> mAlarmBatches = new ArrayList<>();
// 时间比较器! staticfinal IncreasingTimeOrder sIncreasingTimeOrder = new IncreasingTimeOrder();
staticfinal BatchTimeOrder sBatchOrder = new BatchTimeOrder();
final Comparator<Alarm> mAlarmDispatchComparator = new Comparator<Alarm>() { @Override publicintcompare(Alarm lhs, Alarm rhs){ // priority class trumps everything. TICK < WAKEUP < NORMAL if (lhs.priorityClass.priority < rhs.priorityClass.priority) { return -1; } elseif (lhs.priorityClass.priority > rhs.priorityClass.priority) { return1; }
// within each class, sort by nominal delivery time if (lhs.whenElapsed < rhs.whenElapsed) { return -1; } elseif (lhs.whenElapsed > rhs.whenElapsed) { return1; }
// same priority class + same target delivery time return0; } };
finallong RECENT_WAKEUP_PERIOD = 1000L * 60 * 60 * 24; // one day
// minimum recurrence period or alarm futurity for us to be able to fuzz it staticfinallong MIN_FUZZABLE_INTERVAL = 10000;
// set to null if in idle mode; while in this mode, any alarms we don't want // to run during this time are placed in mPendingWhileIdleAlarms Alarm mPendingIdleUntil = null;