|
| 1 | +package android.os; |
| 2 | + |
| 3 | +import java.io.FileDescriptor; |
| 4 | + |
| 5 | +/** |
| 6 | + * This class provides access to the centralized jni bindings for |
| 7 | + * SELinux interaction. |
| 8 | + * {@hide} |
| 9 | + */ |
| 10 | +public class SELinux { |
| 11 | + |
| 12 | + /** |
| 13 | + * Determine whether SELinux is disabled or enabled. |
| 14 | + * @return a boolean indicating whether SELinux is enabled. |
| 15 | + */ |
| 16 | + public static final native boolean isSELinuxEnabled(); |
| 17 | + |
| 18 | + /** |
| 19 | + * Determine whether SELinux is permissive or enforcing. |
| 20 | + * @return a boolean indicating whether SELinux is enforcing. |
| 21 | + */ |
| 22 | + public static final native boolean isSELinuxEnforced(); |
| 23 | + |
| 24 | + /** |
| 25 | + * Set whether SELinux is permissive or enforcing. |
| 26 | + * @param boolean representing whether to set SELinux to enforcing |
| 27 | + * @return a boolean representing whether the desired mode was set |
| 28 | + */ |
| 29 | + public static final native boolean setSELinuxEnforce(boolean value); |
| 30 | + |
| 31 | + /** |
| 32 | + * Sets the security context for newly created file objects. |
| 33 | + * @param context a security context given as a String. |
| 34 | + * @return a boolean indicating whether the operation succeeded. |
| 35 | + */ |
| 36 | + public static final native boolean setFSCreateContext(String context); |
| 37 | + |
| 38 | + /** |
| 39 | + * Change the security context of an existing file object. |
| 40 | + * @param path representing the path of file object to relabel. |
| 41 | + * @param con new security context given as a String. |
| 42 | + * @return a boolean indicating whether the operation succeeded. |
| 43 | + */ |
| 44 | + public static final native boolean setFileContext(String path, String context); |
| 45 | + |
| 46 | + /** |
| 47 | + * Get the security context of a file object. |
| 48 | + * @param path the pathname of the file object. |
| 49 | + * @return a security context given as a String. |
| 50 | + */ |
| 51 | + public static final native String getFileContext(String path); |
| 52 | + |
| 53 | + /** |
| 54 | + * Get the security context of a peer socket. |
| 55 | + * @param fd FileDescriptor class of the peer socket. |
| 56 | + * @return a String representing the peer socket security context. |
| 57 | + */ |
| 58 | + public static final native String getPeerContext(FileDescriptor fd); |
| 59 | + |
| 60 | + /** |
| 61 | + * Gets the security context of the current process. |
| 62 | + * @return a String representing the security context of the current process. |
| 63 | + */ |
| 64 | + public static final native String getContext(); |
| 65 | + |
| 66 | + /** |
| 67 | + * Gets the security context of a given process id. |
| 68 | + * Use of this function is discouraged for Binder transactions. |
| 69 | + * Use Binder.getCallingSecctx() instead. |
| 70 | + * @param pid an int representing the process id to check. |
| 71 | + * @return a String representing the security context of the given pid. |
| 72 | + */ |
| 73 | + public static final native String getPidContext(int pid); |
| 74 | + |
| 75 | + /** |
| 76 | + * Gets a list of the SELinux boolean names. |
| 77 | + * @return an array of strings containing the SELinux boolean names. |
| 78 | + */ |
| 79 | + public static final native String[] getBooleanNames(); |
| 80 | + |
| 81 | + /** |
| 82 | + * Gets the value for the given SELinux boolean name. |
| 83 | + * @param String The name of the SELinux boolean. |
| 84 | + * @return a boolean indicating whether the SELinux boolean is set. |
| 85 | + */ |
| 86 | + public static final native boolean getBooleanValue(String name); |
| 87 | + |
| 88 | + /** |
| 89 | + * Sets the value for the given SELinux boolean name. |
| 90 | + * @param String The name of the SELinux boolean. |
| 91 | + * @param Boolean The new value of the SELinux boolean. |
| 92 | + * @return a boolean indicating whether or not the operation succeeded. |
| 93 | + */ |
| 94 | + public static final native boolean setBooleanValue(String name, boolean value); |
| 95 | + |
| 96 | + /** |
| 97 | + * Check permissions between two security contexts. |
| 98 | + * @param scon The source or subject security context. |
| 99 | + * @param tcon The target or object security context. |
| 100 | + * @param tclass The object security class name. |
| 101 | + * @param perm The permission name. |
| 102 | + * @return a boolean indicating whether permission was granted. |
| 103 | + */ |
| 104 | + public static final native boolean checkSELinuxAccess(String scon, String tcon, String tclass, String perm); |
| 105 | +} |
0 commit comments