jsBridge communication method, device and storage medium when Hongmeng applet is running

By registering the proxy method in the web container during the runtime of the Hongmeng applet and using preset shared memory space, the jsBridge communication performance bottleneck and synchronous call problems are solved, and efficient data transmission and functional expansion are achieved.

CN118331765BActive Publication Date: 2024-11-05ZHUHAI FANTAI GEEK TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202410751741.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-12
Publication Date
2024-11-05
Estimated Expiration
2044-06-12

AI Technical Summary

Technical Problem

The jsBridge communication method of the running mini-programs in the existing Hongmeng system has performance bottlenecks when the amount of large data is large, and it cannot support synchronous calls of the native layer, resulting in some functions being unable to be implemented.

Method used

By registering proxy methods in a web container and using preset shared memory space for direct calls and data access, the performance loss of serialization and pipeline communication is reduced, and synchronous calls are supported.

Benefits of technology

Effectively reduces the performance overhead of serialization and deserialization, supports synchronous calls of native methods, extends the implementable functions, and allows processing of data types that cannot be serialized, such as binary data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118331765B_ABST
    Figure CN118331765B_ABST
Patent Text Reader

Abstract

The embodiments of the present disclosure provide a jsBridge communication method, device and storage medium when the Hongmeng applet is running, which solves the performance overhead caused by serialization when the Hongmeng applet is running in the prior art. The method includes: requesting parameters from the native layer through a JavaScript object; determining the proxy method registered in the Web container according to the object identifier of the JavaScript object; calling the corresponding native method through the proxy method; and obtaining the return result after the execution of the native method from the preset shared memory space. The embodiments of the present disclosure are applicable to the communication process between the Web layer and the native layer when the Hongmeng applet is running.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present disclosure relate to the field of computer technology, and specifically to a jsBridge communication method, device, and storage medium when a Hongmeng applet is running. Background Art

[0002] With the continuous development of computer technology, various applications have entered people's daily lives, and mini programs are applications that can be sent from the server to the host client of a third-party application platform. Mini programs are run by providing an operating environment through the host client. However, there is no other mini program running platform on the current Hongmeng system, and a mechanism is needed to achieve two-way interactive communication between the native layer and the Web layer. Therefore, a jsBridge (bridge) needs to be created between the native layer and the Web layer to achieve communication between the two based on jsBridge. However, in the current communication method, when the amount of data is large, the serialization and deserialization process will cause performance bottlenecks, and it is impossible to support synchronous calls of the native layer, which makes some functions of the mini program impossible to achieve. Summary of the invention

[0003] The purpose of the embodiments of the present disclosure is to provide a jsBridge communication method, device and storage medium when a Hongmeng applet is running. The corresponding native method can be directly called through the proxy method registered in the Web container, thereby reducing the communication performance loss of serialization and pipeline.

[0004] The first aspect of the disclosed embodiments provides a jsBridge communication method during the runtime of a Hongmeng mini-program, including: requesting parameters from the native layer through a JavaScript object; determining the proxy method registered in the Web container based on the object identifier of the JavaScript object; calling the corresponding native method through the proxy method; and obtaining the return result after the execution of the native method from a preset shared memory space.

[0005] In some embodiments of the present disclosure, the method further includes: registering the proxy method in the Web container through the Chromium Embedded Framework.

[0006] In some embodiments of the present disclosure, calling the corresponding native method through the proxy method includes: searching for data required to call the native method in the preset shared memory space according to the object identifier.

[0007] In some embodiments of the present disclosure, the preset shared memory space is a memory space located in the main process of the Hongmeng applet, and all JavaScript objects required for the Hongmeng applet to run are stored in the preset shared memory space.

[0008] In some embodiments of the present disclosure, the data in the shared memory space can be accessed by the Web layer and the native layer.

[0009] The second aspect of the disclosed embodiment provides a jsBridge communication device during the runtime of a Hongmeng applet, including: a request module, used to request parameters from the native layer through a JavaScript object; a proxy determination module, used to determine the proxy method registered in the Web container according to the object identifier of the JavaScript object; a calling module, used to call the corresponding native method through the proxy method; and a result acquisition module, used to obtain the return result after the execution of the native method from a preset shared memory space.

[0010] In some embodiments of the present disclosure, the apparatus further includes: a registration module, configured to register the proxy method in the Web container via the ChromiumEmbedded Framework.

[0011] In some embodiments of the present disclosure, the calling module is further used to search for data required to call the native method in the preset shared memory space according to the object identifier.

[0012] In some embodiments of the present disclosure, the preset shared memory space is a memory space located in the main process of the Hongmeng applet, and all JavaScript objects required for the Hongmeng applet to run are stored in the preset shared memory space.

[0013] The third aspect of the embodiments of the present disclosure provides a machine-readable storage medium, on which instructions are stored, and the instructions are used to enable the machine to execute the jsBridge communication method when the Hongmeng mini program is running as described in the first aspect of the above-mentioned embodiment.

[0014] Other features and advantages of the embodiments of the present disclosure will be described in detail in the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] The accompanying drawings are used to provide a further understanding of the embodiments of the present disclosure and constitute a part of the specification. Together with the following specific embodiments, they are used to explain the embodiments of the present disclosure, but do not constitute a limitation on the embodiments of the present disclosure. In the accompanying drawings:

[0016] Figure 1 It is a schematic diagram of the overall architecture of a Hongmeng applet running engine provided by an embodiment of the present disclosure;

[0017] Figure 2 is a schematic diagram of the startup process of the mini-program provided in the embodiment of the present disclosure;

[0018] Figure 3 It is a flowchart of a jsBridge communication method when a Hongmeng applet is running, provided by an embodiment of the present disclosure;

[0019] Figure 4 It is a schematic diagram of the jsBridge communication process when the Hongmeng applet is running during a network request provided by an embodiment of the present disclosure;

[0020] Figure 5 It is a schematic diagram of the architecture of a jsBridge communication device when a Hongmeng applet is running, provided by an embodiment of the present disclosure;

[0021] Figure 6 This is a schematic diagram of the architecture of another jsBridge communication device when the Hongmeng mini program is running provided by an embodiment of the present disclosure.

[0022] It should be noted that the elements in the drawings are schematic and not drawn to scale. DETAILED DESCRIPTION

[0023] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution of the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present disclosure, rather than all of the embodiments. Based on the described embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without creative work also fall within the scope of protection of the present disclosure.

[0024] Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by those skilled in the art to which the subject matter of the present disclosure belongs. It will be further understood that terms such as those defined in commonly used dictionaries should be interpreted as having a meaning consistent with their meaning in the context of the specification and the relevant art, and will not be interpreted in an idealized or overly formal form unless otherwise explicitly defined herein.

[0025] In order to solve the performance overhead of serialization and deserialization during the runtime of Hongmeng Mini Programs in the prior art and the problem of not being able to support synchronous calls of native methods, the present disclosure reduces the communication performance loss of serialization and pipelines by enabling the proxy method registered in the Web container to directly call the corresponding native method and by reserving a preset shared memory space accessible to both the native layer and the Web layer. Figure 1As shown, the present disclosure provides an overall architecture diagram 100 of the Hongmeng mini-program running engine, which is applied to a computer device running the Hongmeng system, which can be a mobile phone, a computer, a tablet computer and other devices. The architecture includes: a user mini-program 110, a mini-program Web container 120, jsBridge 130 and a Hongmeng native interface 140, wherein jsBridge 130 and the Hongmeng native interface 140 are adapted for the native layer of the Hongmeng system, and realize mini-program related functions.

[0026] See also Figure 2 The schematic diagram of the mini program startup process shown in the figure, wherein step 1 permission verification, step 4 loading the mini program common basic library, step 5 loading the user mini program code, and step 6 rendering the mini program page are all the same as the mini program startup process executed in other systems (e.g., Android system, IOS system), and will not be repeated here. As for step 2 binding the Hongmeng runtime context and step 3 creating the mini program container, they are all adaptations for the native layer of the Hongmeng system. Among them, step 2 binds the Hongmeng application runtime context and window object to handle application-level events. For example, after listening to the event that the application exits the background, the event is sent to the mini program running engine through jsBridge to trigger the corresponding user listening event. For step 3, it not only includes creating the mini program Web container of the Hongmeng system, but also includes creating and initializing jsBridge, and registering the native interface. Among them, JSBridge is equivalent to a bridge for full-duplex communication between JavaScript (JS) and the native layer, and it defines a set of specifications for JS to communicate with the native layer.

[0027] In the disclosed embodiment, the key point that the native layer needs to adapt when the Hongmeng applet is running is the jsBridge communication method, which not only solves the performance overhead problem of serialization and deserialization in conventional communication methods, but also supports synchronous calls. Figure 3 A flowchart of a jsBridge communication method when a Hongmeng applet is running is provided. The method is applied to a computer device running a Hongmeng system, which may be a mobile phone, a computer, a tablet computer, and other devices, and specifically includes the following steps:

[0028] Step 310: Request parameters from the native layer through the JavaScript object.

[0029] Among them, since the permissions of the Web layer are restricted, it needs to communicate with the native layer in order to entrust the native layer to implement certain functions. Therefore, when the Web layer requests certain parameters, these requests can be encapsulated in JavaScript objects for transmission to the native layer.

[0030] Step 320: Determine the proxy method registered in the Web container according to the object identifier of the JavaScript object.

[0031] The disclosed embodiment has opened up the JavaScript execution engine layer, and the native layer can directly register the corresponding native method in the Web container in a proxy manner. Specifically, the proxy method is registered in the Web container through the Chromium Embedded Framework.

[0032] Among them, the registered proxy method can be found in the Web container according to the object identifier of the JavaScript object, so as to subsequently call the corresponding native method synchronously.

[0033] Step 330, calling the corresponding native method through the proxy method;

[0034] Step 340: Obtain the return result after the execution of the native method from the preset shared memory space.

[0035] Wherein, according to the object identifier, the data required for calling the native method is searched in the preset shared memory space.

[0036] The preset shared memory space is a memory space located in the main process of the Hongmeng applet. The preset shared memory space stores all JavaScript objects required for the Hongmeng applet to run, and the data in the preset shared memory space can be accessed by the Web layer and the native layer. Moreover, due to the existence of such a preset shared memory space, the performance overhead of serializing JavaScript objects into JSON strings and deserializing JSON string results into JavaScript objects after returning the results in the conventional jsBridge communication method is avoided. In the disclosed embodiment, when jsBridge communication starts, the Web layer can directly obtain the required data from the preset shared memory space. When the native method call obtains the return result after execution, since the native method is in arkts language, it is itself a JavaScript object. Therefore, after the native method is called, the native layer can directly store its return result in the preset shared memory space, so that the Web layer can directly obtain the return result, reducing the communication performance overhead of serialization and pipelines.

[0037] In one implementation of the disclosed embodiment, since the disclosed embodiment does not require serialization, it can support data types that cannot be serialized, such as binary buffer data types. In the conventional jsBridge communication method, binary data needs to be converted into a base64-encoded string before it can be sent through serialization. In the disclosed embodiment, since the binary data itself is also a JavaScript object, there is no need to perform additional special processing on the binary data, and the data in the preset shared memory space can be directly accessed.

[0038] In the disclosed embodiment, the native method is registered in the Web container as a proxy, thereby achieving synchronous calling. Because the native layer and the browser kernel layer are at the same layer, the proxy method is directly registered in the browser kernel through the ChromiumEmbedded Framework, and is synchronous by default without additional processing.

[0039] The following uses the network request of the applet as an example to describe the jsBridge communication process when the Hongmeng applet is running. Figure 4 As shown in the figure, the network request initiated by the Web layer is passed to the native layer through jsBridge, and the native layer replaces the Web layer to initiate the network request and returns the request result to the Web layer. The network request includes necessary network request information such as request method, request address (url), request header (header) and request payload (body).

[0040] Specifically, the user calls the mini-program API (Application Programming Interface) (action 410), and passes the network request parameters (action 420) to the native layer through jsBridge (action 430) in the form of a JavaScript object, which includes determining the proxy method registered in the Web container according to the object identifier of the JavaScript object, and calling the corresponding native method through the proxy method. After the native layer receives the JavaScript object passed by jsBridge, the proxy method calls the corresponding native method, creates a corresponding new network request in the native layer (action 440), and obtains the request result after the execution of the native method through the server (action 450) (action 460), and returns the result as a JavaScript object to the Web container through jsBridge (action 470) (action 480), and the mini-program Web layer can directly read the return result from the Web container, thereby triggering the user code callback to obtain the result.

[0041] Through the embodiments of the present disclosure, the proxy method registered in the Web container can directly call the corresponding native method without serialization and deserialization, which greatly reduces the performance overhead. At the same time, it can support synchronous calling of native methods, expand the achievable functions, and because there is no need to serialize data, the data types that can be implemented in the present disclosure are expanded, such as the binary buffer data type.

[0042] Figure 5 1 is a schematic diagram of the architecture of a jsBridge communication device 50 when a Hongmeng applet is running, provided in an embodiment of the present disclosure. The device 50 is applied to a computer device running a Hongmeng system, which may be a mobile phone, a computer, a tablet computer, or other devices. Figure 5 As shown, it includes: a request module 51, used to request parameters from the native layer through a JavaScript object; a proxy determination module 52, used to determine the proxy method registered in the Web container according to the object identifier of the JavaScript object; a calling module 53, used to call the corresponding native method through the proxy method; a result acquisition module 54, used to obtain the return result after the execution of the native method from the preset shared memory space.

[0043] In some embodiments of the present disclosure, Figure 6 As shown, the device 50 further includes: a registration module 55, which is used to register the proxy method in the Web container through the Chromium Embedded Framework.

[0044] In some embodiments of the present disclosure, the calling module 53 is further configured to search for data required for calling the native method in the preset shared memory space according to the object identifier.

[0045] In some embodiments of the present disclosure, the preset shared memory space is a memory space located in the main process of the Hongmeng applet, and all JavaScript objects required for the Hongmeng applet to run are stored in the preset shared memory space.

[0046] The specific working principle and benefits of the jsBridge communication device when the HarmonyOS mini-program is running provided in the embodiment of the present disclosure are similar to the specific working principle and benefits of the jsBridge communication method when the HarmonyOS mini-program is running provided in the embodiment of the present disclosure, and will not be repeated here.

[0047] In addition, another aspect of the embodiments of the present disclosure further provides a machine-readable storage medium, on which instructions are stored, and the instructions are used to enable the machine to execute the jsBridge communication method when the Hongmeng mini program is running as described in the above embodiments.

[0048] Those skilled in the art will appreciate that the embodiments of the present disclosure may be provided as a system or a computer program product. Therefore, the present disclosure may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present disclosure may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0049] The present disclosure is described with reference to the flowcharts and / or block diagrams of the systems (devices) and computer program products according to the embodiments of the present disclosure. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0050] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0051] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0052] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0053] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0054] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0055] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0056] The above are only embodiments of the present disclosure and are not intended to limit the present disclosure. For those skilled in the art, the present disclosure may have various modifications and variations. Any modification, equivalent substitution, improvement, etc. made within the spirit and principle of the present disclosure shall be included in the scope of the claims of the present disclosure.

Claims

1. A jsBridge communication method when the Hongmeng applet is running. It is characterized in that include: Request parameters from the native layer through JavaScript objects; Determine the proxy method registered in the Web container according to the object identifier of the JavaScript object; Call the corresponding native method through the proxy method; Obtain the return result after executing the native method from the preset shared memory space, The data in the shared memory space can be accessed by the Web layer and the native layer. Wherein, the proxy method is registered in the Web container through the Chromium Embedded Framework.

2. According to the jsBridge communication method during the operation of the Hongmeng applet according to claim 1, It is characterized in that The calling of the corresponding native method through the proxy method includes: According to the object identifier, the data required to call the native method is searched in the preset shared memory space.

3. The jsBridge communication method during the runtime of the Hongmeng applet according to claim 1, It is characterized in that The preset shared memory space is a memory space located in the main process of the Hongmeng applet, and the preset shared memory space stores all JavaScript objects required for the Hongmeng applet to run.

4. A jsBridge communication device when the Hongmeng applet is running, It is characterized in that include: The request module is used to request parameters from the native layer through JavaScript objects; A proxy determination module, used to determine a proxy method registered in a Web container according to an object identifier of the JavaScript object; A calling module, used to call the corresponding native method through the proxy method; A result acquisition module is used to obtain the return result after the execution of the native method from the preset shared memory space. The data in the shared memory space can be accessed by the Web layer and the native layer. Wherein, the device further comprises: A registration module is used to register the proxy method in the Web container through the Chromium Embedded Framework.

5. The jsBridge communication device during the operation of the Hongmeng applet according to claim 4, It is characterized in that The calling module is also used to search for data required to call the native method in the preset shared memory space according to the object identifier.

6. The jsBridge communication device during the operation of the Hongmeng applet according to claim 4, It is characterized in that The preset shared memory space is a memory space located in the main process of the Hongmeng applet, and the preset shared memory space stores all JavaScript objects required for the Hongmeng applet to run.

7. A machine-readable storage medium, It is characterized in that The machine-readable storage medium stores instructions for enabling the machine to execute the jsBridge communication method when the Hongmeng mini program is running as described in any one of claims 1 to 3.

Citation Information

Patent Citations

  • Communication method and device based on JSBridge and storage medium

    CN110502708A

  • Web page and native application interaction method, electronic equipment and storage medium

    CN116414377A

  • Data interaction method and device, electronic equipment and storage medium

    CN116541185A

  • Web end and native end interaction method and terminal equipment

    CN117041234A

  • Method and device for inter-process communication, electronic equipment and medium

    CN117827475A