How does Android modify the permissions of a file in the Java/native layer (mode) with the user (owner)?

Source: Internet
Author: User

Objective
Welcome everyone I share and recommend useful code Snippets ~ ~
Statement
Welcome reprint, but please keep the original source of the article:
Csdn:http://www.csdn.net
Rainy season o mo away: http://blog.csdn.net/luckkof

Body

[Description]
How to modify the permissions of a file in the Java/native layer (mode), user (owner), group, to meet security needs?
[Keyword]
File permissions file user mode owner CHOMD chown permission
[Solution]
On the native layer:
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h> //chmod/fchmod used to update access rights
int chmod (const char *path, mode_t mode);
int fchmod (int fildes, mode_t mode); Chown/fchown/lchown to update the file owner and group
int chown (const char *path, uid_t owner, gid_t Group);
int fchown (int fd, uid_t owner, gid_t Group);
int Lchown (const char *path, uid_t owner, gid_t Group); //used to read file meta data
int stat (const char *path, struct stat *buf);
int fstat (int filedes, struct stat *buf);
int Lstat (const char *path, struct stat *buf); more information can be chmod in Linux, man chown, man stat  in Java layer:
Java default does not provide such functionality, Android to meet internal needs, in the Android.os.FileUtils The SetPermissions method is provided in the class, combining chmod with Chown. Parameter mode is the mode in the chmod parameter, when you do not need to set the UID and group of file, both UID and GID can be set to-1;
Android.os.FileUtils
public static native int SetPermissions (String file, int mode, int uid, int gid);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.