Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em>Edited to elaborate on the solution</em></p> <p><strong>Overview</strong></p> <p>My simple solution was to add a new service and activity to my application. The service uses <a href="http://developer.android.com/reference/android/os/Handler.html" rel="noreferrer"><code>Handler</code></a> and <a href="http://developer.android.com/reference/android/os/Handler.html#postDelayed%28java.lang.Runnable,%20long%29" rel="noreferrer"><code>postDelayed</code></a> to continuously schedule the monitoring task. The monitoring task checks that the current activity is on the whitelist. Getting the currently running activity involves <a href="http://developer.android.com/reference/android/app/ActivityManager.html" rel="noreferrer"><code>ActivityManager</code></a> and a call to <a href="http://developer.android.com/reference/android/app/ActivityManager.html#getRunningTasks%28int%29" rel="noreferrer"><code>getRunningTasks</code></a>. After finishing the check, the monitoring task schedules itself to run again after X seconds (1, in my case).</p> <p>If the activity on top is not on the whitelist, we launch the blocking activity which pops up over whatever is currently running. The key part of the blocking activity is that it overrides <a href="http://developer.android.com/reference/android/app/Activity.html#onBackPressed%28%29" rel="noreferrer"><code>onBackPressed</code></a>, preventing the user from simply going back to the "bad" activity. Pressing the Home key is the only way (to my knowledge) to leave this screen.</p> <p><strong>Tips</strong></p> <ul> <li>Build a backdoor into the lock screen. For example, my solution prompts for a password on a long-press of the back key. After entering the correct password, the monitor service goes to sleep for 5 minutes so I can do my administrative work</li> <li>Display the name of the blocked activity</li> <li>Gather a good whitelist before turning this on! Activities you should definitely whitelist: the launcher, package installer, your own app (obviously), the browser, if your app has a web-based component</li> </ul> <p>I don't like that my service is constantly looping in the background; it seems wasteful. I'd like to find some way to be notified when a new task is being launched, but I couldn't find a way to do that. The battery usage for my particular value of the monitor period and my particular phone is acceptable; though you should definitely test before adopting this yourself.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload