Skip to content

A simple app to keep alive specific apps by attempting to start them periodically.

License

Notifications You must be signed in to change notification settings

hossain-khan/android-keep-alive

Repository files navigation

Android CI License releases

Keep Alive 💓

A simple app to keep specific apps alive by checking if they are running. If not, they will be started for you.

⚠️ DISCLAIMER: The app is mostly generated with AI (copilot, gemini, chatgpt, etc). It doesn't follow any best practices. See CONTRIBUTING guide for more info.

🛑 STOP 🛑 - Know before you use ✋

This app is designed with a very specific use case in mind. It is important to understand what this app does and how.

  • App is designed to be always running in the foreground to watch and restart other applications.
  • App is NOT optimized for battery and will cause high battery 🪫 drain. Ideally, this should not be used on your primary phone that you use daily.
    • ℹ️ I use this on a secondary phone plugged into a power cable 24/7.
  • App contains some additional features like Remote Logging and Heartbeat due to my personal needs. However, the app can be used without enabling those features.
  • See the permission section below to better understand the app.

Limitations 💔

Despite having many needed permissions, this app may still not work due to the strict security of Android.

  • One known issue is related to receiving RECEIVE_BOOT_COMPLETED event that is needed to start the watchdog service of this app. However, the RECEIVE_BOOT_COMPLETED event is not delivered until user unlocks the device after phone is restarted or incase phone got soft-started because of very low memory pressure.
    • In that case, this "Keep Alive" app will fail to start configured apps until the device is unlocked manually. (See #70 for technical details)

📚 How to use the app

  1. Launch the app and accept all the required permissions.
  2. Once all permission are active, you will see 2 options
    1. Configure apps that should be running
    2. Configure app settings like interval of checking for app
  3. Add app that you want to be checked periodically
  4. Done ✔️
    1. This app will always run in the foreground, continuously checking if your selected apps are active. If any are not, it will automatically restart them for you.

Keep Alive App

🔐 Sensitive permissions required ⚠️

Here is the list of permissions needed for the service class (WatchdogService). [Source: AndroidManifest.xml]

Here are the permissions needed for the app along with a summary of why they are needed:

  1. android.permission.INTERNET:

    • Reason: Required to send logs to an API endpoint and send heartbeat check. Both are optional and configurable in the app.
  2. android.permission.FOREGROUND_SERVICE:

    • Reason: Allows the app to run a foreground service, which is necessary for the WatchdogService to monitor other apps and keep them alive by restarting them.
  3. android.permission.FOREGROUND_SERVICE_SPECIAL_USE:

    • Reason: Required for special use cases of foreground services, as indicated by the WatchdogService.
  4. android.permission.RECEIVE_BOOT_COMPLETED:

    • Reason: Allows the app to receive the BOOT_COMPLETED broadcast, enabling it to start itself and monitor the apps that are configured to keep alive.
  5. android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS:

    • Reason: Needed to request the user to exclude the app from battery optimizations, ensuring the app and it's WatchdogService can run continuously without being restricted by the system.
  6. android.permission.POST_NOTIFICATIONS:

    • Reason: Allows the app to post notifications, which is essential for notifying users about ongoing watchdog activity.
  7. android.permission.QUERY_ALL_PACKAGES:

    • Reason: Required to query and interact with all installed packages, which is necessary for the app's functionality to monitor and select apps in the app settings.
  8. android.permission.PACKAGE_USAGE_STATS:

    • Reason: Allows the app to access usage statistics, which is necessary for knowing if specific apps have been recently used.
  9. android.permission.SYSTEM_ALERT_WINDOW:

    • Reason: Required to draw overlays on top of other apps, which is necessary for certain UI elements or notifications that need to be displayed over other apps. And also start other apps from the background service.

Most of the permissions listed above are discouraged and or restricted. Please be sure to use the app with caution.