12

I have read many question about whether it is possible to prevent an Android application from starting, but all of the answers seem to be "no, you cannot".

The idea is very simple: we want the user to be able to use a restrited set of applications that will be preinstalled on his mobile device. If the user tries to start a non authorized application, he will be prompted with a dialog asking for a PIN. If he enters the right PIN, then he will be able to run the application. Otherwise, the application will not be run.

As I said before, all the answers that I could find out there fall into two categories: "you can't do that" and "you can do that by writting your own launcher application".

However, I have seen applications such as ZDBox, which allow you to do just that. That is, with ZDBox you can define "non authorized" apps, in such a way that if the user tries to start one of them, he will need to enter a PIN to actually start the app. If he fails to provide one, the app will not start. The funny thing is that ZDBox does not require root access to do this.

So my question is, how can we prevent other apps from starting, just as ZDBox does?

Knuckles the Echidna
  • 1,716
  • 3
  • 17
  • 22

1 Answers1

4

Option 1

All the examples I've seen involve running your app as a Launcher/Home Screen replacement. This is how all the child lock style apps I've used work. This has the advantage

  • Pressing Home button doesn't leave the app
  • You have control of app launching

You can check out the android Launcher2 code to see how the Android launcher works. https://android.googlesource.com/platform/packages/apps/Launcher2.git

Option 2

There does look to be one alternative that I can see. In that you can try and read the logcat entries to detect when a blacklisted app is launched or brought to foreground and then launch your app over the top.

Similar to how they detect an app launch in How to detect when the user launches another app? (Android)

Community
  • 1
  • 1
Lionel Port
  • 3,492
  • 23
  • 26
  • But ZDBox is not a launcher application. It is a standalone app that can prevent other apps from running. You can download it and try it (its free). – Knuckles the Echidna Jun 17 '13 at 06:31
  • True. Just checked it out and it doesn't replace the launcher. I've updated to add a second option to detect app launches with logcat monitoring. – Lionel Port Jun 17 '13 at 07:03
  • Hmmmm, that seems to be an interesting approach. However I do not undestand what you mean by "launching my app over the top". I mean, we can now detect the user launching an app, but how can we now prevent him from running it if he does not provide a valid PIN? – Knuckles the Echidna Jun 17 '13 at 07:14
  • If every time your monitoring service sees a black listed app being brought to foreground, you check if the pin has been entered and if not call startActivity on your pin screen activity. This will mean that you're pin lock screen will always been in the foreground. – Lionel Port Jun 17 '13 at 07:23
  • Intent dialogIntent = new Intent(getBaseContext(), PinLockActivity.class); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplication().startActivity(dialogIntent); – Lionel Port Jun 17 '13 at 07:28
  • So far so good. But there is something that does not quite convince me about this approach, which is: can we be sure that the logcat output will always be the same? – Knuckles the Echidna Jun 17 '13 at 07:44
  • Not sure if @LionelPort suggestion would work. If the user going to the application management screen and does a force close of the enter pin app, the app they then tried to open would be available. There would also be nothing to stop the user uninstalling the pin app – Boardy Jun 17 '13 at 09:20
  • @Boardy Well, I just checked that what you say is correct: you can go to the apps manager and force close ZDBox, in which case the app stops working and you can enter any application that is in theory blocked. A solution for this, I guess, is to also block the apps manager so the user cannot use it to close other apps. – Knuckles the Echidna Jun 17 '13 at 10:20
  • @KnucklestheEchidna I don't know for certain, but I wouldn't thought you would be able to control what android menu's you would be able to access such as the app management, not without being root anyway – Boardy Jun 17 '13 at 12:29
  • You can use the AlarmManager to trigger read logcat service. Then you don't have a long running background process so there is nothing to kill. Set a recurring alarm every 5s that triggers your service to read the logcat entries. – Lionel Port Jun 17 '13 at 21:51
  • @Lionel well, in that case, wouldn't it consume a lot of battery? I mean, we would be starting a service every 5 seconds. Not very sure about it, but it sounds like a lot to me. – Knuckles the Echidna Jun 18 '13 at 05:32
  • Any update on this mater? i have seen another app "Stay focused" blocking access to other apps.. – Muzafar Ali Jul 24 '16 at 07:09