I made a filemanager that I want go be able to navegate/modify some system folders (say, /data/). I copied my apk to /system/app, gave 644 permission to the apk file, and rebooted. Yet, my app is still run without root privileges (deny simple access to /data). I'm using Cyanogenmod 11.
Any clue?
Thanks!
L.
To clarify, the app being in the /system/app folder does not run it as root. Android is linux based, so having root access means that your app is able to run shell commands as the root user.
Generally speaking an app being in the /system/app folder makes all declared permissions available to it, (for example, declaring WRITE_SECURE_SETTINGS only does anything for system apps), and then the code that was only available to system apps is now available to yours as well.
For reliability, you should use shell commands where possible for anything that's normally unavailable. Do not use java.io.File to access files that are normally restricted.
I would recommend using RootTools as it makes running shell commands as root much easier. The first 3 pages on this linux command cheat sheet will probably cover everything you need.
Related
I wanted to have git available as a CLI tool on my android device, usable via a local terminal app. I've successfully cross-compiled git for aarch64-linux-android and if I use a root shell to move it to one of the ext4 filesystems on the device I can invoke it successfully.
However, installing and using it with root is not desirable. I normally leave my device unrooted and only temporarily enable root to do experiments like this. Installation as root is not so bad, but it seems that the only ext4 filesystems mounted read/write are in locations that the terminal app cannot read from, so I cannot use it as a non-root user, which is a deal breaker *.
I'd prefer to package it as an APK if possible, so it can be sideloaded as a normal user. I'd also like to be able to invoke it from the terminal app. If I have to manually adjust $PATH, that's fine, but bonus points if the APK can place it somewhere on $PATH or have the OS extend $PATH on installation.
* (I know I can remount /system as r/w to install it as root, and that would make it usable to all applications. I don't want to modify /system because then "factory resets" are not ensured to bring me back to a working state. I know it'd be a relatively safe change. If this really is impossible, I'll do that, but an APK would be so much nicer)
I don't think you can do this. Android is designed to prevent such things: each APK can only run in a (somewhat) isolated container.
An APK cannot install an executable in the root folders. Modifying $PATH will also not work (if the system would even allow you to modify it) because each APK is executed by a different user, thus the environment will be different. I'm not even sure you can mark a file as executable on common folders.
One workaround to this would be to make the path of the executable (if you can mark a file as executable, that is) available through a ContentResolver.
I'm building Android from source (for a custom ARM-based device).
I have an app, which I want to have root permissions.
In particular, I want my app to be able to run an arbitrary shell command as root.
I've read lots of articles about how to root phones and use other apps, such as SuperSU, to run apps as root.
I have a root shell on the device over adb.
How can I make my app run as root, without installing other apps and performing complicated work-arounds which I believe I do not need?
I have created this file on my device:
file:///data/user/0/io.ionic.starter/files/mypdf.pdf
But I can’t figure out how to find that file manually using my android device. Any ideas?
Note: I am using an emulator, Nexus 5X.
What do you mean by "manually"?
You can not access this file from another application on your Android device, such as a file manager or a PDF viewer.
This is because you created it inside your applications files directory, which is guarded by file system permissions and is only accessible to your application.
There are two exceptions to this rule:
If your device is rooted, you can use Root explorer to find the file.
If you created the file with "world readable" permission, another application can read it if it has the exact path (including full file name).
Note this may not work on newer versions of Android.
If you wish to access the file from you PC to examine it, you can use adb pull command. Since you are using an emulator, ADB should be running as root.
If it is not, use adb root command to switch ADB to run as root, then you will have no problem accessing any directory on the phone.
Keep in mind, this will not work on a real phone with stock ROM, as ADB can not run with root privileges on production systems.
I have this development board Open-Q 820
It is running an Android 7.0 based on some sources from CodeAurora (that seem based on AOSP sources). Seems it uses proprietary bootloader that can not be changed. I need to access GPIO (/system/class/gpio) from my android app to control an external device. Problem is I can not do this from android app - seems only root can access this files.
I can call "adb root" command from PC and then call from "adb shell" something like
echo 0 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio0/direction
echo 1 > /sys/class/gpio/gpio0/value
and it is working. But I need to do the same from my android app. I know how to access terminal and su from android app. I just dont know how to root custom device. I tried to install SuperSU.apk app and its corresponding su native app manually. It starts and says it need to update su binaries. After installing binaries and reboot the system then it becomes broken - infinite android logo. If I not install binaries update then SuperSU can grant permissions to my app but actully app still can not use su (I dont know why - I use this library inside my app: https://github.com/Chrisplus/RootManager). And after reboot SuperSU not working longer.
So may be you know some SuperSU alternatives (Knigroot not working too) or steps how to correctly install some superuser management app. Or may be I can use su directly (I tried but my app has not rights to access /system/xbin/su). Or may be I can make /sys/class/gpio accessible by android apps somehow (I tried chmod 777 on it - not works). May be some SElinux rights, but I have no experience with this.
Thank you
Magisk helped me. Since it is have option to patch custom boot image. I used this option and now root access works.
I am developing app which will come pre-installed with certain devices, however im testing the app on my own device and will need to demo it on my own device. At the moment its fine as im testing it as a user app, but now i need to use permissions which only the system apps get to use. Is their a way in the project settings to say its a system app so I can test and demo it?
short answer - i would root your phone. However, unlocking the bootloader is possible without root. So, IMO, you could install CWM as your recovery, then boot to CWM, then use the CWM option to MOUNT system, then use adb to copy your .apk to /cache, then use linux util 'cat' to get the apk from /cache to /system/app, then unmount /system using CWM, then reboot.
long answer - if you are developing system apps, learn the security environment of android. Learn the issues around permissions in the /system folder, and learn the recovery type tools that allow a developer to have access to the /system folder where adb activities like install , uninstall are restricted.
This is an older discussion 'froyo' on how-to install system app, illustrating some of the permissions issues in the /system folder. I would not simply follow these instructions without reading up on how its done in honeycomb and in ICS.