How to run an application a system / root in android - android

I've been searching about this topic but I haven't found a clear solution yet. As far as I know, you can specify different protectionLevel in your AndroidManifest.xml, those permissions allow other applications to interact with the one you are developing. As an example, imagine that I want to kill a processes, that is not mine (from another package) or that I want to install a driver I've developed. In both cases the problem is the same, those things need to be run as a system / root. How can I develop programs that require system / root permissions, do I need an special license?
Note: Please, note that granting the permission:
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>
Using android:sharedUserId="android.uid.system" does not work either.
Also, consider that I cannot ask the users to have their mobiles "rooted".
Thanks in advance.

Use
Process myprocess = Runtime.getRuntime().exec("su");
to request root access.

This is not possible.
Either you ask your users to root their devices or you limit your applications abilities to the things you can do without root access.

It is possible to not displaying the GUI of requesting root authorization from the user? in a rooted device, installed as a system application under /system/app

Related

Can I Use Superuser Permissions To See All Apps Currently Running

I want to make an app that essentially mines every bit of data that it can from a phone for a university research project. For this, I will need to know what apps are open (all of them) and it seems that, as of API 21, just listing the current app is a rather tricky endeavor. If the user grants superuser access requested via:
<uses-permission android:name="android.permission.ACCESS_SUPERUSER">
</permission>
can I get around Googles obvious attempts to make it harder to get even tiny bits of information out of the phone. Or have they gone as far as making superuser access not so super anymore?
Also, I know I can just root the device, but this application will be installed on other peoples devices (data will be stored locally). As I understand it, non rooted devices can still grant superuser access upon permission (or via toast message if permissions are not listed in the manifest)
EDIT: apparently, as of android 5.0, SU is no longer available to non rooted devices...
Thanks

Android: how to get system rights officialy

I need to Turn ON/OFF Mobile data programmatically. For this issue I need to use MODIFY_PHONE_STATE permission.
As we know in latest Android versions it's not possible for non-rooted phones unless the app has system rights.
I know that exists some workaround how to sign the app as system app. But as I understand it's not possible to publish such app at the Play Store.
My question is the next - is it possible to get system rights officially? If it is possible which way I have to go to get them?
THe only way to get them is a rooted device, or to build the device image yourself. The idea of system permissions is that only apps which are trusted by the creator of the system (the OEM) can request them. You can also get them by rooting the device, because of how they're granted (its based on the directory the app is installed in, which can be accessed if you have root). But there is no way to do it without root or without creating your own OS image.
MODIFY_PHONE_STATE is a system-only permission so there's no way to get that permission unless you root your phone.

root access side effects

I want to test my app and I have a device with root access to test on.
Can I be confident the the behavoir of the app is not affected by the root access?
If it is affected are the specific areas of behavoir in which root access may cause different/unexpected behavior?
Is there a way to retrieve files (logs, test results) from a device without root access?
Thanks
AFIAK there really aren't any APIs that require root permissions. Apps that require root permissions execute system commands using the Runtime.getRuntime().exec(commandStringHere);
If you try to execute commands that you don't have permissions to run then the execution will fail. To get around the permissions problem you can execute the commands as root using su.
So if you aren't doing any of this you app should run exactly the same on rooted and non-rooted phones.
As long as you App doesn't require root access it does not have any sideaffects
You can see the log via adb logcat or the Logcat-View in Eclipse (with Installed ADT).Also you can use JUnit Tests on Android.
If your application asks and uses root permissions, then the application won't work in unrooted devices. Assuming that you don't need any root access, there is no difference between an application running in rooted or unrooted device. You can also test in emulator to see the differences if they exist.

Rooting VS permissions

first of all, I'm not involved in any kind of Android development. I'm only curious.
The question is: does an app obtaining root privileges still need to declare its required permissions in the manifest?
I mean, if my app doesn't declare that it needs to acquire camera input, can it invoke some APIs or executable and acquire camera after becoming root?
I know this could sound stupid but I repeat, I'm just curious about Android features.
On your typical rooted Android device, (which would use the Superuser application and its corresponding su binary) applications which request root access can only run commands as root via the su binary.
So yes, in that the application itself still runs as a underprivileged user process, so anything it needs to do using the "normal" APIs still need the correct permissions. So if you want to (as in your example) access the camera using the normal Java API, you can't do that unless you have declared that permission.
But no, in that if your application requests and receives root privileges via the su binary, you can do anything you want within that command. So if you wrote a special binary or script that can access the camera outside of the normal API methods, that might work. (I suspect this would be more trouble than it's worth.)

How android/linux sets whether the root user is logged in or a normal user is logged in?

It seems almost every android device comes without root permission, so some people provide a new ROM to root it. How do they achieve it? (Do they change anything in init process, or do they change some apps' access attributes on the storage, such as launcher or toolkit, or some process's uid/gid?)
I have a non-root mobile and another rooted one. I can't find the difference between them. The launcher are both with a uid/gid exceeding 10000.
In Linux desktop, this is controlled through the login process. But I still don't know the key reason.
It's confusing.
On a rooted Android, you can install apps that require special access (like the hardware)
Because the hardware manufacturers and the developers at Google did not want to let users tweak the hardware, the root user is blocked.
For example you can run softwares like Titanium backup (for making backups of application data), SetCPU (for overclocking your Android) and LES (Linux enhancement suite) if you have a rooted phone. Note that the rooted phone will allow apps to run through root only when asked for. Otherwise all the apps will work as the normal user.
In Linux, you can use the su command to get ALL the root permissions or sudo to get minimal root permissions (controlled su)
You can get the superuser permissions by rooting the phone, installing a terminal (Better Terminal Emulator) and typing "su" into the console. (Click "yes" if Superuser asks for permission)

Categories

Resources