Android/Tip&Tech
루팅폰 확인하기
행복한 수지아빠
2011. 6. 23. 12:19
반응형
루팅폰에 system/sd 폴더는 퍼미션이 r/w로 되어있다는 것에 착안 거기에 파일을 생성하고 생성이
제대로 되면 루팅폰이라는걸 판단하는 코드
Process p; try { // Preform su to get root privledges p = Runtime.getRuntime().exec("su"); // Attempt to write a file to a root-only DataOutputStream os = new DataOutputStream(p.getOutputStream()); os.writeBytes("echo \"Do I have root?\" >/system/sd/temporary.txt\n"); // Close the terminal os.writeBytes("exit\n"); os.flush(); try { p.waitFor(); if (p.exitValue() != 255) { // TODO Code to run on success toastMessage("root"); } else { // TODO Code to run on unsuccessful toastMessage("not root"); } } catch (InterruptedException e) { // TODO Code to run in interrupted exception toastMessage("not root"); } } catch (IOException e) { // TODO Code to run in input/output exception toastMessage("not root"); }
반응형