Skip to content

SimonMarquis/SleepTimer

Repository files navigation

Sleep Timer

Android CI Google Play F-Droid

Quick Settings Tile Notification
Tile Notification

Sleep Timer helps you fall asleep while listening to music or podcasts.
When the timer stops, audio playback is gradually lowered then paused.

Usage

  1. Add the Tile in the Quick Settings panel.
  2. Tap the Tile to start a timer.
  3. Extend, reduce or cancel the timer with the notification actions.

Note: Don't look for a launcher icon, this app only provides a Quick Settings Tile.

Automation

You can trigger the Sleep Timer with tools like Tasker or by using adb commands:

  • Start the timer
    adb shell am broadcast -a fr.smarquis.sleeptimer.action.START -n fr.smarquis.sleeptimer/.SleepActionReceiver
  • Start the timer with custom duration (10 min)
    adb shell am broadcast -a fr.smarquis.sleeptimer.action.START -n fr.smarquis.sleeptimer/.SleepActionReceiver --el extras:duration 600
  • Update the timer (-1 min)
    adb shell am broadcast -a fr.smarquis.sleeptimer.action.UPDATE -n fr.smarquis.sleeptimer/.SleepActionReceiver --el extras:duration -60
  • Stop the timer
    adb shell am broadcast -a fr.smarquis.sleeptimer.action.STOP -n fr.smarquis.sleeptimer/.SleepActionReceiver
  • Increment (default +10 min)
    adb shell am broadcast -a fr.smarquis.sleeptimer.action.INCREMENT -n fr.smarquis.sleeptimer/.SleepActionReceiver
  • Decrement (default -10 min)
    adb shell am broadcast -a fr.smarquis.sleeptimer.action.DECREMENT -n fr.smarquis.sleeptimer/.SleepActionReceiver

APIs

Important

Android 17 introduced Background audio hardening which prevents calling AudioManager.adjustStreamVolume(streamType, direction, flags) from a background thread.
And the system does not allow PendingIntent used in Notification.Builder.setDeleteIntent(intent) to reference a foreground Service.
Therefore, an alarm must be scheduled at a precise time to trigger such foreground Service and pause audio playback.

License

Copyright 2020 Simon Marquis

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed: in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.