Wake up delay of IDLE Alarm in Doze mode

Posted by gilgimech on Thu, 02 Jan 2020 18:15:15 +0100

1. Simulation enters into Doze mode

  1. Set no charge state
adb shell dumpsys battery unplug
  1. Set forced entry depth module
adb shell dumpsys deviceidle force-idle deep
  1. Set alarm log on
adb shell dumpsys alarm log on

Then we can connect USB and view the log behavior dynamically in logcat.

2. IDLE Alarm wake-up delay in doze mode

An alarm clock of type=2 is set in the calendar interface. The time is 19:06, but idle cannot wake up if it has to be sent

Only see the settings, not the trigger

2018-08-22 19:04:28.710 934-1401/? V/AlarmManager: set(PendingIntent{9a425b2: PendingIntentRecord{80c7903 com.xxx.calendar broadcastIntent}}) : type=2 triggerAtTime=266359 win=0 tElapsed=270360 maxElapsed=266359 interval=0 flags=0x1
2018-08-22 19:04:28.712 934-1401/? V/AlarmManager: set(PendingIntent{580a080: PendingIntentRecord{80c7903 com.xxx.calendar broadcastIntent}}) : type=2 triggerAtTime=266361 win=0 tElapsed=270362 maxElapsed=266361 interval=0 flags=0x1

3. Normal wake-up log in doze mode

Set a type=0 and 1534936865974 [2018-08-22 19:21:05.974] to wake up at any time, and the log will wake up on time with an error of 1ms

// Set a type=0 and1534936865974[2018-08-22 19:21:05.974]Wake up on time
2018-08-22 19:17:05.975 934-1422/? V/AlarmManager: set(PendingIntent{20d5a62: PendingIntentRecord{b0587f3 com.android.xxx.powersave startService}}) : type=0 triggerAtTime=1534936865974(2018-08-22 19:21:05.974Wake-up call win=0 tElapsed=1262624 maxElapsed=1262624 interval=0 flags=0x9
2018-08-22 19:21:05.974 934-1067/? V/AlarmManager: Checking for alarms... rtc=1534936865974, elapsed=1262624
// Wake up on time, error1ms
2018-08-22 19:21:05.975 934-1067/? V/AlarmManager: Triggering alarm #0: Alarm

{72bd3ba type 0 when 1534936865974 com.android.xxx.powersave}
2018-08-22 19:21:05.978 934-1067/? V/AlarmManager: sending alarm Alarm{72bd3ba type 0 when 1534936865974 com.android.xxx.powersave}
2018-08-22 19:21:05.978 934-1067/? D/AlarmManager: wakeup alarm = Alarm

{72bd3ba type 0 when 1534936865974 com.android.xxx.powersave}
; package = com.android.xxx.powersave, needGrouping = false

The normal timer code is as follows

    public static void starAlarmTaskByService(Context context, int intervalMinute, Intent intent) {
        AlarmManager mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        long triggerAtMillis = System.currentTimeMillis() + (intervalMinute * 60 * 1000);

        PendingIntent operation = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            mAlarmManager.setExact(AlarmManager.RTC_WAKEUP, triggerAtMillis, operation);
        } else {
            mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerAtMillis, operation);
        }
    }

Topics: Android shell