[android-developers] Re: How to change device file permission from Java app.
Hello Mark, In java.io, the File API is supposed to provide APIs like setExecutable (boolean) setWritable (boolean) setReadable (boolean) However, in the android.jar which includes all the needed classes, the java.io package doesn't provide the above APIs in the File class. Has this been done for security reasons ? Which means if an application downloads some bytes and writes to a file created through the below code File destination = new File (/sdcard/myfile.txt); there is no way to change permissions of 'myfile.txt' to 777 ? There is a 'Runtime' facility provided through java.lang, but I'm skeptical whether to use this or not. Runtime would only work on rooted devices right? eg., http://stackoverflow.com/questions/6290307/android-runtime-command-problem -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: How to change device file permission from Java app.
On Tue, Aug 9, 2011 at 2:38 AM, uday kiran jandhyala udayjandhy...@gmail.com wrote: Has this been done for security reasons ? Probably. Which means if an application downloads some bytes and writes to a file created through the below code File destination = new File (/sdcard/myfile.txt); there is no way to change permissions of 'myfile.txt' to 777 ? First, nobody uses /sdcard, since it is wrong. Use Environment.getExternalStorageDirectory(). Second, nobody bothers to try to change Linux file permissions on external storage, since for the vast majority of current devices, that's FAT32 (vfat in Linux-ese), and file permissions do not matter much on that filesystem. There is a 'Runtime' facility provided through java.lang, but I'm skeptical whether to use this or not. Runtime would only work on rooted devices right? More importantly, you cannot reliably change permission bits that way either. And, most of all, you shouldn't be changing permission bits in the first place. I have no idea what you think change the permission of lcd device file permission, but it has nothing to do with the Android SDK. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android 3.1 Programming Books: http://commonsware.com/books -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: How to change device file permission from Java app.
On Tuesday, August 9, 2011 7:17:30 AM UTC-4, Mark Murphy (a Commons Guy) wrote: Has this been done for security reasons ? Probably. Unlikely, as it can be done with the ndk, and we are repeatedly told that the ndk does not have special permissions. Most likely they just didn't bother implementing support in javaj for something that wasn't envisioned as needed. Which means if an application downloads some bytes and writes to a file created through the below code File destination = new File (/sdcard/myfile.txt); there is no way to change permissions of 'myfile.txt' to 777 ? First, nobody uses /sdcard, since it is wrong. Use Environment.getExternalStorageDirectory(). Second, nobody bothers to try to change Linux file permissions on external storage, since for the vast majority of current devices, that's FAT32 (vfat in Linux-ese), and file permissions do not matter much on that filesystem. However, on internal storage where permissions matter, the java file creation tools do let you set the permissions to some extent (ie, various android presets, but not full unix bit-level control) There is a 'Runtime' facility provided through java.lang, but I'm skeptical whether to use this or not. Runtime would only work on rooted devices right? More importantly, you cannot reliably change permission bits that way either. The runtime facility does not require root, though it's perhaps not future-proof since it's not officially supported. It's also needlessly roundabout. A better way to do it would be to invoke an ndk subroutine through jni which uses the chmod() syscall. There's nothing even slightly improper about doing that. first place. I have no idea what you think change the permission of lcd device file permission, but it has nothing to do with the Android SDK. This may be the only real problem - the device files are certainly not owned by application users, and so cannot have their permissions changed by one. (_That_ might be the reason the task would require an ability to execute a stand alone program as root) Ordinary files owned by an application user id and residing on a filesystem where it is meaningful can however have their permission bits changed. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: How to change device file permission from Java app.
On Tue, Aug 9, 2011 at 11:53 AM, Chris Stratton cs07...@gmail.com wrote: Unlikely, as it can be done with the ndk, and we are repeatedly told that the ndk does not have special permissions. Most likely they just didn't bother implementing support in javaj for something that wasn't envisioned as needed. Possibly, but I'm skeptical. Bear in mind that the decision to remove those methods was made years before the NDK existed. However, on internal storage where permissions matter, the java file creation tools do let you set the permissions to some extent (ie, various android presets, but not full unix bit-level control) Very true. Ordinary files owned by an application user id and residing on a filesystem where it is meaningful can however have their permission bits changed. That being said, IMHO it's rarely a good idea. I would rather developers provide a real API (remote service, content provider, etc.). -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android Training in Oslo: http://bit.ly/fjBo24 -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en