9

Okay, I'm pretty sure that this is not possible but a client had asked me to do so in one of our Android application we developed for her.

What she had wanted is that if our application is running, and user navigate to:

 Settings > Manage Application > [Our Application]

, the button for "Force Stop" is disabled.

Is this possible? If it is possible, could someone point me out which way I should walk, or if it is not possible, how, using a valid argument based on facts, should I break the news to her.

Update: She just sent me a screenshot that, in her opinion, validates her request that there's an Android application that disables "Force Stop" button. How am I supposed to explain this to her?

Evernote Launcher - Force Stop disabled

Rhama Arya Wibawa
  • 250
  • 1
  • 2
  • 15
  • This is not possible in just the application code. I can only think of malicious reasons for wanting this. You would have to write your own off-shoot of the Android OS. – Spidy Feb 28 '12 at 06:59
  • Why does she want to disable that? You might be able to break it to her while presenting another way to satisfy the real desire. It may be for something like Toddler Lock; it may be acceptable if your app is immediately restarted when killed. – Julian Fondren Feb 28 '12 at 07:01
  • @JulianFondren I'm actually not entirely sure why she had wanted it in the first place. If I have to make a guess, it was because the app we had developed is not an unique app (you could find an alternative on the Market, easily), but because it's a corporate client, she didn't want her users to look for an alternative and forcing them to use her app instead. – Rhama Arya Wibawa Feb 28 '12 at 07:19
  • 2
    You realize of course, that if you had such an option, there would be another StackOverflow post entitled "How do I force stop an application that has force stop disabled?". And once that was answered, there'd be a "How do I disable force-stopping of my app, even when the user uses force-force-stop?" and so forth. Eventually, you have to accept that users like to actually, you know, *own* their devices and have control over them. – Edward Falk Aug 13 '12 at 16:09
  • 6
    p.s. Perhaps in the screen shot, Evernote wasn't actually running. You can't force stop an app that's not running in the first place. – Edward Falk Aug 13 '12 at 16:11

6 Answers6

12

How to disable the "Force Stop" button

Short answer: Use the Device Administration API.

How to explain this to my client?

Show this to your client. It is a nice slideshow providing an easy-to-understand overview of the Device Administration API and its uses.

How do I demonstrate that it works?

Yes, back to your job. Use the API link provided above and the Api Demos included in Google's sample collection to figure out how to integrate this into your app.

  1. Build the demo and run it on your device.
  2. Choose API Demos->App->Device Admin->General->Enable admin.
  3. Choose Activate once the Device Administration API prompts you with its enabling screen.
  4. Exit the app and attempt to manage the app via your device's settings menu (specifics for this step varies by device).
  5. When viewing the Api Demo's "app info" screen, you should see both Force Stop and Uninstall are disabled.

How do I do this in my own app?

Review DeviceAdminSample.java in the Api Demos app for inspiration. You will need the following:

The following code is what brings up the activation screen:

                        // Launch the activity to have the user enable our admin.
                    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
                    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminSample);
                    intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                            mActivity.getString(R.string.add_admin_extra_app_text));
                    startActivityForResult(intent, REQUEST_CODE_ENABLE_ADMIN);

However, there are a few other pieces you will need to get this to work:

  1. A broadcast receiver that derives from DeviceAdminReceiver.
  2. Entries in your manifest file that refer to the above broadcast receiver.
  3. Permissions in your manifest for using the Device Administrator API.
  4. An xml file stating what policies your app can access.

All of this can be found in the above links. Good luck with your client!

gonzobrains
  • 7,856
  • 14
  • 81
  • 132
  • I forgot to mention that I don't know how Evernote managed to allow uninstall but not force stop. My solution prevents both. I, too, would like to know how Evernote does this! – gonzobrains Jun 22 '13 at 00:14
  • Does this also prevent the app being Force Killed by the Task managers too ? – Swaroop Nov 14 '13 at 05:35
  • I found that with my sample application. Yes both "Force Stop" (What I was looking for) and "Uninstall" (Not wanted by me) have been disabled. Also observed that the app can be killed via the Eclipse DDMS. I noticed that the application automatically re-launches sometimes only when I kill. So folks who're designing their applications should make them auto-relaunchable in a fresh launch state if they were to use this. I also noticed that it wont re-launch automatically when I swipe and kill the process from the "Recent used apps shortcut" Long press home in the older phones or direct button. – Swaroop Nov 15 '13 at 10:32
  • This would also mean that the Task managers would most likely kill the application and it might not-relaunch. Verified via the processes list from Eclipse DDMS. – Swaroop Nov 15 '13 at 10:33
10

This is not remotely possible, for great reason.

You should tell her that making this possible would be a huge security disaster. Imagine what would happen if you could create apps which just ate at your processor time by holding a wake lock, and you couldn't kill them. This would be horrible.

In general, if you're wondering if you can modify the "extra-app" behavior of the device, the answer is usually *no*. You should take the viewpoint that nothing on the device is yours to control besides your app and (to a limited extent) the resources to which you're granted access.

No other app has this kind of control, so it's not reasonable to expect that your client's would either. However, the fact that she's asking for this control usually implies something else: that they are worried the user will stop the app and then something bad will happen (the locations will stop being synced, data will stop being sent out to the net, etc...). This would imply that you should look into improving the resilience of the app to different situations. Remember, your app can even be killed off at any time by Android (for example, in the case of low memory).

Kristopher Micinski
  • 7,572
  • 3
  • 29
  • 34
  • I think they wanted to "force" users to use this application instead of trying to look (and use) for another similar application elsewhere (which, given the nature of the app, there are plenty of alternatives). – Rhama Arya Wibawa Feb 28 '12 at 07:23
  • Well, that definitely counts as the exact type of behavior we really want to *not allow*! – Kristopher Micinski Feb 28 '12 at 07:26
  • so, in summation, can I say to her that this behavior is not allowed because by forcing the app to run persistently, we're going to sacrifice a lot of things. User experience, perhaps? Or do you have any other suggestions? I really don't have anyone to talk to a non-technical, business guy in my team right now :( – Rhama Arya Wibawa Feb 28 '12 at 07:38
  • I would say that in general you can't do this because it would compromise the security of the device. The device works because if you ever get into bad situations with apps, the user always has the last resort of killing the offending app off. No app on the market has this ability, so it's not unexpected that it would be disallowed. – Kristopher Micinski Feb 28 '12 at 07:40
  • Great. Thanks! Anyway, she has just sent me an example, a screenshot that shows "Evernote Launcher" has its "Force Stop" button disabled. My initial reaction was to typed in reply furiously about how the app must've been not running and therefore its "Force Stop" button wasn't enabled. But what if she's right? I mean, how confident are we that there's "No app on the market that has this ability?" – Rhama Arya Wibawa Feb 28 '12 at 07:45
  • 1
    Any app that could possibly have this would have to be supported by custom firmware, otherwise this is impossible. I'm quite confident this would be impossible, as an Android security researcher, if any app did have this ability I'd like to hear about it and investigate it :-) – Kristopher Micinski Feb 28 '12 at 07:46
  • Did you check that the app was *actually running* when she said it was not greyed out? – Kristopher Micinski Feb 28 '12 at 07:52
  • Big thanks again, but I just had one question left :) I just edited my question to include the screenshot she has just sent me and I'm not confident enough to debunk her claim. Could you take a look at it for a bit? Oh, also, physically, she is two timezones away from me. – Rhama Arya Wibawa Feb 28 '12 at 07:54
  • It's possible that the app is included in the firmware distribution, which would make it possible to "grey out" the button. If you write an app and want to install it on the phone, then you don't have this as a possibility (you don't unless your name is Sprint, Virgin Mobile, etc...). But again, make sure the app is actually running. If it's not, it can't be stopped to begin with. – Kristopher Micinski Feb 28 '12 at 07:57
  • this is possible from ics. if the app has a active device admin then force stop will be disabled – nandeesh Aug 13 '12 at 13:44
  • 1
    @nandeesh that's correct, and you can also disable it from earlier builds (if you hacked the firmware), but at the time of writing this was not the case. (I believe?) – Kristopher Micinski Aug 13 '12 at 14:33
  • 1
    This answer question needs to be revisited. – gonzobrains Oct 09 '13 at 21:47
  • 2
    @gonzobrains yup, you're right, the device admin API does add this functionality – Kristopher Micinski Oct 10 '13 at 00:15
6

I think the device screen shot has confused us. Even I can show my application that is installed on the device and the "Force Stop" button is disabled. Where as I have not done any thing specific to that.

The reason of the "Force Stop" button being disabled is, that particular application is NOT running currently. Hence there is not meaning in having the button enabled. @Rhama you can ask your client to start the application once, press the home button of the device, and goto the settings and see. Surely the "Force Stop" button will be enabled this time.

Regards,

Rajan

Rajan
  • 292
  • 2
  • 10
4

From ICS, disabling Force stop is possible. If your app has an active device admin then the framework will not allow user to kill the process

nandeesh
  • 24,740
  • 6
  • 69
  • 79
2

Hey I think it is quite possible to disable the "Force Stop" button...check Kaspersky Parental Control from the market it is doing the same. Its service is running in the background then also the force stop button is disabled.

The application service is running in background

Niraj Gupta
  • 311
  • 1
  • 4
  • 9
0

you can disable the forcestop when the app has admin rights. but soon as those admin rights are revoked then it is back to normal. however in android 4, an application called applock (domobile) was able to prevent that by asking a password when you tried to change admin rights. It could only be done by installing an extra program that applock asked you to. And I guess this might even be seen as a security flaw, infact it no longer works in Android 5.

Sina
  • 401
  • 5
  • 12