Detailed Description
In order to describe the technical contents, the achieved objects and effects of the present invention in detail, the following description will be made with reference to the embodiments in conjunction with the accompanying drawings.
Referring to fig. 1 and fig. 3 to fig. 6, a unified channel communication method for an Android terminal includes the steps of:
s1, establishing a data transfer program in an Android terminal, and respectively establishing a first connection between the data transfer program and a PC end and a second connection between the data transfer program and a server;
s2, establishing a third connection between the data transfer program and the service program in the Android terminal;
And S3, carrying out communication between the service program and the PC side or the server through the data transfer program.
From the above description, the beneficial effects of the invention are as follows: setting a data transfer program, integrating connection with a PC end and connection with a server end in the data transfer program, and carrying out data interaction between service programs in the Android terminal and the PC end or the server through the data transfer program without additionally establishing an interaction module in the service programs, so that communication data of each service program in the Android terminal are conveniently collected and managed, the data transfer program can be directly called when the service programs are required to be added, flexibility and expansibility of a frame are enhanced, and centralized management and control of a communication interface of the Android terminal is realized.
Further, the S1 specifically is:
Establishing a data transfer program and a first adb program in an Android terminal;
establishing a first sub-connection between the data transfer program and the first adb program;
establishing a second sub-connection between the first adb program and a second adb program in the PC end, wherein the second adb program in the PC end and a service program are in TCP connection;
The first sub-connection is a TCP connection;
The second sub-connection is a USB connection.
From the above description, it can be seen that the first adb program in the Android terminal is connected with the second adb program in the PC, the data transfer program in the Android terminal is connected with the first adb program by TCP, and the USB connection ensures the security of the PC on the Android terminal operation.
Further, the S2 specifically is:
acquiring the attribute of the service program;
Determining the connection type between the data transfer program and the service program according to the attribute of the service program;
and establishing the third connection between the data transfer program and the service program according to the connection type.
As can be seen from the above description, different types of connections are established with different service programs according to the attributes of the different service programs, so that the most suitable connection types can be matched with the different service programs, and the efficiency of data interaction with the service program connection is improved.
Further, the step S2 further includes:
Establishing a communication protocol, wherein the communication protocol comprises a service program identifier;
and realizing communication between the service program corresponding to the service program identifier and the PC side or the server through the data transfer program according to the service program identifier.
As can be seen from the above description, the transfer program transfers the service program from the PC or the server through the service program identifier, so that the data can be ensured to be correctly sent to the corresponding service program, and the data can be prevented from being sent by mistake.
Further, the step S1 further includes:
receiving data sent by the PC end or the server;
and filtering the data through a preset filtering strategy in the data transfer program.
According to the description, after the data sent by the PC end or the server is received, the data is filtered according to a preset filtering strategy, so that the data transfer program can also serve as a function equivalent to a security gateway, and the data security in the Android terminal is further improved.
Referring to fig. 2, an Android terminal unified channel communication terminal includes a memory, a processor, and a computer program stored in the memory and capable of running on the processor, wherein the following steps are implemented when the processor executes the computer program:
s1, establishing a data transfer program in an Android terminal, and respectively establishing a first connection between the data transfer program and a PC end and a second connection between the data transfer program and a server;
s2, establishing a third connection between the data transfer program and the service program in the Android terminal;
And S3, carrying out communication between the service program and the PC side or the server through the data transfer program.
The invention has the beneficial effects that: setting a data transfer program, integrating connection with a PC end and connection with a server end in the data transfer program, and carrying out data interaction between service programs in the Android terminal and the PC end or the server through the data transfer program without additionally establishing an interaction module in the service programs, so that communication data of each service program in the Android terminal are conveniently collected and managed, the data transfer program can be directly called when the service programs are required to be added, flexibility and expansibility of a frame are enhanced, and centralized management and control of a communication interface of the Android terminal is realized.
Further, the S1 specifically is:
Establishing a data transfer program and a first adb program in an Android terminal;
establishing a first sub-connection between the data transfer program and the first adb program;
establishing a second sub-connection between the first adb program and a second adb program in the PC end, wherein the second adb program in the PC end and a service program are in TCP connection;
The first sub-connection is a TCP connection;
The second sub-connection is a USB connection.
From the above description, it can be seen that the first adb program in the Android terminal is connected with the second adb program in the PC, the data transfer program in the Android terminal is connected with the first adb program by TCP, and the USB connection ensures the security of the PC on the Android terminal operation.
Further, the S2 specifically is:
acquiring the attribute of the service program;
Determining the connection type between the data transfer program and the service program according to the attribute of the service program;
and establishing the third connection between the data transfer program and the service program according to the connection type.
As can be seen from the above description, different types of connections are established with different service programs according to the attributes of the different service programs, so that the most suitable connection types can be matched with the different service programs, and the efficiency of data interaction with the service program connection is improved.
Further, when the processor executes the computer program to implement the step S2, the method further includes:
Establishing a communication protocol, wherein the communication protocol comprises a service program identifier;
and realizing communication between the service program corresponding to the service program identifier and the PC side or the server through the data transfer program according to the service program identifier.
As can be seen from the above description, the transfer program transfers the service program from the PC or the server through the service program identifier, so that the data can be ensured to be correctly sent to the corresponding service program, and the data can be prevented from being sent by mistake.
Further, after the processor executes the computer program to implement the step S1, the method further includes:
receiving data sent by the PC end or the server;
and filtering the data through a preset filtering strategy in the data transfer program.
According to the description, after the data sent by the PC end or the server is received, the data is filtered according to a preset filtering strategy, so that the data transfer program can also serve as a function equivalent to a security gateway, and the data security in the Android terminal is further improved.
Referring to fig. 1, a first embodiment of the present invention is as follows:
A unified channel communication method of an Android terminal comprises the following steps:
s1, establishing a data transfer program in an Android terminal, and respectively establishing a first connection between the data transfer program and a PC end and a second connection between the data transfer program and a server;
In this embodiment, S1 is specifically: establishing a data transfer program and a first adb program in an Android terminal; establishing a first sub-connection between the data transfer program and the first adb program; establishing a second sub-connection between the first adb program and a second adb program in the PC end, wherein the second adb program in the PC end and a service program are in TCP connection; the first sub-connection is a TCP connection; the second sub-connection is a USB connection;
s2, establishing a third connection between the data transfer program and the service program in the Android terminal;
Referring to fig. 4, S2 in this embodiment is specifically: acquiring the attribute of the service program; determining the connection type between the data transfer program and the service program according to the attribute of the service program; establishing the third connection between the data transfer program and the service program according to the connection type;
In this embodiment, S2 further includes: establishing a communication protocol, wherein the communication protocol comprises a service program identifier; according to the service program identification, the communication between the service program corresponding to the service program identification and the PC end or the server is realized through the data transfer program; referring to fig. 6, a communication protocol structure is shown, which includes a frame header, a version, a transaction code, a Data format, a Data type, a frame number, a service module, a Data length (Data length), a Data segment, a check value and a frame tail, wherein the frame header identifies the beginning of a frame of information, the version identifies the version number of the frame protocol used by the frame of information, the transaction code is the transaction code of the frame of information, the Data format identifies the Data format of the Data segment carried by the frame of information, such as JSON format, the Data type identifies the Data type of the Data segment carried by the frame of information, such as message Data, handshake Data and the like, the frame number identifies the number of the frame of Data, the service module indicates to which service module the frame of information belongs, the Data length generally adopts module coding of the corresponding module, the Data length indicates the byte length of the Data segment carried by the frame of Data, the Data segment indicates the actual Data word segment carried by the frame of Data, the check value is the check value of the frame of information, and the frame tail identifies the end of the frame of information;
s3, carrying out communication between the service program and the PC end or the server through the data transfer program;
In this embodiment, S1 further includes: receiving data sent by the PC end or the server; filtering the data through a preset filtering strategy in the data transfer program; the data of all business programs of the Android terminal are collected in the data transfer program, so that the data can be uniformly managed and controlled in the data transfer program;
In an optional implementation manner, corresponding logic is set in the data transfer program to judge whether the data frame has malicious behaviors, if yes, the data frame is filtered, the safety of the internal service program of the Android terminal is protected, and the intrusion of the internal service program by malicious data frames is avoided.
Referring to fig. 3 to 6, a second embodiment of the present invention is as follows:
the unified channel communication method of the Android terminal is applied to an actual scene:
Referring to fig. 3, in the Android terminal, a data transfer program (DataRouter) is configured, the data transfer program establishes a first connection with the PC end through the adb component, establishes a second connection with the server through the network, and establishes a third connection with the service program through a communication mechanism provided in the Android system;
referring to fig. 3, the data terminal program establishes a communication link with each service program by using a process communication mechanism of the Android system, and the service programs include, but are not limited to, an application update service and a data acquisition service; different requirements are determined according to the type of the service program, and further different communication modes are determined, wherein the communication modes such as localsocket can be used for interaction scenes without limiting any data format;
Specifically, in the communication protocol in the first embodiment, a domain "service module" is set, where the range of values of the domain is a module number allocated to each service program during design, a module information configuration table is set in the data transfer program, where the module information configuration table includes information of each service program, such as a module number, a communication mode, a module address, and the like, and in the communication process, the data transfer program can read the value of the "service module" in one frame of information, and then query the module information configuration table according to the value to obtain information (such as a communication mode, a module address, and the like) corresponding to the module, and then communicate with the corresponding service program;
Specifically, referring to fig. 4, the first connection includes a first sub-connection between a data transfer program in the Android terminal and a first adb program (adb-daemon) in the Android terminal, a second sub-connection between the first adb program and a second adb program (adb-server) in the PC terminal, and a third sub-connection between a service program (PC-tol) in the PC terminal and the second adb program; the first sub-connection and the third sub-connection are TCP connections, and the second sub-connection is USB connection; an adb component is arranged in an Android system of the Android terminal, USB communication with a PC is achieved through calling the adb component by a first adb program, and specifically, the adb-server and the adb-daemon are adb components provided by Android native sources; the adb-server runs on the PC, the adb-daemon runs on the Android terminal, and USB communication between the PC and the Android terminal is realized by the adb-server; on the one hand, the adb-daemon realizes USB communication with the PC end adb-server in the Android terminal; on the other hand, the socket client identity is connected to a data transfer program, and the data transfer program runs in the socket server identity; on the PC side, on one hand, the adb-server realizes the USB communication with the adb-daemon of the Android terminal; on the other hand, the PC-TOOL runs with the identity of the socket server, receives the connection from the PC-TOOL, and runs with the identity of the socket client.
Namely, in the PC end, TCP protocol communication is realized between the adb-server and the PC-TOOL; TCP protocol communication is realized between the adb-daemon and the data transfer program at the Android terminal; in addition, USB communication is realized between the adb-server and the adb-daemon, so that each module is connected in series, and TCP protocol communication can be realized between PC-TOOL and a data transfer program; wherein PC-TOOL is the identity of the socket client and the data transfer program is the identity of the socket server;
specifically, an adb forward instruction is used for establishing a TCP port forwarding channel (third sub-connection) with the Android terminal in the PC terminal, and the PC-TOOL can establish connection with the data transfer program by using the identity of the socket client, so that communication between the PC terminal and the data transfer program is realized;
referring to fig. 5, the data transfer program and the server establish a connection to communicate using a TCP protocol through a wireless/wired network;
in this embodiment, the adb program of the PC includes an adb-server and an adb-client, and the adb program of the Android terminal is adb-deamon, that is, adbd. .
Referring to fig. 2, a third embodiment of the present invention is as follows:
the Android terminal unified channel communication terminal 1 comprises a processor 2, a memory 3 and a computer program stored in the memory 3 and capable of running on the processor 2, wherein the processor 2 realizes the steps in the first embodiment or the second embodiment when executing the computer program.
In summary, the invention provides a unified channel communication method and a terminal for an Android terminal, which realize a data transfer program in the Android terminal, so that the communication between each service program and a PC end or between each service program and a server is completed through the data transfer program without integrating communication functions, thereby forming a unified data channel, facilitating unified management and control of data flowing in and out of the Android terminal, and improving the safety of the data in the Android terminal; the framework has strong expansibility, if a newly added service program exists, the communication between the framework and a PC end or a server can be realized only by establishing the connection between the framework and a data transfer program, and the use of other service programs is not influenced; the PC terminal and the Android system are communicated through the adb of the Android system, the safety is high, the PC terminal and the server are communicated through the TCP protocol, and the PC terminal and the server can be supported by various networks, so that wired communication and wireless communication can be realized; when the data transfer program realizes the communication between the PC end/server and the service program, the service program identification of the service program is used for identifying the data, such as the service module specified by the communication protocol in fig. 6, so that the data can be ensured to be correctly received and forwarded.
The foregoing description is only illustrative of the present invention and is not intended to limit the scope of the invention, and all equivalent changes made by the specification and drawings of the present invention, or direct or indirect application in the relevant art, are included in the scope of the present invention.