Interaction method and related device within application program

By embedding the animation engine in the native application and creating main and child processes, using the interface definition language and shared memory mechanism, the black screen and flashback problems caused by the embedding of the animation engine are solved, and stable multi-process interaction and memory optimization are achieved.

CN116009992BActive Publication Date: 2025-08-26TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111237319.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-22
Publication Date
2025-08-26
Estimated Expiration
2041-10-22

AI Technical Summary

Technical Problem

When embedding animation engines in native applications, it is easy to cause black screens, flashbacks and interaction instability, especially in the continuous data flow interaction between multiple processes, memory growth is too fast, resulting in process killing.

Method used

After embedding the animation engine in the native application, the main process and child process are created, and the interface definition language object is used to realize inter-process interaction, combined with the shared memory mechanism to optimize memory usage, and semaphores are used to control shared memory access.

Benefits of technology

It realizes stable interaction between the animation engine and native programs, reduces memory consumption, avoids process killing, and improves the stability and responsiveness of the application.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116009992B_ABST
    Figure CN116009992B_ABST
Patent Text Reader

Abstract

An embodiment of the present application provides an intra-application interaction method and related device, the method comprising: embedding an animation engine in a native application, the native application comprising a native program docking module; creating a main process based on the native application, and having the main process create a sub-process based on the animation engine and the native program docking module; providing the sub-process with a first interface definition language object of the main process, and providing the main process with a second interface definition language object of the sub-process; performing interaction between the main process and the sub-process based on the first interface definition language object and the second interface definition language object; calling a method of the native program docking module in the animation engine, calling an interface of the animation engine in the native program docking module, and performing interaction between the animation engine and the native program docking module. The present application implements complete interaction between the native application and the animation engine based on multiple processes, which can make the interaction within the application containing the animation engine more stable.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of software development technology, and in particular to an interaction method within an application and related devices. Background Art

[0002] Currently, applications that include animation engines generally use the animation engine as the main project. However, embedding an animation engine in a mature native application often leads to unstable interaction issues such as black screen, crashes, and unresponsiveness. Summary of the Invention

[0003] The embodiments of the present application provide an intra-application interaction method and related apparatus, thereby making the interaction within an application containing an animation engine more stable, at least to a certain extent.

[0004] Other features and advantages of the present application will become apparent from the following detailed description, or may be learned in part by practice of the present application.

[0005] According to one aspect of an embodiment of the present application, a method for interaction within an application is provided, the method comprising: embedding an animation engine in a native application, the native application comprising a native program docking module; creating a main process based on the native application, and having the main process create a sub-process based on the animation engine and the native program docking module; providing the sub-process with a first interface definition language object of the main process, and providing the main process with a second interface definition language object of the sub-process; performing interaction between the main process and the sub-process based on the first interface definition language object and the second interface definition language object; calling a method in the native program docking module in the animation engine, and calling an interface provided by the animation engine in the native program docking module, so as to perform interaction between the animation engine and the native program docking module in the sub-process.

[0006] According to one aspect of an embodiment of the present application, an intra-application interaction device is provided, the device comprising: an embedding unit for embedding an animation engine in a native application, the native application comprising a native program docking module; a creating unit for creating a main process based on the native application, and the main process creating a sub-process based on the animation engine and the native program docking module; a providing unit for providing the sub-process with a first interface definition language object of the main process and providing the main process with a second interface definition language object of the sub-process; a first interaction unit for performing interaction between the main process and the sub-process based on the first interface definition language object and the second interface definition language object; a second interaction unit for calling a method in the native program docking module in the animation engine, and calling an interface provided by the animation engine in the native program docking module, so as to perform interaction between the animation engine and the native program docking module in the sub-process.

[0007] In some embodiments of the present application, based on the aforementioned scheme, the embedded unit is configured to: decompress the program package of the animation engine to obtain a decompression result; copy the decompression result to the project directory of the native application; modify the target properties in the configuration file corresponding to the animation engine to configure the animation engine as a separate process.

[0008] In some embodiments of the present application, based on the aforementioned solution, the embedding unit is further used to: delete the verification code in the animation engine.

[0009] In some embodiments of the present application, based on the aforementioned scheme, the providing unit is configured as follows: when the active component in the sub-process is started, the service component in the main process is bound through the sub-process, and the first interface definition language object of the main process is obtained from the service component; the method of the first interface definition language object is called through the sub-process to pass the second interface definition language object of the sub-process to the main process.

[0010] In some embodiments of the present application, based on the aforementioned scheme, the first interaction unit is also used to: create a data sending object in the main process, and create a corresponding shared memory object for the data sending object, wherein the shared memory object corresponds to the shared memory; obtain a file descriptor and data parsing protocol information corresponding to the shared memory object, wherein the data parsing protocol information includes block information of the shared memory and information related to the data stored in the shared memory; send the file descriptor and the data parsing protocol information to the child process, and the child process creates a data receiving object based on the received file descriptor and the data parsing protocol information; construct the shared memory object in the child process based on the file descriptor and the data parsing protocol information; and read data from the shared memory corresponding to the shared memory object through the data receiving object in the child process.

[0011] In some embodiments of the present application, based on the aforementioned scheme, the first interaction unit is configured to: create a new thread in the child process; and read data from the shared memory corresponding to the shared memory object in a polling manner through the new thread.

[0012] In some embodiments of the present application, based on the aforementioned scheme, the first interaction unit is configured to: create a new shared memory file; construct a shared memory sub-object based on the file descriptor and the data parsing protocol information; create a buffer mapping object; assign values ​​to the shared memory file through a reflection mechanism and based on the buffer mapping object and the shared memory sub-object to obtain the shared memory object.

[0013] In some embodiments of the present application, based on the aforementioned solution, the size of the shared memory is the sum of the size of a frame of picture data and the length of a predetermined offset.

[0014] In some embodiments of the present application, based on the aforementioned scheme, the first interaction unit is also used to: obtain the semaphore recorded at the specified position from the shared memory corresponding to the shared memory object through the main process and the child process respectively as the target semaphore, wherein the specified position is located in the shared memory corresponding to the predetermined offset; determine whether to access the shared memory corresponding to the shared memory object in the main process and the child process according to the target semaphore.

[0015] According to one aspect of an embodiment of the present application, a computer-readable medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the interaction method within the application program as described in the above embodiment is implemented.

[0016] According to one aspect of an embodiment of the present application, an electronic device is provided, comprising: one or more processors; a storage device for storing one or more programs, which, when executed by the one or more processors, enables the one or more processors to implement the interaction method within the application as described in the above embodiments.

[0017] In the technical solutions provided in some embodiments of the present application, after embedding the animation engine in the native application, a main process and a sub-process are created respectively, wherein the main process is created based on the native application, and the sub-process is created based on the animation engine and the native program docking module in the native application. On this basis, on the one hand, the interface definition language object of the other process is provided to the main process and the sub-process respectively, so that the main process and the sub-process can interact based on the interface definition language object. On the other hand, the native program docking module can call the interface provided by the animation engine, and the animation engine can call the method in the native program docking module, thus realizing the interaction between the animation engine and the native program docking module. Therefore, the entire solution takes the native application as the main project, and while embedding the animation engine in the native application, it realizes the complete interaction between the native application part and the animation engine in the application based on multiple processes, which can make the interaction within the application containing the animation engine more stable.

[0018] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The accompanying drawings are incorporated into and constitute a part of the specification, illustrating embodiments consistent with the present application and, together with the specification, explaining the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and those skilled in the art can derive other drawings based on these drawings without inventive effort. In the drawings:

[0020] Figure 1 A schematic diagram showing an exemplary system architecture to which the technical solutions of the embodiments of the present application can be applied;

[0021] Figure 2 A flowchart showing an interaction method within an application according to an embodiment of the present application is shown;

[0022] Figure 3 A flowchart of embedding an animation engine in a native application according to one embodiment of the present application is shown;

[0023] Figure 4A flowchart of providing an interface definition language object to a main process and a sub-process according to an embodiment of the present application is shown;

[0024] Figure 5 A structural diagram illustrating interaction with an animation engine based on multi-process implementation according to an embodiment of the present application is shown;

[0025] Figure 6 A flowchart illustrating the use of shared memory to implement data flow interaction within an application program according to an embodiment of the present application is shown;

[0026] Figure 7 A schematic diagram showing the principle of different processes interacting through shared memory according to an embodiment of the present application is shown;

[0027] Figure 8 A flowchart illustrating how to implement read-write synchronization when different processes access shared memory according to an embodiment of the present application is shown;

[0028] Figure 9 A block diagram showing an interaction device within an application according to an embodiment of the present application is shown;

[0029] Figure 10 A schematic diagram of the structure of a computer system suitable for implementing an electronic device according to an embodiment of the present application is shown. DETAILED DESCRIPTION

[0030] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this application will be thorough and complete and will fully convey the concepts of the example embodiments to those skilled in the art.

[0031] In addition, described feature, structure or characteristic can be combined in one or more embodiments in any suitable manner.In the following description, many specific details are provided so as to provide a full understanding of the embodiments of the present application. However, it will be appreciated by those skilled in the art that the technical scheme of the present application can be put into practice without one or more of the specific details, or other methods, components, devices, steps etc. can be adopted. In other cases, known methods, devices, implementations or operations are not shown or described in detail to avoid blurring the various aspects of the application.

[0032] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically separate entities. That is, these functional entities may be implemented in software, in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.

[0033] The flowcharts shown in the accompanying drawings are for illustrative purposes only and do not necessarily include all contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may be decomposed, while others may be combined or partially combined. Therefore, the actual execution order may vary depending on the actual situation.

[0034] With the advent of the Internet, especially the mobile Internet era, users need applications (Apps) with more and more rich functions. More and more Apps need to provide users with animation playback functions. To achieve this function, it is necessary to set up an animation engine in the App.

[0035] In Android apps that include animation engines, the animation engine is generally used as the main project. If a mature native app is used as the main project and the animation engine is embedded in the native app, the following defects may occur based on a single-process or multi-process approach:

[0036] 1. Secondary flashback caused by animation engine limitations

[0037] On the one hand, when most animation engines were first designed, they did not consider the native App as the main project and embedding the animation engine in it. Therefore, the RootActivity check will be performed on the Activity exposed in the engine, and exiting the Activity will kill the entire process.

[0038] On the other hand, animation engines typically default to initializing the engine only once per process and then terminating the process immediately after use. Therefore, they don't consider how to safely destroy the engine. Consequently, when the engine is reopened, null pointers to variables may appear because the previous instance wasn't fully destroyed, causing a crash.

[0039] 2. Multi-process based embedding

[0040] The interaction solution between multiple processes lacks real-time and stability, and multiple processes will cause a huge increase in memory usage in continuous data flow interaction scenarios, resulting in process killing.

[0041] To this end, the present application first provides an in-application interaction method. The in-application interaction method provided in the embodiments of the present application can overcome the above-mentioned drawbacks. The in-application interaction method provided in the embodiments of the present application not only embeds the animation engine into the Android native App in a multi-process manner, realizing complete interaction between the animation engine and the native program, but also solves the memory growth problem caused by continuous data flow interaction between multiple processes.

[0042] Figure 1A schematic diagram shows an exemplary system architecture to which the technical solutions of the embodiments of the present application can be applied.

[0043] like Figure 1 As shown, the system architecture may include terminal devices (such as Figure 1 One or more of the smartphone 101, tablet computer 102 and portable computer 103 shown in the figure, which may also be a desktop computer, a vehicle-mounted terminal, etc.), network 104, server 105 and personal computer 106. Network 104 is a medium for providing a communication link between the terminal device and the server 105. Network 104 may include various connection types, such as wired communication links, wireless communication links, etc. In the embodiment of the present application, personal computer 106 is an execution terminal of an interaction method within an application provided by the present application, and personal computer 106 is used by the developer. When the interaction method within an application provided by the present application is applied to Figure 1 In the system architecture shown, a process may be as follows: first, the developer develops a native application and an animation engine on a personal computer 106 respectively, and embeds the animation engine in the native application to obtain an application; then, the corresponding logic is further set in the application so that the following process is performed after the application is started: a main process and a child process are created respectively, and the interaction between the main process and the child process is realized by providing the interface definition language object of the other process to the other process, and the interaction within the child process is realized by calling the interface and method. In this way, the internal interaction of the application with the embedded animation engine is realized based on multiple processes; then, the developer uploads the final application package to the server 105, so that each terminal device can download the application package from the server 105 through the network 104 and can install the application package on the terminal device.

[0044] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is merely illustrative. Any number of terminal devices, networks and servers may be provided as needed. For example, the server 105 may be a server cluster consisting of multiple servers.

[0045] In one embodiment of the present application, the operating system used by each terminal device is the Android system.

[0046] In one embodiment of the present application, when the application is running on each terminal device, the application starts a main process and a sub-process, and performs continuous data flow interaction between the main process and the sub-process through a shared memory on the local terminal device.

[0047] In one embodiment of the present application, the child process reads data from the shared memory in a polling manner through an established new thread.

[0048] In one embodiment of the present application, the main process and the sub-process determine whether to perform a data transmission operation with the shared memory by reading a semaphore in a specified location of the shared memory.

[0049] It should be noted that, although in the embodiment of the present application, the native application and the animation engine are both developed by developers on the personal computer 106, in other embodiments of the present application, any one of the native application and the animation engine can be obtained by the personal computer 106 from other devices, such as the native application or the animation engine can be downloaded from the server by the personal computer 106, and the native application and the animation engine can come from different devices respectively; although in the embodiment of the present application, after the construction of the application package is completed, it is directly uploaded to the server, in other embodiments of the present application, the application package can also be sent to the test terminal first, and after the test terminal completes the testing of the application package, the application package can be uploaded to the server. The embodiment of the present application does not impose any limitation on this, and the scope of protection of the present application should not be limited in any way.

[0050] Furthermore, it is easy to understand that the in-application interaction method provided in the embodiments of the present application is generally executed by a terminal device, and accordingly, the in-application interaction device is generally provided in the terminal device. However, in other embodiments of the present application, the server may also have similar functions to the terminal device, thereby implementing the in-application interaction solution provided in the embodiments of the present application.

[0051] The application constructed based on the method provided in the embodiment of the present application can be distributed to the user terminal through the server, and the service end corresponding to the application constructed based on the method provided in the embodiment of the present application can also be deployed on the server. The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The terminal can be a smart phone, tablet computer, laptop computer, desktop computer, smart speaker, smart watch, etc., but is not limited to this. The terminal and the server can be directly or indirectly connected through wired or wireless communication, and this application does not limit this.

[0052] The embodiments of the present application can be applied to cloud computing technology. Specifically, the application program constructed according to the method of the embodiments of the present application can be distributed to the user terminal through cloud computing technology. Cloud computing is a computing model that distributes computing tasks on a resource pool composed of a large number of computers, so that various application systems can obtain computing power, storage space and information services as needed. The network that provides resources is called a "cloud". The resources in the "cloud" appear to be infinitely scalable to users, and can be obtained at any time, used on demand, expanded at any time, and paid for on a per-use basis.

[0053] As a provider of cloud computing infrastructure, a cloud computing resource pool (referred to as a cloud platform, often referred to as IaaS (Infrastructure as a Service)) is established. Within this pool, various virtual resources are deployed for external customers to choose from. This resource pool primarily includes computing devices (virtualized machines, including operating systems), storage devices, and network equipment.

[0054] Based on logical functional divisions, the PaaS (Platform as a Service) layer can be deployed on top of the IaaS (Infrastructure as a Service) layer, and the SaaS (Software as a Service) layer can be deployed on top of the PaaS layer. SaaS can also be deployed directly on top of IaaS. PaaS is a platform for software execution, such as databases and web containers. SaaS is a variety of business software, such as web portals and text messaging tools. Generally speaking, SaaS and PaaS are upper layers relative to IaaS.

[0055] The following is a detailed description of the implementation details of the technical solution of the embodiment of the present application:

[0056] Figure 2 A flowchart of an interaction method within an application according to an embodiment of the present application is shown. The interaction method within the application can be executed by a device with computing and storage functions, such as Figure 1 The personal computer 106 shown in FIG. Figure 2 As shown, the interaction method within the application includes at least the following steps:

[0057] In step 210 , an animation engine is embedded in a native application, where the native application includes a native program docking module.

[0058] The native application can be an app native to the Android system, and the application built based on the in-application interaction method provided in the embodiment of the present application can be an app that can be deployed on the Android system. The solution of the embodiment of the present application can be applied to any application with an animation playback function.

[0059] Taking the native application as the main project and embedding the animation engine in the native application, an initial project project is obtained. Reliable interaction between the animation engine and the native application has not yet been achieved in the initial project project. It is necessary to further add other interaction logics to the initial project project. These interaction logics can be used to execute the method of steps 220-250, thereby realizing the complete interaction process between the animation engine and the native application, and then obtaining a complete application with an embedded animation engine.

[0060] The native program docking module is a module in the native application used to communicate with the animation engine, that is, the intermediary for communication between the native application and the animation engine.

[0061] Figure 3 FIG. 1 shows a flow chart of embedding an animation engine in a native application according to an embodiment of the present application. Figure 3 As shown, the following steps are included:

[0062] In step 310, the animation engine program package is decompressed to obtain a decompression result.

[0063] Decompress the APK (Android application package) obtained by packaging the engine main project to obtain a decompression result.

[0064] In step 320 , the decompression result is copied to the project directory of the native application.

[0065] Analyze the decompression results and copy the compiled products to the native App project directory.

[0066] In step 330 , the target attribute in the configuration file corresponding to the animation engine is modified to configure the animation engine as a separate process.

[0067] For Activity components exposed by the engine, configure the android:process attribute in the corresponding manifest file to configure it as a separate process.

[0068] In one embodiment of the present application, the method further includes: deleting the verification code in the animation engine.

[0069] Specifically, after decompressing the animation engine apk and obtaining the decompression result containing the engine source code, the logic related to RootActivity in the engine source code can be deleted.

[0070] In the embodiment of the present application, by modifying the engine source code to remove the logic of RootActivity verification, the process corresponding to the animation engine is avoided from being killed due to RootActivity verification, thereby avoiding the App from crashing and improving the stability of the App.

[0071] In step 220, a main process is created according to the native application, and the main process creates a sub-process according to the animation engine and the native program docking module.

[0072] The created main process can execute the code in the native application, which may not include the native program docking module.

[0073] In one embodiment of the present application, the method further includes: starting an Activity component corresponding to the animation engine.

[0074] Specifically, the main process can use the startActivity method to start the Activity component and sub-process.

[0075] In step 230, the first interface definition language object of the main process is provided to the sub-process, and the second interface definition language object of the sub-process is provided to the main process.

[0076] The first interface definition language object and the second interface definition language object are both AIDL (Android Interface Definition Language) objects.

[0077] AIDL is a tool that users can use to abstract IPC (Inter-Process Communication). The interface provided by AIDL can be used to communicate across processes.

[0078] Figure 4 FIG. 1 shows a flow chart of providing an interface definition language object to a main process and a sub-process according to an embodiment of the present application. Figure 4 As shown, the following steps are included:

[0079] In step 410, when the active component in the child process is started, the service component in the main process is bound through the child process, and the first interface definition language object of the main process is obtained from the service component.

[0080] Specifically, the main process calls the child process through startActivity (Intent intent). After the Activity component exposed by the child process animation engine is started, it actively binds the Service component of the main process and obtains the AIDL object of the main process in the serviceConnection.

[0081] In step 420, the method of the first interface definition language object is called by the child process to pass the second interface definition language object of the child process to the main process.

[0082] The child process passes its own AIDL object to the main process by calling methods on the main process's AIDL object. This allows the main process to also hold the child process's AIDL object and call methods provided by the child process. This allows RPC (remote procedure call) communication between the main and child processes.

[0083] In the embodiment of the present application, inter-process communication is achieved by having the main process and the sub-process respectively hold each other's AIDL objects.

[0084] Please continue to see Figure 2 In step 240, the main process and the sub-process interact based on the first interface definition language object and the second interface definition language object.

[0085] The sub-process communicates with the main process by calling the method corresponding to the first interface definition language object, and the main process communicates with the sub-process by calling the method corresponding to the second interface definition language object.

[0086] Figure 5 FIG. 1 shows a structural diagram of interaction with an animation engine based on multi-process implementation according to an embodiment of the present application. Figure 5 As shown, both the animation engine and the Bridge class reside in the child process. First, the animation engine uses reflection to call native Java methods related to the Bridge class in the child process. The child process then calls the corresponding method in the main process through the sub-call-main AIDL object of the main process. Then, if the call is successful, the return value from the main process is sent to the main-call-sub AIDL object of the child process, which then passes the return value to the Bridge class in the child process. When the main process wants to control the child process, it does so by calling the remote method provided by the child process's AIDL object.

[0087] In step 250, the method in the native program docking module is called in the animation engine, and the interface provided by the animation engine is called in the native program docking module to perform interaction between the animation engine and the native program docking module in the sub-process.

[0088] Please continue to see Figure 5 The complete interaction process can be divided into: animation engine -> child process Java native -> main process Java native -> child process Java native -> animation engine. The child process Java native is represented by the Bridge class. Specifically, a Bridge class is defined on the native side as the core bridge for communication between the native and animation engine, and the Bridge path is set in the animation engine. The animation engine can call the child process's native static methods through reflection. For example, in JavaScript, the callStaticMethod method can be used to call a static method of the agreed path class. By passing the Java class name, method name, method signature, and dependent parameters as parameters, the Java static method can be directly called and the Java method's return value obtained. In the child process, after receiving the return value passed from the main process to the child process via the main-call-sub AIDL object, the Bridge class can then pass the return value to the animation engine by calling the interface exposed by the animation engine.

[0089] Since the variables and data in multiple processes are independent, if it is necessary to process the continuous data flow in the main process in the child process in scenarios such as audio and video, two memories will be occupied, causing memory growth, which will lead to the process being killed.

[0090] Based on this, the embodiment of the present application also achieves memory optimization in a continuous data stream interaction scenario.

[0091] Figure 6 FIG. 1 shows a flow chart of using shared memory to implement data flow interaction within an application program according to an embodiment of the present application. Figure 6 As shown in the figure, using shared memory to implement data flow interaction within an application program may include at least the following steps:

[0092] In step 610, a data sending object is created in the main process, and a corresponding shared memory object is created for the data sending object, where the shared memory object corresponds to the shared memory.

[0093] For example, taking the transmission of multiple video data streams between the main process and the child process, the main process performs initialization operations when it receives a data stream. At this time, it will establish a dataSender object responsible for data transmission. Each dataSender object will hold a shared memory.

[0094] The shared memory object is a MemoryFile. MemoryFile is an object that Android encapsulates for anonymous shared memory and is used to transfer large data between processes. Therefore, both the shared memory object and MemoryFile have corresponding shared memory.

[0095] In step 620, a file descriptor and data parsing protocol information corresponding to the shared memory object are obtained. The data parsing protocol information includes block information of the shared memory and information related to data stored in the shared memory.

[0096] Specifically, a block of shared memory is created and uniquely named in the dataSender object's constructor. This shared memory is configured with the corresponding data parsing protocol information. Because the shared memory created by the dataSender object is abstracted as a MemoryFile, and the file descriptor in a MemoryFile is private, the MemoryFile's file descriptor must be obtained through reflection, serialized, and persisted.

[0097] In the data parsing protocol information, the shared memory block information may include the size of the shared memory block, and the information related to the data stored in the shared memory may include additional information such as the length and width of the frame data, the format of the video stream, and the offset.

[0098] In step 630, the file descriptor and data parsing protocol information are sent to the child process, and the child process creates a data receiving object according to the received file descriptor and data parsing protocol information.

[0099] In one embodiment of the present application, sending the file descriptor and the data parsing protocol information to the child process includes: converting the file descriptor and the data parsing protocol information into a predetermined format; and sending the conversion result to the child process.

[0100] In one embodiment of the present application, sending the file descriptor and the data parsing protocol information to the child process includes: sending the file descriptor and the data parsing protocol information to the child process through a second interface definition language object.

[0101] Specifically, after the main process is initialized, the dataSender object converts the file descriptor of the shared memory and the parsing protocol corresponding to MemoryFile into a json string and sends it to the child process through AIDL.

[0102] In step 640, a shared memory object is constructed in the child process according to the file descriptor and the data parsing protocol information.

[0103] After obtaining the JSON string sent by the dataSender object, the child process constructs the same shared memory object based on the file descriptor and data parsing protocol information in the JSON string.

[0104] In one embodiment of the present application, a shared memory object is constructed in a child process based on a file descriptor and data parsing protocol information, including: creating a new shared memory file; constructing a shared memory sub-object based on the file descriptor and data parsing protocol information; creating a buffer mapping object; and assigning values ​​to the shared memory file through a reflection mechanism and based on the buffer mapping object and the shared memory sub-object to obtain a shared memory object.

[0105] Specifically, MemoryFile is a wrapper around SharedMemory, with its two core private member variables being SharedMemory and buffer mapping. In Android 8.0 and later, the MemoryFile source code was changed to wrap SharedMemoryFile, making it impossible to construct shared memory via reflection. Therefore, for systems running Android 8.0 and later, you must first create a new MemoryFile file, then construct SharedMemory through reflection and create a buffer mapping. Finally, set the SharedMemory and buffer mapping into the MemoryFile file through reflection to complete the shared memory redirection of the MemoryFile.

[0106] In step 650, data is read from the shared memory corresponding to the shared memory object through the data receiving object in the child process.

[0107] After the child process obtains the shared memory object, it can access the corresponding shared memory.

[0108] In one embodiment of the present application, reading data from the shared memory corresponding to the shared memory object through the data receiving object in the child process includes: creating a new thread in the child process; and reading data from the shared memory corresponding to the shared memory object in a polling manner through the new thread.

[0109] Specifically, polling is a process of periodically determining whether data needs to be read from the shared memory, and then performing a data reading operation based on the determination result. The entire process is repeated over and over again.

[0110] Since the polling task will block the call of AIDL in the Binder Thread, it will cause the inter-process communication to be unable to proceed. In the embodiment of the present application, a new thread is opened to read data in a polling manner, which ensures that inter-process communication can also be achieved when executing the polling task.

[0111] In an embodiment of the present application, different processes directly operate on the same shared memory, realizing inter-process communication, improving communication efficiency, and greatly reducing memory usage. It solves the problem of memory growth caused by continuous data flow interaction between multiple processes, avoids killing processes, and greatly reduces the possibility of problems such as flash back and no response.

[0112] In one embodiment of the present application, the method further includes: resetting the cursor whenever data reading is completed.

[0113] Specifically, when using FileInputStream to read data, you need to reset the cursor after each reading, otherwise the next reading will fail.

[0114] In one embodiment of the present application, the size of the shared memory is the sum of the size of a frame of picture data and the length of a predetermined offset.

[0115] Specifically, the shared memory can be a shared memory block, the size of the shared memory block = the size of one frame of picture data + a predetermined offset, the predetermined offset can be 1 byte in length, and is used to store 0, 1 analog PV semaphores to control thread reading and writing between different processes.

[0116] In the embodiment of the present application, by retaining the size of one frame of picture data in the shared memory, the process of transmitting picture data between different processes through the shared memory is made simpler and more direct.

[0117] In other embodiments of the present application, other shared memory sizes may be set. For example, the shared memory size may be set to the sum of the size of two frames of picture data and the length of a predetermined offset.

[0118] Figure 7 Schematic diagram showing the principle of different processes interacting through shared memory according to an embodiment of the present application. Figure 7 As shown, process A and process B each have their own logical address space, and the two processes can access the same shared memory in the physical memory. Process A can write data to the shared memory, and process B can read data from the shared memory. Similarly, process B can also write data to the shared memory, and process A can also read data from the shared memory.

[0119] Figure 8 FIG. 1 shows a flow chart of implementing read-write synchronization when different processes access shared memory according to an embodiment of the present application. Figure 8 As shown, the following steps may be included:

[0120] In step 810, the main process and the child process respectively obtain the semaphore recorded at the specified position from the shared memory corresponding to the shared memory object as the target semaphore, wherein the specified position is located in the shared memory corresponding to the predetermined offset.

[0121] Please continue to see Figure 7 , shared memory can be Figure 7 The entire physical memory is shown. The physical memory is divided into 8 blocks, each of which can correspond to one data stream. Figure 7 In the embodiment, a block of shared memory identified by text may include a portion corresponding to a predetermined offset and a portion corresponding to the data, and the designated position may be located at the portion corresponding to the predetermined offset.

[0122] In step 820 , the main process and the child process determine whether to access the shared memory corresponding to the shared memory object according to the target semaphore.

[0123] Specifically, the main process and child process first set polling times based on their respective tasks. For example, the main process writes data every 33ms, while the child process reads data every 20ms. If one process fails to complete reading or writing, the other process abandons the read or write task.

[0124] When the main process begins writing data to this MemoryFile, it first reads the value of the semaphore at this offset. If the semaphore's value is 0, it indicates that the data in the MemoryFile is empty, or the child process has already consumed the data in the MemoryFile. The MemoryFile is now writable, and the main process begins writing. When the main process finishes writing, it sets the value of this offset to 1, indicating that the data in the MemoryFile is now available for consumption. When the next main process frame data arrives and wants to write again, if the value of this offset is still 1, it indicates that the child process has not yet completed the reading and the write operation is abandoned.

[0125] The child process is similar. Each time it reads data, it first reads the value of the offset position. If the value is 1, it indicates that there is data available in the MemoryFile and the data is read. When the reading is completed, the value of the offset position is set to 0, indicating that the data can be written.

[0126] In the embodiment of the present application, the reading and writing synchronization of shared memory between processes is achieved efficiently and accurately, ensuring the orderly reading and writing of data in the shared memory.

[0127] In summary, according to the interaction method within the application provided by the embodiment of the present application, after embedding the animation engine in the native application, a main process and a child process are created respectively, wherein the main process is created based on the native application, and the child process is created based on the animation engine and the native program docking module in the native application. On this basis, on the one hand, the interface definition language object of the other process is provided to the main process and the child process respectively, so that the main process and the child process can interact based on the interface definition language object. On the other hand, the native program docking module can call the interface provided by the animation engine, and the animation engine can call the method in the native program docking module, thus realizing the interaction between the animation engine and the native program docking module. Therefore, the entire scheme uses the native application as the main project, embeds the animation engine in the native application, and realizes the complete interaction between the native application part and the animation engine in the application based on multiple processes, which can make the interaction within the application containing the animation engine more stable. In addition, the shared memory mechanism is used to optimize the memory consumption under the multi-process scheme and avoid the process being killed. At the same time, by determining whether the access operation to the shared memory is executed based on the semaphore, data read and write errors in the shared memory are avoided, ensuring that the reading and writing of the shared memory by different processes can be carried out efficiently and smoothly.

[0128] The following describes an embodiment of the device of the present application, which can be used to execute the interactive method within the application in the above-mentioned embodiment of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the interactive method within the application in the above-mentioned embodiment of the present application.

[0129] Figure 9 A block diagram of an interaction device within an application according to an embodiment of the present application is shown.

[0130] Reference Figure 9As shown, an intra-application interaction device 900 according to an embodiment of the present application includes: an embedding unit 910, a creation unit 920, a providing unit 930, a first interaction unit 940, and a second interaction unit 950. The embedding unit 910 is used to embed an animation engine in a native application, wherein the native application includes a native program docking module; the creation unit 920 is used to create a main process based on the native application, and the main process creates a sub-process based on the animation engine and the native program docking module; the providing unit 930 is used to provide the sub-process with a first interface definition language object of the main process and a second interface definition language object of the sub-process; the first interaction unit 940 is used to perform interaction between the main process and the sub-process based on the first interface definition language object and the second interface definition language object; the second interaction unit 950 is used to call a method in the native program docking module in the animation engine, and call an interface provided by the animation engine in the native program docking module, so as to perform interaction between the animation engine and the native program docking module in the sub-process.

[0131] In some embodiments of the present application, based on the aforementioned scheme, the embedding unit 910 is configured to: decompress the program package of the animation engine to obtain a decompression result; copy the decompression result to the project directory of the native application; modify the target properties in the configuration file corresponding to the animation engine to configure the animation engine as a separate process.

[0132] In some embodiments of the present application, based on the aforementioned solution, the embedding unit 910 is further configured to: delete the verification code in the animation engine.

[0133] In some embodiments of the present application, based on the aforementioned scheme, the providing unit 930 is configured as follows: when the active component in the sub-process is started, the service component in the main process is bound through the sub-process, and the first interface definition language object of the main process is obtained from the service component; the method of the first interface definition language object is called through the sub-process to pass the second interface definition language object of the sub-process to the main process.

[0134] In some embodiments of the present application, based on the aforementioned scheme, the first interaction unit 940 is further used to: create a data sending object in the main process, and create a corresponding shared memory object for the data sending object, wherein the shared memory object corresponds to the shared memory; obtain a file descriptor and data parsing protocol information corresponding to the shared memory object, wherein the data parsing protocol information includes block information of the shared memory and information related to the data stored in the shared memory; send the file descriptor and the data parsing protocol information to the child process, and the child process creates a data receiving object based on the received file descriptor and the data parsing protocol information; construct the shared memory object in the child process based on the file descriptor and the data parsing protocol information; and read data from the shared memory corresponding to the shared memory object through the data receiving object in the child process.

[0135] In some embodiments of the present application, based on the aforementioned solution, the first interaction unit 940 is configured to: create a new thread in the child process; and read data from the shared memory corresponding to the shared memory object in a polling manner through the new thread.

[0136] In some embodiments of the present application, based on the aforementioned scheme, the first interaction unit 940 is configured to: create a new shared memory file; construct a shared memory sub-object based on the file descriptor and the data parsing protocol information; create a buffer mapping object; assign values ​​to the shared memory file through a reflection mechanism and based on the buffer mapping object and the shared memory sub-object to obtain the shared memory object.

[0137] In some embodiments of the present application, based on the aforementioned solution, the size of the shared memory is the sum of the size of a frame of picture data and the length of a predetermined offset.

[0138] In some embodiments of the present application, based on the aforementioned scheme, the first interaction unit 940 is also used to: obtain the semaphore recorded at the specified position from the shared memory corresponding to the shared memory object through the main process and the child process respectively as the target semaphore, wherein the specified position is located in the shared memory corresponding to the predetermined offset; determine whether to access the shared memory corresponding to the shared memory object in the main process and the child process according to the target semaphore.

[0139] Figure 10 A schematic diagram of the structure of a computer system suitable for implementing an electronic device according to an embodiment of the present application is shown.

[0140] It should be noted that Figure 10 The computer system 1000 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0141] like Figure 10 As shown, the computer system 1000 includes a central processing unit (CPU) 1001, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1002 or the program loaded from the storage part 1008 into the random access memory (RAM) 1003, such as executing the method described in the above embodiment. Various programs and data required for system operation are also stored in the RAM 1003. The CPU 1001, ROM 1002 and RAM 1003 are connected to each other via a bus 1004. An input / output (I / O) interface 1005 is also connected to the bus 1004.

[0142] The following components are connected to the I / O interface 1005: an input section 1006 including a keyboard, a mouse, and the like; an output section 1007 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and a speaker; a storage section 1008 including a hard disk and the like; and a communication section 1009 including a network interface card such as a LAN (Local Area Network) card or a modem. The communication section 1009 performs communication processing via a network such as the Internet. A drive 1010 is also connected to the I / O interface 1005 as needed. Removable media 1011, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 1010 as needed, so that computer programs read therefrom can be installed into the storage section 1008 as needed.

[0143] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 1009, and / or installed from a removable medium 1011. When the computer program is executed by the central processing unit (CPU) 1001, the various functions defined in the system of the present application are executed.

[0144] It should be noted that the computer-readable medium shown in the embodiments of the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, which carries a computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wired, or any suitable combination thereof.

[0145] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. Among them, each box in the flowchart or block diagram can represent a module, program segment, or part of the code, and the above-mentioned module, program segment, or part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0146] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. In some cases, the names of these units do not constitute limitations on the units themselves.

[0147] As one aspect, the present application further provides a computer-readable medium, which may be included in the electronic device described in the above embodiments, or may exist independently without being incorporated into the electronic device. The computer-readable medium carries one or more programs, and when the one or more programs are executed by the electronic device, the electronic device implements the method described in the above embodiments.

[0148] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiment of the application, the features and functions of two or more modules or units described above can be concretized in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into multiple modules or units to be concretized.

[0149] Through the description of the above embodiments, it is easy for those skilled in the art to understand that the example embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solution according to the embodiments of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a touch terminal, or a network device, etc.) to execute the method according to the embodiments of the present application.

[0150] Those skilled in the art will readily conceive of other embodiments of the present application after considering the specification and practicing the embodiments disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present application that follow the general principles of this application and include common knowledge or customary techniques in the art that are not disclosed herein.

[0151] It should be understood that the present application is not limited to the exact structures described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. An interactive method within an application, characterized in that: The method comprises: Embedding an animation engine in a native application, wherein the native application includes a native program docking module; Creating a main process according to the native application, and having the main process create a sub-process according to the animation engine and the native program docking module; providing the first interface definition language object of the main process to the sub-process, and providing the second interface definition language object of the sub-process to the main process; Performing interaction between the main process and the sub-process based on the first interface definition language object and the second interface definition language object; The method in the native program docking module is called in the animation engine, and the interface provided by the animation engine is called in the native program docking module to perform interaction between the animation engine and the native program docking module in the sub-process.

2. The interactive method within an application according to claim 1, characterized in that: Embedding the animation engine in a native application includes: Decompress the animation engine package to obtain the decompression result; Copy the decompression result to the project directory of the native application; The target attribute in the configuration file corresponding to the animation engine is modified to configure the animation engine as a separate process.

3. The interactive method within an application according to claim 2, characterized in that: The method further comprises: Delete the verification code in the animation engine.

4. The interactive method within an application according to claim 1, characterized in that: The providing the first interface definition language object of the main process to the sub-process and providing the second interface definition language object of the sub-process to the main process includes: When the active component in the sub-process is started, the service component in the main process is bound through the sub-process, and the first interface definition language object of the main process is obtained from the service component; The method of the first interface definition language object is called by the sub-process to transfer the second interface definition language object of the sub-process to the main process.

5. The interactive method within an application according to claim 1, characterized in that: The method further comprises: Creating a data sending object in the main process, and creating a corresponding shared memory object for the data sending object, wherein the shared memory object corresponds to the shared memory; Obtaining a file descriptor and data parsing protocol information corresponding to the shared memory object, wherein the data parsing protocol information includes block information of the shared memory and information related to data stored in the shared memory; Sending the file descriptor and the data parsing protocol information to the child process, and having the child process create a data receiving object according to the received file descriptor and the data parsing protocol information; Constructing the shared memory object in the child process according to the file descriptor and the data parsing protocol information; In the child process, data is read from the shared memory corresponding to the shared memory object through the data receiving object.

6. The method for interaction within an application according to claim 5, characterized in that: The reading data from the shared memory corresponding to the shared memory object through the data receiving object in the child process includes: Creating a new thread in the child process; Data is read from the shared memory corresponding to the shared memory object in a polling manner through the new thread.

7. The interactive method within an application according to claim 5, characterized in that: The constructing the shared memory object in the child process according to the file descriptor and the data parsing protocol information includes: Create a new shared memory file; Constructing a shared memory sub-object according to the file descriptor and the data parsing protocol information; Create a buffer mapping object; The shared memory file is assigned a value based on the buffer mapping object and the shared memory sub-object through a reflection mechanism to obtain the shared memory object.

8. The interactive method within an application according to claim 5, characterized in that: The size of the shared memory is the sum of the size of one frame of picture data and the length of a predetermined offset.

9. The interactive method within an application according to claim 8, characterized in that: The method further comprises: Retrieving, by the main process and the child process, a semaphore recorded at a specified position from the shared memory corresponding to the shared memory object as a target semaphore, wherein the specified position is located in the shared memory corresponding to the predetermined offset; In the main process and the sub-process, it is determined whether to access the shared memory corresponding to the shared memory object according to the target semaphore.

10. An interactive device within an application, characterized in that: The device comprises: An embedding unit, configured to embed the animation engine in a native application, wherein the native application includes a native program docking module; A creation unit, configured to create a main process according to the native application, and to have the main process create a sub-process according to the animation engine and the native program docking module; a providing unit, configured to provide the first interface definition language object of the main process to the sub-process, and provide the second interface definition language object of the sub-process to the main process; a first interaction unit, configured to perform interaction between the main process and the sub-process based on the first interface definition language object and the second interface definition language object; The second interaction unit is used to call the method in the native program docking module in the animation engine, and call the interface provided by the animation engine in the native program docking module to perform interaction between the animation engine and the native program docking module in the sub-process.

Citation Information

Patent Citations

  • Resource loading method and device

    CN108572965A

  • Animation playing method based on iOS system, electronic equipment and medium

    CN112070868A