I need to access a UNIX domain socket from my Android app. Its file is located in /dev, so I need root permissions to open it. My phone is rooted, so gaining this permissions is not a problem. However, I failed to find a way to access this socket from root and forward the communication to my app.
AFAIK, the only way Android apps can get root permissions is through the su tool, so I need to find a native tool (already installed in the phone) that can make a bridge between STDIN/STDOUT and UNIX domain packets (so that my app can control the communication). The typical tools for that purpose are nc and socat. The former is available through busybox, but that version does not support UNIX domain sockets. The latter is not available at all. I'd rather avoid modifying the system partition to install a different tool.
My app could also launch a script that communicate with that socket from su directly without the need to forward the communication to my app, but again, I found no way to write such a script without the previously mentioned tools.
Is it possible to do what I want without installing/developing a native binary tool?
Maybe it is possible to do something with iptables/netfilter, but that does not seem to support this kind of sockets.
EDIT: well, I ended up developing a native binary executable which opens the Unix domain socket as root, and forwards it to the Java part using another Unix domain socket (created by the Java part). There is a hidden constructor for LocalSocket which takes a file descriptor and uses it as the opened socket. The biggest challenge was to find out how to compile a native executable with Android studio (not a library), but this answer helped a lot.
Related
currently we're porting 2 applications (from Windows), both programs do different tasks and is on separate programs because it is designed this way, one program will do the UDP communication basically a daemon and it will translate those UDP packets to json and it will write to a file, the other program will read to that file and it will display to the user. But on the Android file system it seems impossible, I have to deal with storage permissions and basically I can't find a solution, I need a folder in Android that allows reading and writing of files from 2 programs simultaneously without worrying about permissions.
I have tried all the folders in Android.OS.Environment and seems like there's no folder that allows such thing, I'm working on Android Q and I can't even create a file on storage/emulated/0, is there any way for this to happen?
I'm developing an android application using Qt. As far as I understood the default path for deployment and installation of application is /data/user/0/... and this path is inaccessible unless my android device has been root. I would like to know if there is any possible way to change this path and make it accessible since I need to access some of the files in this directory.
Thank you some much for your help in advance!
As long as your device is not rooted, you can not access this location from other applications. If you just want to do it for development purposes, you can simply run
adb root
from the command line to access that location from the development host and thorough the adb.
For example, you will then have access to push/pull files from that location using a command like this in Windows
adb pull /data/user/0/.../somesqlite.db %USERPROFILE%\Desktop\
I need to connect to Active Directory from Android application. I woudn't like to create Active Directory wrapper - web service or something like that for this task. Are there any standard libraries for that?
Question looks similiar to Connect to Active Directory from iOS application except operating system.
I want to send email from terminal android application. Is there any command for this or any email functions?
I, too, want to be able to send emails from terminal/shell scripts in Android. It took me over a week to figure out how to do it. Obstacles included:
Android's default command line toolbox doesn't offer this functionality
The busybox (v1.22.1 bionic) on my android device (MotoG with CyanogenMod 11) seems to have been compiled without the sendmail applet (!?)
Judging from the fact that I was not able to find an answer to your question anywhere, it seems that not many people seem to care about this functionality
I finally did find a simple solution: curl. It is dead-simple to get it working, but only if you have root access to your device. Here's how to set it up:
A. On your computer (desktop or laptop):
Download the curl package for android available here: http://curl.haxx.se/download.html (scroll down until you find the version for android)
Extract the package's contents using your preferred application
B. Use USB cable to plug your android device into your computer
C. Copy the curl binary from your computer (/data/local/bin/curl in the extracted package) to somewhere in your android device's PATH (I copied it into the /system/xbin directory) and make sure that the file is executable
D. Disconnect device from your computer and happy emailing!
Now you can use curl at the command line (or in your shell scripts) to send emails. Usage example is here: Using curl to send email. You can even send text messages! (see here: http://osxdaily.com/2014/03/12/send-sms-text-message-from-command-line/)
I'm porting a C++ Linux application to Android using NDK and testing using the emulator. The application tries to create an /etc/myApp directory and fails because the component /etc does not have the necessary write file system permissions required to create.
Should my application be able to create such a directory? I used adb to inspect and try to make the directory from the shell and it fails too:
mkdir failed for myApp, Read-only file system
Does the file system being read only in adb mean it is also read-only for my application?
Can my application expect to create this directory and if not, is there another location that is more appropriate?
No, you should not be able to do that. Android apps are not permitted to write to system directories.
You should probably create this directory within your app's private storage area. Generally it is best to discover the path of that from Java (don't hardcode it) and then pass it through to the native side.
Depending on your needs for the file, the ExternalStorage might also be an option, especially during development where you might need to easily modify it manually - though keep in mind that others things will be able to change it there, too. Again, you should determine the path on your particular device in Java and then pass that through to the native code.