cuốn sách gpt4 ai đã làm

java - 从应用程序重新安装/系统

In lại Tác giả: Walker 123 更新时间:2023-11-29 03:32:02 25 4
mua khóa gpt4 Nike

我正在尝试创建一个小型应用程序,它需要对/system 文件夹进行读/写访问(它正在尝试删除一个文件,并创建一个新文件来代替它)。我可以使用 adb 毫无问题地重新挂载该文件夹,如果我这样做,我的应用程序肯定可以正常工作,直到重新启动。

我的设备已获得 root 权限(sgs3 和 stock 4.1.2)。我可以毫无问题地获得 root 访问权限 - 我在可以启用它的地方收到弹出消息。但在那之后它并没有真正响应命令。

我有这样的东西:

//at this point I get the popup to grant root access
Runtime.getRuntime().exec("su");

//no error messages - not on console, not in logcat
Runtime.getRuntime().exec("mount -w -o remount -t ext4 /dev/block/mmcblk0p9 /system");

//trying to do things in the system folder...
FileWriter fw=new FileWriter(file);
fw.write("a");
fw.close();

//trying to remount the folder as read only only once everything is done
Runtime.getRuntime().exec("mount -r -o remount -t ext4 /dev/block/mmcblk0p9 /system");

如果我从 adb shell 运行相同的重新安装命令,一切都会完美。如果我不运行它,而是尝试依赖该应用程序,当我尝试从文件系统写入/删除时,会收到以下错误消息(抛出 IOException):

open failed: EROFS (read-only file system)

一些附加信息:我正在使用 2.2 SDK,在我的 list 文件中具有 WRITE_EXTERNAL_STORAGE 权限(尽管我不确定是否需要它,因为我正在尝试使用内部存储)。

欢迎所有想法。

câu trả lời hay nhất

你的问题是你挂载的进程与你的 root 进程不同,尝试这样的事情:

Process suProcess;
DataOutputStream os;


thử{
//Get Root
suProcess = Runtime.getRuntime().exec("su");
os= new DataOutputStream(suProcess.getOutputStream());

//Remount writable FS within the root process
os.writeBytes("mount -w -o remount -t ext4 /dev/block/mmcblk0p9 /system\n");
os.flush();

//Do something here
os.writeBytes("rm /system/somefile\n");
os.flush();

//Do something there
os.writeBytes("touch /system/somefile\n");
os.flush();

//Remount Read-Only
os.writeBytes("mount -r -o remount -t ext4 /dev/block/mmcblk0p9 /system\n");
os.flush();

//End process
os.writeBytes("exit\n");
os.flush();

}
catch (IOException e) {
throw new RuntimeException(e);
}

关于java - 从应用程序重新安装/系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17685157/

25 4 0
Đề xuất bài viết: php - 目录名称无效 : 1046 No database selected
Đề xuất bài viết: mysql连接查询比mssql慢
Đề xuất bài viết: Mysql 从每个月获取最后一条日志条目
Đề xuất bài viết: ios - Box api 编辑文件
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress