How to read /proc/pid/status in Android? - android

I want to read the status file of all processes in an Android system. I check the permission of /proc/pid/status files, it is -r-r-r-, seems like it could be read from every user, and I have turn seAndroid off.
In shell, it works fine, but when I read the file in an application (.apk), it always return "no such file". I think maybe it is the permission issue, but I don't know why, what blocks an application from reading this file.

Related

How can I write a file to my SD card in Android?

I have a requirement for my Android app to be able to receive files from a server and save them in an arbitrary location on my SD card. When I say "SD card", I don't mean the /sdcard/ directory - AKA /storage/emulated/0/, I mean the physical removable SD card.
My initial attempt:
FileOutputStream(File("storage/ABCD-1234", "test_file.txt")).use {
it.write("Hello world!".toByteArray())
}
where "ABCD-1234" is replaced with the actual storage ID string. This gives me an IOException saying permission denied, even though I have the WRITE_EXTERNAL_STORAGE permission granted. Fine, there must just be some restrictions on SD card writing access. So I spent most of today researching around the internet for apps which can already do this. And I come across this one called SSH/SFTP Server, using which I was able to push a file to the device's SD card via WinSCP from a laptop over WiFi. The thing is, I can't figure out how to go about requesting this ability in my app. Can anyone point me in the right direction?
This is targeting Android Q (10), in case it matters at all.

android HAL, how the application grant permission to access the sensor?

I'm looking into android HAL and try to understand how the apps grant permission to access the sensor or hardware. The case is, I do not root my device(I can, but I won't), so if you want to tell me root the device or modify init.rc file, please save your time, thanks.
I did some tests.
I tried to directly get access to some sensors or hardwares in JAVA code, like new FileOutputStream("/dev/XXX"), failed.
I tried to use JNI, like, fd = open("/dev/XXX", O_RDWR, 0), failed.
I guess both of them above are permission denied.
I used the sample named "native-activity" under NDK directory. It's a pure C code. And finally get the value from the sensors.
So I don't know in the case 3, how and when this "native-activity" app grant the permission, which is able to get the value from sensors.
I may misunderstand something. Correct me if you think there is something wrong. Thanks

How to write the data to USB stick(Pendrive) from the application in android

In my application i have to write the Data to USB stick(Pendrive) from the application.
My application will support to write the data to Local memory and USB stick(Pendrive).
Currently i am able to write the data to Local memory ,but i am unable to write to USB stick(Pendrive).
Do we need to add any extra permission other than WRITE_EXTERNAL_STORAGE?
Is writing to USB stick(Pendrive) through app possible?
I am able to ready the files which are there in the USB,i am not able to write the data.
Here is the folder path where i want to write the data.
"/storage/usb1/TestFolder"
Can i get some help on this?
In order to write some data to USB, we need
uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE"
By referring some links i got to know that the above permission can get by Provider of the device.
So we can apply above mechanism to get it done.

Create a socket in android code(not in android application) getting Permission Denied

I am trying to open a socket in the android source code. Specifically, right now, I am in the DisplayDevice.cpp file, but the location of the socket code may change. Right now after I do:
int fd = socket(AF_INET, SOCK_STREAM, 0);
fd gets returned as -1, and when i check the error message it is listed as Permission Denied. I have looked around a lot for this, most answers involve adding the internet permission to the AndroidManifest file. This will not work for me as the code I am adding is inside of the android source code.
I was wondering if there is a way to bypass the permission denied. Or if there is a better way to do this/ a different type of socket to use(right now I am using sockets from
Thank you.
It is quite natural that you get Permission Denied error. This is simply because you don't have correct permission :). Check out android permission model!
Imagine a scenario like a normal user in an operating system and you write a program which tries to open a socket like yours. You would most probably face the same problem, depending on where the named socket is to be created.
As you are trying to create the socket in DisplayDevice.cpp (compiling android from the source), you may be interested in compiling the source as a superuser. Here is a solution posted by m-ric (I have never tested it).
Some useful pointers/references in similar direction and which I found useful during research on this enthralling topic are:
https://android.stackexchange.com/questions/18857/how-to-build-compile-su-from-source
execv command => http://code.google.com/p/superuser/source/browse/trunk/su/su.c?r=2#169
https://github.com/ChainsDD/su-binary
http://e2e.ti.com/support/omap/f/849/p/178679/648158.aspx#648158
A video from Google I/O 2011 http://www.youtube.com/watch?v=5yorhsSPFG4

Log Just My App and View it Remotely

I have an application/phone which I am developing to be given to people who will be using it in remote areas and not so tech-savvy. I want a mechanism to be able to read their log files remotely. The android app is making use of the logcat logging. I want to be able to just read my logs for my app by some remote mechanism. I was thinking more along the lines of reading the logcat then posting that up periodically to a REST service where I can database these. So question is how do I read the Logcat files programatically from my app?
If you invoke:
Proccess p = Runtime.getRuntime().exec("logcat");
InputStream in = p.getInputStream();
//code to process the InputStream
I honestly do not know the entire process of getting the input stream back, but the code above will allow your app to read the logcat file. You can go here for possible command-line paramaters for "logcat". The exec method runs the string through a linux shell, btw.
You must have the permission READ_LOGS

Categories

Resources