Code updating method, device, equipment, storage medium and product
By generating code update patches using edge AI models and distributing them only to the cloud, the issues of network bandwidth and storage space consumption during code updates are resolved. This achieves a good user experience and dynamic code generation even in poor network environments, and avoids the failure of preset rules.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING QIHOOD TECHNOLOGY CO LTD
- Filing Date
- 2026-04-29
- Publication Date
- 2026-06-19
Smart Images

Figure CN122240154A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to code update methods, apparatus, devices, storage media, and products. Background Technology
[0002] Currently, it is generally necessary to control the operation of mobile applications (such as mobile phones, tablets, etc.) via the cloud (such as gray-scale switching, A / B testing, emergency fixes). However, existing solutions require the distribution of fixed patch packages (full software packages or incremental patch packages) for each code update, which consumes a lot of network bandwidth and storage space, and especially affects the user experience in environments with poor network conditions.
[0003] Furthermore, the generation of patch packages generally relies on preset static rules and human experience judgment, without taking into account the context information of the device runtime. When the device runtime environment changes (such as system version updates, hardware configuration differences, changes in user behavior patterns), the preset rules are often prone to failure or produce unexpected effects. Summary of the Invention
[0004] The main objective of this application is to provide a code update method, apparatus, device, storage medium, and product, aiming to solve the technical problems that related technologies require a large amount of network bandwidth and storage space when updating code, and are prone to default rules failure or unexpected effects.
[0005] To achieve the above objectives, this application proposes a code update method, the method comprising: Based on the update strategy information and device context information, the edge AI model is invoked to generate a code update patch, and the update strategy information is distributed from the cloud. The code update patch is compiled to generate a patch compilation file; Update the code based on the patch compilation file.
[0006] Optionally, the step of invoking the edge AI model based on the update strategy information and device context information to generate a code update patch includes: The update strategy information is split to generate a candidate strategy set; The candidate strategy set is traversed, and the traversed candidate strategy is taken as the current strategy; The conditional expressions in the current strategy are parsed to generate a strategy condition set; If all policy execution conditions in the policy condition set match the device context information, then the current policy will be used as the policy to be executed. At the end of the traversal, the strategies to be executed are aggregated into a set of strategies to be executed; Based on the set of strategies to be executed and the device context information, the client-side AI model is invoked to generate a code update patch.
[0007] Optionally, the step of invoking the edge AI model based on the update strategy information and device context information to generate a code update patch includes: The update strategy information is broken down to obtain multiple candidate strategies; The candidate strategies are grouped according to the target class and target method contained in the strategy to generate at least one strategy subgroup; Sort the strategies in the strategy subgroups to generate the sorting results for each strategy subgroup. Aggregate the top-ranked strategy from the sorting results of each strategy subgroup into the target strategy set; Based on the target strategy set and the device context information, the endpoint AI model is invoked to generate a code update patch.
[0008] Optionally, sorting the strategies in the strategy subgroup to generate a sorting result corresponding to each strategy subgroup includes: The strategies in the strategy subgroup are sorted based on the strategy priority and / or the strategy setting time, and a sorting result is generated for each strategy subgroup.
[0009] Optionally, updating the code based on the patch compilation file includes: The class loading chain is updated based on the patch compilation file to achieve hot patch loading for code updates.
[0010] Optionally, updating the class loading chain based on the patch compilation file to achieve hot patch loading includes: Obtain the file path of the patch compilation file; An optimized output directory is generated based on the file path; A class loading instance is constructed based on the file path and the optimized output directory; The class loading instance is loaded before the original class loader to update the class loading chain and achieve hot loading of patches.
[0011] Optionally, loading the class loading instance before the original class loader includes: Obtain the original class loader; The parent class field in the original class loader is modified to the class loading instance, so that the class loading instance is loaded before the original class loader.
[0012] Optionally, modifying the parent class field in the original class loader to the class loading instance, so as to load the class loading instance before the original class loader, includes: Obtain the parent class field object using reflection; The access restrictions on the parent class field object are modified to allow modification of private fields; By modifying the set function in the modified parent class field object, the parent class field in the original class loader is modified to the class loading instance, so that the class loading instance is loaded before the original class loader.
[0013] Optionally, the step of invoking the edge AI model based on the update strategy information and device context information to generate a code update patch includes: Based on the updated policy information and device context information, the edge AI model is invoked to generate policy intent information; The patch code generator is invoked based on the policy intent information to generate a code update patch.
[0014] Optionally, compiling the code update patch to generate a patch compilation file includes: The code update patch is compiled to generate a patch compilation file; The patch compilation file is signed using a pre-set private key, and the signature information corresponding to the patch compilation file is generated and stored.
[0015] Optionally, updating the code based on the patch compilation file includes: Read the byte data corresponding to the patch compilation file and find the signature information corresponding to the patch compilation file; The byte data and the signature information are verified using a public key certificate; Once the signature verification passes, the code is updated according to the patch compilation file.
[0016] Furthermore, to achieve the above objectives, this application also proposes a code updating device, which includes: The module is used to invoke the edge AI model based on the update strategy information and device context information to generate a code update patch. The update strategy information is sent from the cloud. The compilation module is used to compile the code update patch and generate patch compilation files; The update module is used to update the code based on the patch compilation file.
[0017] Optionally, the calling module is further configured to: split the update strategy information to generate a candidate strategy set; traverse the candidate strategy set and use the traversed candidate strategies as the current strategy; parse the conditional expressions in the current strategy to generate a strategy condition set; if the execution conditions of each strategy in the strategy condition set match the device context information, then the current strategy is used as the strategy to be executed; at the end of the traversal, the strategies to be executed are aggregated into a strategy set to be executed; and call the edge AI model according to the strategy set to be executed and the device context information to generate a code update patch.
[0018] Optionally, the calling module is further configured to split the update strategy information to obtain multiple candidate strategies; group the candidate strategies according to the target class and target method contained in the strategy to generate at least one strategy subgroup; sort each strategy in the strategy subgroup to generate a sorting result corresponding to each strategy subgroup; aggregate the strategy ranked first in the sorting result corresponding to each strategy subgroup into a target strategy set; and call the edge AI model according to the target strategy set and the device context information to generate a code update patch.
[0019] Optionally, the calling module is further configured to sort each strategy in the strategy subgroup based on the strategy priority and / or the strategy setting time, and generate a sorting result for each strategy subgroup.
[0020] Optionally, the update module is further configured to update the class loading chain according to the patch compilation file to achieve hot patch loading for code updates.
[0021] Optionally, the update module is further configured to obtain the file path of the patch compilation file; generate an optimized output directory based on the file path; construct a class loading instance based on the file path and the optimized output directory; and load the class loading instance before the original class loader to update the class loading chain and achieve hot loading of the patch.
[0022] In addition, to achieve the above objectives, this application also proposes a code update device, the device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the code update method as described above.
[0023] In addition, to achieve the above objectives, this application also proposes a storage medium, which is a computer-readable storage medium, on which a computer program is stored, and which, when executed by a processor, implements the steps of the code update method described above.
[0024] In addition, to achieve the above objectives, this application also proposes a computer program product comprising a computer program that, when executed by a processor, implements the steps of the code update method described above.
[0025] One or more technical solutions proposed in this application have at least the following technical effects: By generating code update patches based on update policy information using an edge AI model, updates can be performed, allowing the cloud to implement updates simply by issuing policies. This greatly reduces the amount of data transmitted, lowers the demand for network bandwidth and storage space, and ensures a good user experience even in poor network conditions. At the same time, when generating patches, the device context is taken into account, and the corresponding code can be dynamically generated according to the device's operating environment to ensure that it meets the actual needs. This can effectively avoid the failure of preset rules or the generation of unexpected results. Attached Figure Description
[0026] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0027] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0028] Figure 1 This is a flowchart illustrating the code update method of this application in Embodiment 1. Figure 2 This is a flowchart illustrating Embodiment 2 of the code update method of this application; Figure 3 This is a flowchart illustrating Embodiment 3 of the code update method of this application; Figure 4 This is a schematic diagram of the module structure of the code update device according to an embodiment of this application; Figure 5 This is a schematic diagram of the device structure of the hardware operating environment involved in the code update method in this application embodiment.
[0029] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0030] It should be understood that the specific embodiments described herein are merely illustrative of the technical solutions of this application and are not intended to limit this application.
[0031] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.
[0032] Based on this, embodiments of this application provide a code update method, referring to... Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the code update method of this application.
[0033] In this embodiment, the code update method includes steps S10 to S30: Step S10: Based on the update strategy information and device context information, call the edge AI model to generate a code update patch. The update strategy information is distributed from the cloud.
[0034] It should be noted that the execution subject of this embodiment can be a code update device, which can be a mobile terminal used by the user, such as a mobile phone, tablet computer, laptop computer, or other electronic device. It can also be other devices that can achieve the same or similar functions. This embodiment does not limit this. In this embodiment and the following embodiments, the code update device is used as an example to illustrate the code update method of this application.
[0035] It should be noted that the update policy information can be a policy distributed from the cloud to the code update device, and the device context information can include the system version, hardware model, user segmentation tags, and other contextual information of the code update device. The edge AI model can be a lightweight model deployed on the code update device, such as a lightweight Transformer model, loaded through TFLiteInterpreter, and with NNAPI enabled to accelerate inference and ensure efficiency.
[0036] In practical use, a global policy configuration center can be deployed in the cloud. Operations and security experts can formulate dynamic remediation rules, canary release policies, and security degradation instructions for mobile applications here. The policy configuration center adopts a key-value storage structure, supports adding, deleting, modifying, and querying policies, and automatically assigns a unique identifier, timestamp, and priority information to each policy. The system automatically infers the policy priority by parsing DSL conditional expressions, ensuring that critical security policies always take precedence over ordinary operational policies.
[0037] The policy configuration center can implement thread-safe policy storage based on ConcurrentHashMap, supporting high-concurrency policy read and write operations. Each policy can contain four core fields: target class name, target method name, effective condition script (DomainSpecific Language, DSL), and patch logic description. Other additional fields can be set when necessary.
[0038] In practical applications, the cloud-based policy configuration center can serialize policies into standardized JSON format or DSL script files and distribute them to the daemon process on the code update device via a WebSocket long connection (or other similar long connection methods, such as queues) between the code update device and the daemon process on the code update device.
[0039] The transmission strategy can employ a dual-channel strategy delivery mechanism to ensure reliability. The channels can be divided into a primary channel and a backup channel. For example, the primary channel uses JSON format, and the strategy object is serialized into a standard JSON string using the Gson library, and then pushed to the specified device in real time via a WebSocket long connection. The backup channel uses a custom DSL script format, which is suitable for scenarios that need to express complex logical conditions.
[0040] In practice, when the code update device receives the update strategy information from the cloud, it can call the edge AI model deployed on the code update device based on the update strategy information and the device context information. The edge AI model understands the specific code logic that needs to be modified according to the update strategy information, modifies the App's code, and generates a code update patch.
[0041] The input to the edge AI model can be a joint encoded vector of the DSL text and device context information in the update strategy information.
[0042] In a specific implementation, to reduce the complexity of the edge AI model, step S10 in this embodiment may include: Based on the updated policy information and device context information, the edge AI model is invoked to generate policy intent information; The patch code generator is invoked based on the policy intent information to generate a code update patch.
[0043] It should be noted that the strategy intent information can be represented by a structured intent object (PatchIntent object). The PatchIntent object can include information such as the target class name, method signature, and method body. The method signature can include information such as return type, method name, and parameter list, which can be extracted from the original intent, that is, from the update strategy information. The method body can be generated by the edge AI model.
[0044] In practical use, the patch code generator can be invoked through policy intent information to generate code update patches.
[0045] The patch code generator can be pre-configured by the code update device, which can parse the intent object and generate the corresponding code file.
[0046] For example, a patch code generator can be represented by the following code: public class PatchCodeGenerator { / / Dynamically generate standard Java patch source code based on the parsed intent public String generate(PatchIntent intent) { StringBuilder code = new StringBuilder(); code.append("package ").append(intent.targetClass .substring(0, intent.targetClass.lastIndexOf('.'))).append(";\n\n"); code.append("public class ").append(extractClassName(intent.targetClass)) .append("_Patch {\n"); code.append("public static ") .append(intent.returnType).append(" ") .append(intent.targetMethod).append("(") .append(buildParams(intent)).append(") {\n"); code.append(" / / AI-generated patch logic\n"); code.append("").append(intent.codeTemplate).append("\n"); code.append("}\n"); code.append("}\n"); return code.toString(); } private String extractClassName(String fullClass) { / *... * / return "";} private String buildParams(PatchIntent i) { / * ... * / return "";} } Here, intent is the input intent object, i.e. the policy intent information. The patch code generator can read the corresponding attributes from the intent object, automatically infer the package path and class name based on the target class name, and concatenate them in a preset format to generate the corresponding code update patch (such as a patch class with the "_Patch" suffix).
[0047] Step S20: Compile the code update patch to generate a patch compilation file.
[0048] In practical use, after the code update patch is determined, the code update patch can be compiled to convert it into an executable bytecode file, thereby generating the patch compilation file.
[0049] For example, taking the Android system as an example, the source code written in Java language generated by AI is first written to a local file to generate a code update patch. Then, the javac compiler ported on the client side is called to compile the code update patch into a standard class bytecode file (compatible with Java 8 syntax), generating a class file. Then, the Android d8 tool is called to convert it into a dex bytecode file that can be executed by the Dalvik virtual machine. At this time, the dex bytecode file is the patch compilation file.
[0050] The examples above are only for the purpose of understanding the generation of patch compilation files and do not limit the specific system environment, compiler, or compilation tools. This embodiment does not impose any restrictions on these aspects.
[0051] Step S30: Update the code according to the patch compilation file.
[0052] In practical use, after generating the patch compilation file, you can use the patch compilation file to update the application code on the code update device (such as directly replacing the dex file corresponding to the application). After that, you can try restarting the application to ensure that the running application can apply the latest updated code.
[0053] If the device updating the code also stores the Java code corresponding to the application, the Java code file can also be replaced; this embodiment does not impose any restrictions on this.
[0054] Understandably, the above processing ensures that the cloud only needs to issue a policy to update the code on the client side. Compared with the traditional patch-based code update, the amount of data that needs to be transmitted is greatly reduced from the MB level to the KB level, which greatly reduces the demand for network bandwidth and the occupation of cloud storage space.
[0055] In a specific implementation, to facilitate subsequent detection of the generated patch compilation file, step S20 in this embodiment may include: The code update patch is compiled to generate a patch compilation file; The patch compilation file is signed using a pre-set private key, and the signature information corresponding to the patch compilation file is generated and stored.
[0056] It should be noted that the pre-set private key can be a private key pre-issued by the cloud and can be stored in the code update device. In order to ensure security and avoid the pre-set private key from being cracked as much as possible, the pre-set private key can be processed by format conversion, obfuscation and other processing and then stored in a specific storage space (such as the core protection area of the device).
[0057] In practical use, in order to record the generated patch compilation files, the patch compilation files can be signed with a pre-set private key to generate the signature information corresponding to the patch compilation files. Then, the signature information is bound to the identifier of the patch compilation files and stored.
[0058] The signature algorithm used can be SHA256 with RSA, but other algorithms can also be used; this embodiment does not impose any restrictions. The identifier of the patch compilation file can be assembled from information such as file name, file path, and update time.
[0059] To ensure security, the signature information can be bound to the identifier of the patch compilation file and stored in a binding information table. The binding information table can be restricted to specific permissions, for example, only allowing processes or applications with root privileges to access the binding information table.
[0060] In a specific implementation, to prevent the patch compilation files used during code updates from being tampered with, step S30 in this embodiment may include: Read the byte data corresponding to the patch compilation file and find the signature information corresponding to the patch compilation file; The byte data and the signature information are verified using a public key certificate; Once the signature verification passes, the code is updated according to the patch compilation file.
[0061] It should be noted that the public key certificate can be pre-delivered from the cloud and pre-installed in the code update device, and is a public key corresponding to the pre-installed private key mentioned above.
[0062] In practical use, to prevent the patch compilation file from being a tampered file, you can first assemble an identifier based on the information corresponding to the patch compilation file, then look up the corresponding signature information in the binding information table based on the identifier, and then verify the byte data and signature information through the public key certificate. For example, input the public key certificate, direct data and signature information into the SHA256withRSA algorithm for verification.
[0063] In practical applications, if the signature verification passes, it means that the patch compilation file has not been tampered with. Therefore, the code can be updated based on the patch compilation file.
[0064] If the signature verification fails, it means that the patch compilation file may have been tampered with. In this case, the code update can be stopped, and the patch compilation file, signature information, verification results and other information can be recorded to build an alarm log. The alarm log can be stored or the administrator of the code update device can be notified.
[0065] This embodiment provides a code update method that generates code update patches based on update strategy information using an edge AI model to update the code. This allows the cloud to implement updates simply by issuing the strategy, greatly reducing the amount of data transmitted and the demand for network bandwidth and storage space. It also ensures a good user experience when the network is poor. At the same time, when generating patches, the device context is taken into account, and the corresponding code can be dynamically generated according to the device's operating environment to ensure that it meets the actual needs. This can effectively avoid the failure of preset rules or the generation of unexpected effects.
[0066] Based on the first embodiment of this application, in the second embodiment of this application, the content that is the same as or similar to that in Embodiment 1 above can be referred to the above description, and will not be repeated hereafter. Based on this, please refer to... Figure 2 Step S30 includes step S30': Step S30': Update the class loading chain according to the patch compilation file to achieve hot patch loading for code updates.
[0067] It should be noted that, in order to ensure the actual user experience, you can try to implement hot reloading of patches to update the code without closing the application.
[0068] Specifically, the system's class loading chain can be updated based on the patch compilation file, so that the class loading order prioritizes the patch compilation file, rather than the original compilation file before the update.
[0069] For example, taking the Android system as an example, the Android system uses the class loading mechanism of the parent delegation model. At this time, the class loading chain of the Android system can be modified so that the independent dex file containing the patch class is dynamically loaded first when the application runs, thereby parsing the class in the patch compilation file first, thereby realizing method replacement or logic overriding, so as to achieve hot loading of patches.
[0070] In a specific implementation, to ensure the proper hot loading of patches, step S30' in this embodiment may include: Obtain the file path of the patch compilation file; An optimized output directory is generated based on the file path; A class loading instance is constructed based on the file path and the optimized output directory; The class loading instance is loaded before the original class loader to update the class loading chain and achieve hot loading of patches.
[0071] In practical use, the file path of the obtained patch compilation file can be the absolute path of the obtained patch compilation file, that is, the complete path starting from the root directory of the file system.
[0072] Meanwhile, since dex files cannot be executed efficiently directly in Android, they need to be optimized by DexOpt (Dalvik) or oat compilation (ART) to generate optimized files before running. These optimized files must be stored in a specific directory and have write permissions. Therefore, the optimized output directory can be generated based on the file path. For example, a folder named opt at the same level as the file path can be used as the optimized output directory.
[0073] In practical use, after determining the file path of the patch compilation file and the optimized output directory, the constructor of the class loader can be called according to the file path and the optimized output directory to build a class loading instance. Then, the class loading instance is loaded before the original class loader, which can realize the update of the class loading chain and ensure that the system accesses the newly built class loading instance first when loading classes, rather than the original class loader, thereby realizing hot loading of patches.
[0074] The original class loader can be the class loader accessed by the system when loading classes before the update.
[0075] For example, taking the Android system as an example, DexClassLoader is a dynamic class loading mechanism provided by the Android system. At this time, the constructor in DexClassLoader can be called based on the file path and optimized output directory to build a class loading instance (also known as a patch ClassLoader). Before inserting the built class loading instance into the original ClassLoader, when the Android system virtual machine resolves class references, it will first look in the class loading instance, thereby realizing the transparent replacement of the original ClassLoader by the class loading instance without modifying the application's startup process.
[0076] In specific implementations, to ensure that the class loading instance is correctly loaded before the original class loader, the steps described in this embodiment before loading the class loading instance before the original class loader may include: Obtain the original class loader; The parent class field in the original class loader is modified to the class loading instance, so that the class loading instance is loaded before the original class loader.
[0077] In practical use, the original class loader in the system can be obtained through the class loader's acquisition function. Then, the parent field in the original class loader can be modified to the class loading instance to change the object reference, thereby loading the class loading instance before the original class loader.
[0078] The original class loader can be obtained by calling the class loader extraction function. For example, in the Android system, the original class loader can be obtained by calling getClass().getClassLoader().
[0079] In specific implementation, to ensure that the parent class field in the original class loader can be correctly modified, the step of modifying the parent class field in the original class loader to the class loading instance, so as to load the class loading instance before loading it into the original class loader, as described in this embodiment, may include: Obtain the parent class field object using reflection; The access restrictions on the parent class field object are modified to allow modification of private fields; By modifying the set function in the modified parent class field object, the parent class field in the original class loader is modified to the class loading instance, so that the class loading instance is loaded before the original class loader.
[0080] It should be noted that the parent class field object can be an object provided by the system to represent a specific field. However, in actual use, the parent class field object is a protected field and is generally not allowed to be modified. In this case, the access restrictions of the parent class field object can be modified first to allow modification of private fields. Then, the setter function in the modified parent class field object can be used to modify the parent class field in the original class loader to a class loading instance, so that the class loading instance is loaded before the original class loader.
[0081] For example, taking the Android system as an example, the following code example can be used to modify the parent class field in the original class loader to a class loading instance: private void injectToClassLoaderChain(DexClassLoader cl) { try { java.lang.reflect.Field parentField = ClassLoader.class.getDeclaredField("parent"); parentField.setAccessible(true); ClassLoader original = getClass().getClassLoader(); parentField.set(original,cl); } catch (Exception e) { / * fallback strategy * / } } Here, cl is the previously constructed class loading instance, parentField is the parent class field object obtained through reflection; parentField.setAccessible(true) modifies the access restrictions of the parent class field object to allow modification of private fields; original is the obtained original class loader; parentField.set( original,cl) calls the set() function in the parent class field object to modify the parent class field in the original class loader to a class loading instance; If an exception is caught during the processing, a fallback strategy can be executed. For example, by removing the patch ClassLoader reference, the process can fall back to the original class loading chain, thus enabling the patch to be withdrawn immediately.
[0082] This embodiment provides a code update method that implements hot reloading, enabling code updates to take effect without restarting the application. This ensures that an update takes effect in a very short time and avoids the need for users to restart the application, thus improving the user experience.
[0083] Based on the first embodiment of this application, in the third embodiment of this application, the content that is the same as or similar to that in the first embodiment described above can be referred to the above description, and will not be repeated hereafter. Based on this, please refer to... Figure 3 Step S10 includes steps S101-S106: Step S101: Split the update strategy information to generate a candidate strategy set.
[0084] In practical use, when the cloud sends out update strategy information, it will send it in JSON format or in the form of DSL script. Based on this, the code update device can parse it and split it into multiple candidate strategies to obtain a candidate strategy set.
[0085] Step S102: Traverse the candidate strategy set and take the traversed candidate strategy as the current strategy.
[0086] In practical use, the candidate strategy set can be traversed in ascending order, descending order, or random order, and the candidate strategy encountered can be used as the current strategy. The specific traversal method can be preset by the administrator of the code update device according to actual needs. This embodiment does not limit this.
[0087] Step S103: Parse the conditional expression in the current strategy to generate a strategy condition set.
[0088] Step S104: If the execution conditions of each policy in the policy condition set match the device context information, then the current policy is taken as the policy to be executed.
[0089] In practical use, the code update device can parse the conditional expressions in the current policy to determine the policy conditions required to execute the current policy and obtain the policy condition set.
[0090] The policy conditions can be restrictions on device performance, system version, user group classification, etc., or other conditions. This embodiment does not impose any restrictions on them.
[0091] For example, a condition evaluator can be pre-set in the code update device to read the data corresponding to the conditionDsl field in the current policy, obtain the condition expression, parse it (such as splitting, identifying, etc.) to obtain the policy condition set, and then compare each policy condition in the policy condition set with the device context information. If each policy execution condition in the policy condition set matches the device context information (i.e. the device context information meets the requirements in the policy execution conditions), it means that the current policy can be applied to the code update device. Therefore, the current policy can be used as the policy to be executed. If any policy execution condition does not match the device context information, it means that the current policy cannot be applied to update the device via code, and therefore, the current policy can be ignored.
[0092] Step S105: At the end of the traversal, aggregate the strategies to be executed into a set of strategies to be executed.
[0093] Step S106: Based on the set of strategies to be executed and the device context information, call the edge AI model to generate a code update patch.
[0094] In practical use, at the end of the traversal, all candidate strategies that have been determined to be executed can be aggregated into a set of strategies to be executed. Then, based on the set of strategies to be executed and the device context information, the edge AI model is called to generate a code update patch. The specific construction method of the code update patch is similar to the above implementation method of calling the edge AI model based on the update strategy information and the device context information to generate a code update patch, which will not be repeated here.
[0095] It is understandable that by executing the above steps S101-S106, precise policy filtering is achieved on the mobile side, which can avoid processing policies that are irrelevant to the current code update device and effectively reduce the computational overhead on the device side.
[0096] In a specific implementation, to avoid strategy conflicts, step S10 in this embodiment may include: The update strategy information is broken down to obtain multiple candidate strategies; The candidate strategies are grouped according to the target class and target method contained in the strategy to generate at least one strategy subgroup; Sort the strategies in the strategy subgroups to generate the sorting results for each strategy subgroup. Aggregate the top-ranked strategy from the sorting results of each strategy subgroup into the target strategy set; Based on the target strategy set and the device context information, the endpoint AI model is invoked to generate a code update patch.
[0097] It should be noted that in some cases, the update strategy information sent from the cloud may contain multiple candidate strategies. Different candidate strategies may target the same method in the same class. In such cases, it is necessary to eliminate the conflict between the two. Therefore, the update strategy information can be split first to obtain multiple candidate strategies. Then, using the target class and target method as the joint grouping target, multiple candidate strategies that correspond to the same target class and the same target method are grouped into the same group, thereby obtaining at least one strategy subgroup.
[0098] Next, the strategies in the strategy subgroups can be sorted to generate the sorting results for each strategy subgroup. Then, the strategy ranked first in the sorting results for each strategy subgroup is aggregated into a target strategy set. Finally, the edge AI model is called based on the target strategy set and device context information to generate a code update patch.
[0099] Understandably, this approach ensures that only one target strategy will be selected for the same class and the same method, thereby eliminating logical conflicts between multiple strategies in the same scenario.
[0100] In specific implementation, to ensure that the selected target strategy is the most suitable strategy, this embodiment sorts the strategies in the strategy subgroup and generates a sorting result corresponding to each strategy subgroup, including: The strategies in the strategy subgroup are sorted based on the strategy priority and / or the strategy setting time, and a sorting result is generated for each strategy subgroup.
[0101] It should be noted that the policy priority can be set by the relevant administrators when adding a new policy in the cloud policy configuration center. The higher the policy priority, the more important the policy is.
[0102] The policy setting time can be the time when the policy is stored in the cloud-based policy configuration center.
[0103] In practical use, depending on the actual needs, the strategies in the strategy subgroup can be sorted by strategy priority and / or strategy setting time.
[0104] For example, if the latest strategy needs to be selected as the target strategy, the strategies in the strategy subgroup can be sorted from largest to smallest based on the strategy setting time corresponding to the strategy, and the sorting results corresponding to each strategy subgroup can be generated. If the strategy with the highest priority needs to be selected as the target strategy, then the strategies in the strategy subgroup can be sorted from high to low based on the strategy priority corresponding to the strategy, and the sorting results corresponding to each strategy subgroup can be generated. If a higher priority and newer strategy is required as the target strategy, the strategies in the strategy subgroup can be sorted from high to low based on their priority. Then, the strategies with the same priority can be sorted again from large to small based on their corresponding strategy setting time, thus generating the sorting results for each strategy subgroup.
[0105] In the specific implementation, the above two methods (i.e., strategy filtering and strategy sorting and selection) can be executed separately or used in combination. For example, first execute the processing flow of steps S101-S105 to determine the set of strategies to be executed, then divide the set of strategies to be executed into multiple strategy subgroups, and then obtain the target strategy set through sorting. Alternatively, the update strategy information can be first grouped and sorted to obtain the target strategy set, and then the target strategy set can be processed in steps S101-S105 as described above. This embodiment does not limit this approach.
[0106] This embodiment provides a code update method. This embodiment implements precise policy filtering on the mobile device side, which can avoid processing policies that are irrelevant to the current code update device and effectively reduce the computational overhead on the device side.
[0107] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the code update method of this application. Any simple modifications based on this technical concept are within the protection scope of this application.
[0108] This application also provides a code updating device, please refer to... Figure 4 The code update device includes: The module is used to invoke the edge AI model based on the update strategy information and device context information to generate a code update patch. The update strategy information is sent from the cloud. The compilation module is used to compile the code update patch and generate patch compilation files; The update module is used to update the code based on the patch compilation file.
[0109] The code update apparatus provided in this application, employing the code update method described in the above embodiments, can solve the technical problems of related technologies requiring significant network bandwidth and storage space for code updates, and being prone to defaulting to invalid rules or producing unexpected effects. Compared with the prior art, the beneficial effects of the code update apparatus provided in this application are the same as those of the code update method described in the above embodiments, and other technical features in the code update apparatus are the same as those disclosed in the methods of the above embodiments, and will not be repeated here.
[0110] This application provides a code update device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the code update method in Embodiment 1 above.
[0111] The following is for reference. Figure 5 The diagram illustrates a structural schematic of a code update device suitable for implementing embodiments of this application. The code update device in embodiments of this application may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Description), PMPs (Portable Media Players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 5 The code update device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0112] like Figure 5 As shown, the code update device may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.) that can perform various appropriate actions and processes according to a program stored in the read-only memory 1002 or a program loaded from the storage device 1003 into the random access memory 1004. The random access memory 1004 also stores various programs and data required for the operation of the code update device. The processing unit 1001, the read-only memory 1002, and the random access memory 1004 are interconnected via a bus 1005. An input / output interface 1006 is also connected to the bus. Typically, the following systems can be connected to the input / output interface 1006: input devices 1007 including, for example, touchscreens, touchpads, keyboards, mice, image sensors, microphones, accelerometers, gyroscopes, etc.; output devices 1008 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 1003 including, for example, magnetic tapes, hard disks, etc.; and communication devices 1009. Communication device 1009 allows the code update device to communicate wirelessly or wiredly with other devices to exchange data. While the figure shows code update devices with various systems, it should be understood that implementation or possession of all the systems shown is not required. More or fewer systems may be implemented alternatively.
[0113] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from read-only memory 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.
[0114] The code update device provided in this application, employing the code update method described in the above embodiments, can solve the technical problems of related technologies requiring significant network bandwidth and storage space for code updates, and being prone to defaulting to invalid rules or producing unexpected effects. Compared with the prior art, the beneficial effects of the code update device provided in this application are the same as those of the code update method provided in the above embodiments, and other technical features of this code update device are the same as those disclosed in the previous embodiment method, and will not be repeated here.
[0115] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.
[0116] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0117] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, the computer-readable program instructions being used to execute the code update method in the above embodiments.
[0118] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems or devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.
[0119] The aforementioned computer-readable storage medium may be included in the code update device; or it may exist independently and not be assembled into the code update device.
[0120] The aforementioned computer-readable storage medium carries one or more programs. When the one or more programs are executed by the code update device, the code update device: calls the edge AI model according to update strategy information and device context information to generate a code update patch, wherein the update strategy information is distributed from the cloud; compiles the code update patch to generate a patch compilation file; and performs code update according to the patch compilation file.
[0121] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof. These programming languages include object-oriented programming languages—such as Python, Java, Smalltalk, and C++—and conventional procedural programming languages—such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0122] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0123] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.
[0124] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the above-described code update method. This solves the technical problems of related technologies where code updates require significant network bandwidth and storage space, and are prone to defaulting to invalid rules or producing unexpected effects. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the code update method provided in the above embodiments, and will not be repeated here.
[0125] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the code update method described above.
[0126] The computer program product provided in this application can solve the technical problems that related technologies require a large amount of network bandwidth and storage space when updating code, and are prone to the failure of preset rules or the generation of unexpected effects. Compared with the prior art, the beneficial effects of the computer program product provided in this application are the same as those of the code update method provided in the above embodiments, and will not be repeated here.
[0127] All user-related data involved in this application (such as user privacy data, user behavior data, etc.) were obtained with the user's permission or consent; that is to say, when this application is used in a specific product or technology, user permission is required to obtain and process the relevant data, and the processing of the relevant data must comply with the relevant laws, regulations and regulatory standards of the relevant countries and regions.
[0128] The above description is only a part of the embodiments of this application and does not limit the scope of protection of this application. All equivalent structural transformations made under the technical concept of this application and using the content of this application specification and drawings, or direct / indirect applications in other related technical fields, are included in the scope of protection of this application.
[0129] This application also discloses A1, a code update method, the code update method comprising: Based on the update strategy information and device context information, the edge AI model is invoked to generate a code update patch, and the update strategy information is distributed from the cloud. The code update patch is compiled to generate a patch compilation file; Update the code based on the patch compilation file.
[0130] A2. The code update method as described in A1, wherein the step of calling the edge AI model based on update strategy information and device context information to generate a code update patch includes: The update strategy information is split to generate a candidate strategy set; The candidate strategy set is traversed, and the traversed candidate strategy is taken as the current strategy; The conditional expressions in the current strategy are parsed to generate a strategy condition set; If all policy execution conditions in the policy condition set match the device context information, then the current policy will be used as the policy to be executed. At the end of the traversal, the strategies to be executed are aggregated into a set of strategies to be executed; Based on the set of strategies to be executed and the device context information, the client-side AI model is invoked to generate a code update patch.
[0131] A3. The code update method as described in A1, wherein the step of calling the edge AI model based on update strategy information and device context information to generate a code update patch includes: The update strategy information is broken down to obtain multiple candidate strategies; The candidate strategies are grouped according to the target class and target method contained in the strategy to generate at least one strategy subgroup; Sort the strategies in the strategy subgroups to generate the sorting results for each strategy subgroup. Aggregate the top-ranked strategy from the sorting results of each strategy subgroup into the target strategy set; Based on the target strategy set and the device context information, the endpoint AI model is invoked to generate a code update patch.
[0132] A4. The code update method as described in A3, wherein sorting each strategy in the strategy subgroup and generating a sorting result corresponding to each strategy subgroup includes: The strategies in the strategy subgroup are sorted based on the strategy priority and / or the strategy setting time, and a sorting result is generated for each strategy subgroup.
[0133] A5. The code update method as described in A1, wherein updating the code based on the patch compilation file includes: The class loading chain is updated based on the patch compilation file to achieve hot patch loading for code updates.
[0134] A6. The code update method as described in A5, wherein updating the class loading chain according to the patch compilation file to achieve hot patch loading includes: Obtain the file path of the patch compilation file; An optimized output directory is generated based on the file path; A class loading instance is constructed based on the file path and the optimized output directory; The class loading instance is loaded before the original class loader to update the class loading chain and achieve hot loading of patches.
[0135] A7. The code update method as described in A6, wherein loading the class loading instance before the original class loader includes: Obtain the original class loader; The parent class field in the original class loader is modified to the class loading instance, so that the class loading instance is loaded before the original class loader.
[0136] A8. The code update method as described in A7, wherein modifying the parent class field in the original class loader to the class loading instance, so as to load the class loading instance before the original class loader, includes: Obtain the parent class field object using reflection; The access restrictions on the parent class field object are modified to allow modification of private fields; By modifying the set function in the modified parent class field object, the parent class field in the original class loader is modified to the class loading instance, so that the class loading instance is loaded before the original class loader.
[0137] A9. The code update method as described in A1, wherein the step of calling the edge AI model based on update strategy information and device context information to generate a code update patch includes: Based on the updated policy information and device context information, the edge AI model is invoked to generate policy intent information; The patch code generator is invoked based on the policy intent information to generate a code update patch.
[0138] A10. The code update method as described in any one of A1-A9, wherein compiling the code update patch to generate a patch compilation file includes: The code update patch is compiled to generate a patch compilation file; The patch compilation file is signed using a pre-set private key, and the signature information corresponding to the patch compilation file is generated and stored.
[0139] A11. The code update method as described in A10, wherein updating the code based on the patch compilation file includes: Read the byte data corresponding to the patch compilation file and find the signature information corresponding to the patch compilation file; The byte data and the signature information are verified using a public key certificate; Once the signature verification passes, the code is updated according to the patch compilation file.
[0140] This application also discloses B12, a code updating device, the code updating device comprising: The module is used to invoke the edge AI model based on the update strategy information and device context information to generate a code update patch. The update strategy information is sent from the cloud. The compilation module is used to compile the code update patch and generate patch compilation files; The update module is used to update the code based on the patch compilation file.
[0141] B13. In the code update device described in B12, the calling module is further configured to: split the update strategy information to generate a candidate strategy set; traverse the candidate strategy set and take the traversed candidate strategy as the current strategy; parse the condition expression in the current strategy to generate a strategy condition set; if the execution conditions of each strategy in the strategy condition set match the device context information, then the current strategy is taken as the strategy to be executed; at the end of the traversal, the strategies to be executed are aggregated into a strategy set to be executed; and call the edge AI model according to the strategy set to be executed and the device context information to generate a code update patch.
[0142] B14. The code update device as described in B12, wherein the calling module is further configured to split the update strategy information to obtain multiple candidate strategies; group the candidate strategies according to the target class and target method contained in the strategy to generate at least one strategy subgroup; sort each strategy in the strategy subgroup to generate a sorting result corresponding to each strategy subgroup; aggregate the strategy ranked first in the sorting result corresponding to each strategy subgroup into a target strategy set; and call the edge AI model according to the target strategy set and the device context information to generate a code update patch.
[0143] B15. The code update device as described in B14, wherein the calling module is further configured to sort each strategy in the strategy subgroup based on the strategy priority corresponding to the strategy and / or the strategy setting time, and generate a sorting result corresponding to each strategy subgroup.
[0144] B16. The code update apparatus as described in B12, wherein the update module is further configured to update the class loading chain according to the patch compilation file to achieve hot patch loading for code update.
[0145] B17. The code update apparatus as described in B16, wherein the update module is further configured to obtain the file path of the patch compilation file; generate an optimized output directory based on the file path; construct a class loading instance based on the file path and the optimized output directory; and load the class loading instance before the original class loader to update the class loading chain and achieve hot loading of the patch.
[0146] This application also discloses C18, a code update device, the device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the code update method as described above.
[0147] This application also discloses D19, a storage medium, which is a computer-readable storage medium, on which a computer program is stored, and which, when executed by a processor, implements the steps of the code update method described above.
[0148] This application also discloses E20, a computer program product comprising a computer program that, when executed by a processor, implements the steps of the code update method described above.
Claims
1. A code update method, characterized in that, The code update method includes: Based on the update strategy information and device context information, the edge AI model is invoked to generate a code update patch, and the update strategy information is distributed from the cloud. The code update patch is compiled to generate a patch compilation file; Update the code based on the patch compilation file.
2. The code update method as described in claim 1, characterized in that, The step of calling the edge AI model based on update strategy information and device context information to generate a code update patch includes: The update strategy information is split to generate a candidate strategy set; The candidate strategy set is traversed, and the traversed candidate strategy is taken as the current strategy; The conditional expressions in the current strategy are parsed to generate a strategy condition set; If all policy execution conditions in the policy condition set match the device context information, then the current policy will be used as the policy to be executed. At the end of the traversal, the strategies to be executed are aggregated into a set of strategies to be executed; Based on the set of strategies to be executed and the device context information, the client-side AI model is invoked to generate a code update patch.
3. The code update method as described in claim 1, characterized in that, The step of calling the edge AI model based on update strategy information and device context information to generate a code update patch includes: The update strategy information is broken down to obtain multiple candidate strategies; The candidate strategies are grouped according to the target class and target method contained in the strategy to generate at least one strategy subgroup; Sort the strategies in the strategy subgroups to generate the sorting results for each strategy subgroup. Aggregate the top-ranked strategy from the sorting results of each strategy subgroup into the target strategy set; Based on the target strategy set and the device context information, the endpoint AI model is invoked to generate a code update patch.
4. The code update method as described in claim 3, characterized in that, The step of sorting the strategies in the strategy subgroups to generate a sorting result for each strategy subgroup includes: The strategies in the strategy subgroup are sorted based on the strategy priority and / or the strategy setting time, and a sorting result is generated for each strategy subgroup.
5. The code update method as described in claim 1, characterized in that, The code update based on the patch compilation file includes: The class loading chain is updated based on the patch compilation file to achieve hot patch loading for code updates.
6. The code update method as described in claim 5, characterized in that, The step of updating the class loading chain based on the patch compilation file to achieve hot patch loading includes: Obtain the file path of the patch compilation file; An optimized output directory is generated based on the file path; A class loading instance is constructed based on the file path and the optimized output directory; The class loading instance is loaded before the original class loader to update the class loading chain and achieve hot loading of patches.
7. A code updating device, characterized in that, The code update device includes: The module is used to invoke the edge AI model based on the update strategy information and device context information to generate a code update patch. The update strategy information is sent from the cloud. The compilation module is used to compile the code update patch and generate patch compilation files; The update module is used to update the code based on the patch compilation file.
8. A code update device, characterized in that, The device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the code update method as described in any one of claims 1 to 6.
9. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the steps of the code update method as described in any one of claims 1 to 6.
10. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the steps of the code update method as described in any one of claims 1 to 6.