{"version":"0.1.0","code":"0000","result":true,"message":"处理成功","errdetail":"","timestamp":1671508905593,"data":{"id":71713061,"title":"8.5.5 热更新文件","slug":"cu8bof","format":"lake","bookId":26046811,"body":null,"body_draft":null,"body_html":"

简介

热更新文件功能使得本地文件随云端实时在线更新,从而使得终端用户最及时的获得最新的体验。

目前支持热更新的文件类型:

• global.db文件

• changplay.bin文件

• common.irf文件

• route_file规划页文件

• config_file配置文件


热更新文件功能还提供信息流数据输出的功能,在请求检查热更新文件成功后,其回调观察者会透出用户反馈快速标签信息流,用以降低问题反馈成本,提高问题反馈率。

场景图

\"image.png\"

\"image.png\"

\"image.png\"

\"image.png\"

\"image.png\"

\"image.png\"

\"image.png\"

\"image.png\"

\"image.png\"

\"image.png\"

时序图

初始化 & 反初始化

关键参数

com.autonavi.gbl.data.model.HotUpdateFileType

com.autonavi.gbl.data.observer.IHotUpdateCheckObserver

备注:IHotUpdateCheckObserver.onInitNotify()成员函数的参数 AutoInitResponseData 表示返回的信息流数据(即场景图所示快速反馈标签),用户反馈标签字符串以";"号分隔。

com.autonavi.gbl.data.observer.IHotUpdateFileObserver

备注:IHotUpdateFileObserver.OnHotUpdateFile()成员函数的最后一个字符串表示下载保存文件的临时目录路径,而“请求下载热更新文件函数”和“保存热更新文件到指定目录函数”的路径字符串参数表示的是文件最终保存路径。


核心接口

int com.autonavi.gbl.data.HotUpdateService.requestCheckHotUpdate(HotUpdateCheckParam param, IHotUpdateCheckObserver observer)

int com.autonavi.gbl.data.HotUpdateService.requestHotUpdateFile(@HotUpdateFileType.HotUpdateFileType1 int fileType, String strDstPath, IHotUpdateFileObserver observer)

备注:当 fileType 为 HOTUPDATE_FILE_GLOBAL 时,-3 和-5 不返回,由引擎内部检查,观察者通知是否完成。

void com.autonavi.gbl.data.HotUpdateService.abortRequestHotUpdate(int nTaskId)

备注:参数nTaskId为“请求检查热更新文件”和“请求下载热更新文件”请求成功时的返回值。

int com.autonavi.gbl.data.HotUpdateService.saveHotUpdateFile(@HotUpdateFileType.HotUpdateFileType1 int fileType, String strDstPath)

int com.autonavi.gbl.data.HotUpdateService.resetFileVersion(@HotUpdateFileType.HotUpdateFileType1 int fileType)

备注:重置后将清除 AutoSDK 缓存中对应文件的版本信息,下次调用请求检查热更新文件时,服务端下发新的版本号。


说明:函数详情,请复制函数名称到在线API搜索

调用示例

public class HotUpdateImpl {\n\tprivate ArrayList<int> taskIdList;\n    private HotUpdateCheckObserver hotUpdateCheckObserver;\n    private HotUpdateFileObserver hotUpdateFileObserver;\n    \n    public boolean requestCheckHotUpdate()\n    {\n        // 从引导服务获取引导引擎版本号\n        HotUpdateCheckParam param;\n    \tparam.strTbtVersion = getGuideService().getEngineVersion();\n        \n        int taskId = getHotUpdateService().requestCheckHotUpdate(param, hotUpdateCheckObserver);\n        if (0 > taskId)\n        {\n            Log.e(TAG, "requestCheckHotUpdate faile,taskId < 0");\n            return false;\n        }\n        \n        taskIdList.add(taskId);\n        return true;\n    }\n    \n    // 更新文件\n    public void requestUpdateFiles(String strfeedBackContent)\n    {\n       \t// 将返回的用户反馈快速标签信息流写入配置文件\n    \tgetConfigHandle().setfeedBackContent(strfeedBackContent);\n        \n        // 更新全部热更新文件\n        boolean ret = requestHotUpdateFileGlobalDB();\n        if (false == ret)\n        {\n        \tLog.e(TAG, "requestHotUpdateFileGlobalDB faile");\n        }\n        \n        ret = requestHotUpdateFileCommonIrf();\n        if (false == ret)\n        {\n        \tLog.e(TAG, "requestHotUpdateFileCommonIrf faile");\n        }\n        \n        ret = requestHotUpdateFileChangePlay();\n        if (false == ret)\n        {\n        \tLog.e(TAG, "requestHotUpdateFileChangePlay faile");\n        }\n        \n        ret = requestHotUpdateFileRouteFile();\n        if (false == ret)\n        {\n        \tLog.e(TAG, "requestHotUpdateFileRouteFile faile");\n        }\n        \n        ret = requestHotUpdateFileConfigFile();\n        if (false == ret)\n        {\n        \tLog.e(TAG, "requestHotUpdateFileConfigFile faile");\n        }\n    }\n    \n    \n    // 请求更新global.db\n    public boolean requestHotUpdateFileGlobalDB()\n    {\n    \tString destGDBPath = "/storage/emulated/0/amapauto9/res/";\n        int taskId = getHotUpdateService().requestCheckHotUpdate(HOTUPDATE_FILE_CONFIG_FILE, destGDBPath, hotUpdateFileObserver);\n        if (0 == taskId)\n        {\n            Log.e(TAG, "requestCheckHotUpdate faile,taskId == 0");\n            return false;\n        }\n        else if (-1 == taskId)\n        {\n        \tLog.e(TAG, "requestCheckHotUpdate faile,observer is null");\n            return fasle;\n        }\n        else if (-2 == taskId)\n        {\n\t\t\tLog.e(TAG, "requestCheckHotUpdate faile,param err");\n            return fasle;\n        }\n        else if (-3 == taskId)\n        {\n\t\t\tLog.e(TAG, "requestCheckHotUpdate faile,has updated");\n            return true;\n        }\n        \n        taskIdList.add(taskId);\n        return true;\n    }\n    \n    // 请求更新common.irf\n    public boolean requestHotUpdateFileCommonIrf()\n    {\n    \tString destGDBPath = "/storage/emulated/0/amapauto9/data/voice/";\n        int taskId = getHotUpdateService().requestCheckHotUpdate(HOTUPDATE_FILE_COMMON, destGDBPath, hotUpdateFileObserver);\n        if (0 == taskId)\n        {\n            Log.e(TAG, "requestCheckHotUpdate faile,taskId == 0");\n            return false;\n        }\n        else if (-1 == taskId)\n        {\n        \tLog.e(TAG, "requestCheckHotUpdate faile,observer is null");\n            return fasle;\n        }\n        else if (-2 == taskId)\n        {\n\t\t\tLog.e(TAG, "requestCheckHotUpdate faile,param err");\n            return fasle;\n        }\n        else if (-3 == taskId)\n        {\n\t\t\tLog.e(TAG, "requestCheckHotUpdate faile,has updated");\n            return true;\n        }\n        \n        taskIdList.add(taskId);\n        return true;\n    }\n    \n    // 请求更新ChangePlay.bin\n    public boolean requestHotUpdateFileChangePlay()\n    {\n    \tString destGDBPath = "/storage/emulated/0/amapauto9/res/guide/";\n        int taskId = getHotUpdateService().requestCheckHotUpdate(HOTUPDATE_FILE_CHANGEPLAY, destGDBPath, hotUpdateFileObserver);\n        if (0 == taskId)\n        {\n            Log.e(TAG, "requestCheckHotUpdate faile,taskId == 0");\n            return false;\n        }\n        else if (-1 == taskId)\n        {\n        \tLog.e(TAG, "requestCheckHotUpdate faile,observer is null");\n            return fasle;\n        }\n        else if (-2 == taskId)\n        {\n\t\t\tLog.e(TAG, "requestCheckHotUpdate faile,param err");\n            return fasle;\n        }\n        else if (-3 == taskId)\n        {\n\t\t\tLog.e(TAG, "requestCheckHotUpdate faile,has updated");\n            return true;\n        }\n        \n        taskIdList.add(taskId);\n        return true;\n    }\n    \n    // 请求更新route file\n    public boolean requestHotUpdateFileRouteFile()\n    {\n    \tString destGDBPath = "/storage/emulated/0/amapauto9/res/dynamic_style/";\n        int taskId = getHotUpdateService().requestCheckHotUpdate(HOTUPDATE_FILE_ROUTE_FILE, destGDBPath, hotUpdateFileObserver);\n        if (0 == taskId)\n        {\n            Log.e(TAG, "requestCheckHotUpdate faile,taskId == 0");\n            return false;\n        }\n        else if (-1 == taskId)\n        {\n        \tLog.e(TAG, "requestCheckHotUpdate faile,observer is null");\n            return fasle;\n        }\n        else if (-2 == taskId)\n        {\n\t\t\tLog.e(TAG, "requestCheckHotUpdate faile,param err");\n            return fasle;\n        }\n        else if (-3 == taskId)\n        {\n\t\t\tLog.e(TAG, "requestCheckHotUpdate faile,has updated");\n            return true;\n        }\n        \n        taskIdList.add(taskId);\n        return true;\n    }\n    \n    // 请求更新ConfigFile\n    public boolean requestHotUpdateFileConfigFile()\n    {\n    \tString destGDBPath = "/storage/emulated/0/amapauto9/";\n        int taskId = getHotUpdateService().requestCheckHotUpdate(HOTUPDATE_FILE_CONFIG_FILE, destGDBPath, hotUpdateFileObserver);\n        if (0 == taskId)\n        {\n            Log.e(TAG, "requestCheckHotUpdate faile,taskId == 0");\n            return false;\n        }\n        else if (-1 == taskId)\n        {\n        \tLog.e(TAG, "requestCheckHotUpdate faile,observer is null");\n            return fasle;\n        }\n        else if (-2 == taskId)\n        {\n\t\t\tLog.e(TAG, "requestCheckHotUpdate faile,param err");\n            return fasle;\n        }\n        else if (-3 == taskId)\n        {\n\t\t\tLog.e(TAG, "requestCheckHotUpdate faile,has updated");\n            return true;\n        }\n        \n        taskIdList.add(taskId);\n        return true;\n    }\n    \n    // 热更新替换已经下载的global.db文件\n    public boolean saveHotUpdateFileGlobalDB()\n    {\n    \tString destGDBPath = "/storage/emulated/0/amapauto9/res/";\n        int code = getHotUpdateService().saveHotUpdateFile(HOTUPDATE_FILE_GLOBAL, destGDBPath);\n        if (errorcode.common.Service.ErrorCodeOK != code)\n        {\n            log.e(TAG, "saveHotUpdateFile faile, code = "+code);\n        \treturn false;\n        }\n        \n        return true;\n    }\n    \n    // 热更新替换已经下载的common.irf文件\n    public boolean saveHotUpdateFileCommonIrf()\n    {\n    \tString destGDBPath = "/storage/emulated/0/amapauto9/data/voice/";\n        int code = getHotUpdateService().saveHotUpdateFile(HOTUPDATE_FILE_COMMON, destGDBPath);\n        if (errorcode.common.Service.ErrorCodeOK != code)\n        {\n            log.e(TAG, "saveHotUpdateFile faile, code = "+code);\n        \treturn false;\n        }\n        \n        return true;\n    }\n    \n    // 热更新替换已经下载的ChangePlay.bin文件\n    public boolean saveHotUpdateFileChangePlay()\n    {\n    \tString destGDBPath = "/storage/emulated/0/amapauto9/res/guide/";\n        int code = getHotUpdateService().saveHotUpdateFile(HOTUPDATE_FILE_CHANGEPLAY, destGDBPath);\n        if (errorcode.common.Service.ErrorCodeOK != code)\n        {\n            log.e(TAG, "saveHotUpdateFile faile, code = "+code);\n        \treturn false;\n        }\n        \n        return true;\n    }\n    \n    // 热更新替换已经下载的Route File文件\n    public boolean saveHotUpdateFileRouteFile()\n    {\n    \tString destGDBPath = "/storage/emulated/0/amapauto9/res/dynamic_style/";\n        int code = getHotUpdateService().saveHotUpdateFile(HOTUPDATE_FILE_ROUTE_FILE, destGDBPath);\n        if (errorcode.common.Service.ErrorCodeOK != code)\n        {\n            log.e(TAG, "saveHotUpdateFile faile, code = "+code);\n        \treturn false;\n        }\n        \n        return true;\n    }\n    \n    // 热更新替换已经下载的ConfigFile\n    public boolean saveHotUpdateFileConfigFile()\n    {\n    \tString destGDBPath = "/storage/emulated/0/amapauto9/";\n        int code = getHotUpdateService().saveHotUpdateFile(HOTUPDATE_FILE_CONFIG_FILE, destGDBPath);\n        if (errorcode.common.Service.ErrorCodeOK != code)\n        {\n            log.e(TAG, "saveHotUpdateFile faile, code = "+code);\n        \treturn false;\n        }\n        \n        return true;\n    }\n    \n    // 重置热更新版本号\n    public boolean resetHotUpdateFileGlobalDB()\n    {\n    \treturn getHotUpdateService().resetFileVersion(HOTUPDATE_FILE_GLOBAL) == ErrorCodeOK;\n    }\n    \n    // 重置热更新版本号\n    public boolean resetHotUpdateFileCommonIrf()\n    {\n    \treturn getHotUpdateService().resetFileVersion(HOTUPDATE_FILE_COMMON) == ErrorCodeOK;\n    }\n    \n    // 取消请求\n    public boolean abortRequestHotUpdate()\n    {\n    \tfor (int taskId, taskIdList)\n        {\n        \tgetHotUpdateService().abortRequestHotUpdate(taskId);\n        }\n        \n        taskIdList.clear();\n    }\n}
public class HotUpdateCheckObserver implements IHotUpdateCheckObserver {\n    @Override\n    public void onInitNotify(int opErrCode, AutoInitResponseData data) \n    {\n    \tif (errorcode.common.Service.ErrorCodeOK == opErrCode)\n        {\n        \trunOnUiThread(new Runnable(){\n\t\t\t\t@Override\n            \tpublic void run() {\n                    getHotUpdateImpl().requestUpdateFiles(data.strFeedBackContent);\n                }\n            });\n        }\n        else\n        {\n        \tLog.e(TAG, "RequestCheckHotUpdate error");\n        }\n    }\n}


public class HotUpdateFileObserver implements IHotUpdateFileObserver {\n    @Override\n    public void onHotUpdateFile(@HotUpdateFileType.HotUpdateFileType1 int fileType, int opErrCode, String filePath) \n    {\n    \tif (errorcode.common.Service.ErrorCodeOK == opErrCode)\n        {\n        \tif (HOTUPDATE_FILE_COMMON == fileType)\n            {\n            \tboolean isNeedMD5Check = getConfigHandle().getIsNeedMD5Check();\n                if (isNeedMD5Check)\n                {\t\n                    // 创建线程计算文件md5\n                \tcalculateFileMd5Runnable = new CalculateFileMd5Runnable();\n                    calculateFileMd5Runnable.setFilePath(filePath + "common.irf");\n                    calculateFileMd5Runnable.start();\n                }\n            }\n            else if (HOTUPDATE_FILE_CONFIG_FILE == fileType)\n            {\n            \tgetHotUpdateImpl().saveHotUpdateFileConfigFile();\n            }\n        }\n        else\n        {\n        \tlog.e(TAG, "ERROR: fileType = "+fileType+", opErrCode = "+opErrCode);\n        }\n    }\n}

备注1:IHotUpdateCheckObserver.onHotUpdateFile() 回调表示热更新下载文件已经下载完成并保存到临时目录,后续需要调用 HotUpdateService.saveHotUpdateFile 保存热更新文件到指定目录。

备注2:在 IHotUpdateFileObserver.onHotUpdateFile() 回调中仅处理changplay.bin的md5计算,为了避免保存替换时文件被系统占用,建议热更新文件下载完成后不直接保存到指定目录,待下次系统启动时在初始化阶段调用替换保存。


void InitAutoSDK()\n{\n\t// 执行初始化操作\n    \n    // 保存替换热更新文件\n    boolean bUpdateGlobalDB = getConfigHandle().getIsNeedUpdateGlobalDB();\t/**< 是否需要更新热更新文件 */\n    boolean bUpdateChangePlay = getConfigHandle().getIsNeedUpdateChangePlay(); /**< 是否需要更新common.irf文件 */\n    \n    if (bUpdateGlobalDB)\n    {\n    \tgetHotUpdateImpl().resetHotUpdateFileGlobalDB();\n    }\n    \n    if (bUpdateChangePlay)\n    {\n    \tgetHotUpdateImpl().resetHotUpdateFileCommonIrf();\n    }\n    \n    getHotUpdateImpl().saveHotUpdateFileGlobalDB();\n    getHotUpdateImpl().saveHotUpdateFileCommonIrf();\n    getHotUpdateImpl().saveHotUpdateFileChangePlay();\t/**< 可以放到引导服务初始化后调用 */\n    getHotUpdateImpl().saveHotUpdateFileRouteFile();\t/**< 可以放到图层服务初始化后调用 */\n}


","body_lake":null,"pub_level":null,"status":"0","updated_at":"2022-04-06 07:05:36","deleted_at":null,"nameSpace":"mnlcaa/v610","browseCount":80,"collectCount":0,"estimateDate":29,"docStatus":0,"permissions":true,"overView":false}}