Android Lollipop - prevent task manager from ending my app - android

My goal is to make my app unkillable.
Application has admin permissions granted.
I have one activity and one service.
Applionation cannot be uninstalled while Admin permission is active (thats good).
Service is auto re-creating. That's also correct.
Unfortunately on Android 5 - Lollipop user can click on all apps button - then go to Task Manager and simply END my app without any problems. After that service is destroyed for good (activity too obviously...)
Is this a way to prevent that?

1) Xposed. At the cost of execution speed and dependency on the TaskManager that you will have to reverse-engineer a bit...
2) USER_PRESENT and friends. Your application can register a BroadcastReceiver and re-start on events. That is, it will be killable, but it will restart.

I think you are interested in something like a kiosk mode: displaying a single app and preventing to break out from it.
There are various tutorials out there. This one is quite good:
http://www.andreas-schrade.de/2015/02/16/android-tutorial-how-to-create-a-kiosk-mode-in-android/
Edit: if your main target are Android 5.0+ devices you can also make use of screen pinning. http://developer.android.com/about/versions/android-5.0.html#Enterprise

Related

Not getting push notification when swipe from recent

I'm not getting notification when user swipe the app from recent. I've notice that behavior occurs in some specific device for instance I've tested it on nexus devices and HTC devices it's working fine but when user swipe the app from the recent in huawei and some samsung devices it doesn't show notification. I mean i don't get onMessageReceived() callback
After some research I found out that in these devices when user swipe it from recent it force stop the app (the process is completely killed) and I don't get any notification. In huawei they have protected and unprotected apps and if I add the app in protected list from the setting, I start getting notification because i this case it doesn't force stop the app. and I believe in samsung they have the same thing with blacklist and whitelist apps.
I've also tried some solutions like restart the service onTaskRemoved() callbacks or make your app START_STICKY. I've also tried WakefulBroadcastReceiver but nothing is working for me.
So my question is how can i get notification even if it gets forced stop, like it's happening when swiping app from recent.
An old question, but I think it’s important to know that HUAWEI has a feature called “power-intensive app monitor “. It kills every app that runs in the background for a long time unless user gives special permissions to it.
The path to do this:
Settings -> Security & privacy -> Location services -> recent location requests: YOUR APP NAME -> Battery -> uncheck Power-intensive prompt, App launch: Manage manually: check all three positions: Auto-launch, secondary launch, run in background.
I don’t know if there's a way to do this programmatically. I think the best way is to create a sort of help activity and explain the user what to do if application won’t work.

Prevent my app to sleep when device goes to sleep mode

I have written an app that should be running continually event if device goes to sleep mode.I have tried many things like services (with startForground also) , alarm manager and persistant="true", but when device go to sleep (by user or by device) , my app is terminated.and even PowerManager does not work too.
There is an option in device setting that is 'Keep running after screen off' (in huawei device : setting > app > my app options > battery > Keep running after screen off). So when this option is active , the app is running for ever.I want implement something like this in my app programitically.
I saw some apps that implemented this , but I dont know how.
So how can I do that?
Use ForgroundService.
If you check your device applications with an app manager, you can see that some of them using a sevice that is always running. even if you stop them, some of them start working again.
see more about services behavior in android developer.
and search for "keeping a service alive".
On some devices (Huawei, Xiaomi, LG) there is a special setting that contains a list of apps that are allowed to run in the background. It sounds like you are talking about trying to accomplish the same thing. This cannot be done on those devices. On those devices, unless your app is added to the list of apps that are allowed to run in the background ("Protected Apps" on Huawei), the Android framework will not restart your app if it is shutdown. There is no way for you to programatically add your app to this list, and there is no way for you to work around this feature.
Certain apps need to keep the screen turned on, such as games or movie apps. The best way to do this is to use the FLAG_KEEP_SCREEN_ON in your activity (and only in an activity, never in a service or other app component).
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Running a Service without opening the application

After 3.1 , Android introduced a security feature, where the application's code can't be run unless the user opens the application. Check the link for more info http://commonsware.com/blog/2011/07/13/boot-completed-regression-confirmed.html
I would like to know if anyone has found any hack or work around for this problem, where i can listen to a system broadcasts like boot, connectivity changed and run a service without opening the installed application.
This is not what the posts said. You can still register broadcast listeners, or alarms. You just need the user to actually start your application once. And, if the user forcefully stops your application, they'll need to start it manually again.
Why would you want a way around this behavior? It seems to make a lot of sense.

android mobile control

I don't want to do advertisement but sample app for behavior of my application is ESET antivirus.
One requested feature of my application is that for uninstall is needed password. I add my app to device admin list and it is not possible to uninstall it now. But you can Deactive app as admin device. Whan you go to Settings > Location & security > Select device administrators and you try to deactive ESET Security it starts the activity (I guess from DeviceAdminReceiver.onDisableRequested()) which is waiting for password and your mobile is locked. Home button, back button and even SwitchOff button doesn't react=>
How it is possible that Home,Back,SwitchOff and Camera button doesn't react?
EDIT - second question removed
(After I took out battery from my phone - ESET wasn't device admin too)
Thank you for ideas.
Ok, sorry ESET but this feature looks very interesting so I took a look at decompiled sources :)
The basic workflow is the following:
com.eset.ems.antitheft.receiver.AdminReceiver subclass of DeviceAdminReceiver is registered for broadcast actions DEVICE_ADMIN_ENABLED and DEVICE_ADMIN_DISABLED
When device admin is disabled com.eset.ems.antitheft.receiver.AdminReceiver.onDisabled() is called
com.eset.ems.antitheft.LockActivity is started from the AdminReceiver.onDisabled()
LockActivity shows com.eset.ems.antitheft.LockingDialog where the most blocking magic happens
As for the Home and other button block antivirus do the following trick - it uses ActivityManagerNative from Android internals. To keep LockActivity at the top of all other activities it starts a thread which contsantly calls ActivityManagerNative.moveTaskToFront() with LockActivity task ID. Prior to API level 10 reflection is used to access hidden moveTaskToFront() from ActivityManager class and after API 10 it just uses ActivityManagerNative code from Android codebase to access it.
Also both LockActivity and LockingDialog call ActivityManagerNative.closeSystemDialogs() method many times. Probably this is done in order to cancel system dialog which arises after power button long press.
As for the stopping execution of DeviceAdminReceiver.onDisableRequested actually I didn't notice anything special about it in the code. It only starts the activity after device admin is disabled and that's all. And on my phone device admin was disabled after I took the battery out.

How to Lock(Block) an android application from starting / How to stop an android application (service) from starting at boot

I would like to know if there is a way to lock (prevent) an application from starting.
And i also would like to know if there is a way to prevent a service(application) from starting at boot of the device
...i would like to know because i would like to create an anti-malware app.
I know this question is old, but for others stumbling over it:
Autostarts is an application that can disable apps from starting at boot time. It's the best I've found to do that (it isn't resident and doesn't kill processes like a task manager, it actually parses apk packages and reads registered actions and blocks the actions you tell it to). BUT it needs root and hasn't been updated for a while (december 2011). It works on Android 2.3 on which I tested it. Because it was discontinued, I don't know if it works on newer OS versions.
It's commercial now, but that's not the point, you need a peek at the source code.
If you search a bit, you'll be able to find the source code for an older version and see how it implements the blocking system.
I would be very interested in an application that could block certain services. NOT kill, but prevent them from starting in the first place. And the list is quite big: Facebook (OrcaService, MqttPushService, MediaUploadService, BackgroundDetectionService), Twitter, Maps (NetworkInitiatedService), Yahoo Mail Sync, etc. I don't use the features that the services provide, I even disabled some of them in the app interface where possible, but they still pop up and remain resident after exiting the application.
I would like to know if there is a way to lock (prevent) an application from starting.
Not in any supported fashion. Anything that does this is malware, and the techniques for doing it are security holes.
And i also would like to know if there is a way to prevent a service(application) from
starting at boot of the device
The user can boot their phone in safe mode (I forget the exact process, but it's something like holding down the HOME key while turning the phone on).

Categories

Resources