Home > Tricks & Tips > The Magic behind App Protector Application

The Magic behind App Protector Application

As you see on Google Play Store, there’re various app protector applications like:

+ Perfect App Protector

+ Smart App Protector

+ App Lock

+ Smart AppLock

+ App Defender

+ Secret App Lock Pro

+ ZDBox

… and many more.

But how do they work actually?

After two days of investigation through these apps on Play Store, I’ve found the machenism.

Basically, the App Protector (so called AP) need to create a Service that runs in background to detect whether a locked application is launched or not.

Also, there are two ways I found to detect when an application is launched.

1) Using the Top Task:

– First refer to this documentation on Google Android Developers about ActivityManager.RunningTaskInfo

– In description, all running tasks on Android phone are put in a stack, so the launching application should be somehow on the top, which displays on mobile screen currently. By this way, you can detect the launching application.

RunningTaskInfo topTask = actMgr.getRunningTasks(1).get(0);

– I have tried many times and not sure when it can fail, so I assume it works as my expectation.

2) Monitor the Logcat:

– If you read Logcat, when an application is launched there should be some lines like this:

I/ActivityManager( 1269): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.andrew.apollo/.activities.MusicLibrary bnds=[240,557][360,707]} from pid 18431

– This is the clue, so the Service needs to monitor the Logcat continuously for this. Of course, parsing the Logcat for the time being.

– Here the Logcat command to filter the above line:

$ logcat ActivityManager:I *:S
$ logcat -c

– Remember to clear after each parsing.

– I guess you can write your own piece of code to parse.


(*) Note: if you want to try it, then you will see the difficult problems when to lock, when to unlock, when to detect app state…so please don’t ask me about this, because it’s your own math logic. But it’s fun to test IQ though.

Anyway, make your own App Protector and share your concepts and techniques!


Pete Houston



  1. Ankit Gaur
    March 25, 2016 at 6:53 pm

    Can you suggest me the code to be implemented in service so that i can run a code repetitively to check the top activity.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: