Android platform message passing method and system

By designing a dynamicjni component and binding with fbjni, the protocol field information is dynamically obtained and transformed, solving the problems of cumbersome protocol definition and difficult hot-fix in the message passing process of the Android platform, and realizing efficient message passing and simplified object management.

CN121880040APending Publication Date: 2026-04-17XINGYUAN INFORMATION TECH (XIAMEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
XINGYUAN INFORMATION TECH (XIAMEN) CO LTD
Filing Date
2023-10-24
Publication Date
2026-04-17

AI Technical Summary

Technical Problem

Existing technologies on the Android platform suffer from cumbersome and error-prone protocol definitions during message passing, leading to low development efficiency, performance bottlenecks, and difficulties in hotfixing.

Method used

The DynamicJNI component is designed to bind the native and Java layers through the FBJNI component, dynamically obtain and transform protocol field information, reduce the dependence on native layer code, and support multiple data types and nested structures.

Benefits of technology

It simplifies the protocol definition process, improves development efficiency, supports hotfix and performance optimization, reduces memory usage, and simplifies object lifecycle management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121880040A_ABST
    Figure CN121880040A_ABST
Patent Text Reader

Abstract

The invention provides an Android platform message passing method and system, a more convenient framework function is designed by designing a dynamicjni component, the designed dynamicjni component can provide various data types and increase protocol field information, when an error occurs, only the protocol field information needs to be modified, a code of a native layer so does not need to be modified, and the error can be avoided. And meanwhile, recompilation is not needed for modifying the fields, so that development and debugging can be greatly facilitated. Meanwhile, when the bug on the line is repaired, compared with a previous scheme in which hot repair cannot be carried out due to the fact that a native layer so needs to be modified when a field needs to be modified, the scheme in the invention can conveniently carry out hot repair on the line by only modifying a java layer.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of message transmission, and more specifically, to a message transmission method and system for the Android platform. Background Technology

[0002] Currently, on the Android platform, live streaming rooms, especially large ones, receive a large number of server-side bullet screen messages. Each bullet screen message needs to be parsed to extract its fields and implement specific functionalities, such as the bullet screen content field for displaying the message, the bullet screen level field for displaying the message level, and the bullet screen color, etc. Existing solutions typically involve developing a shared object (SO) component in C or C++ at the underlying native layer, handling network data transmission and reception within this SO component. After receiving the data, it is then converted to the business logic layer (Java layer) for displaying the bullet screen content.

[0003] The existing solution involves the native layer receiving a message and then assigning the message content to a Java layer object. Each time a new message is defined, the name and type of the member variable of the Java layer object need to be defined, while the native layer needs to set the value by setting the name of the member variable. This makes adding new protocols quite cumbersome. Moreover, if a single character is misspelled, the program needs to be recompiled, packaged, and tested, which takes a long time. In addition, it also has a performance bottleneck when dealing with a large number of messages, which is also inefficient for developers.

[0004] Examples of existing technologies are provided:

[0005] For example:

[0006] Java layer code:

[0007] Suppose there is a message in the Java layer, define a class to manage and store this message:

[0008] public class MyClass{

[0009] Public String name; The member variable name is of type String.

[0010] public int age; The member variable age is of type Int integer.

[0011] }

[0012] Native C++ layer code:

[0013] Suppose that the native C++ code receives a message from the server containing the two data values ​​mentioned above: the name value and the age value. The next step is to assign this data to a Java object so that the Java object can display the corresponding data.

[0014] Next, we use the system-provided JNI layer in native code to assign values ​​to the objects:

[0015] 1. Obtain the MyClasses class

[0016] jclass cls=env->FindClass("com / example / MyClass");

[0017] The code above first uses JNI's environment variables (env) to locate the corresponding Java class object. `FindClass` is a JNI system function, and `"com / example / MyClass"` represents the path and name of the corresponding Java class.

[0018] 2. Retrieve the name field, a member variable of class MyClass.

[0019] jfieldIDnameField=env->GetFieldID(cls,"name","Ljava / lang / String;");

[0020] The code above retrieves the attribute of the MyClass member variable, where "name" is the name of the member variable, and "Ljava / lang / String;" indicates that the member variable name is of type string.

[0021] 3. Convert C++ strings to Java type strings.

[0022] jstring nameValue=env->NewStringUTF("John");

[0023] The C++ string "John" is converted into a Java string object namedValue using the JNI system function NewStringUTF.

[0024] 4. Assigning values ​​to Java layer objects

[0025] env->SetObjectField(obj,nameField,nameValue);

[0026] The code above assigns a string value from the C++ layer to a Java layer object.

[0027] The same method can be used to assign a value to the member variable age.

[0028] The entire process involves first defining the protocol content, then developing the Java layer code, and then developing the native SO layer code. After development is complete, the code needs to be compiled, packaged, run, and tested.

[0029] However, if a single character is mistyped during the entire process, such as typing "Jonn" instead of "John", the entire program will crash, and it will need to be corrected, recompiled, and repackaged, making the whole process very time-consuming.

[0030] If the protocol has 100 fields, assigning values ​​in the native code becomes quite cumbersome. It also requires calling numerous JNI system functions for data type conversion.

[0031] In addition, each new protocol requires modification of the .so code to complete the task. Summary of the Invention

[0032] This invention addresses the technical problems existing in the prior art by providing a message passing method and system for the Android platform.

[0033] According to a first aspect of the present invention, an Android platform message passing method is provided, comprising:

[0034] Design dynamic JNI components in the native layer;

[0035] When the native SO receives network protocol data from the server through the network socket, it obtains the information of each protocol field in the network protocol data and constructs a dynamicjni object in the native layer. The data structure of the dynamicjni object includes at least the name of each protocol field.

[0036] Based on the basic component fbjni component, the native layer dynamicjni object and the Java layer Jdynamicjni object are bound together, forming a one-to-one association between the native layer dynamicjni object and the Java layer Jdynamicjni object, so that the Java layer dynamicjni object holds the native layer dynamicjni object;

[0037] In the Java layer, the interface of the native layer's dynamicjni object is called to obtain the information of each protocol field in the native layer's dynamicjni object. Based on the name of each protocol field, the corresponding member variables in the Java layer's Jdynamicjni object are assigned values, thus converting the native layer's dynamicjni into a Java layer Jdynamicjni object and realizing message passing.

[0038] According to a second aspect of the present invention, an Android platform messaging system is provided, comprising:

[0039] The design module is used to design dynamicjni components in the native layer, and to bind native layer dynamicjni objects and Java layer Jdynamicjni objects based on the basic component fbjni component, forming a one-to-one association between native layer dynamicjni objects and Java layer Jdynamicjni objects, so that Java layer dynamicjni objects hold native layer dynamicjni objects.

[0040] The construction module is used to obtain the information of each protocol field in the network protocol data when the native SO receives network protocol data from the server through the network socket, and construct a dynamicjni object in the native layer. The data structure of the dynamicjni object includes at least the name of each protocol field.

[0041] The conversion constructor module is used to obtain the protocol field information of the native layer's dynamicjni object by calling the interface of the native layer's dynamicjni object in the Java layer, and assign values ​​to the corresponding member variables in the Java layer's Jdynamicjni object according to the name of each protocol field, thereby converting the native layer's dynamicjni into a Java layer Jdynamicjni object to realize message passing.

[0042] According to a third aspect of the present invention, an electronic device is provided, including a memory and a processor, wherein the processor is configured to implement the steps of a message passing method on the Android platform when executing a computer management program stored in the memory.

[0043] According to a fourth aspect of the present invention, a computer-readable storage medium is provided, on which a computer management class program is stored, wherein the computer management class program, when executed by a processor, implements the steps of a message passing method for the Android platform.

[0044] This invention provides a message passing method and system for the Android platform. It utilizes a dynamic JNI component to facilitate more convenient framework functionality. This component can provide multiple data types and add protocol fields. When an error occurs, only the protocol fields need to be modified, without modifying the native layer's shared object (SO) code. Furthermore, modifying fields does not require recompilation, greatly simplifying development and debugging. Moreover, when fixing bugs online, compared to previous solutions that required modifying native layer SOs and hindered hotfixing, this invention only requires modifying the Java layer, enabling convenient hotfixing of online issues. Attached Figure Description

[0045] Figure 1 This invention provides a flowchart of a message passing method for the Android platform.

[0046] Figure 2 This is a schematic diagram of the structure of an Android platform message passing system provided by the present invention;

[0047] Figure 3 A schematic diagram of the hardware structure of a possible electronic device provided by the present invention;

[0048] Figure 4 This is a schematic diagram of the hardware structure of a possible computer-readable storage medium provided by the present invention. Detailed Implementation

[0049] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention. In addition, the technical features of the various embodiments or individual embodiments provided by the present invention can be arbitrarily combined with each other to form feasible technical solutions. Such combinations are not constrained by the order of steps and / or structural composition patterns, but must be based on the ability of those skilled in the art to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed by the present invention.

[0050] Figure 1 A flowchart of a message passing method for the Android platform provided by this invention is shown below. Figure 1 As shown, the method includes:

[0051] Step 1: Design the dynamicjni component in the native layer.

[0052] Understandably, based on the problems in the background technology, this invention designs a dynamic data structure to support the entire function. This invention uses the `dynamicjni` data structure, which supports multiple data types, including at least strings, integers, floating-point numbers, booleans, map dictionary data classes, and nested `dynamicjni` types. Nesting refers to the fact that the data type can be itself, thus creating nested structures, which also facilitates nested data structures in signaling.

[0053] Nesting looks like this:

[0054] ("key","value"),("key2",dynamicjni::("key3","key4"));

[0055] The dynamicjni::("key3","key4") data type is a nested data type.

[0056] In addition, the dynamicjni component provides multiple data type judgment interfaces, multiple data type data acquisition interfaces, as well as a first conversion interface and a second conversion interface. The data type judgment interface is used to determine the data type of the current protocol field, the data acquisition interface is used to obtain the protocol field information of the corresponding type, the first conversion interface is used to convert the native dynamicjni object into a Java layer Jdynamicjni object, and the second conversion interface is used to convert the Java layer Jdynamicjni object into a native dynamicjni object.

[0057] Understandably, the DynamicJNI component provides data type detection interfaces to determine the data type of the current DynamicJNI object. These interfaces include interfaces for string type detection, nested type detection, boolean type detection, integer type detection, floating-point number type detection, and map type detection. The various data type detection interfaces are as follows:

[0058] bool isString(); provides an interface to determine whether a string is a string type.

[0059] bool isdynamicjni(); provides an interface for determining whether a type is nested.

[0060] bool isBool(); provides an interface to determine whether a value is of type bool.

[0061] bool isInt(); provides an interface to determine whether a type is an integer.

[0062] bool isDouble(); provides an interface to determine whether a number is a floating-point number.

[0063] The `bool isMap()` method provides an interface to determine whether a data type is a map.

[0064] It also provides data retrieval interfaces corresponding to various data type judgment interfaces. These interfaces include interfaces for retrieving string data from a dynamicjni object, boolean data from a dynamicjni object, integer data from a dynamicjni object, floating-point data from a dynamicjni object, map data from a dynamicjni object, and nested data from a dynamicjni object. Multiple data retrieval interfaces are listed below:

[0065] String getString(); retrieves string data from a dynamicjni object.

[0066] Bool getBool(); retrieves Bool data from a dynamicjni object.

[0067] `int getInt();` retrieves integer data from a `dynamicjni` object.

[0068] Double getDouble(); retrieves floating-point data from a dynamicjni object.

[0069] Map getMap(); retrieves map data from a dynamicjni object.

[0070] Dynamicjni getdynamicjni(); retrieves nested data from a dynamicjni object.

[0071] It's also crucial to provide an interface to convert the entire data into JSON format, and to initialize the entire Dynamic JNI structure based on the JSON format. The specific interface code is as follows:

[0072] Dynamicjni parseJson(String data) provides an interface to convert a JSON string into a Dynamicjni object.

[0073] The `String toJson(Dynamicjni data)` function also supports converting Dynamicjni objects into JSON data.

[0074] Step 2: When the native SO receives network protocol data from the server through the network socket, it obtains the information of each protocol field in the network protocol data and constructs a dynamicjni object in the native layer. The dynamicjni object data structure includes at least the name of each protocol field.

[0075] As an example, before message transmission, the network protocol is improved. The improved network protocol includes the name of each protocol field in the protocol message, the value of each protocol field, and the source of the protocol message. The source of the protocol message includes the server ID, module name, thread name, and protocol unique ID.

[0076] Understandably, for the purposes of this invention, the protocol content needs to be redesigned, and the protocol content will subsequently be passed to the Java business layer for functional demonstration.

[0077] To facilitate automated and convenient data transmission and display in the future, more information needs to be added to the protocol content for easier subsequent processing. At the same time, to facilitate the location of online issues, some fields (message source fields) also need to be added to the protocol to facilitate troubleshooting.

[0078] The original agreement is as follows:

[0079] The live chat signaling includes necessary fields such as: live chat information protocol (protoid), room number (roomid), user unique identifier (uid), and user identity information (userinfo, which is a nested data, i.e., a second-level data).

[0080] The original protocol was encoded using protobuf, which only required the content of each protocol.

[0081] a / @ / 123 / @ / 489 / @ / jonh,23 / @ /

[0082] The protocol field uses / @ / to separate fields.

[0083] The revised agreement is as follows:

[0084] The modified protocol content must include the names of the protocol fields. This way, when converting the data into Java objects later, the protocol field names will indicate which member variable to assign a value to.

[0085] Protoid:a roomid 123uid 489userinfo{name jonh age 23}.

[0086] The difference between the modified and original protocol is that additional data fields have been added to the protocol. For each field, its name is stored within the protocol, such as `protoid`, `roomid`, and `uid`. These field names will correspond to the names of member variables in the Java layer classes, facilitating subsequent assignment of values ​​to these member variables in the Java layer.

[0087] In addition, source information for each protocol message is added to the protocol content. Since subsequent data is passed to the Java layer via the Dynamic JNI component, it's necessary to know the data's origin to facilitate troubleshooting online issues. Therefore, additional information is needed regarding which layer and thread the underlying layer passes the protocol to the Java layer. Furthermore, a unique protocol ID is added to each protocol message to prevent confusion in locating problems caused by identical protocol messages. The fields added to the protocol content include:

[0088] Serverid: Server ID

[0089] datSource: Module Name

[0090] Threadname: Thread name

[0091] Uniqueid: The protocol-unique ID uses a 64-bit unsigned integer as the ID, which increments by 1 for each protocol received from the server, thus ensuring uniqueness.

[0092] The above adds four fields: server ID to facilitate problem location since the protocol comes from the server, module name, thread name, and protocol unique ID to facilitate subsequent troubleshooting when anomalies occur.

[0093] The above modifications have altered the communication protocol, and subsequent data transmission must adhere to the protocol.

[0094] When a native SO receives network protocol data from a server via a network socket, it needs to store the network protocol data in the native layer and then pass it to the Java layer for subsequent functionality.

[0095] The specific protocol serialization between the server and the client is based on the above settings. Protobuf can be used for serialization for online deployment to improve program performance, or JSON string format can be used for transmission during the development stage. JSON strings are more readable and easier to locate problems.

[0096] This invention uses the dynamicjni component, which has excellent support for JSON conversion. It can initialize the dynamicjni component with JSON data format, and can also convert the data of the dynamicjni object into JSON format data.

[0097] As mentioned above, Dynamic JNI supports the following data types: bool, double (floating-point), int (integer), string, and map (dictionary). Importantly, it supports nested types, meaning that the data type itself can also be Dynamic JNI. This provides excellent support for the userinfo signaling protocol mentioned above, which is a nested data type.

[0098] The process of acquiring information about each protocol field in the network protocol data and constructing a native-layer dynamicjni object includes: creating multiple data fields with the same name in the native-layer dynamicjni object based on the names of each protocol field, and adding a protocol message source field, which includes server ID, module name, thread name, and protocol unique ID; determining the data type of each protocol field based on the data type judgment interface in the dynamicjni object, and obtaining the value of the corresponding type of protocol field based on the data acquisition interface; storing the obtained protocol field value in the data field with the same name created in the dynamicjni object based on the name of each protocol field, and storing it in the corresponding protocol message source field based on the server ID, module name, thread name, and protocol unique ID.

[0099] Understandably, upon receiving the protocol message from the server in the native layer, multiple data fields with the same names are created in the native layer's `dynamicJNI` object based on the names of the fields in the protocol message, along with an added protocol message source field, thus constructing the data structure of the native layer's `dynamicJNI` object. The values ​​of each field in the protocol message are then filled into the corresponding fields of the `dynamicJNI` object. Several additional fields are added to the `dynamicJNI` object to store the source of the protocol message, primarily using the server ID, module name, thread name, and protocol unique ID; these fields indicate the source of the protocol message.

[0100] Step 3: Based on the basic component fbjni component, bind the native layer dynamicjni object and the Java layer Jdynamicjni object to form a one-to-one association between the native layer dynamicjni object and the Java layer Jdynamicjni object, so that the Java layer dynamicjni object holds the native layer dynamicjni object.

[0101] Specifically, based on the binding of the base component fbjni component to the native layer dynamicjni object and the Java layer Jdynamicjni object, a one-to-one association is formed between the native layer dynamicjni object and the Java layer Jdynamicjni object. This includes: defining a dynamicjni object in the native layer, which inherits from the base class of the fbjni component, and defining the association between the dynamicjni object in the native layer and the Java layer Jdynamicjni object; defining a Java layer interface in the Java layer, and registering the correspondence between native layer functions and the Java layer interface in the base class; correspondingly, obtaining the various protocol field information in the native layer dynamicjni object by calling the interface of the native layer dynamicjni object in the Java layer, including: calling the native function corresponding to the Java interface in the native layer to obtain the protocol field information in the native layer dynamicjni object by calling the Java layer interface in the Java layer, where each protocol field information includes the name of the protocol field and the value of the field.

[0102] Understandably, DynamicJni supports directly initializing a DynamicJni object with JSON string data, thus creating the DynamicJni object and making it ready for use.

[0103] std::string jsonString=R"({"name":"john"})";

[0104] Dynamicjni dStr=parseJson(jsonString);

[0105] The JSON data mentioned above is then directly converted into a Dynamicjni object, allowing direct access to the data content from the Dynamicjni object.

[0106] Similarly, for Dynamicjni objects, you can call their interface to convert them into JSON data format, making it easier to print dynamic objects to logs to locate problems and view data.

[0107] std::string json=toJson(dstr);

[0108] Calling its provided interface toJson can convert the Dynamicjni object dstr into a JSON string.

[0109] Regarding the protocol of this invention:

[0110] Protoid: a roomid 123uid 489userinfo{name jonh age 23} protocol

[0111] There is a nested data field called userinfo, and since DynamicJNI itself supports nested data, it can support this kind of nested data structure very well.

[0112] DynamicJNI itself supports converting native DynamicJNI objects into Java-level DynamicJNI objects, making it extremely convenient to convert data from C++ to Java.

[0113] DynamicJNI also has a wrapper in the Java layer, which maintains the consistency of the interface with the C++ layer. Therefore, when data is stored in a C++ object, JDynamicJNI in the Java layer can retrieve the corresponding data from the Java layer.

[0114] Once the client receives the protocol data from the server, it can convert the protocol data into a dynamicjni object for storage.

[0115] To reduce memory usage, all raw data in this invention is stored in native dynamic JNI objects. When data is needed, it is converted to the Java layer through an interface. This ensures that a single copy of the raw data is always maintained, with a one-to-one binding between the data and the Java object. When the Java object is destroyed, the corresponding native dynamic JNI object is also destroyed. The lifecycle is controlled by the Java layer.

[0116] There are three advantages to this design: (1) All data is accessed and used by the Java layer. Therefore, when the Java layer stops using the data, the object will be destroyed, and the native dynamic JNI object will also be destroyed. This simplifies the lifecycle management of the object and avoids problems caused by forgetting to release or releasing the native dynamic JNI object prematurely. (2) The raw data is stored in the native layer. Since the native layer has better performance, all data operations can be completed in the native layer before the results are sent to the Java layer for display. (3) If it is necessary to send the native layer data back to the server, the data can be sent directly in the native layer, avoiding the process of getting the data from the Java layer and converting it to the native layer.

[0117] During the design phase, this invention associates native objects and Java-layer objects, using the open-source foundational component FBJNI to do so. Through this association, the Java-layer object controls the lifecycle of the native object.

[0118] 1. Define the native layer object.

[0119] class Dynamicjni:public HybridClass <dynamicjni>{

[0120] Create a native layer class Dynamicjni that inherits from the base class HybridClass of fbjni.

[0121] public:

[0122] Static constexpr const char*kJavaDescriptor="Lcom / package / Dynamicjni;";

[0123] The string "Lcom / package / JDynamicjni" above defines which class in the Java layer is associated with the native layer's Dynamicjni.

[0124] static void registerNatives(){ This interface is used to register the mapping between native functions and Java layer interfaces.

[0125] registerHybrid({

[0126] makeNativeMethod("getTypes",Dynamicjni::getTypes),

[0127] makeNativeMethod("getKeys",Dynamicjni::getKeys),

[0128] makeNativeMethod("getValues",Dynamicjni::getValues),

[0129] });

[0130] The native function Dynamicjni::getTypes corresponds to the getTypes function in the Java layer.

[0131] The native function Dynamicjni::getKeys corresponds to the Java layer's getKeys function.

[0132] The native function Dynamicjni::getValues ​​corresponds to the getValues ​​function in the Java layer.

[0133] }

[0134] jni::local_ref<jni::JArrayClass <jobject>>getTypes();

[0135] jni::local_ref<jni::JArrayClass <jobject>>getKeys();

[0136] jni::local_ref<jni::JArrayClass <jobject>getValues();

[0137] The above are the function calls getTypes, getKeys, and getValues ​​from the three native layers.

[0138] protected:

[0139] JDynamicjni dyn_; The native layer stores JDynamicjni objects.

[0140] explicit Dynamicjni(JDynamicjni dyn); native constructor, requires a JDynamicjni parameter to be assigned a value.

[0141] 2. Define Java layer objects.

[0142] Public class JDynamicjni { The Java layer class Dynamicjni corresponds to the native class registered above.}

[0143] Public Dynamicjni(HybridData hybridData){

[0144] mHybridData = hybridData;

[0145] }

[0146] The interface described above receives a native object, hybridData, and stores it in the Java layer. The Java layer then controls the lifecycle of the native object, which corresponds to the native class Dynamicjni.

[0147] public

[0148] native Object[]getTypes();

[0149] native Object[]getKeys();

[0150] native Object[]getValues();

[0151] The above defines three Java layer interfaces, which correspond to native interfaces. Therefore, when the Java layer calls the above interfaces, it will call the corresponding native layer interfaces.

[0152] private

[0153] HybridData mHybridData; defines a member variable to store the native object.

[0154] The above method associates the native layer's dynamicjni object with the Java layer's Jdynamicjni object, and binds the C++ interface of the native layer's dynamicjni object with the Java interface of the Java layer's Jdynamicjni object one-to-one.

[0155] Step 4: In the Java layer, obtain the information of each protocol field in the native layer's dynamicjni object by calling the interface of the native layer's dynamicjni object, and assign values ​​to the corresponding member variables in the Java layer's Jdynamicjni object according to the name of each protocol field, thus constructing the Java layer's Jdynamicjni object data structure.

[0156] Understandably, when the native SO receives the server's network protocol through the network socket, it stores the network protocol data in the native layer's dynamicjni object and creates a Java layer's Jdynamicjni object. Therefore, the Java layer's Jdynamicjni object can obtain all the protocol data.

[0157] Next, the protocol content needs to be assigned to a Java object to facilitate subsequent functionality.

[0158] 1. Define the Java class for the protocol.

[0159] Typically, after a protocol message with the server is determined, a Java class is defined to correspond one-to-one with the protocol message. The values ​​of the fields in the protocol message are then assigned to the Java object. Subsequently, whether it is for UI display or functional logic judgment, only this Java object needs to be used to perform logic-related operations.

[0160] Specifically, a Java class is created in the Java layer using the Jdynamicjni object. Multiple member variables are created in the Java class, and the names of these member variables are consistent with the names of the multiple protocol fields. The value of each protocol field is then assigned to a member variable with the same name.

[0161] For example, regarding the above agreement content:

[0162] Protoid:a roomid 123uid 489userinfo{name jonh age 23}

[0163] This invention will define a Java class to correspond to this one-to-one:

[0164] public class SignalProtol { Defines a class named SignalProtol}

[0165] Public String Protoid; Defines a member variable protoid, which is a string type and its name is protoid. As described above, the member variable name will be assigned a value based on the member variable name.

[0166] Public String roomid; Defines a member variable roomid, which is of string type and has the name roomid.

[0167] public int uid; defines a member variable uid, which is an integer.

[0168] Each protocol field information includes the data type of each protocol field, and the number of Java classes created in the Jdynamicjni object is determined based on the data type of each protocol field.

[0169] Understandably, each protocol message can correspond to one Java class, or multiple Java classes can be created. If the DynamicJNI object contains nested data types and other data types, then multiple Java classes need to be created, with one Java class corresponding to other data types and each Java class corresponding to a nested type.

[0170] For example, Class Userinfo{ Here a class named Userinfo is defined.

[0171] This class is a nested class. Since the userinfo field is a nested field as seen in the protocol, nested data needs to be defined consistently for this field so that it can match the dynamic data. This also makes it easier to use a unified and universal solution to assign values ​​to the member variables in the class.

[0172] Public String name; Defines a member variable name of the class userinfo, which is a string.

[0173] public int age; defines the member variable age of the class userinfo, which is an integer.

[0174] }

[0175] }

[0176] After defining the Java object in the Java layer, the dynamic JNI object is used to assign values ​​to it. Specifically, in the Java layer, calling the Java layer interface will invoke the corresponding native function in the native layer to retrieve the protocol field information from the native layer's dynamic JNI object. Each protocol field includes the name of the protocol field and a value. The value of each field is then assigned to the corresponding member variable of the Java class.

[0177] Within the dynamic object, the data can be iterated over. According to the previous protocol design, all the data is stored in the form of key-value pairs. Therefore, the key corresponds to the name of the member variable of the Java class, and the value corresponds to the value to be assigned to that member variable.

[0178] The specific implementation involves writing the following interface to achieve data transformation:

[0179] public void setValues(dynamic valueMap)throws NoSuchFieldException,IllegalAccessException{

[0180] The modifiers for this function are: throws NoSuchFieldException, IllegalAccessException.

[0181] It should be noted that if the corresponding protocol field information cannot be found in the native object of the native layer when calling the native function corresponding to the Java interface through the Java layer interface, the abnormal data is located according to the source of the protocol message.

[0182] Understandably, considering the need to locate and discover problems early during development, and given the specific context of this invention, which uses a general algorithm to assign values ​​to all member variables of a class through a protocol, the NoSuchFieldException modifier in this interface indicates that an exception will be thrown if a member variable of a Java class cannot be found. This allows exceptions to be captured and error logs to be printed, thus enabling early detection and resolution of problems.

[0183] Class<? >clazz=this.getClass();

[0184] for(String fieldName:valueMap.keySet()){

[0185] Object fieldValue=valueMap.get(fieldName);

[0186] try{

[0187] Field field=clazz.getDeclaredField(fieldName);

[0188] The attribute is retrieved from the Java class based on its key-value pair. As described above, the key-value pairs of the protocol fields correspond one-to-one with the member variable names. Specifically, the `clazz.getDeclaredField` interface of the corresponding class is called to obtain the member attribute object `field`.

[0189] `field.setAccessible(true)`; Considering that some member variables in a class may be defined as private attributes, and this invention uses reflection to assign values ​​to class member variables, it is necessary to bypass the permission control checks of the Java language. Therefore, it is necessary to call the system-provided `setAccessible` to bypass permission control so that member variables can be assigned values. That is, for private member variables, which have certain permissions, it is necessary to call the system-provided `setAccessible` to bypass permission control and then assign values ​​to the member variables.

[0190] The `field.set(this, fieldValue)` method assigns a value to a member variable. You can assign a value to a member variable by calling the `set` method of the `field` member property object.

[0191] }catch(NoSuchFieldException e){

[0192] System.out.println("Field "+fieldName+" could not be found, the corresponding value is "+fieldValue+"server id"+Serverid+"protocol source:"+datSource+"thread name:"+Threadname+"protocol unique id:"+Uniqueid));

[0193] throw e; / / Rethrow the exception so that the upper layer can catch and handle it.

[0194] When a field is not found in a Java class, we promptly catch the exception and print out the corresponding field name. We also use the protocol's server ID (Serverid), source (datSource), thread name (datSource) handling this protocol, and protocol's unique ID (Uniqueid) to quickly locate the cause of the problem and resolve it.

[0195] }

[0196] }

[0197] See Figure 2 This paper provides a message passing method and system for the Android platform. The system includes a design module 201, a construction module 202, and a conversion module 203, wherein:

[0198] Design module 201 is used to design dynamicjni components in the native layer, and to bind native layer dynamicjni objects and Java layer Jdynamicjni objects based on the basic component fbjni component, forming a one-to-one association between native layer dynamicjni objects and Java layer Jdynamicjni objects, so that Java layer Jdynamicjni objects hold native layer dynamicjni objects.

[0199] The construction module 202 is used to obtain the information of each protocol field in the network protocol data when the native so receives network protocol data from the server through the network socket, and construct a dynamicjni object in the native layer, wherein the data structure of the dynamicjni object includes at least the name of each protocol field.

[0200] The conversion constructor module 203 is used to obtain the protocol field information of the native layer's dynamicjni object by calling the interface of the native layer's dynamicjni object in the Java layer, and assign values ​​to the corresponding member variables in the Java layer's Jdynamicjni object according to the name of each protocol field, thereby converting the native layer's dynamicjni object into a Java layer Jdynamicjni object to realize the transmission of signaling messages.

[0201] It is understood that the Android platform message passing system provided by the present invention corresponds to the Android platform message passing method provided in the foregoing embodiments. The relevant technical features of the Android platform message passing system can be referred to the relevant technical features of the Android platform message passing method, and will not be repeated here.

[0202] Please see Figure 3 , Figure 3 This is a schematic diagram illustrating an embodiment of the electronic device provided in this invention. For example... Figure 3 As shown, an embodiment of the present invention provides an electronic device 300, including a memory 310, a processor 320, and a computer program 311 stored in the memory 310 and executable on the processor 320. When the processor 320 executes the computer program 311, it implements the steps of the message passing method of the Android platform.

[0203] Please see Figure 4 , Figure 4 This is a schematic diagram illustrating an embodiment of a computer-readable storage medium provided by the present invention. (See diagram below.) Figure 4 As shown, this embodiment provides a computer-readable storage medium 400 on which a computer program 411 is stored. When the computer program 411 is executed by a processor, it implements the steps of the message passing method of the Android platform.

[0204] The message passing method and system for the Android platform provided in this invention have the following advantages:

[0205] (1) Design the dynamicjni component to design more convenient framework functions. It can design nested data structures. At the same time, it provides string, integer, floating-point number and bool types, which can meet all data types in the information transmission process and has universality.

[0206] (2) The original protocol was redesigned and a name was added for each field so that the fields could be located more easily when switching from the native layer to the Java layer.

[0207] (3) By designing a universal solution using the dynamicjni component, it is possible to add a new protocol without modifying the native layer SO code, and modifying fields does not require recompiling, which greatly facilitates development and debugging.

[0208] (4) When fixing bugs online, compared with the previous solution, when we need to modify the fields, we need to modify the native layer SO, which makes hot repair impossible. However, the solution in this paper only needs to modify the Java layer, which can easily perform hot repair of online issues.

[0209] It should be noted that the descriptions of each embodiment in the above embodiments have different focuses. For parts that are not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0210] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0211] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0212] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0213] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0214] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the invention.

[0215] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.< / jobject> < / jobject> < / jobject> < / dynamicjni>

Claims

1. A message passing method for the Android platform, characterized in that, include: Design dynamic JNI components in the native layer; When the native SO receives network protocol data from the server through the network socket, it obtains the information of each protocol field in the network protocol data and constructs a dynamicjni object in the native layer. The data structure of the dynamicjni object includes at least the name of each protocol field. Based on the basic component fbjni component, the native layer dynamicjni object and the Java layer Jdynamicjni object are bound together, forming a one-to-one association between the native layer dynamicjni object and the Java layer Jdynamicjni object, so that the Java layer Jdynamicjni object holds the native layer dynamicjni object; In the Java layer, the interface of the native layer's dynamicjni object is called to obtain the information of each protocol field in the native layer's dynamicjni object. Based on the name of each protocol field, the corresponding member variables in the Java layer's Jdynamicjni object are assigned values, thus converting the native layer's dynamicjni into a Java layer Jdynamicjni object and realizing message passing.

2. The message passing method for the Android platform according to claim 1, characterized in that, The design of dynamic JNI components in the native layer includes: Design a dynamicjni component in the native layer, and design a dynamicjni data structure in the dynamicjni component. The dynamicjni data structure supports multiple data types, including at least string, integer, floating-point number, bool type, map dictionary data class and nested dynamicjni type. The dynamicjni component provides multiple data type judgment interfaces, multiple data type acquisition interfaces, a first conversion interface, and a second conversion interface. The data type judgment interface is used to determine the data type of the current protocol field. The data acquisition interface is used to obtain the protocol field information of the corresponding type. The first conversion interface is used to convert the native dynamicjni object into a Java layer Jdynamicjni object. The second conversion interface is used to convert the Java layer Jdynamicjni object into a native dynamicjni object.

3. The message passing method for the Android platform according to claim 1, characterized in that, The various data type judgment interfaces include a string type judgment interface, a nested type judgment interface, a bool type judgment interface, an integer type judgment interface, a floating-point number type judgment interface, and a map type judgment interface. Correspondingly, the various data acquisition interfaces include an interface for obtaining string data from a dynamicjni object, an interface for obtaining bool data from a dynamicjni object, an interface for obtaining integer data from a dynamicjni object, an interface for obtaining floating-point data from a dynamicjni object, an interface for obtaining map data from a dynamicjni object, and an interface for obtaining nested data from a dynamicjni object.

4. The message passing method for the Android platform according to claim 2, characterized in that, Also includes: The network protocol is improved, and the improved network protocol includes the name of each protocol field in the protocol message, the value of each protocol field, and the source of the protocol message. The source of the protocol message includes the server ID, module name, thread name, and protocol unique ID.

5. The message passing method for the Android platform according to claim 4, characterized in that, Obtain the protocol field information from the network protocol data and construct a native layer dynamicjni object, including: Based on the names of each protocol field, multiple data fields with the same names are created in the dynamicjni object of the native layer, and a protocol message source field is added, which includes server id, module name, thread name and protocol unique id; The data type determination interface in the dynamicjni object determines the data type of each protocol field, and the data retrieval interface retrieves the value of the corresponding protocol field. Based on the name of each protocol field, the value of the obtained protocol field is stored in a data field with the same name created in the dynamicjni object, and the value is stored in the corresponding protocol message source field according to the server ID, module name, thread name, and protocol unique ID.

6. The message passing method for the Android platform according to claim 1, characterized in that, The process of binding native-layer dynamicjni objects and Java-layer Jdynamicjni objects based on the basic component fbjni component to form a one-to-one association between native-layer dynamicjni objects and Java-layer Jdynamicjni objects includes: Define a dynamicjni object in the native layer. The dynamicjni object inherits from the base class of the fbjni component, and define the association between the dynamicjni object in the native layer and the Jdynamicjni object in the Java layer. Define Java layer interfaces in the Java layer, and register the correspondence between native layer functions and Java layer interfaces in the base class; Correspondingly, in the Java layer, the various protocol field information in the native layer's dynamicJNI object is obtained by calling the interface of the native layer's dynamicJNI object, including: In the Java layer, the native function corresponding to the Java interface is called in the native layer to obtain the protocol field information in the native layer's dynamicjni object. Each protocol field information includes the name of the protocol field and the value of the field.

7. The message passing method for the Android platform according to claim 6, characterized in that, The process of assigning values ​​to the corresponding member variables in the Java layer Jdynamicjni object according to the names of each protocol field, converting the native layer dynamicjni into a Java layer Jdynamicjni object, and realizing message passing includes: In the Java layer, a Java class is created from a Jdynamicjni object. Multiple member variables are created in the Java class, and the names of the multiple member variables are consistent with the names of multiple protocol fields. Assign the value of each protocol field to a member variable with the same name.

8. The message passing method for the Android platform according to claim 7, characterized in that, Each protocol field also includes the data type of each protocol field, and the number of Java classes created in the Jdynamicjni object is determined based on the data type of each protocol field.

9. The message passing method for the Android platform according to claim 6, characterized in that, The step of retrieving each protocol field information in the native layer's dynamicjni object by calling a native function corresponding to the Java interface in the native layer through a Java layer interface call in the Java layer also includes: If the corresponding protocol field information cannot be found in the native function corresponding to the Java interface when calling the native function in the native layer by calling the Java layer interface, the abnormal data is located according to the source of the protocol message.

10. A messaging system for the Android platform, characterized in that, include: The design module is used to design dynamicjni components in the native layer, and to bind native dynamicjni objects and Java Jdynamicjni objects based on the basic component fbjni component, forming a one-to-one association between native dynamicjni objects and Java Jdynamicjni objects, so that Java Jdynamicjni objects hold native dynamicjni objects. The construction module is used to obtain the information of each protocol field in the network protocol data when the native SO receives network protocol data from the server through the network socket, and construct a dynamicjni object in the native layer. The data structure of the dynamicjni object includes at least the name of each protocol field. The conversion constructor module is used to obtain the protocol field information of the native layer's dynamicjni object by calling the interface of the native layer's dynamicjni object in the Java layer, and assign values ​​to the corresponding member variables in the Java layer's Jdynamicjni object according to the name of each protocol field, thereby converting the native layer's dynamicjni object into a Java layer Jdynamicjni object to realize message passing.