原因: 需要隱藏手機下拉框菜單。實際就是刪除/system/app/SystemUI.apk文件,即能達到隱藏效果。(不足:會使手機操作系統強制重啟) 解決思路: 1.首先獲取到/system掛載點所對應的設備文件 2.以root許可權將其重新掛載為可讀寫 3.以root許可權刪除/system/app ...
原因: 需要隱藏手機下拉框菜單。實際就是刪除/system/app/SystemUI.apk文件,即能達到隱藏效果。(不足:會使手機操作系統強制重啟) 解決思路: 1.首先獲取到/system掛載點所對應的設備文件 2.以root許可權將其重新掛載為可讀寫 3.以root許可權刪除/system/app/SystemUI.apk文件 重點: 1.掛載/system路徑為可讀寫 mount -o remount /dev/xxx /system 2.程式獲取到root許可權 su 三個主要函數: 1 輸入: path 此處/system 輸出: path對應的設備文件 獲取設備文件 public static String getDev(String path) 2 輸入: 輸出: 以Root許可權執行 command (先驗證command能正常執行) public static boolean runRootCommand(String command) 3 輸入: 輸出: 重命名文件 public static int move(String sourceFile, String destFile) 一種實現: public static String getDev(String path) { if(null == path) return null; BufferedReader in = null; try { Process p = Runtime.getRuntime().exec("mount"); p.waitFor(); in = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; while((line = in.readLine()) != null){ if(line.contains(path)) { return line; } } } catch (IOException e) { // TODO 自動生成的 catch 塊 e.printStackTrace(); } catch (InterruptedException e) { // TODO 自動生成的 catch 塊 e.printStackTrace(); } return null; } public static boolean runRootCommand(String command){ Process process = null; DataOutputStream os = null; try{ process = Runtime.getRuntime().exec("su"); os = new DataOutputStream(process.getOutputStream()); os.writeBytes(command+"\n"); os.writeBytes("exit\n"); os.flush(); process.waitFor(); }catch(Exception e){ try{ if(null != os){ os.close(); } if(null != process){ process.destroy(); } }catch(Exception e){ e.printStackTrace(); } return false; }finally{ try{ if(null != os){ os.close(); } if(null != process){ process.destroy(); } }catch(Exception e){ e.printStackTrace(); } } return true; } //@return 0成功 -1 源文件不存 -2轉移失敗 -3參數錯誤 public static int move(String sourceFile, String destFile) { int result = 0; if(null == sourceFile || null == destFile) return -3; File sFile = new File(sourceFile); if(!sFile.exists())//源文件不存在 return -1; String dev = getDev("/system"); if(null != dev){ for(int i=0; i<dev.length(); i++) System.out.println("-----------"+(int)dev.charAt(i)); String[] contents = dev.split(" "); String command = "mount -o remount "+contents[0]+" /system"; runRootCommand(command); System.out.println("----------"+command); } try{ String command = "mv "+sourceFile+" "+destFile; runRootCommand(command); //Process move = Runtime.getRuntime().exec("mv "+sourceFile+" "+destFile+""); }catch(Exception e){ System.out.println("------------"+e.getMessage()); return -2; } File dFile = new File(destFile); if(dFile.exists() && !sFile.exists()){ result = 0; }else{ result = -2; } return result; } 註意:手機需root