How to use systemless root on android - android

I have an app that helps locate your lost android phone and for rooted phones I have a one click convert to system app feature (so it will survive a factory reset).
Now some of my users complains and say it no longer works on devices that uses systemless root. So questions of the day are:
how do I detect if a user has systemless installed programmatically?
how do I use systemless? I guess it is not through the normal SU command
BR. Theis

Well, I had one of my users do some tests on his phone and a simple call like this will tell you if the user has su installed:
which su
Yes, the new systemless root also uses "su" as a command. Details can be found on XDA

Related

Connect to RS232 from Android - No permission dialog or shell command

Objective
I'm developing a custom app for internal use on a rooted android mini-pc.
The goal (between others... so...many...others...) is to be able to turn on and off a tv using the serial port embeeded on the tv.
I'm using an FTDI UART RS232 serial usb cable for it.
Status
The application is working right now, using an android library (serial-driver) i can communicate with the tv, but the problem is that the device asks for permissions every install (and sometimes, weirdly, again on the same device), so it needs to be improved.
Issue
Since the device doesn't have mouse or keyboard by default, when this happens someone has to click the buttons, and since the device is normally hidden behind the screen, it can be really annoying.
My two bits
This problem, i feel, can be solved by two methods, but i still haven't been able to make them work.
Since the device is rooted, i might be able to modify an unknown (to me) parameter that allows me to bypass the permission request. For this i have tried to make an intent filter for the usb device, and to rewrite the interface that controlls this behaviour, both without success. Is there a way to make this android version more lenient about permissions?
I use for other reasons SuperSU inside the app, so i can use the full width of the might shell power. Using this i've been trying to send commands manually to the device (/dev/bus/usb/00X/00Y), but this haven't worked. My theory is that it's beacuse of the permissions of the device path, but even doing an unhealthy chmod 777 i cannot have them working.
So, that's my problem right now. I hope someone here can help me.
Additional data
Running: Custom Android 4.4.2 (Cannot be changed)
Needs to be doable solely from within the apk (but it can use shell commands)
We don't have the manufacturer signature to install it as a system app
We can use only one app, so i cannot have another one to move this one to /sys/apps, and i don't know if an app can do that to itself.
using Busybox stty -F /dev/.../ returns "Operation not permitted"

Android command list

I have many questions about Android command. I do not know where I should start But, anyway, I have put all question related Android commands. Here ;
Is subset of Linux commands come in Android by default ? Or, Are we installing something ?
In system/bin, there are lots of commands. Where can I find their meaning ? I have tried man, but man is not built in.
Can I start and stop application via start and stop command ?
Why cannot I run the reboot from terminal emulator ? The error permission is denied.
NOTE : feel free to reedit the question, if you see meaningless part.
Is subset of Linux commands come in Android by default ? Or, Are we installing something ?
A subset exists by default within the system. Things like ls, cd, mkdir, cat etc... are present. You can gain access to a wider range by installing Busy Box on a rooted device, as stated by Zac.
In system/bin, there are lots of commands. Where can I find their meaning ? I have tried man, but man is not built in.
The ADB Page is a good place to start. That covers many of the basic ADB and shell commands. It states near the bottom:
"For a complete list of commands and programs, start an emulator instance and use the adb -help command."
So you can use adb -help on an emualator or device to see a full list of the ADB and shell commands (note I think this list will be android specific commands only, it won't include things like cd,ls and other basic unix commands).
Can I start and stop application via start and stop command ?
No, it states on the ADB dev page:
start ........ Starts (restarts) an emulator/device instance.
stop ........ Stops execution of an emulator/device instance.
To start an application you'll use the am utility iirc it will look something like am start com.your.packagename It's been a while though, I might have syntax wrong. The instructions are listend if you issue the am command by itself with no params in a shell.
Why cannot I run the reboot from terminal emulator ? The error permission is denied.
The system prevents applications from rebooting the device unless they are signed with the same key as the OS. When you use the terminal emulator you are restricted to whatever permissions that application has declared. The reboot permission is not granted to any third party applications, so it won't work correctly from any terminals. You could probably do it if your device was rooted and you used su though
EDIT:
Here is another good resource that lists more of the shell commands
There are not many Linux commands included in android, however if you are rooted you can easily install busybox which has a large range of linux commands.
You need to have root access to reboot your device via the command line (to prevent any old app being able to do it)

Testing if a phone is rooted [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Determine if running on a rooted device
I would like to know just whether or not a phone is rooted, without requesting root privileges. How can I do that?
Testing if File.Exists("/system/bin/su")? Not sure, I think I cannot due to permissions
Testing if Superuser app is installed? Hmm, I think I need a special permission to use PackageManager and Superuser is not the onlu su manager (I know SuperSU for example)
Trying to run su is not an option because it triggers the su prompt which is something I don't want in a non-root app
Any idea? My purpose is to obtain anonymous statistics on how many devices are rooted, obviously with user's consent :)
Option 1. It is possible, it doesn't need any special permission.
Option 2. The rooted phone may not come with any Superuser manager application.
Option 3. As you said, it's not a good way to detect.
Besides, there's another option that is to check ro.build.tag (using getprop | grep ro.buil.tag or android.os.Build.TAG) if it contains testkeys string.
Edit: for option 1, I would suggest you find by setuid/setgid permission (i.e. find / -perm -2000 -o -perm -4000, and check if su is in the list)
You cannot reliably do this, as what it means for a phone to be "rooted" is not always the same. What all the proposals you will get do is test for some of the popular root-related tools. But it is not possible to detect if the phone has been rooted in a way that does not utilize those tools.

What are the steps to get root access in android emulator for rebooting through code?

How do I get root access in order to reboot the emulator? How do I kill all unwanted processes along with the child process?
You have already root access to your emulator. To kill a process and all childs just use the device view in eclipse, select the emulator theere and chose which process you want to kill.
I have no idea on how to restart from code if you are looking for that. Rebooting the device should be easy: just close it and than boot it up again.
(I have the feeling I don't really get what you want...)
Most su binaries for Android depend on SuperUser.apk (available for free through the market). The su binary uses this apk to ask the user if it's ok to do whatever is being requested (and the user can opt to remember the answer). If you're using such a su, you need to also have that apk.
Once the pieces are in place, your application can spawn a process with the right arguments... something like argv[0]="/path/to/su", argv[1]="-c", argv[2]="(whatever command you want to run)", argv[3...n]=arguments to your command.
To kill a process in the command line, simply issue the following command line on the shell:
kill-9 YOUR_PID
If you know the name of the process, but not the pid, use
kill -9 $(pidof NAME_OF_PROCESS)
You can also use it on your code:
Runtime.getRuntime().exec("kill-9 YOUR_PID");
Check the man page for more details: http://unixhelp.ed.ac.uk/CGI/man-cgi?kill
ps-after rebooting i also wanted to kill all unwanted process except my specific app and its child process alone to run in emulator.
If that is really what you want to do - repurpose an android build as a generic embedded linux, then the way to go about it is to regenerate a ramdisk image (which android packs onto the kernel) containing an init.rc which launches your application rather than the android native services and (java-esque dalvik) android runtime. Rebuilding the ramdisk requires a unix-like OS and that arcane cpio command line which you can find in web search. I'd be tempted to leave the startup of ADB in there so you can debug the various things which will go wrong.
For testing purposes simply typing "stop" from the adb shell will shut down the android runtime and give you a UI-less virtual pocket linux box. There will still be some native services running but they may be more help than harm. Ultimately you may need to set OOM killer values on the things you add, though without the runtime up that may not be an issue in the near term if you don't consume much memory.
Or if what you want to do is have a very locked down and limited UI built on top of the android runtime, you would instead develop a custom home screen , test this on an unmodified emulator, and then deploy it on a build customized to lack any means of installing other applications.

Can you get to a command line on the G1 phone?

I understand the Android OS is based on Linux. Does that mean the G1 phone has a terminal emulator and you can open a console and use commands like cd, ls, etc? Or failing that, would it be possible to write a terminal emulator for it?
On a related note, would it be possible to run a ssh server on the G1 and log into it over a wifi connection?
Actually, until recently everything you typed on the keyboard got echoed to a root shell. Nasty bug.
That said, you want PTerminal, from the Android Market.
As for SSH, yep. You can even install Debian on the phone.
Currently there are a few terminal emulators in the market and elseware on the web (quick google search and you'll see), but if you are running the latest OS patch level (RC30) you will no longer be able to get root at all. The shell's are still somewhat useful to poke around the file system and see the results of ps and top for example.
In case you don't know, it's worth pointing out that android has a fairly secure application sandbox. Each installed app runs as it's own user. Not many binaries on the phone are world-executable, and a lot of files aren't even world-readable.
However, I don't think anything is preventing you from copying executables to the phone and running them as a non-privileged user.
The android SDK comes with a tool that lets you run a shell from your development machine over USB. The su command does not work on the TMobile phone but does work on the unlocked phone that comes direct from google.
Very easy to flash back to RC29 and get root, I did and have Terminal Emulator running good. I just don't know many commands.

Categories

Resources