A kind of receiving/transmission method for broadcasting the message between application program in android system and
System
Technical field
The present invention relates in a kind of android system broadcast message security mechanism more particularly to a kind of android system
The receiving/transmission method and system to broadcast the message between middle application program.
Background technology
Broadcast is the mechanism that a kind of extensive utilization transmits information among applications in android system, in Android
Broadcast be used for monitoring system event or application event.
The broadcast message of android system belongs to open nature, and any application program can be by realizing that broadcast connects
Device is received to receive broadcast message, the interface that any application program can be provided by system sends broadcast message.It can lead in this way
Cause cankered third party application that can listen to the broadcast message of normal application, while the broadcast for sending personation disappears
The operation of breath interference normal application, has seriously affected the safety of android system.Android system provides a variety of
Method avoids the above situation, it is apparent that it is incomplete, for example broadcast transmission side is allowed to specify specific radio receiver, permission
The application program of broadcast message intended receiver only allows broadcast message to be transmitted inside broadcast transmission side's application program, but this
A little safeties for not ensuring that broadcast message.The broadcast message interference that third party application still can send personation is normal
The sender of the operation of application program, broadcast message can not specify multiple application programs to receive broadcast message simultaneously, cause more
Broadcast message between application program can not safe transmission and reception.For example same company develops multiple application programs, needs
Broadcast message is transmitted between this multiple application program, but is not allowed other Unknown Applications to receive the broadcast and disappeared
Breath, existing android system can not complete the function.
Invention content
The purpose of the present invention is just to provide the receiving/transmission method to broadcast the message between application program in a kind of android system
And system, when sending broadcast message, multiple application programs for allowing to receive can be specified, third party's Unknown Applications is avoided to steal
Broadcast message is got, when receiving broadcast message, the application program that broadcast message can be specified to send, to avoid personation is received
Broadcast message, interferes with the operation of application.
The present invention provides the receiving/transmission method to broadcast the message between application program in a kind of android system,
The specific steps are:
The broadcast reception sides S1 register radio receiver to campaign management services, include broadcast reception side in log-on message
Packet name;
The broadcast transmission sides S2 send the broadcast message for including broadcast transmission side's packet name;
S3 campaign management services determine broadcast by broadcast transmission side's packet name and/or broadcast reception side's packet name verification mode
Whether receiver receives broadcast message;
If being verified, S4 is entered step, if authentication failed, radio receiver does not receive broadcast message;
The broadcast reception sides S4 are received by the radio receiver and are broadcast the message.
Broadcast message transmission and broadcast message reception in present android system, if what broadcast transmission side specified
Action is consistent with the Action in broadcast reception side's registration message to can be carried out broadcast message reception.This mode exists wide
Broadcast the case where message is stolen or received the broadcast message of personation by other application program and interferes with the operation of broadcast reception side.
The packet name of application program has uniqueness in android system level, can be used for identification application, in we
In case, by increasing the verification mode of application package name, reach more accurate message transmission and message sink.
Preferably,
In S1 steps, when broadcast reception side registers radio receiver, setting allows the broadcast transmission side's packet name structure received
At the first packet list of file names;
In S3 steps, campaign management services match the first packet list of file names described in broadcast transmission side Bao Mingyu, if matching
Success, enters step S4, if it fails to match, broadcast reception side does not receive broadcast message.
This mode is crossed, the operation of application can be interfered with to avoid the broadcast message of personation is received.
Preferably,
In S2 steps, when broadcast transmission side sends broadcast message, it is wide comprising allowing reception to broadcast the message to send information
Broadcast the second packet list of file names of recipient's packet name composition;
Further include step after S2 steps:
S31, campaign management services match the second packet list of file names described in broadcast reception side Bao Mingyu, if successful match into
Enter step S4, if it fails to match, broadcast reception side does not receive broadcast message.
By the above verification mode, when sending broadcast message, multiple application programs for allowing to receive can be specified, are avoided
Third party's Unknown Applications steal broadcast message.
Preferably, registration radio receiver is dynamic registration and/or static registration.
Preferably, when the broadcast reception side starts, campaign management services parse the file of the static registration, extraction
With the relevant information for preserving radio receiver, when the broadcast reception side closes, campaign management services delete radio receiver
Relevant information.
The present invention also provides the receive-transmit system to broadcast the message between application program in a kind of android system, feature exists
In, including broadcast transmission side, broadcast reception side, the campaign management services of system,
Broadcast transmission side includes:
Calling module is sent, the broadcast message for calling campaign management services to be provided sends function, and broadcast is disappeared
Breath specifying information group is woven in parameter;
Broadcast reception side includes:
Registration module registers radio receiver to campaign management services, includes broadcast reception side's packet name in log-on message;
Receiving module, broadcasts the message for being received by radio receiver, and campaign management services include:
Broadcast the message sending module, calls broadcast message to send function for receiving broadcast transmission side, and send broadcast and disappear
Breath;
Receive registration module, the information registered for receiving broadcast reception side;
Log-on message parsing module, for parsing registered information;
Packet name authentication module, for being verified to broadcast transmission side's packet name and/or broadcast reception side's packet name, if packet name is tested
Card passes through, and broadcast message processing module processing broadcast message, if authentication failed, receiving module does not receive broadcast message;
Broadcast the message processing module, for handling broadcast message, after broadcast transmission side, which is sent, to broadcast the message, and broadcast message
Processing module sends broadcast messages to specific broadcast reception according to system proof rule and the verification result of packet name authentication module
Device.
Preferably,
It broadcasts the message in registration module, also includes:
First packet name adds submodule, allows to receive broadcast transmission side's packet name for adding, constitutes the first packet list of file names;
Packet name authentication module also includes:
First verification submodule, for matching the first packet list of file names described in broadcast transmission side Bao Mingyu.
Preferably,
Message sends calling module:
Second packet name adds submodule, allows to receive broadcast transmission side's packet name for adding, constitutes the second packet list of file names;
Packet name authentication module also includes:
Second verification submodule, for matching the second packet list of file names described in broadcast reception side Bao Mingyu.
Preferably,
The registration module that broadcasts the message includes static registration submodule and dynamic registration submodule.
Preferably,
Log-on message parsing module, is used for, and when the broadcast reception side starts, parses the file of the static registration,
Extraction and the relevant information for preserving radio receiver delete the related letter of radio receiver when the broadcast reception side closes
Breath.
When broadcast reception side registers radio receiver, setting allows the first packet for receiving broadcast transmission side's packet name composition to rank
Table, when broadcast transmission side Bao Mingyu the first packet list of file names successful match, broadcast reception side is received wide by the radio receiver
Message is broadcast, the operation of application is interfered with to avoid the broadcast message of personation is received by specified broadcast transmission side;
When broadcast transmission side sends broadcast message, it includes to allow to receive that the broadcast reception side packet name to broadcast the message constitutes the to send information
Two packet list of file names, described in broadcast reception side Bao Mingyu when the second packet list of file names successful match, broadcast reception side passes through the broadcast
Receiver receives broadcast message, by specifying multiple broadcast reception sides, avoids third party's Unknown Applications from stealing broadcast and disappears
Breath.
Description of the drawings
Fig. 1 is the receiving/transmission method first embodiment to broadcast the message between application program in a kind of android system of the present invention
Flow diagram;
Fig. 2 is the receive-transmit system first embodiment to broadcast the message between application program in a kind of android system of the present invention
Structural schematic diagram;
Fig. 3 is the receiving/transmission method second embodiment to broadcast the message between application program in a kind of android system of the present invention
Flow diagram;
Fig. 4 is the receive-transmit system second embodiment to broadcast the message between application program in a kind of android system of the present invention
Structural schematic diagram;
Fig. 5 is the receiving/transmission method 3rd embodiment to broadcast the message between application program in a kind of android system of the present invention
Flow diagram;
Fig. 6 is the receive-transmit system 3rd embodiment to broadcast the message between application program in a kind of android system of the present invention
Structural schematic diagram.
Specific implementation mode
In order to more clearly explain the embodiment of the invention or the technical proposal in the existing technology, to embodiment or will show below
There is attached drawing needed in technology description to be briefly described, it should be apparent that, the accompanying drawings in the following description is only this
Some embodiments of invention for those of ordinary skill in the art without creative efforts, can be with
Obtain other attached drawings according to these attached drawings.
Embodiment one:
The present embodiment provides the receiving/transmission methods to broadcast the message between application program in a kind of android system.
In android system, broadcast is a kind of mechanism for transmitting information among applications of extensive utilization.Pass through
Broadcast message sends and receives, and information can be mutually transmitted between application program, for the convenience of description, we are passed with primary information
It is introduced for defeated, in this time message transmitting procedure, we are known as the application program for sending out broadcast message to broadcast hair
The application program for receiving broadcast message is known as broadcast reception side by the side of sending.
Broadcast message transmission and broadcast message reception in present android system, if what broadcast transmission side specified
Action is consistent with the Action in broadcast reception side's registration message to can be carried out message sink.This mode disappears in the presence of broadcast
The case where breath is stolen or is received the broadcast message of personation by other application program and interferes with the operation of broadcast reception side.
The packet name of application program has uniqueness in android system level, can be used for identification application, in we
In case, by increasing the verification mode of application package name, reach more accurate message transmission and message sink.
As shown in Figure 1, the specific steps are:
The broadcast reception sides S1 register radio receiver to campaign management services, include broadcast reception side in log-on message
Packet name;
Broadcast reception device assembly is used to receive and the message of response system broadcast.Broadcast mechanism, for essence, it is one
Kind message subscribing/issue mechanism, therefore, the first step using this message-driven model are subscription message, and to Android
For application program, it is exactly to register radio receiver in fact to subscribe to message, and after system, which is sent, to broadcast the message, system is according to registration
Situation obtains corresponding radio receiver, then calls the processing function of radio receiver respectively in application, completes broadcast
The processing of message.
There are two ways to registering radio receiver, one is static registrations, and one is dynamic registrations.Android's
In broadcast mechanism, the priority of dynamic registration is higher than static registration priority.
The broadcast transmission sides S2 send the broadcast message for including broadcast transmission side's packet name;
In android system, the campaign management services of system process are run on (in industry common name
ActivityManagerService) registration, transmission and the dispatch deal of management broadcast message externally mainly provides dynamic and notes
Volume broadcast message (RegisterReceiver) and transmission broadcast message (BroadcastIntent) two interface functions, application
Process calls the two interface functions to complete the correlation function of broadcast message by Binder interface striding courses.
Broadcast transmission side broadcasts the message function to send by the transmission of calling system ActivityManagerService
Message;
S3 campaign management services (ActivityManagerService) are connect by broadcast transmission side's packet name and/or broadcast
Debit's packet name verification mode, determines whether radio receiver receives broadcast message;
If being verified, S4 is entered step, if authentication failed, radio receiver does not receive broadcast message;
After sending broadcast message, campaign management services ActivityManagerService obtains correspondence from register list
Radio receiver, and broadcast transmission side's packet name and/or broadcast reception side's packet name are verified, are proved to be successful then broadcast reception
Device receives broadcast message.
The broadcast reception sides S4 are received by the radio receiver and are broadcast the message.
As shown in Fig. 2, the present invention also provides the transmitting-receiving systems to broadcast the message between application program in a kind of android system
System, including broadcast transmission side, broadcast reception side, the campaign management services of system,
Wherein, broadcast transmission side includes:
Calling module is sent, the broadcast message for calling campaign management services to be provided sends function, and broadcast is disappeared
Breath specifying information group is woven in parameter;
Broadcast reception side includes:
Registration module registers radio receiver to campaign management services, includes broadcast reception side's packet name in log-on message;
Receiving module broadcasts the message for being received by radio receiver,
Campaign management services include:
Broadcast the message sending module, calls broadcast message to send function for receiving broadcast transmission side, and send broadcast and disappear
Breath;
Receive registration module, the information registered for receiving broadcast reception side;
Log-on message parsing module, for parsing registered information;
Packet name authentication module, for being verified to broadcast transmission side's packet name and/or broadcast reception side's packet name, if packet name is tested
Card passes through, and broadcast message processing module processing broadcast message, if authentication failed, receiving module does not receive broadcast message;
Broadcast the message processing module, for handling broadcast message, after broadcast transmission side, which is sent, to broadcast the message, and broadcast message
Processing module sends broadcast messages to specific broadcast reception according to system proof rule and the verification result of packet name authentication module
Device.
Broadcast transmission side, by sending calling module, the broadcast message transmission function for calling campaign management services to be provided,
And broadcast message specifying information group is woven in parameter, campaign management services send mode transfer block by receiving and receive broadcast transmission side
It calls broadcast message to send function, and sends broadcast message;
Broadcast reception side registers radio receiver to campaign management services by registration module, includes in log-on message
Broadcast reception side's packet name, campaign management services receive the information that broadcast reception side is registered by receiving registration module, and pass through
Log-on message parsing module parses log-on message;
Campaign management services carry out broadcast transmission side's packet name and/or broadcast reception side's packet name by packet name authentication module
Verification, system convention verify (i.e. Action verifications) by and packet name be verified, broadcast message processing module, will broadcast the message
It is sent to specific radio receiver, if system authentication failed, broadcast message reception module cannot receive broadcast message.
Embodiment two:
Packet name is verified, can be divided into and broadcast transmission side's packet name is verified and broadcast reception side's packet name is verified, this reality
It applies example and describes the specific embodiment verified to broadcast transmission side's packet name, basic implementation steps are identical as embodiment one, no longer in detail
Thin description, difference lies in:
As shown in figure 3, broadcast transmission side's packet name is verified, the specific steps are:
Include broadcast reception side's packet name in log-on message when broadcast reception side registers radio receiver in S1 steps,
The first packet list of file names that broadcast transmission side's packet name that also setting up allows to receive is constituted;
Broadcast message filter (IntentFilter) is responsible for filtering out the broadcast message that component cannot respond to and handle
The broadcast message Intent that oneself is concerned about only is received and is handled by Intent.In order to ensure radio receiver only receives
Broadcast message transmitted by specified broadcast transmission side needs to increase broadcast hair in broadcast message filter (IntentFilter)
The side of sending packet concrete number group membership defines:JAVA codes are as follows:
private ArrayList<String>mAllowPackages;
Application program where // restriction broadcast transmission side
Increase the interface function of addition broadcast transmission side's packet name simultaneously:
JAVA codes are as follows:
Broadcast reception side registration radio receiver be divided into dynamic registration and static registration, introduce separately below dynamic registration and
Static registration realization method.
Dynamic registration is realized:
The dynamic registration of broadcast message is the RegisterReceiver functions for calling ActivityManagerService
Come what is completed, subsidiary radio receiver entity (BroadcastReceiver) and broadcast message filter (IntentFilter).
In this way when calling the RegisterReceiver functions of ActivityManagerService, IntentFilter parameters are built
When, the addAllowPackage functions of IntentFilter can be called the packet name of specified application is arranged, to limit
Send the application program of broadcast message.
Static registration is realized:
The static registration of radio receiver is completed in the AndroidManifest.xml of application program, is also needed
Increase the Package titles of defining application, example is as follows:
Packet where application program is entitled " com.android.package1 ", defines one
It is " android.intent.action.TEST_STATE " that BroadcastReceiver, which is used for receiving broadcast message Action,
Limit send the broadcast message where application program packet entitled " com.android.package2 " and "
Com.android.package3 ", that is to say, that the broadcast message of only the two Package transmissions "
Android.intent.action.TEST_STATE " could allow to receive, the broadcast message that other all Package are sent
It will be filtered.
Due to " package " members belong to and newly increase, need to increase for " parsing of package ".
The member definition of AndroidManifest.xml needs to add wherein in attrs_manifest.xml " package " at
Member's definition:
In this way, when being parsed to XML, can be matched to " package " members, specific XML, which is parsed, to exist
In parseIntent functions in PackageParser.java, parseIntent functions are specifically used to parse
Member defined in InentFilter, needed in while cycles in the function addition for " processing of package " members,
It is specific as follows:
By parsing and matching " package " members, obtain the restriction in XML file for IntentFilter
Then Package titles call the addAllowPackage functions newly increased in IntentFilter to be sent extensively to be arranged to limit
Sender's packet name is broadcast, relevant information has just been stored in IntentFilter entities.
Only when application program is opened, parsing AndroidManifest.xml files can be just removed, and preserve and wherein broadcast
The information of receiver (BroadcastReceiver) and broadcast message filter (IntentFilter) is sent out when there is broadcast message
It when sending, needs to carry out broadcast message matching in these data, when closing application program, deletes the related letter of broadcast message
Breath.
In S3 steps, campaign management services match the first packet list of file names described in broadcast transmission side Bao Mingyu, if matching
Success, enters step S4, if it fails to match, broadcast reception side does not receive broadcast message.
Broadcast reception side is provided with the first packet that receivable broadcast transmission side's packet name is constituted when registering radio receiver
List of file names, broadcast transmission side are that ActivityManagerService sends Message function transmission message, system by calling
ActivityManagerService obtains corresponding radio receiver from register list, matches broadcast transmission side's packet name and note
Packet name the first packet list of file names set by volume radio receiver after successful match, could allow radio receiver reception corresponding
Broadcast message.In this way, the operation of application can be interfered with to avoid the broadcast message of personation is received.
As shown in figure 4, the transmitting-receiving to broadcast the message between application program in a kind of android system that the present embodiment is provided
System, it is essentially identical with embodiment one, difference lies in,
It broadcasts the message in registration module, also includes:
First packet name adds submodule, allows to receive broadcast transmission side's packet name for adding, constitutes the first packet list of file names;
Packet name authentication module also includes:
First verification submodule, for matching the first packet list of file names described in broadcast transmission side Bao Mingyu.
Broadcast reception side adds submodule when registering radio receiver, by the first packet name, and addition, which allows to receive, to be broadcasted
Sender's packet name constitutes the first packet list of file names, and campaign management services receive log-on message by receiving registration module, and pass through note
Volume information analysis module parses log-on message, therefore campaign management services obtain registered radio receiver and additional permission
Receive the first packet list of file names that broadcast transmission side's packet name is constituted.
The broadcast message sending module of campaign management services is called, is sent wide by sending calling module in broadcast transmission side
When broadcasting message, it includes sender's packet name to send information.
The first verification submodule in the packet name authentication module of campaign management services, for verifying broadcast transmission side Bao Mingyu
First packet list of file names just fills radio receiver reception broadcast perhaps and disappears there are sender's packet name in the first packet list of file names
Breath.
By this verification mode, the operation of application can be interfered with to avoid the broadcast message of personation is received.
Embodiment three
The present embodiment describes the specific embodiment verified to broadcast reception side's packet name.Basic implementation steps and embodiment one
It is identical, it is not described in detail, difference lies in:
As shown in figure 5, in S2 steps, when broadcast transmission side sends broadcast message, it includes to allow reception wide to send information
Broadcast the second packet list of file names that broadcast reception side's packet name of message is constituted;
Further include step after S2 steps:
S31, campaign management services match the second packet list of file names described in broadcast reception side Bao Mingyu, if successful match into
Enter step S4, if it fails to match, broadcast reception side does not receive broadcast message.
When sending broadcast message, pass through Binder remote interface tune ActivityManagerService's
BroadcastIntent functions are handled, and specific broadcast message is encapsulated in Intent data structures, in order to send broadcast
When message, broadcast reception side's packet name is specified, the interpolation data member in Intent is needed:
JAVA codes are as follows:
private HashSet<String>mAllowPackages;
Addition processing function is needed simultaneously:
JAVA codes are as follows:
When sending broadcast message structure Intent data structures, addAllowPackage functions can be called to add
Allow the Package titles for receiving the broadcast message application program.
By the above verification mode, when sending broadcast message, multiple application programs for allowing to receive can be specified, are avoided
Third party's Unknown Applications steal broadcast message.
As shown in fig. 6, the transmitting-receiving to broadcast the message between application program in a kind of android system that the present embodiment is provided
System, it is essentially identical with embodiment one, difference lies in,
Message sends calling module:
Second packet name adds submodule, allows to receive broadcast transmission side's packet name for adding, and constitutes the second packet list of file names, the
Two packets rank table organization in parameter.
Packet name authentication module also includes:
Second verification submodule, for matching the second packet list of file names described in broadcast reception side Bao Mingyu.
The broadcast message sending module of campaign management services is called to send broadcast by sending calling module in broadcast transmission side
When message, submodule is added by the second packet name, addition allows to receive the broadcast reception side's packet name to broadcast the message, constitutes the second packet
List of file names.
Campaign management services receive log-on message by receiving registration module, and are parsed and noted by log-on message parsing module
Therefore volume information, campaign management services obtain broadcast reception side's packet name.
The second verification submodule in the packet name authentication module of campaign management services, for verifying broadcast transmission recipient packet
Name and the second packet list of file names are just filled radio receiver perhaps and are received extensively there are recipient's packet name in the second packet list of file names
Broadcast message.
Example IV
The verification mode to sender's packet name is described in above example two, is described in embodiment three and recipient is wrapped
The verification mode of name, in the present embodiment, including both the above verification mode, specific verification and embodiment two, embodiment three-phase
Together, it is not described in detail, only all passes through there are two types of verification mode, just fill the radio receiver registered perhaps and receive broadcast message.
It solves the broadcast message for avoiding receiving personation to sender's packet name verification mode above, interferes with this application journey
The problem of operation of sequence, can specify multiple application programs for allowing to receive to recipient's packet name verification mode, avoid third party
Unknown Applications steal broadcast message.
Two kinds of verification modes are combined, both the above function can be completed at the same time, realize that the accurate of message sends and receives.
The above is only a preferred embodiment of the present invention, it is noted that for the ordinary skill people of the art
For member, various improvements and modifications may be made without departing from the principle of the present invention, these improvements and modifications are also answered
It is considered as protection scope of the present invention.