CN106547631B - Cross-process communication method and device based on android platform - Google Patents

Cross-process communication method and device based on android platform Download PDF

Info

Publication number
CN106547631B
CN106547631B CN201610852726.7A CN201610852726A CN106547631B CN 106547631 B CN106547631 B CN 106547631B CN 201610852726 A CN201610852726 A CN 201610852726A CN 106547631 B CN106547631 B CN 106547631B
Authority
CN
China
Prior art keywords
cross
calling
data
target native
unified
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201610852726.7A
Other languages
Chinese (zh)
Other versions
CN106547631A (en
Inventor
莫富文
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201610852726.7A priority Critical patent/CN106547631B/en
Publication of CN106547631A publication Critical patent/CN106547631A/en
Application granted granted Critical
Publication of CN106547631B publication Critical patent/CN106547631B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/545Interprogram communication where tasks reside in different layers, e.g. user- and kernel-space

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mobile Radio Communication Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention relates to a cross-process communication method and a device based on an android platform, wherein the method can be applied to terminals, the terminals can comprise a vehicle-mounted terminal, a handheld terminal and the like, and the method comprises the following steps: a first uniform method in a first uniform access layer of a first process responds to a calling instruction sent by a service layer to any one native cross-process method, generates a cross-process calling request and sends the cross-process calling request to a second process corresponding to a target native cross-process method requested to be called; a second uniform method in a second uniform access layer of the second process acquires the identification and the access parameter of the target native cross-process method according to the request; the second unifying method determines a corresponding target native cross-process method from the second process according to the identification and the access participation of the target native cross-process method, acquires corresponding calling data according to the target native cross-process method, and returns the calling data to the first unifying method; and the first unified method returns the call data to the service layer, and performs processing operation related to the call data according to the first unified method. The expandability and the expansion efficiency of the cross-process method are improved.

Description

Cross-process communication method and device based on android platform
Technical Field
The invention relates to the technical field of computers, in particular to a cross-process communication method and device based on an android platform.
Background
For the android system, when multiple processes exist in one application, the memory data among the processes are not intercommunicated due to the limitation of an operating system. When processes need to access each other's data, cross-process data calls need to be made by means of cross-process communication, for example, by calling a cross-process method.
However, when defining a cross-process method, Android native needs to declare a function in an aid l (Android Interface definition language, which is an Interface description language) file, and then generates a corresponding code by using a compiler to declare the function in the aid l file according to a fixed template, where the function is a code that can perform inter-process communication (IPC) between two processes on an Android device. Therefore, because the native template of the android system is fixed, if one wants to uniformly modify all the cross-process methods defined by the native android (for example, uniformly adding a new cache function or uniformly adding a new call speed measurement function), the specific implementation logic of each cross-process method needs to be modified one by one, and obviously, the conventional cross-process method is not easy to expand.
Disclosure of Invention
In view of the above, there is a need to provide an android platform-based cross-process communication method and apparatus capable of facilitating extension.
A cross-process communication method based on an android platform comprises the following steps:
a first uniform method in a first uniform access layer of a first process responds to a calling instruction sent by a service layer to any one native cross-process method, generates a cross-process calling request, and sends the cross-process calling request to a second process corresponding to a target native cross-process method requested to be called;
a second uniform method in a second uniform access layer of the second process acquires the identifier of the target native cross-process method and the access parameter of the target native cross-process method according to the cross-process calling request;
the second unified method determines a corresponding target native cross-process method from the second process according to the identification of the target native cross-process method and the participation of the target native cross-process method, acquires corresponding calling data according to the determined target native cross-process method, and returns the calling data to the first unified method;
and the first unified method returns the call data to the service layer, and carries out processing operation related to the call data according to the first unified method.
An android platform-based cross-process communication device, the device comprising:
the cross-process calling request module is used for responding to a calling instruction of any one native cross-process method sent by a service layer through a first uniform method in a first uniform access layer of a first process, generating a cross-process calling request and sending the cross-process calling request to a second process corresponding to a target native cross-process method requested to be called;
a native method data obtaining module, configured to obtain, according to the cross-process call request, an identifier of the target native cross-process method and an entry parameter of the target native cross-process method by using a second unified method in a second unified access layer of the second process;
a calling data obtaining module, configured to determine, by the second unified method, the corresponding target native cross-process method from the second process according to the identifier of the target native cross-process method and the entry parameter of the target native cross-process method, obtain corresponding calling data according to the determined target native cross-process method, and return the calling data to the first unified method;
and the unified method processing module is used for returning the calling data to the service layer through the first unified method and carrying out processing operation related to the calling data according to the first unified method.
According to the cross-process communication method and device based on the android platform, a first uniform method in a first uniform access layer of a first process responds to a calling instruction sent by a service layer for any one native cross-process method, a cross-process calling request is generated, and the cross-process calling request is sent to a second process corresponding to a target native cross-process method requested to be called; a second uniform method in a second uniform access layer of a second process acquires the identification of the target native cross-process method and the access parameter of the target native cross-process method according to the cross-process calling request; the second unifying method determines a corresponding target native cross-process method from the second process according to the identification of the target native cross-process method and the access parameter of the target native cross-process method, acquires corresponding calling data according to the determined target native cross-process method, and returns the calling data to the first unifying method; the first unified method returns the call data to the business layer, and processing operations related to the call data are performed according to the first unified method. Namely, a unified access layer is added in the process, a unified method is set in the unified access layer, and the unified method can be used for carrying out other corresponding processing on the calling data while the calling of the native cross-process method is completed through the unified method. And each cross-process method does not need to be modified one by one to add new methods and functions, so that the expandability of the cross-process method is improved, and the expansion efficiency is improved.
Drawings
Fig. 1 is a schematic diagram of an internal structure of a terminal in one embodiment;
FIG. 2 is a flowchart illustrating a cross-process communication method based on an android platform in an embodiment;
FIG. 3 is an architecture diagram of inter-process communication, in one embodiment;
FIG. 4 is a flowchart illustrating a cross-process call request method according to an embodiment;
FIG. 5 is a flow diagram illustrating a method for cache detection in one embodiment;
FIG. 6 is a flowchart illustrating a method for invoking a data state snoop in one embodiment;
FIG. 7 is a schematic structural diagram of an android platform-based cross-process communication device in an embodiment;
FIG. 8 is a diagram illustrating the structure of a cross-process call request module in one embodiment;
FIG. 9 is a schematic structural diagram of a cross-process communication device based on an android platform in another embodiment;
fig. 10 is a schematic structural diagram of a cross-process communication device based on an android platform in another embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
In one embodiment, a terminal is provided, the internal structure of which is shown in fig. 1, and which includes a processor, an internal memory, a non-volatile storage medium, a network interface, a display screen, and an input device, which are connected through a system bus. The non-volatile storage medium of the terminal stores an operating system and further comprises a cross-process communication device based on an android platform, and the cross-process communication device based on the android platform is used for realizing a cross-process communication method based on the android platform. The processor is used for providing calculation and control capability and supporting the operation of the whole terminal. An internal memory in the terminal provides an environment for the operation of the android platform based cross-process communication device in the nonvolatile storage medium, and computer readable instructions are stored in the internal memory and can be executed by a processor, so that the processor can execute a cross-process communication method based on the android platform. The network interface is used for connecting to a network for communication. The display screen of the terminal can be a liquid crystal display screen or an electronic ink display screen, and the input device can be a touch layer covered on the display screen, a key, a track ball or a touch pad arranged on the shell of the electronic equipment, or an external keyboard, a touch pad or a mouse. The terminal can be a mobile phone, a tablet computer, a notebook computer, a desktop computer and the like. Those skilled in the art will appreciate that the configuration shown in fig. 1 is a block diagram of only a portion of the configuration relevant to the present application, and does not constitute a limitation on the terminal to which the present application is applied, and that a particular terminal may include more or less components than those shown in the drawings, or may combine certain components, or have a different arrangement of components.
As shown in fig. 2, a cross-process communication method based on the android platform is provided, which is now exemplified by applying the method to the terminal in fig. 1. The method specifically comprises the following steps:
step 202, a first uniform method in a first uniform access layer of a first process responds to a call instruction sent by a service layer to any one native cross-process method, generates a cross-process call request, and sends the cross-process call request to a second process corresponding to a target native cross-process method requested to be called.
It is understood that a method refers to a function encapsulated inside a class, which emphasizes that the object of this class encapsulates some variables and functions and provides services to the outside.
A cross-process method refers to a method declared in one process, and calling the method can directly/indirectly call a method of another process, so that memory data in another process can be accessed.
It will be appreciated that a cross-process method in one process is equivalent to a proxy for a corresponding cross-process method in another process. When a cross-process method in one process is called, it is actually one method in another process that is the same as the cross-process method. For example, there are cross-process method 1 and method 2 in process a, and cross-process method 1 and method 2 in process B, and when process a calls its own method 1, it will actually call corresponding method 1 in process B, i.e. cross-process method 1 in process a is equivalent to the proxy of method 1 in process B.
Further, in this embodiment, the cross-process method includes a native cross-process method and a unified method.
A native cross-process method refers to declaring a function in an AIDL (Android Interface definition language, which is an Interface description language) file according to a native definition of an Android, and is used for generating a code capable of performing inter-process communication (IPC) between two processes on an Android device, and then generating a corresponding code by declaring the function in the AIDL file according to a fixed template through a compiler. I.e. the method defined by android native, needs to be described by aid dl language and further compiled to generate.
In this embodiment, a unified access layer is added in the process, and a unified method is set in the unified access layer. The unified method is a function code directly defined by a JAVA language, and when a business layer calls any one of the native cross-process methods, the unified method is triggered to be called. That is, the processing and functions implemented in the unified method are applicable to any one of the native cross-process methods when it is called. Furthermore, the unified method can have the functions of calling speed measurement, caching calling data and the like. Obviously, compared with the complex and tedious steps of generating JAVA codes by an AIDL file declaration function and then compiling the JAVA codes according to a fixed template through a compiler, the definition and the extension of the uniform method greatly improve the efficiency of the extension of the cross-process method.
It should be noted that the newly added unified access layer and the unified method are transparent to the service layer of the upper layer. When a first process in a terminal needs to acquire memory data in a second process, a service layer of the first process always sends a calling instruction to a native cross-process method, and for subsequent cross-process communication processing performed in a unified method, the service layer is transparent and agnostic, and the service layer is used for directly realizing subsequent operations by calling the native cross-process method.
FIG. 3 is a block diagram illustrating the architecture of interprocess communication in one embodiment. When the service layer request in the first process a calls the native cross-process method f1, a cross-process call request is sent to the second process B by calling the first unified method fa in the first unified access layer 310A through Binder cross-process transmission. The second unified method B in the second unified access layer 310B of the second process B allocates the cross-process call request to the corresponding target native cross-process method f 1. After obtaining the call data, the second process B returns the call data to the first unified method fa in the first unified access layer 310A of the first process a by the second unified method fb in the second unified access layer 310B. The first unified method fa or the second unified method fb may have functions of invoking a speed measurement, caching invoking data, and the like.
In this embodiment, when the service layer of the first process issues a call instruction to any one of the native cross-process methods, the first unification method in the first unification access layer of the first process generates a cross-process call request in response to the call instruction.
Further, the first uniform method sends the generated cross-process call request to a second process corresponding to the target native cross-process method requested to be called.
It will be appreciated that in conjunction with the foregoing, when a process invokes its native cross-process method, it will actually invoke that cross-process method in another process. The second process corresponding to the invoked target native cross-process method contains the same one as the target native cross-process method.
In one embodiment, the first unified method may be to generate a cross-process call request based on the identification of the target native cross-process method and the participation of the target native cross-process method.
In another embodiment, the first unified method may also write the identifier of the target native cross-process method and the entry parameter of the target native cross-process method into a file of the disk, and generate the cross-process call request according to a storage path of the file.
In yet another embodiment, the first unified method may further generate a first cross-process call request according to the identifier of the target native cross-process method and the entry parameter of the target native cross-process method, send the first cross-process call request, write the identifier of the target native cross-process method and the entry parameter of the target native cross-process method into a file of a disk when the data amount is greater than a preset threshold or the sending fails, and generate a second cross-process call request according to a storage path of the file.
And step 204, a second unified method in a second unified access layer of the second process acquires the identifier of the target native cross-process method and the access parameter of the target native cross-process method according to the cross-process call request.
In this embodiment, after receiving the cross-process call request, the second unified method in the second unified access layer of the second process obtains the identifier of the target native cross-process method requested to be called and the entry parameter of the target native cross-process method according to the cross-process call request.
The identifier of the target native cross-process method may be a name of the method, or may be another identifier that uniquely identifies the method. The parameters of the target native cross-process method include the number and type of functions and the like. It is understood that identification according to the method and inclusion of the method are used to uniquely identify a method.
Specifically, the second unified method may obtain an identifier of the target native cross-process method and an entry of the target native cross-process method, which are included in the cross-process call request. Or, the second uniform method may obtain a storage path of a file included in the cross-process call request, find the corresponding file according to the storage path, and obtain the identifier of the written target native cross-process method and the entry parameter of the target native cross-process method from the file.
The embodiment of the invention does not limit how the second uniform method obtains the identification of the target native cross-process method and the entry parameter of the target native cross-process method according to the cross-process calling request.
And step 206, the second unified method determines a corresponding target native cross-process method from the second process according to the identifier of the target native cross-process method and the access parameter of the target native cross-process method, acquires corresponding calling data according to the determined target native cross-process method, and returns the calling data to the first unified method.
In this embodiment, the second unified method determines the corresponding target native cross-process method from the second process according to the obtained identifier of the target native cross-process method and the parameter of the target native cross-process method. Namely, the actually called target native cross-process method is determined from the second process according to the reflection mechanism.
It will be appreciated that in conjunction with the foregoing discussion, a first process, when invoking its own target native cross-process method, will actually invoke that target native cross-process method in a second process.
And further, acquiring corresponding calling data according to the determined target native cross-process method, and returning the calling data to the first uniform method.
And step 208, returning the calling data to the service layer by the first uniform method, and carrying out processing operation related to the calling data according to the first uniform method.
In this embodiment, the first unified method returns the call data returned by the second unified method to the service layer. And further, processing operations related to the call data are performed according to a first uniform method.
The processing operations related to the call data include processing the call data itself and processing operations associated with the call data.
Further, the call data may be cached in the first unified access stratum according to a first unified approach. It is also possible to calculate the length of time taken to acquire the call data according to the first uniform method. Other processing operations related to invoking data may also be performed. The embodiment of the present invention is not limited thereto.
It should be noted that the first process is used to represent a requesting process that initiates a cross-process call, and the second process is used to represent a responding process that responds to the cross-process call.
The above steps will now be described by way of example. For example, the process a is responsible for displaying the name of a song currently being played on the terminal interface, the process B is responsible for playing the song, the process a and the process B each have a unified access layer, and the unified access layers are provided with unified methods, namely a unified method a and a unified method B. The process A needs to cross-process call the name of the song being played in the process B, then the process A calls a native cross-process method getSongName () of the process A, a unified method a in a unified access layer of the process A generates a cross-process call request and sends the cross-process call request to the process B, a unified method B in the process B obtains the name and the access parameter of the native cross-process method actually requested to be called by the unified method a according to the cross-process call request, and then the native cross-process method getSongName () actually requested to be called by the unified method a is determined according to the name and the access parameter. The process B obtains the song name currently being played according to getSongName (), and then returns the played song name to the unified method a by the unified method B. And the uniform method a returns the song name to the service layer for displaying the song name. In addition, the processing operation related to the song title, such as caching the song title in the unified access layer of the process a, or calculating the time taken to call the song title this time, etc., may be performed according to the unified method a.
In this embodiment, equivalently, a unified access layer is added in the process, and a unified method is set in the unified access layer, so that the unified method can be used to perform other processing operations related to the call data while completing the call of the native cross-process method. And the native cross-process methods do not need to be modified one by one to add new methods and functions, so that the expandability of the cross-process method is improved.
As shown in fig. 4, in an embodiment, the step of generating a cross-process call request and sending the cross-process call request to a second process corresponding to the target native cross-process method requested to be called (referred to as a cross-process call request step) includes the following steps:
step 402, a first cross-process call request is generated according to the identification of the target native cross-process method requested to be called and the participation of the target native cross-process method.
Step 404, when the data volume of the first cross-process call request is greater than a preset data volume threshold or when an abnormal error with an excessively large transmission data volume is triggered to be generated in the process of sending the first cross-process call request, the first uniform method writes the identifier of the target native cross-process method and the entry parameter of the target native cross-process method in the first cross-process call request into a file located in a disk.
In this embodiment, the first unification method generates the first cross-process invocation request according to the identification of the target native cross-process method requested to be invoked and the entry parameter of the target native cross-process method.
In one embodiment, a data volume threshold is preset. The generated data volume of the first cross-process call request may be compared with a preset data volume threshold, and when the data volume of the first cross-process call request is greater than the preset data volume threshold, the first unification method may write the identifier of the target native cross-process method and the entry parameter of the target native cross-process method in the first cross-process call request into a file located in a disk.
Further, when the data volume of the first cross-process calling request is smaller than or equal to a preset data volume threshold, the first cross-process calling operation request is directly sent to the second process through a Binder cross-process transmission mode.
In another embodiment, the generated first cross-process call request may be sent to the second process through a Binder cross-process transmission mode (which is a mode for implementing cross-process transmission in an android system), and when an Exception error (TTLE, transaction to Large Exception, an Exception error thrown when a communication error is caused by an excessive data amount in a Binder cross-process transmission process) is triggered and generated in the sending process, the first unified method may write an identifier of the target native cross-process method in the first cross-process call request and an entry parameter of the target native cross-process method into a file located in a disk.
And 406, the first uniform method generates a second cross-process calling request according to the storage path of the file, and sends the second cross-process calling request to a second process corresponding to the target native cross-process method.
Further, the first uniform method generates a second cross-process calling request according to the storage path of the file, and sends the second cross-process calling request to a second process corresponding to the target native cross-process method.
In this embodiment, the step of acquiring, by the second unified method in the second unified access layer of the second process, the identifier of the target native cross-process method and the entry parameter of the target native cross-process method according to the cross-process call request includes: and searching a corresponding file according to the storage path of the file by a second unified method in a second unified access layer of the second process, and reading the written identifier of the target native cross-process method and the parameter of the target native cross-process method from the file.
Specifically, when receiving the second cross-process call request, the second unified method in the second unified access layer in the second process obtains a storage path of a file included in the second cross-process call request, and searches for a corresponding file according to the storage path of the file. Further, the written identifier of the target native cross-process method and the entry parameter of the target native cross-process method are read from the searched file.
In the embodiment, when the cross-process calling request is sent by the unified method, for the first cross-process calling request with the overlarge data volume, the key data used for determining the cross-process method is written into the file, and the file path is transmitted to the second process corresponding to the target native cross-process method, so that the cross-process communication failure caused by the overlarge data volume is avoided. The success rate of cross-process communication is improved.
In an embodiment, before the step of generating the cross-process call request, the method further includes detecting whether call data corresponding to a target native cross-process method requested to be called is cached in the first uniform access layer, if so, directly acquiring the cached call data as the call data corresponding to the target native cross-process method, and if not, performing the step of generating the cross-process call request.
In this embodiment, the call data corresponding to the called native cross-process method may be cached in the first uniform access layer. Then, before generating the cross-process call request, the first unification method may detect whether call data corresponding to the target native cross-process method requested to be called is cached in the first unification access layer.
When the calling data corresponding to the target native cross-process method is cached in the first uniform access layer, the cached calling data is directly obtained to serve as the calling data corresponding to the called target native cross-process method.
And when the calling data corresponding to the target native cross-process method is not cached in the first uniform access layer, executing the step of generating the cross-process calling request.
With reference to the above example, before generating the cross-process call request, the unified method a in the process a detects whether a song name is cached in the unified access layer in the process a, and if so, obtains the cached song name as the song name corresponding to the getsong name () method called this time. If not, generating a cross-process calling request.
In this embodiment, the call data may be cached, before the cross-process call request is generated, it may be detected whether call data that needs to be obtained is cached, if so, the cached call data is directly obtained, and if not, the cross-process call request is generated. The number of times of cross-process calling can be reduced through the cache of calling data and the detection of the cache, so that resources are saved, and the efficiency of calling data acquisition is improved.
As shown in fig. 5, in an embodiment, before the step of generating the cross-process invocation request, a cache detection step is further included, which specifically includes the following steps:
step 502, it is detected whether the first uniform access layer caches call data corresponding to the target native cross-process method requested to be called. If yes, go to step 504, otherwise, go to step 506.
Step 504, detecting whether the cached calling data is expired. If yes, go to step 506, otherwise go to step 508.
At step 506, a cross-process call request is generated.
Step 508, obtain the cached call data as the call data corresponding to the target native cross-process method.
In this embodiment, the call data corresponding to the called native cross-process method may be cached in the first uniform access layer. Then, before generating the cross-process call request, the first unification method may detect whether call data corresponding to the target native cross-process method requested to be called is cached in the first unification access layer.
When the calling data corresponding to the target native cross-process method is cached in the first uniform access layer, whether the cached calling data is expired is further detected. And when the calling data corresponding to the target native cross-process method is not cached in the first uniform access layer, executing the step of generating the cross-process calling request.
In particular, whether the cached call data has expired may be detected by detecting a flag state of the call data.
And when the cached calling data is expired, executing the step of generating the cross-process calling request. And when the cached calling data is not expired, acquiring the cached calling data as calling data corresponding to the target native cross-process method.
Similarly, with reference to the above example, before generating the cross-process call request, the unified method a in the process a detects whether a song name is cached in the unified access layer in the process a, if so, further detects whether the cached song name is expired, and if not, generates the cross-process call request. And when the cached song name is not expired, acquiring the cached song name as the song name corresponding to the method for calling the getSongName (). When the cached song name has expired, a cross-process call request is generated.
In this embodiment, the call data may be cached, before the cross-process call request is generated, it may be detected whether call data that needs to be acquired is cached, if so, it is further detected whether the cached call data is expired, if not, the cached call data is directly acquired, and if so, the cross-process call request is generated. The number of times of cross-process calling can be reduced through the cache of calling data and the detection of the cache, so that resources are saved, and the efficiency of calling data acquisition is improved. In addition, whether the cached calling data is overdue or not is judged, and the accuracy of the calling result is further improved.
As shown in fig. 6, in an embodiment, the method further includes a step of invoking data state monitoring, which specifically includes the following steps:
step 602, the second unified method monitors the update status of the call data returned to the first process in the second process.
In step 604, when the call data is updated, the second process sends an update notification to the first process.
In this embodiment, after the second process returns the call data to the first process, the second process monitors the update state of the returned call data in the memory of the second process by using the second method.
When monitoring that the calling data is updated, the second process sends an update notification to the first process. Specifically, the first unified method of updating the notification to the first process may be sent by the second unified method.
Step 606, the first uniform method of the first process marks the corresponding call data cached in the first uniform access layer as expired state according to the update notification.
After receiving the update notification, the first unified method of the first process marks the corresponding call data cached in the first unified access layer as an expired state according to the update notification.
Further, when detecting that the call data is in an expired state, the first process does not obtain the call data from the cache, but regenerates the cross-process call request to obtain the latest call data. Therefore, the accuracy of the obtained calling result is improved.
The description is continued with reference to the above example. For example, if the song name returned to process a is SN1, process B will monitor the update status of the song name SN1 in process B through the unified method B, and when another song is played in process B, the song name will be updated to another song name SN2 by SN1, that is, the song name SN1 returned to process a is updated. At this point, process B sends an update notification to process A. The process a marks the song name SN1 cached at the unified access layer of the process a as expired according to the update notification by the unified method a.
In one embodiment, when the call data is updated, the step of sending an update notification to the first process by the second process includes: and when the call data is updated, the second process detects whether the call data is in an activated state, when the call data is in the activated state, the second process sends an update notification to the first process, and when the call data is in an inactivated state, the second process does not send the update notification to the first process.
In this embodiment, when it is monitored that the call data returned to the first process in the second process is updated, the second process detects whether the call data in its memory is in an activated state. If so, an update notification is generated to the first process. If not, no update notification is sent to the first process.
Whether the calling data is in the activated state refers to whether the first process cares about the state change of the calling data, and when the first process cares about the state change of the calling data, the calling data in the second process is in the activated state. For example, when a first process acquires call data in a second process by calling a target native cross-process method, it means that the first process cares about the state of the call data.
When the first process does not care about the state change of the call data, the call data in the second process is in an inactive state. For example, when the second process receives a notification from the first process that does not care about the state of the call data, the second process may mark the call data as inactive.
In this embodiment, before sending the update notification to the first process, the second process detects the activation state of the call data, and sends the update notification to the first process only when the call data is in the activation state, instead of sending the update notification every time of update, which avoids sending unnecessary notifications and saves communication resources.
As shown in fig. 7, in one embodiment, an android platform based cross-process communication apparatus is provided, which includes a cross-process call request module 702, a native method data obtaining module 704, a call data obtaining module 706, and a unified method processing module 708, where:
the cross-process call request module 702 is configured to generate a cross-process call request in response to a call instruction for any one native cross-process method, which is issued by the service layer, through a first unification method in a first unification access layer of the first process, and send the cross-process call request to a second process corresponding to a target native cross-process method requested to be called.
A native method data obtaining module 704, configured to obtain, according to the cross-process call request, an identifier of the target native cross-process method and an entry parameter of the target native cross-process method by using a second unified method in a second unified access layer of the second process.
The calling data obtaining module 706 is configured to determine a corresponding target native cross-process method from the second process according to the identifier of the target native cross-process method and the entry parameter of the target native cross-process method by using the second unified method, obtain corresponding calling data according to the determined target native cross-process method, and return the calling data to the first unified method.
The unified method processing module 708 is configured to return the call data to the service layer through the first unified method, and perform a processing operation related to the call data according to the first unified method.
In one embodiment, the unified method processing module 708 is further configured to cache the call data into the first unified access stratum according to the first unified method.
As shown in FIG. 8, in one embodiment, the cross-process call request module 702 includes:
the cross-process call request generating module 702a is configured to generate a first cross-process call request according to the identifier of the target native cross-process method requested to be called and the entry parameter of the target native cross-process method.
The file writing module 702b is configured to, when the data amount of the first cross-process call request is greater than a preset data amount threshold or when an abnormal error with an excessively large transmission data amount is triggered to be generated in a process of sending the first cross-process call request, write, by the first unified method, the identifier of the target native cross-process method and the entry parameter of the target native cross-process method in the first cross-process call request into a file located in the disk.
The cross-process call request generating module 702a is further configured to generate a second cross-process call request according to the storage path of the file by using the first unified method, and send the second cross-process call request to a second process corresponding to the target native cross-process method.
In this embodiment, the native method data obtaining module 704 is further configured to search for a corresponding file according to a storage path of the file by using a second unified method in a second unified access layer of the second process, and read the written identifier of the target native cross-process method and the entry parameter of the target native cross-process method from the file.
In one embodiment, the native method data obtaining module 704 is further configured to obtain, by a second unified method in a second unified access layer of a second process, an identification of the target native cross-process method and an entry of the target native cross-process method included in the cross-process invocation request.
As shown in fig. 9, in one embodiment, the apparatus further comprises:
a detecting module 701, configured to detect whether call data corresponding to a target native cross-process method requested to be called is cached in a first uniform access layer; when the calling data are cached in the first uniform access layer, detecting whether the cached calling data are expired; when the cached invocation data has expired, the cross-process invocation request module 702 is notified to perform the step of generating the cross-process invocation request.
In one embodiment, the detecting module 701 is further configured to, when the cached call data is not expired, obtain the cached call data as call data corresponding to the target native cross-process method.
As shown in fig. 10, in one embodiment, the apparatus further comprises:
a notification module 710, configured to monitor an update state of call data returned to the first process in the second process through a second unified method; and when the calling data is updated, sending an update notification to the first process through the second process.
A marking module 712, configured to mark, according to the update notification sent by the notification module, the corresponding call data cached in the first unified access stratum as an expired state by using the first unification method of the first process.
In one embodiment, the notification module 710 is further configured to detect whether the call data is in an active state through the second process when the call data is updated; and when the calling data is in the activated state, sending an update notification to the first process through the second process, and when the calling data is in the inactivated state, not sending the update notification to the first process.
In an embodiment, the cross-process call request generating module 702a is further configured to send the first cross-process call operation request to the second process directly in a Binder cross-process transmission manner when the data amount of the first cross-process call request is less than or equal to a preset data amount threshold.
It should be noted that the first and second embodiments of the present invention are used for distinguishing purposes only, and are not limited to the order or the like.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a computer-readable storage medium, and can include the processes of the embodiments of the methods described above when the computer program is executed. The storage medium may be a non-volatile storage medium such as a magnetic disk, an optical disk, a Read-Only Memory (ROM), or a Random Access Memory (RAM).
The technical features of the embodiments described above may be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the embodiments described above are not described, but should be considered as being within the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present invention, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the inventive concept, which falls within the scope of the present invention. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (20)

1. A cross-process communication method based on an android platform comprises the following steps:
a first uniform method in a first uniform access layer of a first process responds to a calling instruction sent by a service layer to any one native cross-process method to generate a cross-process calling request, and the cross-process calling request is sent to a second process corresponding to a target native cross-process method requested to be called through a Binder cross-process transmission mode; the first unified access layer is a layer which is newly added in a process and is used for setting the first unified method; the first uniform method is triggered and called when the business layer calls any one of the native cross-process methods to generate the cross-process calling request;
the second uniform method in the second uniform access layer of the second process acquires the identifier of the target native cross-process method and the access parameter of the target native cross-process method according to the cross-process call request, and the method comprises the following steps: the second uniform method obtains an identifier of a target native cross-process method and an entry parameter of the target native cross-process method, which are contained in the cross-process calling request, or obtains a storage path of a file contained in the cross-process calling request, finds a corresponding file according to the storage path, and obtains the written identifier of the target native cross-process method and the entry parameter of the target native cross-process method from the file;
the second unified method determines a corresponding target native cross-process method from the second process according to the identification of the target native cross-process method and the participation of the target native cross-process method, acquires corresponding calling data according to the determined target native cross-process method, and returns the calling data to the first unified method;
the first unified method returns the call data to the service layer, and performs processing operations related to the call data according to the first unified method, including: and caching the calling data into the first unified access layer according to the first unified method.
2. The method of claim 1, wherein the parameters of the target native cross-process method include the number and type of functions.
3. The method of claim 1, wherein the step of generating a cross-process call request and sending the cross-process call request to a second process corresponding to the target native cross-process method requested to be invoked comprises:
generating a first cross-process calling request according to the identification of the target native cross-process method requested to be called and the access parameter of the target native cross-process method;
when the data volume of the first cross-process calling request is larger than a preset data volume threshold value or when an abnormal error with overlarge transmission data volume is triggered to be generated in the process of sending the first cross-process calling request, the first uniform method writes the identification of the target native cross-process method and the entry parameter of the target native cross-process method in the first cross-process calling request into a file located in a disk;
the first uniform method generates a second cross-process calling request according to the storage path of the file, and sends the second cross-process calling request to a second process corresponding to the target native cross-process method;
the step of obtaining the identifier of the target native cross-process method and the entry parameter of the target native cross-process method by a second uniform method in a second uniform access layer of the second process according to the cross-process call request includes:
and searching the corresponding file according to the storage path of the file by a second unified method in a second unified access layer of the second process, and reading the written identifier of the target native cross-process method and the access parameter of the target native cross-process method from the file.
4. The method of claim 1, wherein the step of the second unified method in the second unified access layer of the second process obtaining the identifier of the target native cross-process method and the reference of the target native cross-process method according to the cross-process call request comprises:
and a second unified method in a second unified access layer of the second process acquires the identifier of the target native cross-process method and the access parameter of the target native cross-process method, which are contained in the cross-process calling request.
5. The method of claim 1, wherein prior to the step of generating a cross-process call request, the method further comprises:
detecting whether calling data corresponding to the target native cross-process method requested to be called is cached in the first uniform access layer;
when the calling data is cached in the first uniform access layer, detecting whether the cached calling data is expired;
and when the cached calling data is expired, executing the step of generating the cross-process calling request.
6. The method of claim 5, further comprising:
and when the cached calling data is not expired, acquiring the cached calling data as calling data corresponding to the target native cross-process method.
7. The method of claim 2, further comprising:
the second unified method monitors the updating state of the calling data returned to the first process in the second process;
when the calling data is updated, the second process sends an update notification to the first process;
the first uniform method of the first process marks the corresponding call data cached in the first uniform access layer as an expired state according to the update notification.
8. The method according to claim 7, wherein the step of the second process sending an update notification to the first process when the call data is updated comprises:
when the calling data is updated, the second process detects whether the calling data is in an activated state;
and when the calling data is in an activated state, the second process sends an update notification to the first process, and when the calling data is in an inactivated state, the second process does not send the update notification to the first process.
9. The method of claim 3, further comprising:
and when the data volume of the first cross-process calling request is smaller than or equal to a preset data volume threshold value, directly sending the first cross-process calling operation request to the second process in a Binder cross-process transmission mode.
10. An android platform-based cross-process communication device, the device comprising:
the cross-process calling request module is used for responding to a calling instruction of any one native cross-process method sent by a service layer through a first uniform method in a first uniform access layer of a first process to generate a cross-process calling request, and sending the cross-process calling request to a second process corresponding to a target native cross-process method requested to be called through a Binder cross-process transmission mode; the first unified access layer is a layer which is newly added in a process and is used for setting the first unified method; the first uniform method is triggered and called when the business layer calls any one of the native cross-process methods to generate the cross-process calling request;
a native method data obtaining module, configured to obtain, by a second unified method in a second unified access layer of the second process, an identifier of a target native cross-process method and an entry parameter of the target native cross-process method that are included in the cross-process call request, or obtain a storage path of a file that is included in the cross-process call request, find a corresponding file according to the storage path, and obtain, from the file, the written identifier of the target native cross-process method and the entry parameter of the target native cross-process method;
a calling data obtaining module, configured to determine, by the second unified method, the corresponding target native cross-process method from the second process according to the identifier of the target native cross-process method and the entry parameter of the target native cross-process method, obtain corresponding calling data according to the determined target native cross-process method, and return the calling data to the first unified method;
and the unified method processing module is used for returning the calling data to the service layer through the first unified method and caching the calling data into the first unified access layer according to the first unified method.
11. The apparatus of claim 10, wherein the parameters of the target native cross-process method include a number and a type of functions.
12. The apparatus of claim 10, wherein the cross-process call request module comprises:
the cross-process calling request generating module is used for generating a first cross-process calling request according to the identification of the target native cross-process method requested to be called and the access parameter of the target native cross-process method;
a file writing module, configured to, when a data amount of the first cross-process call request is greater than a preset data amount threshold or when an abnormal error with an excessively large transmission data amount is triggered to be generated in a process of sending the first cross-process call request, write, by the first unification method, an identifier of the target native cross-process method and an entry parameter of the target native cross-process method in the first cross-process call request into a file located in a disk;
the cross-process calling request generating module is further configured to generate a second cross-process calling request according to the storage path of the file through the first uniform method, and send the second cross-process calling request to a second process corresponding to the target native cross-process method;
the native method data acquisition module is further configured to search the corresponding file according to the storage path of the file by using a second unified method in a second unified access layer of the second process, and read the written identifier of the target native cross-process method and the entry parameter of the target native cross-process method from the file.
13. The apparatus of claim 10, wherein the native method data obtaining module is further configured to obtain, through a second unified method in a second unified access layer of the second process, an identification of the target native cross-process method and an entry of the target native cross-process method included in the cross-process call request.
14. The apparatus of claim 10, further comprising:
the detection module is used for detecting whether calling data corresponding to the target native cross-process method requested to be called is cached in the first uniform access layer; when the calling data is cached in the first uniform access layer, detecting whether the cached calling data is expired; and when the cached calling data is expired, notifying the cross-process calling request module to execute the step of generating the cross-process calling request.
15. The apparatus of claim 14, wherein the detection module is further configured to obtain the cached call data as the call data corresponding to the target native cross-process method when the cached call data is not expired.
16. The apparatus of claim 11, further comprising:
the notification module is used for monitoring the updating state of the calling data returned to the first process in the second process through the second unified method; when the calling data is updated, sending an update notification to the first process through the second process;
and the marking module is used for marking the corresponding calling data cached in the first unified access layer into an expired state according to the updating notification sent by the notification module by the first unified method of the first process.
17. The apparatus according to claim 16, wherein the notifying module is further configured to detect whether the call data is in an active state by the second process when the call data is updated; and when the calling data is in an activated state, sending an update notification to the first process through the second process, and when the calling data is in an inactivated state, not sending the update notification to the first process.
18. The apparatus of claim 12, wherein the cross-process call request generating module is further configured to send the first cross-process call operation request to the second process directly through a Binder cross-process transmission manner when a data amount of the first cross-process call request is smaller than or equal to a preset data amount threshold.
19. A terminal comprising a memory and a processor, the memory storing a computer program, characterized in that the processor, when executing the computer program, implements the steps of the method of any of claims 1 to 9.
20. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the steps of the method according to any one of claims 1 to 9.
CN201610852726.7A 2016-09-26 2016-09-26 Cross-process communication method and device based on android platform Active CN106547631B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610852726.7A CN106547631B (en) 2016-09-26 2016-09-26 Cross-process communication method and device based on android platform

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610852726.7A CN106547631B (en) 2016-09-26 2016-09-26 Cross-process communication method and device based on android platform

Publications (2)

Publication Number Publication Date
CN106547631A CN106547631A (en) 2017-03-29
CN106547631B true CN106547631B (en) 2021-04-20

Family

ID=58368076

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610852726.7A Active CN106547631B (en) 2016-09-26 2016-09-26 Cross-process communication method and device based on android platform

Country Status (1)

Country Link
CN (1) CN106547631B (en)

Families Citing this family (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107479958A (en) * 2017-08-16 2017-12-15 郑州云海信息技术有限公司 A kind of process scheduling method and device based on multiple nucleus system
CN109426570A (en) * 2017-08-29 2019-03-05 阿里巴巴集团控股有限公司 A kind of acquisition methods of data, device and equipment
CN108021459B (en) * 2017-12-01 2022-03-04 麒麟合盛网络技术股份有限公司 Method and device for sending dotting logs across processes
CN108984317B (en) * 2018-06-21 2021-07-13 北京奇虎科技有限公司 Method and device for realizing IPC (inter-process communication)
CN109002381B (en) * 2018-06-29 2022-01-18 Oppo(重庆)智能科技有限公司 Process communication monitoring method, electronic device and computer readable storage medium
CN109117278B (en) * 2018-06-29 2021-02-26 Oppo(重庆)智能科技有限公司 Mobile terminal, limiting method for interprocess communication of mobile terminal and storage medium
CN109815033A (en) * 2019-01-24 2019-05-28 努比亚技术有限公司 A kind of striding course data sharing method
CN110532045A (en) * 2019-09-04 2019-12-03 深圳市迅雷网络技术有限公司 A kind of striding course call method and relevant apparatus
CN113934549A (en) * 2020-07-13 2022-01-14 北京国双科技有限公司 Data calling method and device and electronic equipment
CN116954936A (en) * 2022-04-14 2023-10-27 华为技术有限公司 Inter-process communication method and electronic equipment

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103645904A (en) * 2013-12-20 2014-03-19 北京京东尚科信息技术有限公司 Cache realization method of interface calling
CN103902390A (en) * 2014-03-12 2014-07-02 深圳创维-Rgb电子有限公司 Inter-process communication method based on Android application layer and basis application communication system
CN103970601A (en) * 2013-02-06 2014-08-06 北京壹人壹本信息科技有限公司 Operational order execution method and operational order execution device
CN104268025A (en) * 2014-09-30 2015-01-07 珠海市君天电子科技有限公司 Interprocess communication method and system, and server
CN105354081A (en) * 2015-11-26 2016-02-24 北京奇虎科技有限公司 Synchronous service binding method and apparatus

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102624765A (en) * 2011-01-28 2012-08-01 腾讯科技(深圳)有限公司 Shared service call system of intelligent terminal and method
US20150074684A1 (en) * 2013-09-11 2015-03-12 Cellrox, Ltd. Techniques for enabling inter-process communication (ipc) among multiple personas in a mobile technology platform

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103970601A (en) * 2013-02-06 2014-08-06 北京壹人壹本信息科技有限公司 Operational order execution method and operational order execution device
CN103645904A (en) * 2013-12-20 2014-03-19 北京京东尚科信息技术有限公司 Cache realization method of interface calling
CN103902390A (en) * 2014-03-12 2014-07-02 深圳创维-Rgb电子有限公司 Inter-process communication method based on Android application layer and basis application communication system
CN104268025A (en) * 2014-09-30 2015-01-07 珠海市君天电子科技有限公司 Interprocess communication method and system, and server
CN105354081A (en) * 2015-11-26 2016-02-24 北京奇虎科技有限公司 Synchronous service binding method and apparatus

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
Android Bander设计与实现;universus;《https://blog.csdn.net/universus/article/details/6211589》;20110227;第1-20页 *
Android Binder机制实现进程间数据交换(不使用aidl实现);Venscor;《https://blog.csdn.net/u010651541/article/details/46844327》;20150711;第1-13页 *
Android中不使用AIDL实现Service的远程调用;oathevil;《https://blog.csdn.net/oathevil/article/details/39180615》;20140910;第1-3页 *
universus.Android Bander设计与实现.《https://blog.csdn.net/universus/article/details/6211589》.2011, *

Also Published As

Publication number Publication date
CN106547631A (en) 2017-03-29

Similar Documents

Publication Publication Date Title
CN106547631B (en) Cross-process communication method and device based on android platform
US10324734B2 (en) Application containers
KR101790190B1 (en) Application scenario identification method, power consumption management method, apparatus, and terminal device
US9940478B2 (en) Fine-grained user control over usages of sensitive system resources having private data with applications in privacy enforcement
US11853820B2 (en) Cross-process communication method, apparatus, and device
US10956179B1 (en) Third party integration of plugins and widgets
US11042387B2 (en) Deploying cross-platform applications on mobile devices with native and web components
KR102023223B1 (en) Dynamic injection of code into running process
US10963267B2 (en) Bootstrapping profile-guided compilation and verification
CN111209122B (en) Interface calling method and device, electronic equipment and storage medium
US20180060048A1 (en) Hybrid Deoptimization Mechanism for Class Hierarchy Analysis
JP2015506020A (en) Method and computing node for processing sensor data
CN112930530B (en) Client application for network application execution
CN113535587B (en) Target application detection method and device and computer equipment
CN108268274B (en) Application management method and device, storage medium and electronic equipment
CN106775608B (en) Method and device for realizing independent system process
CN116719670B (en) Data processing method, electronic device and readable storage medium
CN109145598A (en) Method for detecting virus, device, terminal and the storage medium of script file
CN108021567B (en) Method and device for self-adaptively customizing fonts of browser
CN114510334A (en) Class instance calling method and device, electronic equipment and automatic driving vehicle
CN116662143A (en) Test method, apparatus, device, storage medium and computer program product
US20120174078A1 (en) Smart cache for a server test environment in an application development tool
CN108664253B (en) Application replacement method and device, storage medium and electronic equipment
CN111104623A (en) Webpage data caching method, device, server and storage medium
CN117724780B (en) Information acquisition method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant