If you’ve ever worked with AlarmManager, you may know that it’s not so easy to test that the alarms are really working. And the things got even worse with the new battery optimization techniques introduced in the latest releases of Android. Read Pablo Guardiola’s blog post to get the whole picture and realize the problem. I’m not going to explain how to create and set the alarms to fire at some time in this post. I’m going to explain how you can test that the alarms will really fire.

There’s a command you can run to check the alarms that are set on the connected device and also some important info about them.

adb shell dumpsys alarm

Try running this and you’ll discover all the alarms that are set by all the apps on your device and some data about them as well as statistics.

To see the alarms from you app you can grep with your package keywords:

adb shell dumpsys alarm | grep -A 3 google

So now you can see if you have correctly implemented your alarms functionality using AlarmManager API. Or at least see that the alarms are scheduled at the time you expected.

Next, you may sit and wait for the alarm to appear in status bar.

Wait? Why should I wait, “I’m going to set the exact time on the device” — you may say. You will go Settings -> Date and Time -> set date, set time. And wait at least 1 minute since you can’t change seconds in settings.

However, sometimes you may find that the alarms are not firing at the right time, or the phone goes into power save mode, etc. And you will start doing the date&time change through commandline:

adb shell ‘su 0 date -s 20160530.213000’

This command will immediately set the date&time on the device, rooted device, saving you some time of settings navigation. Nice!

But even that could be not enough and you may want to do your tests faster or easier. And here we meet.

I passed through all above described stages and at this point decided to write some damn simple program — ADB Date Changer. And later to share it with the community to help other people save their time.

What it does is exactly this, you pick some date&time and it runs the adb shell command to set the time right to your phone.

You can download it here

Just uncompress the zip file and run the app. If you see the OS X alert about unknown developer, go security settings and allow this app run clicking on “Open anyway”.