I am working on a android app and i want the user to be able to view the folders that require root access. I tried looking through the Cyanogenmod file manager code to try and trying the su command in java with the Runtime thing, but I had no luck.
You cannot do this without rooting the device (which simply means gaining required root access level). That's basically the reason for permission system - to keep you away from the places you should not be looking in.
Related
everyone,
I want to build an app scanning all the files in the devices, so I have to access root directory ("/"), but the file.listfile returns NULL. Is there any way to access "/"?
Because you are using the system in a non-root account, whose allowed reading directories are limited. Directory in "/" are only available for root users. However, due to security concerns, root privilege are generally not accessible for third-party installed apps, in case the installed app may modify system level codes to do bad things.
You may get further information from here
That is pretty strange as on an Android 5.1 device it should just do the listing. No root needed.
Also on Android 6 this works on all devices i know.
It only started with Android 7 that "/" is not listable anymore.
Which device is it?
I'm facing an issue trying to get the app root folder, the problem comes in an emulator with Marshmallow. When I do context.getFilesDir() it returns a wrong path:
data/user/0/com.android.appname/files/
When it should be:
data/data/com.android.appname/files/
Somebody know why is this happening and how to solve it or another way to get the right path to the app root folder?
/data/user/0/com.android.appname/files/ is a perfectly valid path to be returned by getFilesDir(). That directory will be usable by your app.
adb is not your app. Its view of the filesystem will be different.
The exact location of where getFilesDir() maps to on the actual filesystem ā or where tools like adb will see it ā will vary based on several criteria, including OS version, which user account is running your app (remember: Android supports multiple users!), and possibly device manufacturer/custom ROM changes.
I'm making an app that read messages from Whatsapp, Viber, mails, etc. and groups it so you can read all that one person said to you in just one App.
To do this I'm trying to read the *.db files each App has on /data/data directory but have encountered two problems.
Since I'm new to programing for rooted phones I don't know how this works and have not found a good tutorial or any documentation. Do you have any that I could read to understand?
Once I know how to access /data/data with root, how can I read the *.db without making a copy. Many other topics say that I should copy the *.db file to a folder and read it there, but wouldn't it be a lot more simple to just read it from where it is?
Apps, regardless of whether the phone is rooted or not, can only ever read files that they themselves own, or that are public (e.g., on a SD card). This is because while the phone may be rooted, the apps themselves do not gain root access.
Instead, on your phone, you have an executable named su lets apps run root commands. However, by default, it refuses to let any app run any root commands. When you root your phone, you replace this executable by a new, modified version that lets approved apps run root commands. It is by using these root commands that you can gain indirect root access to the system.
Now, since you only have indirect root access for your app, you cannot just read any file from the file system. But if you run a root command to copy it to your own, private directory, where you do have permission to read it, your app can directly read it from there.
(Note: you can technically read files without copying them first, by using the su executable, but unless there's a real reason why you can't copy first, and you actually know what you're doing, you probably shouldn't even bother because it's rarely worth the trouble anyways, especially not for sqlite databases.)
For details about how to run root commands with su, see this link (which Gumbo posted in the comments above).
I have a Google Nexus 7, and I've been developing on it. Only recently, however, have I become unable to access the /data/ directory using the file browser in eclipse. The device was never rooted, but now since I upgraded it, I believe that I have lost access to this. Is there any way to get eclipse to use the "run-as" command to access my app's data directory? How come I have suddenly lost access to this?
Is the only option left to root the device?
Thanks
Is there any way to get eclipse to use the "run-as" command to access my app's data directory?
There is nothing for you to run "as" that would help here, AFAIK.
How come I have suddenly lost access to this?
You should not have had access to it in the first place. If you did, that was a security flaw in the device, perhaps fixed by a firmware upgrade.
Is the only option left to root the device?
You could not browse the /data/ directory on production hardware. For example, you can browse /data/ on the emulator.
I am able to given root permission by installing apk.
http://gadgets.ndtv.com/mobiles/features/how-to-root-nokia-x-and-get-access-to-google-play-store-and-google-now-508391
Iām trying to create an app that is able to access and modify a protected database within /data/data/. This process obviously requires root privileges and I am testing this on a rooted device. The general code to access the SQLite database is complete and works against a test database that is located elsewhere (on /sdcard/).
However when I want the application to access the database within /data/data/, it obviously fails as I am trying to access it as a normal user. I have read on the topic of using the su binary on Android for a bit now, and as far as I understand it usually used to execute shell commands only.
So my initial idea of making this work was to simply change the permissions of the file when the application starts, and change it back when it quits. So before actually bothering with implementing that in the application itself, I used my file explorer to change the permission to rw-rw-rw-. However my application was still not able to open the database.
My next idea was to use the sqlite3 program directly from the shell, but I found out, that my ROM does not come with it, so I would have to distribute it myself (Titanium Backup seems to do that).
However there is something that makes me wonder if there might not be a better way: I am using Root Explorer as my file explorer and it has a built-in way to browse any SQLite database. Given that it does not seem to ship with a custom sqlite3 binary, and that my phone does not have one itself, the access seems to happen using the normal Java tools. But how does the app get root rights then?
Is there a way to make an Android application run as root? Or did I forget setting something for the permissions earlier which prevented me from accessing it? Or does anyone know how Root Explorer does it?
You cannot raise the permissions of an already running process as far as I know. The simplest answer would be to copy it somewhere using the root shell / command line edit it, then copy it back as root again. And yes, I did read your question, just didn't explain the answer fully. Hopefully it's clear now. Not sure if root explorer does that or something else, but it would work.