美文网首页
Android升级OTA

Android升级OTA

作者: 使劲挤海绵 | 来源:发表于2018-06-07 07:59 被阅读29次
    • 校验升级包
      调用RecoverySystem类提供的verifyPackage方法进行签名验证
        public static void installPackage(Context context, File packageFile)
            throws IOException {
            String filename = packageFile.getCanonicalPath();
            Log.w(TAG, "!!! REBOOTING TO INSTALL " + filename + " !!!");
    
            final String filenameArg = "--update_package=" + filename;
            final String localeArg = "--locale=" + Locale.getDefault().toString();
            bootCommand(context, filenameArg, localeArg);
        }
    
    • installPackage开始升级
        public static void installPackage(Context context, File packageFile)
            throws IOException {
            String filename = packageFile.getCanonicalPath();
            Log.w(TAG, "!!! REBOOTING TO INSTALL " + filename + " !!!");
    
            final String filenameArg = "--update_package=" + filename;
            final String localeArg = "--locale=" + Locale.getDefault().toString();
            bootCommand(context, filenameArg, localeArg);
        }
    
        private static void bootCommand(Context context, String... args) throws IOException {
            RECOVERY_DIR.mkdirs();  // In case we need it
            COMMAND_FILE.delete();  // In case it's not writable
            LOG_FILE.delete();
    
            FileWriter command = new FileWriter(COMMAND_FILE);
            try {
                for (String arg : args) {
                    if (!TextUtils.isEmpty(arg)) {
                        command.write(arg);
                        command.write("\n");
                    }
                }
            } finally {
                command.close();
            }
    
            // Having written the command file, go ahead and reboot
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            pm.reboot(PowerManager.REBOOT_RECOVERY);
    
            throw new IOException("Reboot failed (no permissions?)");
        }
    

    参考:
    OTA升级
    OTA升级包制作过程
    Recovery升级过程

    相关文章

      网友评论

          本文标题:Android升级OTA

          本文链接:https://www.haomeiwen.com/subject/gjswsftx.html