There is a bug with quiet time in the (7.2.5) Android SDK that I believe still exists in the latest version (8.0.2) and I would like to verify that someone has it working properly.

The bug happens when the start and end times for quiet time extend into the next/previous day.  ( Example: Start time - 10PM,  End time - 8AM ).  In this case, the Date objects returned by PushManager.getQuietTimeInterval() have dates set that cause all calls to PushMananger.isInQuietTime() to always return true.

Example: On Sept 5th,   Quiet time start - Sept 4th @ 10PM,  Quiet time end - Sept 6th @ 8AM.

 

I believe this bug is only partially fixed in 8.0.2.  In this case, there are two QuietTime time intervals in which no alerts should occur.

Example: On Sept 5th,

QuietTime 1 interval: [ Quiet time 1 start - Sept 4th @10PM, Quiet time 1 end - Sept 5th @8AM ]

QuietTime 2 interval: [ Quiet time 2 start - Sept 5th @ 10PM, Quiet time 2 end - Sept 6th @ 8AM]

In 8.0.2, PushManager.isInQuietTime() will incorrectly return false during the QuietTime 1 interval from 12AM to 8AM.

 

Has anyone else had this problem or am I misunderstanding how to use Quiet Time?

To work around this bug, I wrote my own isInQuietTime() function which has been working properly.

private boolean isInQuietTime() {
if(!UAirship.shared().getPushManager().isQuietTimeEnabled()) {
return false;
} else {
Date[] quietTimeInterval = UAirship.shared().getPushManager().getQuietTimeInterval();
if(quietTimeInterval != null && quietTimeInterval.length > 1) {
Calendar now = Calendar.getInstance();
int nowDay = now.get(Calendar.DAY_OF_YEAR);

// Get QuietTime start time and set today's date
Calendar startCalTime = Calendar.getInstance();
startCalTime.setTime(quietTimeInterval[0]);
startCalTime.set(Calendar.DAY_OF_YEAR, nowDay);

// Get QuietTime end time and set today's date
Calendar endCalTime = Calendar.getInstance();
endCalTime.setTime(quietTimeInterval[1]);
endCalTime.set(Calendar.DAY_OF_YEAR, nowDay);

if(endCalTime.after(startCalTime)) {
// Start and End occur sequentially, check if Now is in that range
return now.after(startCalTime) && now.before(endCalTime);
} else {
// End occurs before Start, check if Now is NOT in that range
return now.after(startCalTime) || now.before(endCalTime);
}
}
}
return false;
}

Didn't find what you were looking for?

New post

Comments

11 comments

  • Hi Ben!

    I think there might be some confusion on the Quiet Time flags.

    Specifically, the QuietTimeEnabled flag is something that you or the user controls, not the start and end times.

    In other words, that flag acts almost like a preference or switch. It is very similar to the "Do Not Disturb" on iOS where you can turn it on and determine what the start and end times are.

    So, if QuietTimeEnabled is set to false, any of the QuietTime functionalities will not work.

    If you set QuietTimeEnabled to true, then, then the QuietTime intervals will work properly.

    Can you confirm if/where you're setting QuietTime enabled to true? That might help clear things up a bit.

    Comment actions Permalink
    0
  • Hi Michael,

      Thank you for the quick response.  In our app settings tab, we have a "Quiet time" CheckBox that the user can touch to enable quiet time.  This calls:

    UAirship.shared().getPushManager().setQuietTimeEnabled(true);

    Then we display time controls in which the user can set the start and end times.  We then set these with:

    UAirship.shared().getPushManager().setQuietTimeInterval(startDate, endDate);

     

    Everything currently works as expected when the start/end times occur sequentially (Start: 1PM,  End: 2PM).  The problem only happens when the times are not sequential (Start: 2PM - End: 1PM). 

    Comment actions Permalink
    0
  • Ben,

    Just to clarify, when the time interval is not sequential, like you posted, you're seeing that when making a call to isInQuietTime is not returning the correct boolean, correct?

     

    Comment actions Permalink
    0
  • Hi Michael,

      Yes, that is correct.

    Comment actions Permalink
    0
  • Hi Ben,

    Just to update you, I'm looking into this right now with our Mobile team. I'm suspecting that we've missed a condition in that method, so that might be why yours works, and not ours. Once I've got something for you, I'll let you know, so stay tuned!

    Comment actions Permalink
    0
  • Ben,

    For troubleshooting purposes, would you be able to put in some logging output so we can see what each situation returns? I like logic tables as much as anyone else, but logging is good too :)

    Comment actions Permalink
    0
  • Yes, I can do that.  I'll post up some logs for each case shortly.  Thank you.

    Comment actions Permalink
    0
  • Here is a small section of the log that shows the problem.  Let me know if you need more.  In it, I set four different QuietTime intervals. I also log out:

    1) the dates I am setting

    2) the saved dates returned by calling PushManager.getQuietTimeInterval()

    3) the result from calling PushManager.getIsInQuietTime()

    4) the result from calling my custom getIsInQuietTime()

     

    10-12 15:31:40.665 11077-11119/com.testapplication I/Breaking (Debug) - UALib: Airship taking off!
    10-12 15:31:40.665 11077-11119/com.testapplication I/Breaking (Debug) - UALib: Airship log level: 3
    10-12 15:31:40.665 11077-11119/com.testapplication I/Breaking (Debug) - UALib: UA Version: 8.0.2 / App key = xxxxxxxxxxxxx Production = false
    10-12 15:31:40.715 11077-11119/com.testapplication D/Breaking (Debug) - UALib: RichPushUser - Updating user.
    10-12 15:31:40.765 11077-11119/com.testapplication D/Breaking (Debug) - UALib: Analytics - New session: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    10-12 15:31:40.775 11077-11119/com.testapplication I/Breaking (Debug) - UALib: Airship ready!
    10-12 15:31:40.775 11077-11077/com.testapplication I/Breaking (Debug) - UALib: App APID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    10-12 15:31:52.085 11077-11330/com.testapplication D/Breaking (Debug) - UALib: Analytic events uploaded.
    10-12 15:32:20.485 11077-11328/com.testapplication V/Breaking (Debug) - UALib: PreferenceDataStore - Saving preference: com.urbanairship.push.QUIET_TIME_ENABLED value: true

    - Sequential Time with current time in Quiet Time - *CORRECT*
    10-12 15:33:06.575 11077-11077/com.testapplication E/QuietTimeTest: Setting Start to: Wed Oct 12 14:00:06 PDT 2016
    10-12 15:33:06.575 11077-11077/com.testapplication E/QuietTimeTest: Setting End to: Wed Oct 12 16:00:06 PDT 2016
    10-12 15:33:06.575 11077-11077/com.testapplication E/QuietTimeTest: Saved Start: Wed Oct 12 14:00:00 PDT 2016
    10-12 15:33:06.575 11077-11328/com.testapplication V/Breaking (Debug) - UALib: PreferenceDataStore - Saving preference: com.urbanairship.push.QUIET_TIME_INTERVAL value: {"end_hour":16,"end_min":0,"start_hour":14,"start_min":0}
    10-12 15:33:06.575 11077-11077/com.testapplication E/QuietTimeTest: Saved End: Wed Oct 12 14:00:00 PDT 2016
    10-12 15:33:06.585 11077-11077/com.testapplication E/QuietTimeTest: UAirship.isInQuietTime(): true
    10-12 15:33:06.585 11077-11077/com.testapplication E/QuietTimeTest: Custom isInQuietTime(): true

    - NON-Sequential Time with current time After Quiet Time End - *CORRECT*
    10-12 15:34:54.035 11077-11077/com.testapplication E/QuietTimeTest: Setting Start to: Wed Oct 12 17:00:54 PDT 2016
    10-12 15:34:54.035 11077-11077/com.testapplication E/QuietTimeTest: Setting End to: Wed Oct 12 13:00:54 PDT 2016
    10-12 15:34:54.035 11077-11077/com.testapplication E/QuietTimeTest: Saved Start: Wed Oct 12 17:00:00 PDT 2016
    10-12 15:34:54.035 11077-11077/com.testapplication E/QuietTimeTest: Saved End: Wed Oct 12 17:00:00 PDT 2016
    10-12 15:34:54.035 11077-11328/com.testapplication V/Breaking (Debug) - UALib: PreferenceDataStore - Saving preference: com.urbanairship.push.QUIET_TIME_INTERVAL value: {"end_hour":13,"end_min":0,"start_hour":17,"start_min":0}
    10-12 15:34:54.045 11077-11077/com.testapplication E/QuietTimeTest: UAirship.isInQuietTime(): false
    10-12 15:34:54.045 11077-11077/com.testapplication E/QuietTimeTest: Custom isInQuietTime(): false

    - Sequential Time with current time Before Quiet Time Start - *CORRECT*
    10-12 15:35:03.645 11077-11077/com.testapplication E/QuietTimeTest: Setting Start to: Wed Oct 12 17:00:03 PDT 2016
    10-12 15:35:03.645 11077-11077/com.testapplication E/QuietTimeTest: Setting End to: Wed Oct 12 22:00:03 PDT 2016
    10-12 15:35:03.645 11077-11328/com.testapplication V/Breaking (Debug) - UALib: PreferenceDataStore - Saving preference: com.urbanairship.push.QUIET_TIME_INTERVAL value: {"end_hour":22,"end_min":0,"start_hour":17,"start_min":0}
    10-12 15:35:03.645 11077-11077/com.testapplication E/QuietTimeTest: Saved Start: Wed Oct 12 17:00:00 PDT 2016
    10-12 15:35:03.645 11077-11077/com.testapplication E/QuietTimeTest: Saved End: Wed Oct 12 17:00:00 PDT 2016
    10-12 15:35:03.655 11077-11077/com.testapplication E/QuietTimeTest: UAirship.isInQuietTime(): false
    10-12 15:35:03.655 11077-11077/com.testapplication E/QuietTimeTest: Custom isInQuietTime(): false

    - NON-Sequential Time with current time Before QuietTime End - *INCORRECT*
    10-12 15:35:07.755 11077-11077/com.testapplication E/QuietTimeTest: Setting Start to: Wed Oct 12 17:00:07 PDT 2016
    10-12 15:35:07.755 11077-11077/com.testapplication E/QuietTimeTest: Setting End to: Wed Oct 12 16:00:07 PDT 2016
    10-12 15:35:07.755 11077-11077/com.testapplication E/QuietTimeTest: Saved Start: Wed Oct 12 17:00:00 PDT 2016
    10-12 15:35:07.755 11077-11077/com.testapplication E/QuietTimeTest: Saved End: Wed Oct 12 17:00:00 PDT 2016
    10-12 15:35:07.755 11077-11328/com.testapplication V/Breaking (Debug) - UALib: PreferenceDataStore - Saving preference: com.urbanairship.push.QUIET_TIME_INTERVAL value: {"end_hour":16,"end_min":0,"start_hour":17,"start_min":0}
    10-12 15:35:07.765 11077-11077/com.testapplication E/QuietTimeTest: UAirship.isInQuietTime(): false
    10-12 15:35:07.765 11077-11077/com.testapplication E/QuietTimeTest: Custom isInQuietTime(): true

    Comment actions Permalink
    0
  • Ben,

    Update #2, our Mobile team is investigating currently. Once I have a response from them, I'll update you here.

    Comment actions Permalink
    0
  • Fixed in 8.0.3. Thanks for reporting the issue!

    Comment actions Permalink
    0
  • Great! Thank you for your quick response into this.

    Comment actions Permalink
    0

Please sign in to leave a comment.