Cannot read or write to SDCARD from new system service

491 views
Skip to first unread message

Hombre

unread,
Jul 4, 2011, 12:28:00 PM7/4/11
to android-porting
Hi

I have created a new service launched in SystemServer.java:

try {
Slog.i(TAG, "xxxx Service");
ServiceManager.addService("xxxx", new
xxxxService(context));
} catch (Throwable e) {
Slog.e(TAG, "Failure starting xxxx Service", e);
}

Everything is fine except I cannot write to or read from the SDCARD. I
need to create directories and write files based on a HTTP feed. This
files are the read back for display and other purposes. I understand
that in a stand-alone app the permission mus be set in
AndroidMAnifest.xml. But this is the OS. I would have thought that the
SystemServer would have such permission.

in my code the call to
mContext.checkCallingOrSelfPermission("android.permission.WRITE_EXTERNAL_STORAGE");

returns 0 which is permission denied.

I have tried the following

mContext.enforcePermission("android.permission.WRITE_EXTERNAL_STORAGE",
Binder.getCallingPid(), 0, "xxxCache enforcing sdcard write");

which does not help

I have tried

File sdcard = new
File(Environment.getExternalStorageDirectory().toString());

sdcard.setWritable(true);

this also fails.

So I assume I do not have the permission to write (an read) to the
SDCard

BTW this is done on the emulator.

Can someone please point me in the right direction. I have scoured the
framework source code and cannot find where permissions are set.

Thanks in Advance

Jean-Pierre


freakingtux

unread,
Jul 5, 2011, 4:46:28 PM7/5/11
to android...@googlegroups.com
Hi Jean-Pierre ,

There are a few things I don't understand about your post:
If you are really downloading file and putting them on the sdcard why do you need to create a system service for that?
If you are running as root or system user (as the system_server is) no calling permissions at binder level are executed (see https://github.com/keesj/gomo/wiki/AndroidSecurity )
The System server does have a manifest it can be found here frameworks/base/core/res/AndroidManifest.xml and it itself defines the WRITE_EXTERNAL_STORAGE (so if you read the above links you the return value of the permission check should be different.)
problem anyway is that Adding  "use-permission" WRITE_EXTERNAL_STORAGE in the AndroidManifest will probably not work (the package needs to be installed before the permission exists).

Perhaps those are all big warnings you don't want to to trivial stuff (like downloading over HTTP) in the system_server.

freakingtux

unread,
Jul 6, 2011, 6:10:31 AM7/6/11
to android...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages