Method and device for cross-platform use of dynamic link library
By setting up sandboxes on the Hongmeng platform and generating corresponding service programs and establishing communication interfaces, the cross-platform use of the Android platform dynamic link library on the Hongmeng platform is solved, and the problem of dynamic link library cannot be directly adapted is reduced, thereby reducing development costs and system energy consumption.
Patent Information
- Application Number
- CN202411931759.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-26
- Publication Date
- 2025-03-21
AI Technical Summary
It is difficult for the existing technology to realize the cross-platform use of the Android platform's dynamic link library on the Hongmeng platform, resulting in an increase in development investment and the dynamic link library being unable to be directly adapted.
By setting up a sandbox in the first target system and setting the dynamic link library and the corresponding service program in the sandbox, a service program corresponding to the dynamic link library is generated, and a communication interface is set up in the first target system to establish a communication connection between the first target system and the service program, and cross-platform call of the dynamic link library is realized.
It realizes the use of dynamic link library that needs to be run under the second target system in the first target system, solves the problem that dynamic link library cannot be used across platforms, and reduces development costs and system energy consumption.
Smart Images

Figure CN119668901A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer software, and in particular to a method and device for using a dynamic link library across platforms. Background Art
[0002] With the development of digital service terminals and the demand for localization, more and more terminals will adopt systems based on the OpenHarmony (OHOS, Open Harmony Operating System) platform, and more and more Android applications will begin to be deployed on the Harmony platform.
[0003] However, since the Hongmeng system is not yet as popular as the Android system, some applications and services widely used on the Android platform have not yet been adapted on the Hongmeng platform due to limitations such as development investment. In this case, applications developed by the Hongmeng system may use third-party dynamic link libraries used by the Android platform, such as so libraries. However, the Hongmeng system's handling of dynamic link libraries and dependency management are different from those of the Android system, so the Android platform code needs to be transferred to the Hongmeng platform for compilation, including application architecture and programming language modifications, especially the third-party dynamic link libraries used need to be recompiled based on the Hongmeng system environment. In addition, if the dynamic link library is not open source, it will be difficult for developers to compile a dynamic link library suitable for the Hongmeng platform by themselves. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a method and device for using a dynamic link library across platforms, so that the dynamic link library can be used across platforms between different systems.
[0005] In order to solve the above technical problems, the technical solution adopted by the present invention is: A method for using a dynamic link library across platforms, comprising: Setting a sandbox in the first target system, and setting a dynamic link library to be run in the second target system in the sandbox; generating a service program corresponding to the dynamic link library in the second target system, and setting the service program in the sandbox; A communication interface is set in the first target system to establish a communication connection between the first target system and the service program.
[0006] In order to solve the above technical problems, another technical solution adopted by the present invention is: A device for using a dynamic link library across platforms includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program: Setting a sandbox in the first target system, and setting a dynamic link library to be run in the second target system in the sandbox; generating a service program corresponding to the dynamic link library in the second target system, and setting the service program in the sandbox; A communication interface is set in the first target system to establish a communication connection between the first target system and the service program.
[0007] The beneficial effects of the present invention are as follows: by setting a sandbox in the first target system, a dynamic link library and a service program corresponding to the dynamic link library are set in the sandbox at the same time; since the service program is generated in the second target system, the service program can directly call the dynamic link library; and then by setting a communication interface to establish a communication connection between the first target system and the service program, the first target system can call the dynamic link library in the sandbox through the service program, thereby realizing the use of the dynamic link library that needs to be run under the second target system in the first target system, and solving the problem that the dynamic link library cannot be used across platforms. BRIEF DESCRIPTION OF THE DRAWINGS
[0008] Figure 1 A flowchart of a method for using a dynamic link library across platforms in an embodiment of the present invention; Figure 2 A framework diagram of a method for using a dynamic link library across platforms in an embodiment of the present invention; Figure 3 A schematic diagram of the connection between a first target system and a sandbox in a method for using a dynamic link library across platforms in an embodiment of the present invention; Figure 4 A schematic diagram of the interaction between a first target system and a sandbox in a method for using a dynamic link library across platforms in an embodiment of the present invention; Figure 5 The figure is a schematic diagram of the structure of a device for using a dynamic link library across platforms in an embodiment of the present invention. DETAILED DESCRIPTION
[0009] In order to explain the technical content, achieved objectives and effects of the present invention in detail, the following is an explanation in combination with the implementation modes and the accompanying drawings.
[0010] A method for using a dynamic link library across platforms, comprising: Setting a sandbox in the first target system, and setting a dynamic link library to be run in the second target system in the sandbox; generating a service program corresponding to the dynamic link library in the second target system, and setting the service program in the sandbox; A communication interface is set in the first target system to establish a communication connection between the first target system and the service program.
[0011] From the above description, it can be seen that the beneficial effects of the present invention are: by setting a sandbox in the first target system, and setting the dynamic link library and the service program corresponding to the dynamic link library in the sandbox at the same time, since the service program is generated in the second target system, the service program can directly call the dynamic link library; then by setting a communication interface to establish a communication connection between the first target system and the service program, the first target system can call the dynamic link library in the sandbox through the service program, thereby realizing the use of the dynamic link library that needs to be run under the second target system in the first target system, and solving the problem that the dynamic link library cannot be used across platforms.
[0012] Further, the establishing of the communication connection between the first target system and the service program includes: Generate a call request through the first target system, and send the call request to the service program through the communication interface; To instruct the service program to obtain the target method corresponding to the call request in the dynamic link library; execute the call request according to the target method to obtain an execution result, and feed back the execution result to the first target system through the communication interface.
[0013] From the above description, it can be seen that after establishing the communication connection between the first target system and the service program, the first target system generates a call request for the function to be used and sends it to the service program. The service program then obtains the corresponding target method in the sandbox environment to execute the call request and obtains the execution result corresponding to the function. That is, the corresponding function implementation is completed directly in the sandbox, and the sandbox only needs to feed back the execution result to the first target system.
[0014] Further, sending the call request to the service program through the communication interface includes: Encapsulating the call request into a first preset format and sending it to the service program; Feeding back the execution result to the first target system through the communication interface includes: After the execution result is packaged into the first preset format, it is fed back to the first target system.
[0015] From the above description, it can be seen that when data is transmitted between the first target system and the service program, it is agreed that the data is processed in the same preset format, so that the first target system and the service program can process data in the same way, thereby improving the efficiency of data processing by the first target system and the service program, and improving data security.
[0016] Furthermore, after feeding back the execution result to the first target system through the communication interface, the method further includes: The communication connection between the first target system and the service program is closed.
[0017] From the above description, it can be seen that when the first target system completes calling the corresponding dynamic link library, it closes the communication connection with the service program, which means that the first target system does not need to call the dynamic link library, thereby reducing system energy consumption.
[0018] Further, the instructing the service program to obtain a target method corresponding to the call request in the dynamic link library includes: The service program is instructed to parse the call request to obtain parsed data, and to verify the parsed data, and if the verification is successful, the target method is obtained.
[0019] From the above description, it can be seen that after the call request is obtained, the call request is parsed and the data is verified. Only when the data passes the verification, the target method is executed to improve the security of the program.
[0020] Another embodiment of the present invention provides a device for using a dynamic link library across platforms, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program: Setting a sandbox in the first target system, and setting a dynamic link library to be run in the second target system in the sandbox; generating a service program corresponding to the dynamic link library in the second target system, and setting the service program in the sandbox; A communication interface is set in the first target system to establish a communication connection between the first target system and the service program.
[0021] From the above description, it can be seen that the beneficial effects of the present invention are: by setting a sandbox in the first target system, and setting the dynamic link library and the service program corresponding to the dynamic link library in the sandbox at the same time, since the service program is generated in the second target system, the service program can directly call the dynamic link library; then by setting a communication interface to establish a communication connection between the first target system and the service program, the first target system can call the dynamic link library in the sandbox through the service program, thereby realizing the use of the dynamic link library that needs to be run under the second target system in the first target system, and solving the problem that the dynamic link library cannot be used across platforms.
[0022] Further, the establishing of the communication connection between the first target system and the service program includes: Generate a call request through the first target system, and send the call request to the service program through the communication interface; To instruct the service program to obtain the target method corresponding to the call request in the dynamic link library; execute the call request according to the target method to obtain an execution result, and feed back the execution result to the first target system through the communication interface.
[0023] From the above description, it can be seen that after establishing the communication connection between the first target system and the service program, the first target system generates a call request for the function to be used and sends it to the service program. The service program then obtains the corresponding target method in the sandbox environment to execute the call request and obtains the execution result corresponding to the function. That is, the corresponding function implementation is completed directly in the sandbox, and the sandbox only needs to feed back the execution result to the first target system.
[0024] Further, sending the call request to the service program through the communication interface includes: Encapsulating the call request into a first preset format and sending it to the service program; Feeding back the execution result to the first target system through the communication interface includes: After the execution result is packaged into the first preset format, it is fed back to the first target system.
[0025] From the above description, it can be seen that when data is transmitted between the first target system and the service program, it is agreed that the data is processed in the same preset format, so that the first target system and the service program can process data in the same way, thereby improving the efficiency of data processing by the first target system and the service program, and improving data security.
[0026] Furthermore, after feeding back the execution result to the first target system through the communication interface, the method further includes: The communication connection between the first target system and the service program is closed.
[0027] From the above description, it can be seen that when the first target system completes calling the corresponding dynamic link library, it closes the communication connection with the service program, which means that the first target system does not need to call the dynamic link library, thereby reducing system energy consumption.
[0028] Further, the instructing the service program to obtain a target method corresponding to the call request in the dynamic link library includes: The service program is instructed to parse the call request to obtain parsed data, and to verify the parsed data, and if the verification is successful, the target method is obtained.
[0029] From the above description, it can be seen that after the call request is obtained, the call request is parsed and the data is verified. Only when the data passes the verification, the target method is executed to improve the security of the program.
[0030] The method and device for cross-platform use of dynamic link libraries provided by the present invention can be applied to system architectures based on the Linux kernel, such as Hongmeng and Android system related products, solving the problem that the dynamic link library of the Android platform cannot be directly applied to the Hongmeng system, and achieving the technical effect of cross-platform use of third-party libraries. The following is an explanation through specific implementation methods: Embodiment 1 Please refer to Figure 1 , a method for using a dynamic link library across platforms, comprising: S1. Setting a sandbox in a first target system, and setting a dynamic link library to be run in a second target system in the sandbox.
[0031] Please refer to Figure 2 In this embodiment, the corresponding steps are described by taking the application of the dynamic link library (so library) of the Android platform to the Hongmeng platform (OHOS) as an example, wherein the Android system is the second target system, the dynamic link library needs to run in the Android system, and the Hongmeng system is the first target system. That is, step S1 sets the sandbox in the Hongmeng system, specifically: pre-set the target so library and the required associated files such as lib and bin in the sandbox, and all the files in the sandbox are generated on the Android system, so as to simulate the Android system and make the dynamic link library run in the Android environment.
[0032] S2. Generate a service program corresponding to the dynamic link library in the second target system, and set the service program in the sandbox. That is, generate a service program in the installation platform environment: so_daemon, the service program (so_daemon) serves the bin application, and because the service program (so_daemon) is generated in the Android environment, bin can directly call the so library (target.so).
[0033] S3, setting a communication interface in the first target system to establish a communication connection between the first target system and the service program. Figure 2 As shown, the communication interface is exposed in the Hongmeng system (OHOS) in the form of a Unix socket interface for application services in the Hongmeng system to call.
[0034] Please refer to Figure 3 In the sandbox, the service program (so_daemon) is used to define the corresponding parameters and interface calls of the target so library with different command parameters, and a unix socket is created as the socket server. The corresponding so library interface is indirectly called through the socket to listen to the incoming commands of the client (that is, the Hongmeng platform).
[0035] In the Hongmeng platform, the Hongmeng service (ohos_daemon) is set to receive requests from the Hongmeng application (ohos_app), that is, the Hongmeng application sends the request to the service program (so_daemon) through the Hongmeng service through the socket connection, and issues instructions to call the target so library interface. Among them, the Hongmeng service (ohos_daemon) mainly includes the following functions: 1. Establish a Unix socket connection with the service program (so_daemon) for interactive communication between the two parties; 2. Provide an interface with the corresponding functions of target.so for Hongmeng application (ohos_app) to call; 3. The interface function of Hongmeng service (ohos_daemon) is encapsulated into corresponding command information, and the command information is sent to the service program (so_daemon) through socket and the execution result of the service program (so_daemon) is received. That is, the interaction between ohos-daemon and so-daemon is realized through socket.
[0036] At the same time, in an optional implementation, the Hongmeng service (ohos_daemon) and the service program (so_daemon) transmit data in a preset format. For example, the two parties agree that the data format for communication is: {cmd: [command]; info: [data]; size: [length]; ret: [result];}, and both parties verify the data and perform corresponding operations based on the parsed data received.
[0037] When the first target system interacts with the sandbox: A call request is generated through the first target system, and the call request is sent to the service program through the communication interface; then, the service program is instructed to obtain a target method corresponding to the call request in the dynamic link library, and execute the call request according to the target method to obtain an execution result, and the execution result is fed back to the first target system through the communication interface.
[0038] Please refer to Figure 4 In this embodiment, the interaction process between the Hongmeng platform and the sandbox is described by taking the setting of parameter setParam(params) as an example. The specific interaction process is as follows: 1. The service program (so_daemon) creates a socket named daemon_socket and waits to receive accetp_socket; 2. The Hongmeng application (ohos_app) calls the setParam(stringparams) provided by the Hongmeng service (ohos_daemon); 3. The Hongmeng service (ohos_daemon) receives the setParam request, encapsulates params into data msg in the format of {cmd: [command];info:[params];size:[length];ret:[result];}, and then sends the data msg to daemon_socket through the socket; 4. After receiving the data msg, the service program (so_daemon) parses cmd and calls the corresponding method of the target library (target.so) to perform the do_setParam operation; 5. The target library (target.so) returns the execution result to the service program (so_daemon); 6. The service program (so_daemon) encapsulates the execution result result into data recv_msg in the format of {cmd: [command];info:[params];size:[length];ret:[result];}, and sends it to the Hongmeng service (ohos_daemon) through the socket; 7. After receiving the data recv_msg, the Hongmeng service (ohos_daemon) parses the execution result result, returns the parsed result to the Hongmeng application (ohos_app), and finally closes the socket connection.
[0039] Embodiment 2 Please refer to Figure 5 , a device for using a dynamic link library across platforms, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program: S1. Setting a sandbox in the first target system, and setting a dynamic link library to be run in the second target system in the sandbox; S2, generating a service program corresponding to the dynamic link library in the second target system, and setting the service program in the sandbox; S3. Setting a communication interface in the first target system to establish a communication connection between the first target system and the service program.
[0040] When the first target system interacts with the sandbox: A call request is generated through the first target system, and the call request is sent to the service program through the communication interface. Specifically, the call request is packaged into a first preset format and then sent to the service program.
[0041] The service program obtains the target method corresponding to the call request in the dynamic link library; executes the call request according to the target method to obtain an execution result, and feeds back the execution result to the first target system through the communication interface. When feeding back, the execution result is encapsulated into the first preset format and then fed back to the first target system.
[0042] Meanwhile, during the interaction between the first target system and the sandbox, the first target system and the service program parse and verify the acquired data, and execute corresponding processing when the verification is successful. And when the first target system receives the feedback information, the communication connection between the first target system and the service program is closed.
[0043] In summary, the method and device for using a dynamic link library across platforms provided by the present invention, by setting a sandbox in the first target system, and setting the dynamic link library and the service program corresponding to the dynamic link library in the sandbox at the same time, because the service program is generated in the second target system, the service program can directly call the dynamic link library; then, by setting a communication interface to establish a communication connection between the first target system and the service program, the first target system can call the dynamic link library in the sandbox through the service program, thereby realizing the use of the dynamic link library that needs to be run under the second target system in the first target system, and solving the problem that the dynamic link library cannot be used across platforms.
[0044] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent transformations made using the contents of the present invention's specification and drawings, or directly or indirectly applied in related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A method for using a dynamic link library across platforms, characterized in that: include: Setting a sandbox in the first target system, and setting a dynamic link library to be run in the second target system in the sandbox; generating a service program corresponding to the dynamic link library in the second target system, and setting the service program in the sandbox; A communication interface is set in the first target system to establish a communication connection between the first target system and the service program.
2. A method for using a dynamic link library across platforms according to claim 1, characterized in that: The step of establishing a communication connection between the first target system and the service program includes: Generate a call request through the first target system, and send the call request to the service program through the communication interface; To instruct the service program to obtain the target method corresponding to the call request in the dynamic link library; execute the call request according to the target method to obtain an execution result, and feed back the execution result to the first target system through the communication interface.
3. A method for using a dynamic link library across platforms according to claim 2, characterized in that: The sending the call request to the service program through the communication interface comprises: Encapsulating the call request into a first preset format and sending it to the service program; Feeding back the execution result to the first target system through the communication interface includes: After the execution result is packaged into the first preset format, it is fed back to the first target system.
4. A method for using a dynamic link library across platforms according to claim 2, characterized in that: After feeding back the execution result to the first target system through the communication interface, the following further includes: The communication connection between the first target system and the service program is closed.
5. The method for using a dynamic link library across platforms according to claim 2, characterized in that: The instructing the service program to obtain a target method corresponding to the call request in the dynamic link library comprises: The service program is instructed to parse the call request to obtain parsed data, and to verify the parsed data, and if the verification is successful, the target method is obtained.
6. A device for using a dynamic link library across platforms, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the following steps are implemented: Setting a sandbox in the first target system, and setting a dynamic link library to be run in the second target system in the sandbox; generating a service program corresponding to the dynamic link library in the second target system, and setting the service program in the sandbox; A communication interface is set in the first target system to establish a communication connection between the first target system and the service program.
7. The device for using a dynamic link library across platforms according to claim 6, characterized in that: The step of establishing a communication connection between the first target system and the service program includes: Generate a call request through the first target system, and send the call request to the service program through the communication interface; To instruct the service program to obtain the target method corresponding to the call request in the dynamic link library; execute the call request according to the target method to obtain an execution result, and feed back the execution result to the first target system through the communication interface.
8. The device for using a dynamic link library across platforms according to claim 7, characterized in that: The sending the call request to the service program through the communication interface comprises: Encapsulating the call request into a first preset format and sending it to the service program; Feeding back the execution result to the first target system through the communication interface includes: After the execution result is packaged into the first preset format, it is fed back to the first target system.
9. The device for using a dynamic link library across platforms according to claim 7, characterized in that: After feeding back the execution result to the first target system through the communication interface, the following further includes: The communication connection between the first target system and the service program is closed.
10. The device for using a dynamic link library across platforms according to claim 7, characterized in that: The instructing the service program to obtain a target method corresponding to the call request in the dynamic link library comprises: The service program is instructed to parse the call request to obtain parsed data, and to verify the parsed data, and if the verification is successful, the target method is obtained.