1.在RKUpdateService中调用findFromSdOrUsb检测update.zip文件或者update.img文件
2.检测到文件后 如果是 img文件则携带 version参数跳转 android.rockchip.update.service.FirmwareUpdatingActivity,是zip则直接跳转
3.在 FirmwareUpdatingActivity 文件中 点击 ok 跳转 UpdateAndRebootActivity 携带 文件path;
4.在 UpdateAndRebootActivity 页面 如果是 img 则调用 updateFirmware ,model : RKUPDATE_MODE:1 ; 如果是 zip,model :OTAUPDATE_MODE:2
5. 回到RKUpdateService 的 LocalBinder 的 RKRecoverySystem.installPackage
6.调用 RecoverySystem.installPackage(context, packageFile);
然后回到 frameworks/base/core/java/android/os/RecoverySystem.java
public static void installPackage(Context context, File packageFile, boolean processed)
throws IOException {
synchronized (sRequestLock) {
LOG_FILE.delete();
// Must delete the file in case it was created by system server.
UNCRYPT_PACKAGE_FILE.delete();
String filename = packageFile.getCanonicalPath();
Log.w(TAG, "!!! REBOOTING TO INSTALL " + filename + " !!!");
// If the package name ends with "_s.zip", it's a security update.
boolean securityUpdate = filename.endsWith("_s.zip");
// If the package is on the /data partition, the package needs to
// be processed (i.e. uncrypt'd). The caller specifies if that has
// been done in 'processed' parameter.
if (filename.startsWith("/data/")) {
if (processed) {
if (!BLOCK_MAP_FILE.exists()) {
Log.e(TAG, "Package claimed to have been processed but failed to find "
+ "the block map file.");
throw new IOException("Failed to find block map file");
}
} else {
FileWriter uncryptFile = new FileWriter(UNCRYPT_PACKAGE_FILE);
try {
uncryptFile.write(filename + "\n");
} finally {
uncryptFile.close();
}
// UNCRYPT_PACKAGE_FILE needs to be readable and writable
// by system server.
if (!UNCRYPT_PACKAGE_FILE.setReadable(true, false)
|| !UNCRYPT_PACKAGE_FILE.setWritable(true, false)) {
Log.e(TAG, "Error setting permission for " + UNCRYPT_PACKAGE_FILE);
}
BLOCK_MAP_FILE.delete();
}
// If the package is on the /data partition, use the block map
// file as the package name instead.
filename = "@/cache/recovery/block.map";
}
final String filenameArg = "--update_package=" + filename + "\n";
final String localeArg = "--locale=" + Locale.getDefault().toLanguageTag() + "\n";
final String securityArg = "--security\n";
String command = filenameArg + localeArg;
if (securityUpdate) {
command += securityArg;
}
RecoverySystem rs = (RecoverySystem) context.getSystemService(
Context.RECOVERY_SERVICE);
if (!rs.setupBcb(command)) {
throw new IOException("Setup BCB failed");
}
// Having set up the BCB (bootloader control block), go ahead and reboot
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
String reason = PowerManager.REBOOT_RECOVERY_UPDATE;
// On TV, reboot quiescently if the screen is off
if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
if (wm.getDefaultDisplay().getState() != Display.STATE_ON) {
reason += ",quiescent";
}
}
pm.reboot(reason);
throw new IOException("Reboot failed (no permissions?)");
}
}
如何禁止自动升级并让用户App可以执行升级命令
修改思路及内容
1. 在RKUpdateService中不检测update.zip文件和update.img文件
2. 修改页面布局 notify_dialog,及 UpdateAndRebootActivity页面的显示,使该页面透明悬浮
3. 调用方式为 = 直接跳转
Intent intent = new Intent();
intent.setComponent(new ComponentName("android.rockchip.update.service", "android.rockchip.update.service.UpdateAndRebootActivity") );
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("android.rockchip.update.extra.IMAGE_PATH", path);
context.startActivity(intent);