开发者

How to implement an app locker in android?

开发者 https://www.devze.com 2023-03-03 01:19 出处:网络
I am not satisfied with any of the app locker programs for Android that I have found and would like to create my own, but I am having trouble figuring out how to implement the actual lock.How does one

I am not satisfied with any of the app locker programs for Android that I have found and would like to create my own, but I am having trouble figuring out how to implement the actual lock. How does one go about implementing an app locker for Android?

There are two issues:

  1. Detecting an Intent, usually from the launcher calling startActivity() or from an ad launching the market app (I'm not talking about broadcast intents -- I need to handle explicit Activity Intents).

    • The permissions for the locker apps I have seen all have "read system log files" and/or "retrieve running applications" which suggests they might use polling to look for app launches. I think I could do this, but I would like to find a better solution if possible.
  2. Preventing the locked app from processing the Intent. I would prefer not to allow the locked app to run at all until the passcode is entered since it is impossible to tell what it might do when it starts up.

    • When running my current app locker, logcat shows "ActivityManager: Starting activity" first with the Intent for the locked app, then again with the Intent for the app locker, with nothing in between (separated by 10-20ms). If I enter the correct passcode then I see "ActivityManager: moveTaskToBack".
    • I have experimented with a test app which demonstrates that, using my current app locker, none of the Activity callbacks are invoked if the app is locked and I do not enter the correct passcode. So it appears to be preventing the app from starting (but I don't know how).
    • I could use ActivityManager.killBackgroundProcesses() to stop an app, but I have no guarantee that the app hasn't already started running by the time it gets "killed".
    • I might be able to use PackageManager.setApplicationEnabledSetting() to prevent an app from being instantiated, but I don't think that will take care of apps that are already running (which shouldn't be allowed to process new Intents or come to the foreground). I might be able to use killBackgroundProcesses() to stop all running locked processes so they would have to be re-instantiated. But I don't like this approach because other apps could mess with the Enabled settings and defeat the lock.
    • Optimally, the system would send every Intent to my app for inspection and allow me to stop or let it开发者_开发百科 pass through, but I'm pretty sure that's not possible (at least, not for explicit intents to start activities from a launcher).

Does anyone know how app locker apps are implemented, or have any bright ideas on how it could be done?


I would look into the lifecycle. Once the app in question begins to load, some activity from that package will be added to the forefront activity.

A scan of the changes in forefront activities might do the trick.

http://developer.android.com/reference/android/app/Activity.html#ProcessLifecycle

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号