Home | History | Annotate | Download | only in os
      1 package android.os;
      2 
      3 import android.os.Process;
      4 import android.os.SELinux;
      5 import android.test.AndroidTestCase;
      6 import static junit.framework.Assert.assertEquals;
      7 
      8 public class SELinuxTest extends AndroidTestCase {
      9 
     10     public void testgetFileCon() {
     11         if(SELinux.isSELinuxEnabled() == false)
     12             return;
     13 
     14         String ctx = SELinux.getFileContext("/system/bin/toolbox");
     15         assertEquals(ctx, "u:object_r:system_file:s0");
     16     }
     17 
     18     public void testgetCon() {
     19         if(SELinux.isSELinuxEnabled() == false)
     20             return;
     21 
     22         String mycon = SELinux.getContext();
     23         assertEquals(mycon, "u:r:untrusted_app:s0:c33");
     24     }
     25 
     26     public void testgetPidCon() {
     27         if(SELinux.isSELinuxEnabled() == false)
     28             return;
     29 
     30         String mycon = SELinux.getPidContext(Process.myPid());
     31         assertEquals(mycon, "u:r:untrusted_app:s0:c33");
     32     }
     33 
     34     public void testcheckSELinuxAccess() {
     35         if(SELinux.isSELinuxEnabled() == false)
     36             return;
     37 
     38         String mycon = SELinux.getContext();
     39         boolean ret;
     40         ret = SELinux.checkSELinuxAccess(mycon, mycon, "process", "fork");
     41         assertEquals(ret,"true");
     42         ret = SELinux.checkSELinuxAccess(mycon, mycon, "memprotect", "mmap_zero");
     43         assertEquals(ret,"true");
     44     }
     45 }
     46