public void clickUpdate(View view) {
Process process = null;
DataOutputStream os = null;
String fileName = "SystemUI.apk";
String srcFilename = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + fileName;
String destFilename = "/system/priv-app/" + fileName;
try {
FileUtil.copyFileFromAssets(this, fileName, srcFilename);
process = Runtime.getRuntime().exec("/system/xbin/su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes("mount -o remount /dev/block/by-name/system /system\n");
os.writeBytes("rm -r " + destFilename + "\n");
os.writeBytes("busybox cp -rf " + srcFilename + " " + destFilename + "\n");
os.writeBytes("chmod 644 " + destFilename + "\n");
os.writeBytes(" reboot \n");
os.writeBytes(" exit \n");
os.flush();
process.waitFor();
int ret = process.exitValue();
Log.e(LOG_TAG, "exitValue = "+ret);
if (ret == 0) {
mTV_status.setText("更新成功!请重启系统!");
} else {
mTV_status.setText("更新失败!");
}
} catch (Exception e) {
e.printStackTrace();
mTV_status.setText("更新失败!");
} finally {
try {
if (os != null) {
os.close();
}
if (process != null) {
process.destroy();
}
} catch (Exception e) {
}
}
}
网友评论