Accessing the /cache directory in the Android filesystem - android

How can I write a file in the /cache directory? I continue to get a FileNotFoundException (Permission denied).
Someone told me about the android.permission.ACCESS_CACHE_FILESYSTEM but i can't find it in the Android reference.
Any help will be appreciated.
EDIT: i'm using level 13 apis

You can only write to the cache directory of your own application: use context.getCacheDir() to get its location.

Related

Can android System App (privileged) read or copy /data/tombstones

I've my app as system-priv and build along with my AOSP code. now my app needs to copy the tombstone folder which is under /data/tombstones to /sdcard.
thanks in advance
I got it worked.
There are 2 parts
i) You've to register tombstones path using FileObserver, so whenever new tombstone created you'll get the callback.
ii) Your app should have the permission to read this path otherwise you'll get an avc denied due to SELinux. So add permission to system_app.te file of sepolicy.

getExternalFilesDir(null) gives java.io.IOException: Read-only file system

I'm trying to write a text file in the root folder of my app with the below code
File file = new File(getExternalFilesDir(null), "values.txt");
file.createNewFile();
All i am getting is java.io.IOException: Read-only file system
i have uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" in the manifest file.
How can i fix this issue ?
I have tried it on an emulator and a nexus 7 and cant seem to find what is causing the issue.
I see a lot of answers talking about remounting my file system but i can expect everyone that downloads the app to do that.
getExternalFilesDir(null)
Will return, The path of the directory holding application files on external storage. Returns null if external storage is not currently mounted so it could not ensure the path exists; you will need to call this method again when it is available.
So In your case we don't know whether external storage is mounted or not, but as you want to put file on root folder of your app. just use getFilesDir(). It will store your file in internal storage where your application files are stored.

How to read files placed in root-folder?

I want to know how to read files placed in root folder. For instance let's take file /init.trace.rc. When I'm trying to read it I get exception:
java.io.FileNotFoundException: /init.trace.rc: EACCES (Permission denied)
I thought that I need to get superuser access. I did it but that made no difference ((( I still can't read it. Could anybody help me? ...and also I wonder how file explorers like "RootExplorer" read that stuff?
apparently this is all you need to run to get root access:
Process root = Runtime.getRuntime().exec("su");
taken from:
How can I get root permissions through the Android SDK?

Android NDK can't open any file

I'm trying to open files from C in my Android app/library. This did work at some point but stopped working after changing several things that seem completely irrelevant, and don't run until after this error occurs.
I am using the following function in C: *ppFile = fopen(fullUncFilePathAndName, "r+b"); and then again with permissions "w+b"
After each of these calls, errno = 13 (Permission Denied).
The file path is /data/data/{appFolder}/files/{filename} (got from Context.getFilesDir().getAbsolutePath(), and the working directory according to the C functions is "/". This is on internal storage, but I added the permission WRITE_EXTERNAL_STORAGE just because I had nothing else to do.
Can anyone think why reading or writing to existing and non-existent files in internal storage from an NDK library would fail with permission errors?
This problem solved itself in the best worst way possible. I deleted my app's data folder in the file browser, and then at the next build the app created its files without a hitch.
You could also clean the project and recompile from scratch.

how to grant android mediaserver file write permission?

I am developing several AudioEffect subclasses that are being compiled into Android 4.0.3 ICS... I am trying to dump raw PCM data to files, but because the AudioEffects run in the context of the mediaserver process it seems there is no file writing permissions available.
fopen("/data/local/tmp/pcm_in.pcm", "w");
is returning a NULL pointer and errno 13 (permission denied).
Any ideas how I can grant mediaserver this permission, or write to a folder I can access? I'm compiling the OS, so anything goes...
More specifically: How are permissions for these native/system services determined? I don't suppose they have a AndroidManifest.xml...
I suspect the problem is that you don't have permissions to create a file at /data/local/tmp. In fact i'm not even sure that directory exists on Android.
Instead you should either use the private storage for an app or save the files to the SD card. See this for more information: http://developer.android.com/guide/topics/data/data-storage.html
Maybe you can just create a folder with permission.
root#android:/mount -o remount,rw /
root#android:/mkdir test
root#android:/chown media:media test
root#android:/chmod 777 test
Then you can do whatever you want.
z.B.
fopen("/test/pcm_in.pcm", "w");

Categories

Resources