Security Research Center
User leave tracking
Guardsquare recommended technique
Technique summary | |
Technique | User leave tracking |
Against | UI injections: Activity injections |
Limitations | Does not detect view injections |
Side effects | Causes a false positive when the user initiates app switching by tapping on a system UI element, such as a notification or the quick settings |
Recommendations | Recommended for use combined with other techniques and with reaction logic that accommodates for false positives |
An algorithm to detect an activity injection consists of two parts:
- Detect that the protected activity has been deactivated
- Filter out the cases when the protected activity was deactivated intentionally
The user leave tracking, or ULT technique defines intentional as:
- The user has pressed a button or performed a gesture to switch away from the protected activity, or
- The application where the protected activity is has initiated opening of another internal or external activity.
Deactivation detection
To detect that the protected activity was deactivated, ULT uses the onPause()
method override.
Sometimes the reason for the activity switch is immediately clear (for example, if the protected application initiated the launch of a different activity). In this case, the decision to allow the activity switch can be made immediately.
However, in other cases, the reason cannot be determined on the spot. For example, when the activity switch was initiated by the user clicking the Home button, some time may pass before the protected application receives a broadcast message. For the latter case, onPause()
implementation must launch a thread that would detect valid reasons to switch after the activity was paused.
Intentional switch detection
To detect that the protected activity was switched out intentionally, a number of events have to be intercepted:
- Android buttons:
- For the Back button, override the
onBackPressed()
method. - For the Home and Recents buttons, register a broadcast receiver.
- For the Back button, override the
- Activity launch from the protected application:
- Intercept every instance of the protected application starting activities. For example, using
ActivityMonitor
(see Android documentation).
- Intercept every instance of the protected application starting activities. For example, using
In general, it is not possible to determine whether the activity switch was done as a direct consequence of the user’s or program’s action. Instead, ULT will attribute the switch to the action if it happened shortly after the switch. To do this, you can use a regular timer.
Check algorithm
Code highlights
The explanation here omits many of the implementation details in order to better highlight the general approach of the check. We address the important parts of the implementation but exclude the more mechanical details for the sake of brevity.
Handle OnPause()
to detect activity deactivation:
Handle buttons to detect intentional switch:
Add activity monitoring:
Note
False positives may occur if the user takes advantage of system UI (such as notifications) to switch between apps.
As the action on detection is a soft block (such as a warning message or bringing the obscured activity back on top), having a false positive does not entail severe consequences.
Further reading
See Android documentation on: