星空网 > 软件开发 > 操作系统

android操作/system路径(移动文件)

原因:
需要隐藏手机下拉框菜单。实际就是删除/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;
            }
        }
        return null;
    } 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){
        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



原标题:android操作/system路径(移动文件)

关键词:Android

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

同是质量管理:https://www.goluckyvip.com/tag/804.html
新天地:https://www.goluckyvip.com/tag/8040.html
阿里电商:https://www.goluckyvip.com/tag/8041.html
出口服务方案:https://www.goluckyvip.com/tag/8042.html
信保订单:https://www.goluckyvip.com/tag/8043.html
国际名牌鞋子:https://www.goluckyvip.com/tag/80439.html
九月初新疆旅游服装搭配(新疆游玩必备衣服清单):https://www.vstour.cn/a/408257.html
黄果树瀑布景区景点 - 黄果树瀑布景区景点分布图:https://www.vstour.cn/a/408258.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流