Default/System Android Processes - android

I am currently working on an Android project that monitors what applications a user is running and cross-checks the corresponding processes with a whitelist stored internally on the device.
In order to make this work, I need to know what the default or system processes for the device are so I can add them to the whitelist. That being said, I have a few questions I was hoping you might be able to answer:
Is there a way to differentiate between a default/system process that MUST be running, and a process that belongs to an app on the device?
Are there different default/system processes depending on what phone/version of android the user is running?
If so, are those process names available somewhere for developer use? Or is there some other way to obtain them?
If I need to elaborate more please let me know, thanks for the help.

Let's say that you try ActivityManager and getRunningAppProcesses(). Iterate over that array of RunningAppProcessInfo objects and find those with importance of IMPORTANCE_FOREGROUND. If the docs are correct (haven't tried this), there should only be one process that is IMPORTANCE_FOREGROUND -- the one that is truly in the UI foreground.
(services can call a startForeground() method to get foreground priority, but I am guessing they have IMPORTANCE_PERCEPTIBLE)
You could then examine the pkgList of that foreground process and compare that against your whitelist.
However, this breaks down if:
Something pops up asynchronously (alarm clock app, incoming phone call, etc.)
An app that is logically in your whitelist has changes that affect its package name (e.g., developer released a "pro" app that a student paid for, and the whitelist only has the free app)
if the device has multiple visible items (e.g., Samsung's multi-window capabilities), if all visible apps are not IMPORTANCE_FOREGROUND
This at least gets rid of the problem of pure background stuff that the student cannot control, including your "default/system processes".
However, it requires you to continuously poll, which will be a serious detriment to battery life. That, plus the privacy implications, means to me that this app should, at best, only be used for exams, and should be something that the student can install shortly before the exam and remove shortly after the exam.

Well I think my team and I have come up with the best solution so far. After reading the Android Docs, we found that by using ActivityManager.getRunningServices() we can use the constant FLAG_SYSTEM_PROCESS to determine what processes are core system processes. Then all we would do is cross-check that with the total list of running processes to differentiate between them.

Related

Is it possible to see what user activity an Android app is monitoring / tracking and what data it's sending back to it's servers about the user?

I would like to check the user activity an app is tracking. The Audible app specifically.
e.g. does it log every tap? Does it log how long each session is etc.
Thank you.
This is not possible, no. Computers are not capable of this sort of sophisticated reasoning about a program's possible behaviors (see, for example, the Halting Problem, which shows that an algorithm can't even determine if a given program will finish running). Only a human reverse-engineering the software by hand could possibly make this determination, which would be a very time-consuming process for an app of even moderate complexity.

Permanent background service in AOSP Android?

I'm developing an Android app that is going to be embedded on a non-mobile device owned by our client, and used by our client's customers. My boss is envisioning a second app for the machine that runs in the background and sends data about the device to the backend periodically via a Service. I've employed this method, though I'm aware that it is imperfect because Android is prone to killing background services at will and at unspecified times, namely when it decides the service is obsolete or the system needs more memory.
That said, we are running the open-source version of Android (v5.1.1). I'm wondering if there are any options available to my OS team that aren't available for those building apps for the Google Android flavors, some way to remove those typical house-keeping mechanisms or auto-restart apps that have been closed?
Set android:persistent="true" on your <application> tag in the manifest.
The docs say:
Whether or not the application should remain running at all times — "true" if it should, and "false" if not. The default value is "false". Applications should not normally set this flag; persistence mode is intended only for certain system applications.
For this to work, your APK will need to be installed on the system partition. It may also need to be in the priv-app dir or be signed with the same key as the system (some of these things do; I don't remember for this specific case).
Note that your Application.onCreate() will be started automatically; your Service will not be started automatically. Not that you need it; when you're persistent, the Android system won't (normally) kill your process, so you can just run normal threads doing what you need to.
Finally, make very sure that you're not leaking memory. Persistent apps are killed very late (if at all..?) by the LMK, so it could have adverse effects on the performance or stability of your device.
You have 3 options here in my opinion:
Modify Android OOMKiller to exclude your app. Wouldn't recommend this.
Create a Java system service, that is started by SystemServer
Create a native C "app" (binary), that is started in one of the init.rc scripts. ( The daemon suggested by CommonsWare comment ). This can have the benefit of being able to be run as root if you need it.

Android application without an actual process running the app

I was reading "Multitasking the Android Way" by Dianne Hackborn and found one sentence I don't quite understand (I bolded the puzzling part):
A common misunderstanding about Android multitasking is the difference
between a process and an application. In Android these are not tightly
coupled entities: applications may seem present to the user without an
actual process currently running the app; multiple applications may
share processes, or one application may make use of multiple processes
depending on its needs; the process(es) of an application may be kept
around by Android even when that application is not actively doing
something.
How is it even possible? To "present" an application to the user, we need a least one of its activities to be in resumed state, and for this we need the underlying Linux process up and running, right? Is she talking about the application launcher or something?
To "present" an application to the user, we need a least one of its activities to be in resumed state, and for this we need the underlying Linux process up and running, right?
There are a few ways in which the user can see an app's UI without the app having a currently running process, such as:
The app can have an app widget on the home screen
The app can have a Notification in the status bar, or on a Wear device
The app can have an entry in the recent-tasks list
My interpretation is that "applications may seem present" refers to something like these.

Android app prevent app killing by auto task killer

Is there a way to set some priority to the app, so Task killer can't kill it?
I don't want to add my app to task killer safe list.
I want to my app be invisible to task killer.
Is that possible?
There's no one "App killer". There are apps that act like that, so each user can have different one (wise users do not have any ;) and I do not expect apps like that to allow other apps to auto-add themselves on their whitelist. My suggestion is just ignore this and educate your users that app killers shall be avoided and can cause more harm than benefits. Android can handle own resources quite well and hopefuly there will be no like "task killer" type of app around as Android disallows other apps to mess with tasks since (afair) HC
As lenik points out, the mobile device belongs to the user, and it is the user - and the user only - who decides what software does or does not run on the device. Any app trying to do what you seem to want yours to do would be considered very dubious by security-conscious users. It doesn't matter that you may have good reasons for the app to do this - what matters is how such abilities can be misused.
Don't underestimate the intelligence of your users.
Simply inform your users to not use Task Killer at some appropriate point in the software (or the in-app help/online manual), and you will have handled the issue for 99.999% of your users.

Find how much network traffic other Android apps generate

I am trying to make a background service which should measure traffic usage of various applications so as to be able to show to the user which apps consume most data traffic.
I found that Spare Parts app does exactly that, but after installing it on a 1.6 Dell Streak device I always get "No battery usage data available" for "Network usage". Does this function at all work in Spare Parts?
Also, I couldn't find a working source code for Spare Parts.
https://android.googlesource.com/platform/development/+/froyo-release/apps/SpareParts
looks to be outdated or incomplete. (?)
But Spare Parts seems to measure e.g. CPU usage per app. How does it do that on an unrooted phone?
My general idea of how traffic per app could be measured is to regularly check the
"sys/class/net/" + sWiFiInterface + "/statistics/rx_bytes"
"sys/class/net/" + sWiFiInterface + "/statistics/tx_bytes"
"sys/class/net/" + sMobileInterface + "/statistics/rx_bytes"
"sys/class/net/" + sMobileInterface + "/statistics/tx_bytes"
files and to see which app currently has focus and thus most likely to cause the generated network traffic.
Unfortunately I can't find how to get the app currently having focus.
I found this:
Android, how to get information on which activity is currently showing (in foregorund)?
but seems it's about testing, not just a 3d party service running on non-rooted Android device.
We can get what activities are running with ActivityManager.getCurrentTasks(), but any of them can be the one with focus. It seems like the Android architects explicitly don't want 3d party apps to know what app has focus, because of security concerns
(see http://android.bigresource.com/Track/android-zb2mhvZX4/).
Is there a way around this?
Also, if I want to not only detect which activities eat up traffic but also what services, I can get all currently running services with
ActivityManager.getCurrentSerives()
and even see for each one if it's in foreground mode (unlike to be thrown out if Android needs resources). But this again doesn't bring me any far.
Any ideas?
You can detect currently foreground application with ActivityManager.getRunningAppProcesses call. It will return a list of RunningAppProcessInfo records. To determine which application is on foreground check RunningAppProcessInfo.importance field for equality to RunningAppProcessInfo.IMPORTANCE_FOREGROUND.
But be ware that call to ActivityManager.getRunningAppProcesses() method must be performed NOT in the UI thread. Just call it in the background thread (for example via AsyncTask) and it will return correct results. Check my post for additional details.

Categories

Resources