I've tried googling, and looking on stackoverflow as well, but I can't seem to find any satisfying answer as to how the "App lock" applications(eg: ZDBox, App Lock, etc..) work. Is there a service that runs in the background continuously polling to see if the app is launched and tries to kill it? Or is there a way to intercept launch intents for new activities?
there is a service running in the background to read the activity stack. if find new activity, will start the passwordActivity
they are watching logcat output. whenever you start an activity, you can find specific logcat. like this,
I/ActivityManager( 585): Starting activity: Intent { action=android.intent.action...}
if this logcat printed by locked app, locker service starts password screen.
MORE MODERN ANSWER (Nov 2022):
This can be handled by the new app usage API
The system collects the usage data on a per-app basis, aggregating the data over daily, weekly, monthly, and yearly intervals. The maximum duration that the system keeps this data is as follows:
Daily data: 7 days Weekly data: 4 weeks Monthly data: 6 months Yearly data: 2 years For each app, the system records the following data:
The last time the app was used
The total length of time the app was in the foreground for that time interval (by > day, week, month, or year)
Timestamp capturing when a component (identified by a package and activity name) ?> moved to the foreground or background during a day
Timestamp capturing when a device configuration changed (such as when the device orientation changed because of rotation)
A background service can be used to constantly watch for updates to timestamps for specific apps regarding when they moved to the foreground with the API above.
note: It seems that starting from Android 5/6/7 and higher you cannot read info about other apps, including their status and logs. I believe this makes looking in logcat no longer work. If anyone can confirm this please comment below! Also, the getRunningTasks function to view active activities is now deprecated.
© 2022 - 2024 — McMap. All rights reserved.