File access for native code

by rktb » Wed, 24 Dec 2008 08:59:10 GMT


Sponsored Links
 Hi,

Need some pointers about file access permissions:

Here is what I have tried:

<my_package_name>/files/ using the API openFileOutput(). The
permissions of the file is as follows:
-rw-rw---- app_10   app_10          0 2008-12-23 09:17 testFile1.txt

The files folder itself has the permissions:
 drwxrwx--x app_10   app_10            2008-12-23 09:17 files

When I create a file using native code on /sdcard, the permissions are
as follows:
 ----rw-rw- system   system          0 2008-12-23 09:17
fromNativeCode.txt
Is it right to say that native code process has "system" rights?

Now, when I create a file using the Java layer, I can open the same
file for "reading" through native code. But, I cannot open a file in
the same place using the native code with "writing" capability.  The
permissions of the "files" folder is "app_10", which is the userID of
the app. Right? Doesn't "system" trump "app_10" in terms of
permissions?

In other words, the objective that I am trying to achieve is to create
a file inside native code at a place other than sdcard. Preferably,
application specific location.

Any document that anybody could point that would detail more about
security and permissions? I have already read
 http://code.google.com/android/devel/security.html. But , it does not
deal with native code details.

Thanks,
Ravi


--~--~---------~--~----~------------~-------~--~----~



File access for native code

by freepine » Wed, 24 Dec 2008 10:22:43 GMT


 Each Android package (.apk) file installed on the device is given its own
unique Linux user ID and any files created by that application will be
assigned its user ID which is not normally accessible to other packages

You can refer to below link:
 http://code.google.com/intl/zh-CN/android/devel/security.html 





--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


File access for native code

by freepine » Wed, 24 Dec 2008 10:29:47 GMT


 Sorry I misunderstood your question:)
Is your native code running in the same process of the Java application? or
you want to create some files under the java app's home directory by another
native process?






--~--~---------~--~----~------------~-------~--~----~



File access for native code

by rktb » Wed, 24 Dec 2008 10:30:15 GMT


 Yes. I understand that. I also understand how one application can
access the private data of another application [using sharedUserId].

I think I missed a point in my earlier explanation. The native code
that is trying to create a file in a application specific folder has
been invoked by the same application using JNI.

Example:
Music app has its private folder called /data/data/com.android.music/.
When creating a file, it does create it in /data/data/
com.android.music/files. Now, mediaplayer.cpp, which is the native
code version of the mediaplayer, is not able to create a file in the
same folder.

-Ravi






--~--~---------~--~----~------------~-------~--~----~



File access for native code

by rktb » Wed, 24 Dec 2008 11:18:40 GMT


 Hi freepine,

I am using the Music app which is invoking the mediaplayback service.
So, from what I gather, I believe the native code is running under a
different process.

-Ravi





--~--~---------~--~----~------------~-------~--~----~



File access for native code

by freepine » Wed, 24 Dec 2008 13:16:29 GMT


 i Ravi,

Yes, media playback is actually within the native media server process. The
music Java app only has a BpMediaplayer instance below JNI which
communicates with media server via Binder mechanism.
So normally their UIDs are different. I remember media server's UID/PID is
media/system:)

-freepine


On Wed, Dec 24, 2008 at 7:18 PM, rktb <yend...@pv.com> wrote:


--~--~---------~--~----~------------~-------~--~----~



File access for native code

by Dave Sparks » Wed, 24 Dec 2008 19:34:35 GMT


 Hi Ravi,

I think you need to have the native app create the file and pass the
open file descriptor to the media server. This is how rights are
conferred from one process to another in the Android security model.

Dave



--~--~---------~--~----~------------~-------~--~----~



File access for native code

by rktb » Thu, 25 Dec 2008 01:57:16 GMT


 Hi Dave,

Sorry...I did not understand completely.

What is the native app?

-Ravi




--~--~---------~--~----~------------~-------~--~----~



File access for native code

by freepine » Thu, 25 Dec 2008 04:11:53 GMT


 I guess it's the java app you are using, i.e. com.android.music






--~--~---------~--~----~------------~-------~--~----~



File access for native code

by rktb » Thu, 25 Dec 2008 04:49:19 GMT


 Oh ok.  Thanks freepine !

So, can we summarize that the mediaserver cannot really create a file
in internal memory. And, the best way to provide a file access is to
pass it through a file descriptor from the application to the
mediaserver process.

-Ravi






--~--~---------~--~----~------------~-------~--~----~



File access for native code

by freepine » Thu, 25 Dec 2008 05:05:54 GMT


  think it depends:).
Are you trying to implement something like progressive download in opencore
player?
If so, I think you might not want to grant the access permission of
downloaded files only to the default music player?

Will it be played as ringtone or inserted to MMS? :)

-freepine

On Thu, Dec 25, 2008 at 12:49 PM, rktb <yend...@pv.com> wrote:


--~--~---------~--~----~------------~-------~--~----~



File access for native code

by rktb » Thu, 25 Dec 2008 06:41:31 GMT


 i freepine,

I would like to read more about the permissions and access before
posting any educated question. Can you point me to any code or doc? If
not, read further for my questions :-)

Though progressive download is a good example, the files that I am
referring to is not media content. The media content, I am almost
certain, should be accessed by content providers. What I am talking
about is a normal text file that, in this case, stores the state of
the download. And, a different app. needs access to this text file.
This is the required behavior.

Thanks,
Ravi

On Dec 25, 10:05am, freepine <freep...@gmail.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



File access for native code

by freepine » Thu, 25 Dec 2008 07:02:12 GMT


 i Ravi,
I don't have more useful information except the links your are referring
from android website:( I think Dave might can help to share some resource
for us.

There was some discussions in the list about granting access permission to
other applications, which might require delicate solutions and also depends
on the concrete requirements.

-freepine

On Thu, Dec 25, 2008 at 2:41 PM, rktb <yend...@pv.com> wrote:


--~--~---------~--~----~------------~-------~--~----~



File access for native code

by rktb » Thu, 25 Dec 2008 07:05:38 GMT


 k thanks.

<waiting for Dave> :-)

On Dec 25, 12:01pm, freepine <freep...@gmail.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



File access for native code

by Dianne Hackborn » Sat, 27 Dec 2008 10:24:32 GMT


 ach process runs under its own uid, so can only access files owned by that
uid. If you want to read a file owned by another process/uid, you will need
to have that other process do that for you -- by opening it itself and
giving you the fd, making the file world readable, etc.

Fwiw, creating a text file somewhere with download progress information
sounds to me fairly peculiar. Generally I would expect that information to
be accessed through IPC or, as you seem to mention, as part of the
structured data in a content provider.

On Wed, Dec 24, 2008 at 10:41 PM, rktb <yend...@pv.com> wrote:



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

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

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Using maps with a postcode

Is this possible with the current Maps implementation? I want my map
to navigate to a location dependent on the postcode, just like you
would on the google maps website. Or at least to retrieve the latitude
and longitude from the postcode.

Thanks.
--~--~---------~--~----~------------~-------~--~----~

2. ADC2 [tools] Mezzofanti - Augmented reality through text recognition



Hi,

I installed the apk, and when starting it it reports :
"Not enough space for installation on external storage -
requested:25[MB] free:-1008[MB]"

This is on a HTC Magic, and I have about 30MB free in internal memory,
and 7183MB free on SD card.

--~--~---------~--~----~------------~-------~--~----~

3. To add Image in Listview....

4. Evaluate a javascript expression in android

5. WebView.loadUrl on a hidden view opens the android browser

6. OpenGL ES - How to map 2D-X-Y-screen Coordinates to 3D-X-Y-Z Object

7. How read img files