system process can't write to the /sdcard?

1,115 views
Skip to first unread message

Adrienne Porter Felt

unread,
Sep 17, 2010, 10:08:19 AM9/17/10
to android-...@googlegroups.com
A problem I've run into is that the system process apparently can't write to the sdcard.  Whenever a permission check happens, I have the ContextImpl class use a FileWriter record the check on the sdcard.  (I'm working on building a permission test suite.)  I then see this error:

W/System.err(   98): java.io.FileNotFoundException: /sdcard/Randoop/perms.txt (Permission denied)
W/System.err(   98): at org.apache.harmony.luni.platform.OSFileSystem.openImpl(Native Method)
W/System.err(   98): at org.apache.harmony.luni.platform.OSFileSystem.open(OSFileSystem.java:152)
W/System.err(   98): at java.io.FileOutputStream.<init>(FileOutputStream.java:97)
W/System.err(   98): at java.io.FileOutputStream.<init>(FileOutputStream.java:168)
W/System.err(   98): at java.io.FileWriter.<init>(FileWriter.java:96)
W/System.err(   98): at android.app.ContextImpl.checkPermission(ContextImpl.java:1195)
W/System.err(   98): at android.app.ContextImpl.checkCallingOrSelfPermission(ContextImpl.java:1243)
W/System.err(   98): at android.app.ContextImpl.enforceCallingOrSelfPermission(ContextImpl.java:1280)
W/System.err(   98): at com.android.server.AlarmManagerService.setTimeZone(AlarmManagerService.java:255)
W/System.err(   98): at android.app.IAlarmManager$Stub.onTransact(IAlarmManager.java:122)
W/System.err(   98): at android.os.Binder.execTransact(Binder.java:288)
W/System.err(   98): at dalvik.system.NativeStart.run(Native Method)

Do you have any idea why the system process wouldn't have permission to write to the sdcard?  The file should be world-writable.

(And no, I can't use logcat.)

Christopher Tate

unread,
Sep 17, 2010, 10:44:03 AM9/17/10
to android-...@googlegroups.com
The system process is explicitly forbidden to open files on SD because
those devices are frequently removable during runtime. If a process
holds open file descriptors when the file system is unmounted, that
process will be killed by the kernel. In the case of the system
process, that would bring down the whole Android runtime; hence the
restriction.

(Applications resident on SD complicate this a bit, but that's the
basic problem in a nutshell, and is the reason for the explicit policy
that you're seeing in action.)

For your test suite, you might consider using a two-process
architecture in which the system-process test code communicates via
the Binder or other IPC mechanism with another process whose job is
mostly to handle the file I/O.

--
chris tate
android framework engineer

> --
> You received this message because you are subscribed to the Google Groups
> "android-platform" group.
> To post to this group, send email to android-...@googlegroups.com.
> To unsubscribe from this group, send email to
> android-platfo...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/android-platform?hl=en.
>

nirjon

unread,
Nov 9, 2010, 8:07:16 PM11/9/10
to android-platform
Can it be done, say, by making the system process call a C library
that opens & writes files ?

Nirjon,
University of Virgnia

Dianne Hackborn

unread,
Nov 9, 2010, 8:37:01 PM11/9/10
to android-...@googlegroups.com
On Tue, Nov 9, 2010 at 5:07 PM, nirjon <nir...@gmail.com> wrote:
Can it be done, say, by making the system process call a C library
that opens & writes files ?

No, calling a C library function is still running that code in the caller's process.

--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Nirjon

unread,
Nov 9, 2010, 10:05:42 PM11/9/10
to android-...@googlegroups.com
Right. I was trying to create a file into the /sdcard from a System process (I wrote and start it by modifying the system server and related java files) and got the same error. But, now I changed it to create and write into /data/data folder which is working just fine. I believe with this system uid I can do it into /data/data but not in /sdcard. 

2 questions: 
1. How much data (bytes) can I write (better say log) into /data/data folder? I need to log some low level info (for my own research) every 10 sec for about a day. I need about 180 KB to log each day.
2. What are the other folders that are accessible like this /data/data one?   

Shahriar Nirjon,
University of Virginia.



--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To post to this group, send email to android-...@googlegroups.com.
To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.



--
Nirjon.

Yenliang Liu

unread,
Nov 17, 2010, 1:36:06 AM11/17/10
to android-...@googlegroups.com
if you see permission of files in /sdcard, you will see only application with sdcard_rw group permission can write to /sdcard and this permission is granted by declaring WRITE_EXTERNAL_STORAGE in your AndroidManifest.xml.

Best Regards,
--
yenliangl,

arun gupta

unread,
Nov 17, 2010, 5:04:40 AM11/17/10
to android-...@googlegroups.com
i have an idea please correct me if i am wrong.
 system process can send the data to a service runned by the user (user mode) and pass the data to it.so the service can open/write to the sd card.
please share some view on it.
 
regards
Arun Gupta

Pavan Savoy

unread,
Nov 17, 2010, 6:22:05 AM11/17/10
to android-...@googlegroups.com
http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

tells me that if I am using APi level 7 or below I can use this path
"/Android/data/<package_name>/files/" ...

what does this mean?
Does it mean what I write hear will be reflected on the external
storage root path? /sdcard/ ?
So example I have my bluetooth C program saving an incoming file, I save it to
/data/com.android.bluetooth_ftp/bluetooth and will be reflected in
/sdcard/bluetooth ?

regards,
Pavan

--
--Pavan Savoy

Reply all
Reply to author
Forward
0 new messages