Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is just an idea, and may not be fully transferable. </p> <p>Here's what an AccessibilityService can do:</p> <blockquote> <p>An accessibility service runs in the background and receives callbacks by the system when AccessibilityEvents are fired. Such events denote some state transition in the user interface, for example, the focus has changed, a button has been clicked, etc.</p> </blockquote> <p>You will be informed of the event inside <code>onAccessibilityEvent(AccessibilityEvent)</code>: </p> <pre><code>@Override public void onAccessibilityEvent(AccessibilityEvent event) { // Some event timeSinceLastInteraction = System.currentTimeMillis(); } </code></pre> <p>You could periodically log the updates:</p> <pre><code>Log.i("LOG_TIME_ELAPSED", "Last user interaction was " + ((System.currentTimeMillis() - timeSinceLastInteraction) / 1000) + " seconds ago."); </code></pre> <p>There are two ways in which you can configure your AccessibilityService:</p> <ol> <li><p>In code, inside onServiceConnected(). (API 4 onwards)</p></li> <li><p>In xml, using the <code>meta-data</code> tag in your service. (API 14 onwards)</p></li> </ol> <p>In your application's case, you could probably set <code>AccessibilityServiceInfo.eventTypes</code> to:</p> <pre><code>accessibilitySeviceInfo.eventTypes = AccessibilityEvent.TYPES_ALL_MASK; </code></pre> <p>But, TYPES_ALL_MASK will include notifications such as: AccessibilityEvent.TYPE_ANNOUNCEMENT, AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED etc. which I am guessing you do not care to intercept. So, you'll need to choose a subset of AccessibilityEvent.TYPE_X.</p> <p>Another thing you should be careful about is the notification timeout:</p> <blockquote> <p>The timeout after the most recent event of a given type before an AccessibilityService is notified.</p> <p>The event notification timeout is useful to avoid propagating events to the client too frequently since this is accomplished via <strong>an expensive interprocess call</strong>. One can think of the timeout as a criteria to determine when event generation has settled down.</p> </blockquote> <p>So, be generous with the timeout value.</p> <p>You'll find this page very helpful in case you decide to go with the AccessibilityService option: <a href="http://developer.android.com/training/accessibility/service.html" rel="nofollow">Developing an Accessibility Service</a>.</p> <p>From your comments to Chloe's answer, it seems that the device is under your control: meaning, to some extent, you don't have to rely on the user for enabling the service:</p> <blockquote> <p>The lifecycle of an accessibility service is managed exclusively by the system and follows the established service life cycle. Additionally, <strong>starting or stopping an accessibility service is triggered exclusively by an explicit user action through enabling or disabling it in the device settings</strong>.</p> </blockquote> <p>You can enable the AccessibilityService at time of deployment, and perhaps restrict access to Settings menu using an app like <a href="https://play.google.com/store/apps/details?id=com.domobile.applock" rel="nofollow">AppLock</a>. </p> <p>Another option is to check whether your AccessibilityService is enabled from time to time:</p> <pre><code>AccessibilityManager am = (AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE); List&lt;AccessibilityServiceInfo&gt; listOfServices = am.getEnabledAccessibilityServiceList( AccessibilityServiceInfo.FEEDBACK_ALL_MASK); for (AccessibilityServiceInfo asi : listOfServices) { // Check if your AccessibilityService is running } </code></pre> <p>In case the AccessibilityService has been disabled by a inquisitive/notorious user, you can lock the device by displaying a fullscreen view with text: <code>Device has been locked. Contact a Sales Rep to unlock this device</code>. </p>
 

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