Broadcast message sending method, electronic device, storage medium and program product
By packaging and sending broadcast messages in the broadcast system, the number of interactions between the broadcast system and application processes is reduced, solving the problem of CPU resource consumption during broadcast message sending, and achieving more efficient CPU utilization and improved user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HONOR DEVICE CO LTD
- Filing Date
- 2024-11-12
- Publication Date
- 2026-05-12
AI Technical Summary
The broadcast message sending mechanism consumes a lot of central processing unit (CPU) resources, resulting in high power consumption of electronic devices.
By packaging broadcast messages from multiple broadcast receivers targeting the same event into a single package and sending them to the first application, which then sends them to each broadcast receiver one by one, the number of interactions between the broadcast system and the application process is reduced. This approach employs both blocking and non-blocking sending methods, and allows for ordered or unordered sending based on receiver priority.
It reduces CPU resource consumption, improves user experience, and ensures the correct delivery and priority handling of broadcast messages.
Smart Images

Figure CN122027993A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of terminal technology, and in particular to a method for transmitting broadcast messages, an electronic device, a storage medium, and a program product. Background Technology
[0002] Broadcasting is a crucial communication mechanism used to transmit information between applications or different components of an application. When a broadcast system receives a broadcast message, it can forward it to a broadcast receiver within the application that is listening for that message. The broadcast receiver can then perform appropriate processing based on the broadcast message.
[0003] Currently, the broadcast message sending mechanism consumes a significant amount of central processing unit (CPU) resources, which is detrimental to reducing the power consumption of electronic devices. Summary of the Invention
[0004] This application provides a method for transmitting broadcast messages, an electronic device, a storage medium, and a program product that can reduce the CPU resource consumption of electronic devices.
[0005] In a first aspect, a method for sending a broadcast message is provided, comprising: receiving a first broadcast message, wherein the first broadcast message targets a first broadcast event; if a first application includes multiple broadcast receivers for the first broadcast event, then sending a second broadcast message to the first application, wherein the second broadcast message includes the first broadcast message and list information of the multiple broadcast receivers; and sending the first broadcast message in the second broadcast message to the multiple broadcast receivers through the first application.
[0006] In this embodiment, when the broadcast system sends a broadcast message to the first application, it can package broadcast messages from broadcast receivers targeting the same event into a single package and send the packaged broadcast message (i.e., the second broadcast message) to the first application all at once. The first application then sends the broadcast messages one by one to the corresponding broadcast receivers. Compared to the previous approach where the broadcast system sends broadcast messages for multiple receivers to the first application multiple times, this embodiment reduces the number of interactions between the broadcast system and the application process, lowers CPU resource consumption, and improves user experience. Especially in ordered broadcast scenarios, it significantly reduces the number of interactions between the broadcast system and the application process, thus lowering CPU resource consumption.
[0007] In some implementations, the second broadcast message further includes first indication information, which indicates the sending method of the first broadcast message, including blocking sending and non-blocking sending.
[0008] By carrying the first instruction information in the second broadcast message, the first application can clearly specify how to send the first broadcast message to multiple broadcast receivers, which helps to ensure the correct transmission of the first broadcast message.
[0009] In some implementations, if the first broadcast message is sent in a blocking manner, then sending the first broadcast message in the second broadcast message to the plurality of broadcast receivers includes: selecting a first broadcast receiver from the plurality of broadcast receivers; sending the first broadcast message to the first broadcast receiver; after the first broadcast receiver has finished processing the first broadcast message, selecting a second broadcast receiver from the plurality of broadcast receivers; and sending the first broadcast message to the second broadcast receiver.
[0010] If the first broadcast message is sent in a blocking manner, the first application can iterate through multiple broadcast receiver lists and send the first broadcast message to multiple broadcast receivers in sequence. Only after one broadcast receiver has finished processing the first broadcast message will the first broadcast message be sent to the next broadcast receiver, thus ensuring the orderly transmission of the first broadcast message.
[0011] In some implementations, the method further includes: receiving a second indication message sent by the first application, the second indication message being used to instruct the broadcast system to resume the dispatch of broadcast messages, the second indication message being sent when the first application has sent the first broadcast message to all of the plurality of broadcast receivers and all of the plurality of broadcast receivers have completed processing the first broadcast message.
[0012] Since the first broadcast message is sent in a blocking manner, the first application can send a receipt message (i.e., the second indication information) to the broadcast system after multiple broadcast receivers have finished processing the first broadcast message, so that the broadcast system can clarify whether it can continue to send broadcast messages to the first application. This operation complies with the requirements of the broadcast mechanism.
[0013] In some implementations, if the first broadcast message is sent in a non-blocking manner, then sending the first broadcast message in the second broadcast message to the plurality of broadcast receivers includes: asynchronously sending the first broadcast message to each of the plurality of broadcast receivers.
[0014] If the first broadcast message is sent in a blocking manner, the first application can send the first broadcast message to multiple broadcast receivers asynchronously, so that multiple broadcast receivers can receive the first broadcast message almost simultaneously, thereby ensuring the out-of-order transmission of the first broadcast message.
[0015] In some implementations, the plurality of broadcast receivers have the same priority.
[0016] By packaging and sending broadcast messages from receivers with the same priority, it can be ensured that the first broadcast message is sent in order of priority. If other higher-priority broadcast messages are inserted, this method can also ensure that the higher-priority broadcast messages are sent first.
[0017] In some implementations, before sending the second broadcast message to the first application, the method further includes: obtaining a first broadcast receiver from a process broadcast queue management object, wherein the first broadcast receiver targets the first broadcast event; sending the second broadcast message to the first application includes: if there is a broadcast receiver in the process broadcast queue management object with the same priority as the first broadcast receiver and both targets the first broadcast event, then sending the second broadcast message to the first application.
[0018] The process broadcast queue management object in this application embodiment can provide a list of broadcast receivers with the same priority as the same event, so that the broadcast system can directly package broadcast messages according to the broadcast list information, thereby reducing the complexity of the broadcast system in packaging broadcast messages.
[0019] In some implementations, the method further includes: if there is no broadcast receiver in the process broadcast queue management object that has the same priority as the first broadcast receiver and is targeting the first broadcast event, then the first broadcast message is sent to the first broadcast receiver.
[0020] In some implementations, sending the first broadcast message to the first broadcast receiver includes: sending the first broadcast message to the first broadcast receiver through a first interface, wherein the first interface is an interface dedicated to dispatching broadcast messages to one broadcast receiver; sending the second broadcast message to the first application includes: sending the second broadcast message to the first application through a second interface, wherein the second interface is an interface dedicated to dispatching broadcast messages to multiple broadcast receivers.
[0021] This application embodiment adds a second interface dedicated to multiple broadcast receivers between the broadcast system and the application process, allowing the broadcast system to use different interfaces to send broadcast messages depending on the situation. For example, if the broadcast system needs to send a broadcast message to one broadcast receiver, it can do so through the first interface; if it needs to send a broadcast message to multiple broadcast receivers, it can do so through the second interface. Furthermore, the application process can also determine whether to send a broadcast message to one or multiple receivers based on the interface used to receive the broadcast message, thereby ensuring the smooth transmission of broadcast messages.
[0022] In some implementations, after sending the second broadcast message to the first application, the method further includes: recording the sending status of the second broadcast message, including whether an application non-response ANR was triggered.
[0023] In a second aspect, an electronic device is provided, comprising a unit consisting of software and / or hardware, the unit being used to perform any one of the methods in the technical solution of the first aspect.
[0024] Thirdly, a chip is provided, including a processor; the processor is used to read and execute a computer program stored in a memory to perform any of the methods described in the first aspect.
[0025] Optionally, the chip further includes a memory, which is connected to the processor via a circuit or wire.
[0026] Alternatively, the chip may further include a communication interface.
[0027] Fourthly, an electronic device is provided, comprising: a processor, a memory, and an interface; the processor, memory, and interface cooperate with each other to enable the electronic device to perform any one of the methods described in the first aspect; or to include any one of the chips described in the third aspect.
[0028] Fifthly, a computer-readable storage medium is provided, wherein a computer program is stored therein, and when the computer program is executed by a processor, the processor performs any one of the methods described in the first aspect.
[0029] In a sixth aspect, a computer program product is provided, the computer program product comprising: computer program code, which, when executed on an electronic device, causes the electronic device to perform any one of the methods described in the first aspect. Attached Figure Description
[0030] Figure 1This is a schematic diagram of the hardware structure of an electronic device 100 provided in an embodiment of this application;
[0031] Figure 2 This is a software system architecture diagram of the electronic device provided in the embodiments of this application;
[0032] Figure 3 This is a schematic diagram of a broadcast transmission mechanism provided in an embodiment of this application;
[0033] Figure 4 This is a schematic diagram of an unordered broadcast transmission mechanism provided in an embodiment of this application;
[0034] Figure 5 This is a schematic diagram of an ordered broadcast transmission mechanism provided in an embodiment of this application;
[0035] Figure 6 This is a schematic diagram illustrating the number of registered screen-on broadcast receivers in the electronic device provided in this application embodiment;
[0036] Figure 7 This is a schematic diagram of the orderly broadcast transmission process in related technologies;
[0037] Figure 8 This is a schematic diagram of the transmission process of disordered broadcasting in related technologies;
[0038] Figure 9 This is a schematic diagram illustrating the interaction process between a broadcast system and an app application process.
[0039] Figure 10 This is a flowchart illustrating the process of a broadcast system distributing broadcast messages.
[0040] Figure 11 This is a schematic flowchart illustrating a method for sending broadcast messages provided in an embodiment of this application;
[0041] Figure 12 This is a schematic diagram of an ordered broadcast transmission process provided in an embodiment of this application;
[0042] Figure 13 This is a schematic diagram of an out-of-order broadcast transmission process provided in an embodiment of this application;
[0043] Figure 14 This is a schematic diagram illustrating the process of a broadcast system distributing broadcast messages, provided in an embodiment of this application.
[0044] Figure 15 This is a structural block diagram of an application process and broadcast system provided in an embodiment of this application;
[0045] Figure 16 This is a schematic block diagram of an electronic device provided in an embodiment of this application;
[0046] Figure 17 This is a schematic diagram of the structure of a device provided in an embodiment of this application. Detailed Implementation
[0047] The technical solutions of the embodiments of this application will be described below with reference to the accompanying drawings. In the description of the embodiments of this application, unless otherwise stated, " / " means "or," for example, A / B can mean A or B; "and / or" in this text is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Furthermore, in the description of the embodiments of this application, "multiple" refers to two or more than two.
[0048] Hereinafter, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first," "second," or "third" may explicitly or implicitly include one or more of that feature.
[0049] The solution in this application embodiment is applied to a scenario where an electronic device sends broadcast messages. The electronic device involved in this application embodiment will be described below.
[0050] The electronic device in this application embodiment can be any electronic device with a broadcast mechanism. Such electronic device can be, for example, a mobile phone, tablet computer, PDA, wearable device, augmented reality (AR) / virtual reality (VR) device, etc. Wearable devices can include, for example, watches, bracelets, headphones, etc.
[0051] For example, Figure 1This is a schematic diagram of the structure of an electronic device 100 provided in an embodiment of this application. The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, a sensor module 180, buttons 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an accelerometer sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, etc.
[0052] The mobile communication module 150 may include one or more of second-generation (2G), 3G, 4G, and 5G communication modules. The mobile communication module 150 may include one or more of a filter, a switch, a power amplifier, and a low-noise amplifier (LNA).
[0053] The wireless communication module 160 may include one or more of the following: Bluetooth (BT) module, Wireless Local Area Network (WLAN) module, Global Navigation Satellite System (GNSS) module, Near Field Communication (NFC) module, Infrared (IR) module, and Frequency Modulation (FM) module. The wireless communication module 160 may be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via antenna 2, performs frequency modulation and filtering on the electromagnetic wave signals, and sends the processed signal to processor 110. The wireless communication module 160 can also receive signals to be transmitted from processor 110, perform frequency modulation and amplification on them, and then convert them into electromagnetic waves for radiation via antenna 2.
[0054] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0055] It is understood that the interface connection relationships between the modules illustrated in the embodiments of this application are merely illustrative and do not constitute a structural limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may also employ different interface connection methods or combinations of multiple interface connection methods as described in the above embodiments.
[0056] The following is combined with Figure 2 This application describes the software system architecture of the electronic device (such as a mobile phone) in the embodiments of this application. The software system of the device in the embodiments of this application can adopt a layered architecture, event-driven architecture, microkernel architecture, microservice architecture, or cloud architecture. This application embodiment takes the layered architecture Android system as an example to illustrate the software structure of the device.
[0057] Figure 2 This is a software architecture block diagram of the device according to an embodiment of this application. The layered architecture divides the software into several layers, each with a clear role and function. Layers communicate with each other through software interfaces. In some embodiments, the Android system can be divided into four layers, from top to bottom: the application (APP) layer, the application framework layer, the system (libraries) layer, the kernel layer, and the hardware layer.
[0058] like Figure 2 As shown, the application layer can include a series of application packages, which may include applications such as SMS, calendar, navigation, gallery, and calling.
[0059] The application framework layer provides application programming interfaces (APIs) and a programming framework for applications in the application layer. The application framework layer includes some predefined functions.
[0060] like Figure 2 As shown, the application framework layer can include a window manager, resource manager, phone manager, view system, broadcast system, etc. The broadcast system can also be called the broadcast framework system.
[0061] The window manager is used to manage window applications, including managing the window hierarchy and display order. The window manager can obtain the screen size, determine if a status bar is present, lock the screen, and capture the screen, among other things.
[0062] The file explorer provides applications with various resources, such as localized strings, icons, images, layout files, video files, etc.
[0063] A view system includes visual controls, such as controls for displaying text and controls for displaying images. View systems can be used to build applications. A display interface can consist of one or more views. For example, a display interface may include the display interface for a text notification icon, and views may include views for displaying text and views for displaying images.
[0064] A phone manager is used to provide communication functions for electronic devices. For example, a phone manager can be used to manage call status (including when a call is connected, when a call is disconnected, etc.).
[0065] AMS is responsible for managing four main components of the Android system. These four components are: Activities within the application layer, the broadcast system, services, and content providers within the application framework layer.
[0066] In this context, an Activity represents the display layer of an application. Each Activity typically corresponds to a screen and is used to display the user interface and handle user interactions. Activities can communicate with each other.
[0067] Broadcast systems are used to receive broadcast messages sent by the system or other applications and respond as needed. Broadcast systems can also be used to process system events or application events.
[0068] The service is used to perform long-running operations in the background, such as playing music or downloading files. It does not provide a user interface, but it can communicate with the Activity in the background.
[0069] Content providers are used to share data, such as information in a database, between different applications, allowing other applications to access and manipulate the shared data.
[0070] AMS includes the Active Services module and the BroadcastQueuelmpl module. AMS can manage running services through Active Services, and it can also manage broadcast messages in the broadcast system through BroadcastQueuelmpl. BroadcastQueuelmpl can also be referred to as the process broadcast queue management object.
[0071] The system layer includes the Android Runtime and system libraries. The Android Runtime includes core libraries and a virtual machine. The Android Runtime is responsible for the scheduling and management of the Android system. The core libraries consist of two parts: one part contains the functionalities that the Java language needs to call, and the other part contains the core Android libraries.
[0072] The application layer and application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and application framework layer as binary files. The virtual machine is used to perform functions such as object lifecycle management, stack management, thread management, security and exception management, and garbage collection.
[0073] The system layer can include multiple functional modules. For example: surface manager, media libraries, 3D graphics processing libraries (e.g., OpenGL ES), 2D graphics engines (e.g., SGL), etc.
[0074] The Surface Manager is used to manage the display subsystem and provides the blending of two-dimensional and three-dimensional layers for multiple applications.
[0075] The media library supports playback and recording of various common audio and video formats, as well as still image files. It supports multiple audio and video encoding formats, such as MPEG4, H.164, MP3, AAC, AMR, JPG, and PNG.
[0076] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0077] A 2D graphics engine is a drawing engine for 2D drawing.
[0078] The kernel layer is the layer between hardware and software. It contains at least display drivers and sensor drivers. The display driver drives the display screen, while the sensor driver drives the sensors.
[0079] The hardware layer includes at least physical devices such as a display screen and sensors. The sensors may include pressure sensors, gyroscopes, accelerometers, distance sensors, proximity sensors, fingerprint sensors, etc. The functions of each sensor are not described in detail in this embodiment.
[0080] Broadcasting is a crucial communication mechanism used to transmit information between applications or different components of an application. A broadcast is a message that applications can both send and receive. Broadcasts are used to notify applications of events such as system startup, low battery, or network status changes. Broadcast messages can be sent by applications or by the system itself.
[0081] A key component of broadcast mechanisms is the broadcast receiver, which listens for system broadcasts or application-specific broadcasts and receives and processes them when they occur. Broadcast receivers can be used to enable communication between components, both within the same application and between different applications.
[0082] The program's process can register a broadcast receiver with the broadcast system. After registration is complete, the broadcast receiver can receive broadcasts dispatched by the broadcast system. There are two ways to register a broadcast receiver: static registration and dynamic registration.
[0083] Static registration involves declaring broadcast receivers in a file (such as AndroidManifest.xml). This means the broadcast receivers are registered when the application is installed and do not need to be manually registered or unregistered at runtime. Static registration is suitable for scenarios that listen for global broadcasts or need to receive broadcasts throughout the entire lifecycle of the application. Static-registered broadcast receivers can still receive broadcasts even when the application is not running.
[0084] Dynamic registration involves registering broadcast receivers in code (such as Java code). This means that broadcast receivers need to be manually registered and unregistered at runtime, typically at specific times or within specific pages / components. Dynamic registration is suitable for temporary broadcast receiving needs, such as listening for broadcasts only under specific conditions, or listening for broadcasts within a specific activity or fragment.
[0085] When an application process registers a broadcast receiver, it can specify to the broadcast system the broadcast messages that the receiver can receive and process. When a corresponding broadcast message arrives at the broadcast system, the broadcast system can send that broadcast message to the broadcast receiver. For example, when registering a broadcast receiver with the broadcast system, the application process can indicate to the broadcast system the broadcast event that the receiver is targeting. When the broadcast system receives a broadcast message for that event, it can send that broadcast message to the broadcast receiver.
[0086] In some implementations, the broadcast system can be, for example, the Activity Manager Service (AMS) broadcast system. The AMS broadcast system is a key service of the operating system, responsible for managing and scheduling the lifecycle and interactions of application components. In broadcast scenarios, the AMS broadcast system is responsible for registration management and broadcast distribution. The AMS broadcast system is also known as the AMS broadcast framework system.
[0087] Registration Management: The broadcast system is responsible for recording and managing all broadcast receivers dynamically registered by applications. When an application registers a broadcast receiver, the broadcast system adds it to the list of broadcast receivers and is responsible for sending a broadcast to the appropriate broadcast receiver when it receives a broadcast.
[0088] Broadcast distribution: When a broadcast system receives a broadcast, it is responsible for distributing the broadcast to all broadcast receivers that have registered to match the broadcast action. This ensures that only broadcast receivers that have registered to listen for the corresponding broadcast action will receive the broadcast.
[0089] AMS is responsible for managing four main components of the Android system. These four components are: activities within the application layer, the broadcast system, services, and content providers within the application framework layer.
[0090] An application process can register multiple broadcast receivers with a broadcast receiver. These multiple broadcast receivers can be for different broadcast events or for the same broadcast event; this application embodiment does not specifically limit this. The broadcast event involved in this application embodiment can also be referred to as a broadcast service.
[0091] Figure 3 A schematic diagram of a broadcast transmission process is shown.
[0092] See Figure 3 In step S310, application A can register broadcast receiver 1 with the broadcast system and specify that the broadcast receiver is for broadcast event 1.
[0093] In step S320, application B sends a broadcast message to the broadcast system, which is directed at broadcast event 1.
[0094] In step S330, after receiving the broadcast message, the broadcast system determines that the broadcast message is for broadcast event 1, and then sends the broadcast message to broadcast receiver 1 in application A.
[0095] The data structure for transmitting broadcast messages is an intent. Broadcast receivers can use a filter function to select the broadcast receiver 1 corresponding to broadcast event 1. The broadcast system can send broadcast messages to application A through the binder interface.
[0096] Figure 3 This description uses broadcast messages sent by applications as an example to illustrate the broadcast message sending process, but the embodiments of this application are not limited to this. Besides broadcast messages sent by applications, the broadcast messages in these embodiments can also be system broadcasts. Taking screen-on broadcast as an example, the screen-on broadcast can be sent from the power management system to the broadcast system, which can then distribute the screen-on broadcast to applications that require it.
[0097] The following section uses system broadcasts as an example to introduce the types of broadcast messages.
[0098] ACTION_BOOT_COMPLETED: This broadcast is sent after the device completes the boot process. The broadcast receiver can perform some initialization operations upon receiving this broadcast.
[0099] ACTION_POWER_CONNECTED: This broadcast is sent when the device is connected to power.
[0100] ACTION_POWER_DISCONNECTED: This broadcast is sent when the device is disconnected from power.
[0101] ACTION_BATTERY_LOW: This broadcast is sent when the device battery level is below the warning threshold.
[0102] ACTION_BATTERY_OKAY: This broadcast is sent when the device's battery level returns to normal, indicating that the device is no longer in a low-battery state.
[0103] ACTION_SCREEN_ON: This broadcast is sent when the device's screen is turned on.
[0104] ACTION_SCREEN_OFF: This broadcast is sent when the device screen is off.
[0105] ACTION_USER_PRESENT: This broadcast is sent when a user unlocks the device and enters the home screen.
[0106] ACTION_TIME_TICK: A broadcast sent every minute, which can be used to update the time display in the UI.
[0107] ACTION_PACKAGE_ADDED: This broadcast is sent when a new application is installed.
[0108] ACTION_PACKAGE_REMOVED: This broadcast is sent when the application is uninstalled.
[0109] ACTION_PACKAGE_REPLACED: This broadcast is sent when an application is replaced during installation.
[0110] ACTION_MEDIA_MOUNTED: This broadcast is sent when an external storage device (such as an SD card) is mounted.
[0111] ACTION_MEDIA_UNMOUNTED: This broadcast is sent when an external storage device is unmounted.
[0112] ACTION_HEADSET_PLUG: This broadcast is sent when headphones are plugged in or unplugged.
[0113] ACTION_NEW_OUTGOING_CALL: This broadcast is sent when a new phone number is dialed.
[0114] ACTION_ANSWER: This broadcast is sent when a call is answered.
[0115] ACTION_CALL_STATE_CHANGED: This broadcast is sent when the telephone status (ringing, answering, hanging up, etc.) changes.
[0116] Broadcast messages can be sent in either ordered or unordered manner. Ordered sending is also known as blocking sending, and unordered sending is also known as non-blocking sending. Unordered broadcasts can be called unordered broadcasts, standard broadcasts, or normal broadcasts. Ordered broadcasts can be called ordered broadcasts.
[0117] Out-of-order broadcasts are transmitted entirely asynchronously; all broadcast receivers receive the broadcast message almost simultaneously, and the order of reception is unpredictable. The main characteristic of out-of-order broadcasts is their high transmission speed, because broadcast messages do not need to wait for other receivers to finish processing before continuing transmission.
[0118] by Figure 4For example, if broadcast receiver 1, broadcast receiver 2, and broadcast receiver 3 are all targeting the same broadcast event, such as broadcast event 1, and the broadcast system receives a broadcast message for broadcast event 1, if the broadcast message is sent out of order, the broadcast system can send the broadcast message asynchronously to broadcast receiver 1, broadcast receiver 2, and broadcast receiver 3. Broadcast receiver 1, broadcast receiver 2, and broadcast receiver 3 can receive the broadcast message almost simultaneously.
[0119] Ordered broadcasts are transmitted synchronously; a broadcast receiver receives and processes a broadcast before it is passed on to the next receiver. A broadcast receiver can modify the broadcast data or truncate (or abort) the broadcast, preventing it from being passed on to other receivers. Ordered broadcasts allow the receiving order of receivers to be controlled by setting priorities; higher-priority receivers receive broadcasts first. Receivers with the same priority can receive broadcasts in a random or registered order.
[0120] by Figure 5 For example, broadcast receivers 4, 5, and 6 all target the same broadcast event, such as broadcast event 2. When the broadcast system receives a broadcast message for broadcast event 2, if the broadcast message is sent in an ordered manner, the broadcast system can send the broadcast message to the broadcast receivers according to their priority order. Assuming the priority of the broadcast receivers from high to low is broadcast receiver 4 → broadcast receiver 5 → broadcast receiver 6, the broadcast system will first send the broadcast message to broadcast receiver 4. After broadcast receiver 4 processes the broadcast message, it will then send the broadcast message to broadcast receiver 5. After broadcast receiver 5 processes the broadcast message, it will then send the broadcast message to broadcast receiver 6, and so on.
[0121] Broadcast receivers 4 and 5, which have higher priority, can truncate broadcast messages. If broadcast receiver 4 truncates a broadcast message, the broadcast system will no longer send the broadcast message to broadcast receivers 5 and 6; that is, broadcast receivers 5 and 6 will not receive the broadcast message. If broadcast receiver 5 truncates a broadcast message, the broadcast system will no longer send the broadcast message to broadcast receiver 6; that is, broadcast receiver 6 will not receive the broadcast message.
[0122] If a broadcast receiver needs to truncate a broadcast message, it can send a truncation instruction to the broadcast system. Upon receiving this instruction, the broadcast system will stop sending broadcast messages to the broadcast receiver.
[0123] The method of sending a broadcast message can be determined based on the process sending the broadcast message (denoted as process 1) and the broadcast system. Process 1 can specify the sending method when sending a broadcast message to the broadcast system. Additionally, Process 1 can specify whether it needs to obtain the broadcast message's delivery completion status when sending the broadcast message. The broadcast system can determine the broadcast message's sending method based on the sending method specified by Process 1 and / or whether Process 1 needs to obtain the broadcast message's delivery completion status.
[0124] For example, if process 1 specifies ordered delivery as the sending method, the broadcast system determines that the broadcast message is sent in ordered order. Conversely, if process 1 specifies out-of-order delivery as the sending method, and process 1 needs to obtain the completion status of the broadcast message's delivery, the broadcast system determines that the broadcast message is sent in ordered order. And again, if process 1 specifies out-of-order delivery as the sending method, and process 1 does not need to obtain the completion status of the broadcast message's delivery, the broadcast system determines that the broadcast message is sent out of order.
[0125] The processing of broadcast messages by a broadcast receiver includes one or more of the following operations: reading data from the broadcast message, performing a specific operation, or triggering a response from other components.
[0126] During the broadcast load analysis of electronic devices, it was found that many applications dynamically registered multiple broadcast receivers for the same event. These applications included system applications and third-party applications. Figure 6 Taking the screen-on broadcast receiver as an example, this demonstrates the number of applications that register screen-on broadcast receivers (i.e., broadcast receiver clients).
[0127] After an application process registers a broadcast receiver with the broadcast system, the broadcast system can maintain a list of broadcast receivers. It's important to note that the broadcast system doesn't necessarily maintain a direct list of broadcast receivers; instead, it maintains a list of proxy objects corresponding to each broadcast receiver. One broadcast receiver corresponds to one proxy object. If an application process registers five broadcast receivers with the broadcast system, the broadcast system will maintain information about the five proxy objects corresponding to those five broadcast receivers.
[0128] A broadcast system can include a process broadcast queue management object. Information about proxy objects can be maintained by the process broadcast queue management object. The process broadcast queue management object can maintain information such as the priority of the proxy object and the broadcast events it targets. The priority of the proxy object is the same as the priority of the broadcast receiver.
[0129] A process broadcast queue management object can maintain proxy objects corresponding to broadcast receivers in a process, and different process broadcast queue management objects can maintain proxy objects corresponding to broadcast receivers in different processes.
[0130] The proxy object corresponding to the broadcast receiver will also be referred to as the broadcast receiver proxy object.
[0131] If an application process registers multiple broadcast receivers for the same event with the broadcast system, the broadcast system needs to send the broadcast message to the application process multiple times to complete the delivery of the broadcast message.
[0132] Figure 7 and Figure 8 The diagram illustrates the process of a broadcast system sending broadcast messages to an application process in both ordered and unordered delivery scenarios.
[0133] In an ordered delivery scenario, the broadcast system sequentially traverses the list of broadcast receiver proxy objects and sends broadcast messages to the application process. After the application process processes the broadcast messages, it sends an acknowledgment to the broadcast system to instruct the broadcast system to continue distributing broadcasts.
[0134] See Figure 7 The APP1 application process registered five screen-on broadcast receivers and one broadcast receiver for "another event type". The broadcast system has an APP1 application process broadcast queue management object, which manages the list of broadcast proxy objects corresponding to the APP1 application process.
[0135] The logic of the broadcast system dispatching broadcasts to the APP1 application process is as follows: Figure 7 As shown. After the broadcast system receives the screen-on broadcast from the power management system, the APP1 application process's broadcast queue management object traverses the list of broadcast receiver proxy objects and selects the highest priority APP1-screen-on broadcast receiver proxy object 1. The broadcast system then sends the screen-on broadcast to screen-on broadcast receiver 1 (see number ①). After screen-on broadcast receiver 1 processes the screen-on broadcast, the APP1 application process can send an acknowledgment message to the broadcast system (see number ②) to notify that the screen-on broadcast has been processed. The APP1 application process's broadcast queue management object continues to traverse the list of broadcast receiver proxy objects and selects APP1-screen-on broadcast receiver proxy object 2 according to priority. The broadcast system then sends the screen-on broadcast to screen-on broadcast receiver 2 (see number ③). After screen-on broadcast receiver 2 processes the screen-on broadcast, the APP1 application process can send an acknowledgment message to the broadcast system (see number ④) to notify that the screen-on broadcast has been processed. The APP1 application process's broadcast queue management object continues to traverse the list of broadcast receiver proxy objects. Based on priority, it selects APP1-screen-on broadcast receiver proxy object 3. The broadcast system sends a screen-on broadcast to screen-on broadcast receiver 3 (see number ⑤). After screen-on broadcast receiver 3 finishes processing the screen-on broadcast, the APP1 application process can send an acknowledgment message to the broadcast system (see number ⑥) to notify that the screen-on broadcast has been processed.
[0136] Since the broadcast system receives a higher-priority "other event broadcast" from a certain service after sending a screen-on broadcast to screen-on broadcast receiver 3, the broadcast system, upon receiving the acknowledgment message corresponding to number ⑥, sends the "other event broadcast" to other event broadcast receiver 1 (see number ⑦). After other event broadcast receiver 1 processes the "other event broadcast," the APP1 application process sends an acknowledgment message to the broadcast system. Upon receiving the acknowledgment, the broadcast system continues to dispatch screen-on broadcasts, following the process described by numbers ⑨, ⑩, ...
[0137] Depend on Figure 4 As can be seen, broadcasts dispatched to a process are generally dispatched in order of priority, but broadcasts with higher priority or higher urgency can be inserted.
[0138] exist Figure 7 In the scheme shown, since APP1-screen-on broadcast receiver proxy object 1, APP1-screen-on broadcast receiver proxy object 2, APP1-screen-on broadcast receiver proxy object N, APP1-screen-on broadcast receiver proxy object N+1, and APP1-screen-on broadcast receiver proxy object N+1 have the same priority (priority 11), the broadcast system can randomly select a broadcast receiver from these proxy objects to send the broadcast when sending a screen-on broadcast.
[0139] For out-of-order broadcasts, the broadcast system controls the entire traversal logic within the system process. In scenarios where a process registers multiple broadcast receivers, the broadcast system sequentially traverses the list of broadcast receiver proxy objects and sends broadcasts to the application process. The application process handles the broadcast events; this process does not require the application process to acknowledge the broadcast system.
[0140] See Figure 8 The APP1 application process registered 5 unordered broadcast receivers. The broadcast system has a broadcast queue management object for the APP1 process, used to manage the list of broadcast proxy objects dispatched to the APP1 process. The logic for the broadcast system dispatching broadcast messages to the APP1 process is as follows: Figure 8 As shown.
[0141] The APP1 process's broadcast queue management object iterates through the list of broadcast proxy objects to obtain the five out-of-order broadcast receivers mentioned above. The broadcast system calls the binder interface to send broadcast messages to each of the five out-of-order broadcast receivers, as shown in steps ①, ②, ③, ④, and ⑤. After the broadcast system sends broadcast messages to the five out-of-order broadcast receivers, the out-of-order broadcast dispatch is complete.
[0142] The following section uses ordered broadcasting as an example to provide a detailed introduction to the interaction between the broadcasting system and the APP application process, as well as the APP application process's handling of broadcast messages.
[0143] The interface between the broadcast system and the APP application process is the binder interface.
[0144] Figure 9 This illustrates the process of a broadcast system dispatching broadcasts to application processes. The broadcast system and application processes communicate via the binder interface.
[0145] In the introduction Figure 9 Before presenting the proposed scheme, let's first introduce some parameters of the broadcast mechanism.
[0146] `onReceive` handles received broadcasts. `performReceive` executes when `onReceive` is called and is responsible for passing the received broadcast content (Intent) to `onReceive`. `RegisteredReceiver` registers a broadcast receiver to listen for specific broadcasts. `scheduleRegisteredReceiver` schedules registered broadcast receivers. `Filter` defines the receiving conditions for the broadcast receiver. `LoadedApk` is a class containing information about the loaded application.
[0147] Taking the screen-on broadcast and AMS broadcast system as examples, the power management system sends a screen-on broadcast to the AMS broadcast system, indicating that the broadcast is sent in an unordered manner, but requires obtaining the completion status of the distribution. Since the power management system needs to obtain the completion status of the screen-on broadcast, the AMS broadcast system needs to send the broadcast in an ordered manner. The AMS broadcast system sequentially traverses the list of broadcast receiver proxy objects, sending the screen-on broadcast serially to each broadcast receiver.
[0148] For dispatching screen-on broadcasts, the AMS broadcast system first calls the binder interface `scheduleRegisteredReceiver` to notify the application process. Then, the application process, within its framework, forwards the binder message to a broadcast processing thread for handling. After processing, the broadcast processing thread calls the binder interface `finishReceiver` to notify the broadcast system. Upon receiving the acknowledgement, the broadcast system checks if the current process's broadcast queue management object can continue dispatching. If dispatching can continue, broadcast dispatching resumes.
[0149] See Figure 9In step S902, when a broadcast message arrives at the broadcast system, the process broadcast queue management object (BroadcastQueueModemlmpl) obtains the relevant information of broadcast receiver 1 (or the process broadcast queue management object calls the scheduleRegisteredReceiver function), and calls the binder interface scheduleRegisteredReceiver to send a broadcast message (binder message) to the application process.
[0150] In step S904, the application process receives the binder message and forwards it to an activity thread for processing. The activity thread can then call a LoadedApk based on the binder message.
[0151] In step S906, LoadedApk executes an asynchronous task. LoadedApk can redirect broadcast messages to a thread registered with broadcast receiver 1 for processing. For example, LoadedApk can schedule the onReceive function. Broadcast receiver 1 then processes the broadcast message.
[0152] In step S908, after the broadcast receiver 1 finishes processing the broadcast message, LoadedApk calls the binder interface finishReceiver to send an acknowledgment message to the broadcast system (or the application process calls the finishReceiver function) to indicate that the broadcast receiver 1 has finished processing the broadcast message and the broadcast system can continue to send broadcasts.
[0153] In step S910, after the broadcast system receives the acknowledgment message, the process broadcast queue management object continues to traverse the list of broadcast receivers, selects the next broadcast receiver, that is, obtains the relevant information of broadcast receiver 2 (or the process broadcast queue management object calls the scheduleRegisteredReceiver function), and calls the binder interface scheduleRegisteredReceiver to send a broadcast message (binder message) to the application process.
[0154] In step S912, the application process receives the binder message and transfers it to a processing thread for processing. The active thread can invoke a LoadedApk based on the binder message.
[0155] In step S914, LoadedApk executes an asynchronous task. LoadedApk can redirect broadcast messages to a thread registered with broadcast receiver 1 for processing. For example, LoadedApk can schedule the onReceive function. Broadcast receiver 2 then processes the broadcast message.
[0156] In step S916, after the broadcast receiver 2 finishes processing the broadcast message, LoadedApk calls the binder interface finishReceiver to send an acknowledgment message to the broadcast system (or the application process calls the finishReceiver function) to indicate that the broadcast receiver 2 has finished processing the broadcast message and the broadcast system can continue to send broadcasts.
[0157] In step S918, after the broadcast system receives the acknowledgment message, the process broadcast queue management object continues to traverse the list of broadcast receivers, selects the next broadcast receiver, and calls the binder interface scheduleRegisteredReceiver to send a broadcast message (binder message) to the application process. The above steps are repeated to continue dispatching the broadcast message.
[0158] Figure 10 This is a schematic diagram of a broadcast message sending process provided in an embodiment of this application.
[0159] See Figure 10 In step S1010, when the broadcast system receives a broadcast message, it determines whether the process broadcast queue management object can dispatch a broadcast. For example, the broadcast system can determine whether a broadcast receiver in the process broadcast queue management object needs to receive the broadcast message. If a broadcast receiver in the process broadcast queue management object needs to receive the broadcast message, it indicates that the process broadcast queue management object can dispatch a broadcast; if no broadcast receiver in the process broadcast queue management object needs to receive the broadcast message, it indicates that the process broadcast queue management object cannot dispatch a broadcast.
[0160] If the process broadcast queue management object cannot dispatch broadcasts, the process ends; if the process broadcast queue management object can dispatch broadcasts, proceed to step S1020.
[0161] In step S1020, the process broadcast queue management object acquires a broadcast receiver.
[0162] In step S1030, the process broadcast queue management object calls the binder interface to dispatch the broadcast message to the broadcast receiver.
[0163] In step S1040, the broadcast system records both normal and abnormal transmission of broadcast messages. For example, the broadcast system can record whether a broadcast message triggers an application not responding (ANR). If the broadcast system sends a broadcast message to the broadcast receiver, and the broadcast receiver fails to process it within a predetermined event or fails to acknowledge the broadcast system within a predetermined time, an ANR will be triggered.
[0164] In step S1050, the broadcast system determines whether the broadcast message is sent in a blocking mode.
[0165] If the broadcast message is sent in a blocking manner, the process ends. If the broadcast message is sent in a non-blocking manner, steps S1030 to S1040 continue to be executed in a loop until the broadcast message has been sent to all broadcast receivers.
[0166] Depend on Figure 7 and Figure 8 As shown in the flowchart, when an application process registers multiple broadcast receivers listening for the same event type, the broadcast system needs to send broadcast messages to the application process multiple times. This means the broadcast system needs to interact with the application process multiple times, which consumes significant CPU resources. Especially for ordered broadcasts, the application process needs to send an acknowledgment to the broadcast system every time it sends a broadcast message, increasing the number of interactions between the broadcast system and the application process, further increasing CPU resource consumption.
[0167] by Figure 9 For example, the cross-process interaction between system processes and application processes involves a large number of cross-process binder scheduling operations for scheduleRegisteredReceiver and finishReceiver, resulting in significant CPU resource consumption by the system process.
[0168] In addition, for multiple broadcast scheduling, on the application framework side, it is necessary to go through the broadcast dispatch process of ActivityThread and LoadedApk class, and the binder call message needs to be transformed and encapsulated into an asynchronous task multiple times and transferred to the broadcast processing thread for scheduling. This process also requires the application process to consume some CPU resources.
[0169] Both of these CPU resource consumption components are caused by the broadcast dispatch framework logic. Application business logic cannot optimize this, and as application business features increase, the number of broadcast receivers for the same event type inevitably grows. For example, as shown in Table 1, a screen-on broadcast needs to be dispatched to 100 broadcast receivers. Many system processes and third-party application processes have numerous screen-on broadcast receivers. As the system and applications grow, the number of times the broadcast system needs to dispatch screen-on broadcasts will increase, leading to increased CPU resource consumption. An increase in the number of registered broadcast receivers will increase the overall background CPU resource consumption, making it difficult to guarantee foreground resource supply, which may result in a noticeable deterioration in the user's basic experience.
[0170] To address the aforementioned issues, this application provides a method and apparatus for sending broadcast messages. The broadcast system can package broadcast messages from broadcast receivers within an application process that target the same event type and send them to the application process all at once. Compared to the solutions in the related technologies described above, this process reduces the number of interactions between the broadcast system and the application process, thereby avoiding resource consumption caused by multiple interactions. This helps reduce CPU resource consumption of both the broadcast system and the application process, and improves the basic user experience.
[0171] The following is combined with Figure 11 The present application provides a detailed description of the method for sending broadcast messages according to its embodiments.
[0172] The method for sending broadcast messages in this application embodiment can be applied to electronic devices, which can be any of the electronic devices mentioned above.
[0173] In some implementations, the electronic device may include a first application. The first application can be any application in the electronic device; it can be a system application or a third-party application.
[0174] The first application includes a first process that can handle broadcast-related operations. For example, the first process can register a broadcast receiver with the broadcast system. It can also receive broadcast messages sent by the broadcast system, or send acknowledgment messages to the broadcast system.
[0175] The first application may include one or more processes. If the first application includes multiple processes, the first process may be any one of the multiple processes.
[0176] In some implementations, the electronic device may include a broadcast system. This broadcast system could be, for example, an AMS broadcast system. The broadcast system is responsible for the registration and management of broadcast receivers and the distribution of broadcast messages.
[0177] See Figure 11 In step S1110, the first broadcast message is received.
[0178] The first broadcast message can be sent by an application in the electronic device or by the system; this application embodiment does not specifically limit this. Taking a screen-on broadcast as an example, the first broadcast message can be sent by the power management system. The power management system can send the screen-on broadcast to the broadcast system. The receiver of the first broadcast message is the broadcast system.
[0179] The first broadcast message refers to a broadcast event, also known as a first broadcast event. A first broadcast event can be a system event or an application event. In some embodiments, the first broadcast event can be one or more of the following: screen on broadcast event, screen off broadcast event, low battery broadcast event, application uninstallation broadcast event, new application installation broadcast event, headphone plug-in broadcast event, headphone unplugged broadcast event, dialing a phone call broadcast event, answering a phone call broadcast event, a phone status change broadcast event, time update broadcast event, message received broadcast event, and message sent broadcast event.
[0180] In step S1120, if the first application includes multiple broadcast receivers for the first broadcast event, a second broadcast message is sent to the first application.
[0181] If the first application includes multiple broadcast receivers for the first broadcast event, the broadcast system sends a second broadcast message to the first application.
[0182] The broadcast event targeted by multiple broadcast receivers is the first broadcast event, which can also be understood as the broadcast message listened to by multiple broadcast receivers being the first broadcast message.
[0183] The registration methods for multiple broadcast receivers can include static registration and / or dynamic registration. For example, multiple broadcast receivers may all be registered using dynamic registration. Alternatively, multiple broadcast receivers may all be registered using static registration. Yet another example is where some broadcast receivers are registered using static registration and others using dynamic registration.
[0184] In some implementations, the first application may send a registration request to the broadcast system to request registration of a broadcast receiver for the first broadcast event. In other implementations, the first application may register multiple broadcast receivers with the broadcast system for different services or different application characteristics, and these multiple broadcast receivers may be targeting the same broadcast event.
[0185] When a first application (or the first process in the first application) registers multiple broadcast receivers with the broadcast system, it can indicate to the broadcast system the broadcast events that the multiple broadcast receivers are targeting, so that the broadcast system can send the matching broadcast message to the corresponding broadcast receiver.
[0186] The second broadcast message may include a list of multiple broadcast receivers so that the first application can specify which broadcast receivers to which the first broadcast message is sent.
[0187] In some implementations, the broadcast system may not directly store the information of the broadcast receivers, but instead store the information of the proxy objects corresponding to the broadcast receivers. That is, the broadcast system can store a list of multiple proxy objects corresponding to multiple broadcast receivers, where each proxy object corresponds one-to-one with a different broadcast receiver. In this case, the second broadcast message can include the list of multiple proxy objects corresponding to multiple broadcast receivers.
[0188] After the first process registers multiple broadcast receivers with the broadcast system, the broadcast system can store information about the proxy objects corresponding to these receivers. This proxy object information can include the broadcast event the proxy object targets and the proxy object's priority. The proxy object's priority is the same as the broadcast receiver's priority. The broadcast receiver's priority can be specified by the broadcast receiver itself. When registering, the broadcast receiver can specify its priority for receiving broadcast messages.
[0189] The second broadcast message may include the first broadcast message so that the broadcast receiver can process the first broadcast message. For example, the broadcast receiver may read data from the first broadcast message, perform a specific operation, or trigger a response from other components.
[0190] Taking the screen-on broadcast as an example, the broadcast system can package the screen-on broadcast and the list of proxy objects corresponding to the broadcast receivers listening to the screen-on broadcast into a second broadcast message. The second broadcast message is the packaged broadcast message.
[0191] In step S1130, the first broadcast message in the second broadcast message is sent to multiple broadcast receivers through the first application.
[0192] If the second broadcast message includes a list of multiple proxy objects, the first process can determine multiple broadcast receivers based on the list of multiple proxy objects and the correspondence between the proxy objects and the broadcast receivers, and send the first broadcast message to the multiple broadcast receivers.
[0193] After the first process registers a broadcast receiver with the broadcast system, it can obtain information about the proxy object corresponding to the broadcast receiver and store the correspondence between the broadcast receiver and the proxy object. Upon receiving a second broadcast message, the first process can determine which broadcast receivers the second broadcast message is intended for based on this correspondence.
[0194] In this embodiment, when the broadcast system sends a broadcast message to the first process, it can package broadcast messages from broadcast receivers targeting the same event into a single package and send the packaged broadcast message (i.e., the second broadcast message) to the first process all at once. The first process then sends the broadcast messages one by one to the corresponding broadcast receivers. Compared to the previous method where the broadcast system sends broadcast messages for multiple broadcast receivers to the first process multiple times, this embodiment reduces the number of interactions between the broadcast system and the application process, lowers CPU resource consumption, and improves user experience. Especially in ordered broadcast scenarios, it significantly reduces the number of interactions between the broadcast system and the application process, thus lowering CPU resource consumption.
[0195] The following example illustrates the effects of the embodiments of this application. For an application process, there are two ways to perform the same task.
[0196] Method 1: The application process registers 10 broadcast receivers that listen for the same event type. Each broadcast receiver handles one business function, such as printing a log.
[0197] Method 2: The application process registers a broadcast receiver with the same event type, and processes and prints 10 logs in the broadcast receiver's processing interface.
[0198] Comparative analysis showed that Method 1 consumes more CPU resources than Method 2. This is because multiple broadcast receivers, compared to a single broadcast receiver, increase cross-process interaction between the system and the application, resulting in more cross-process binder scheduling of `scheduleRegisteredReceiver` and `finishReceiver`, thus increasing the CPU resource consumption of the system processes.
[0199] In addition, multiple broadcast schedulings require the application framework to go through the ActivityThread and LoadedApk class broadcast dispatch process. This involves transforming and encapsulating the binder call message into an asynchronous task multiple times and then transferring it to the broadcast processing thread for scheduling. This process also consumes some CPU resources for the application process.
[0200] For ordered broadcasting, Method 1 requires 20 interactions between the system and application processes, while Method 2 only requires 2 interactions. This reduction in interactions significantly lowers CPU resource consumption. Furthermore, in Method 1, the application process needs to transform and encapsulate 10 binder messages to complete the processing task, while in Method 2, it only needs to transform and encapsulate 1 binder message. This reduction in transformation and encapsulation also lowers CPU resource consumption.
[0201] The solution in this application is similar to Method 2, and the solution in related technologies is similar to Method 1. This application reduces CPU resource consumption by reducing the number of interactions between the broadcast system and the application process, as well as the number of times the application process converts and encapsulates binder messages.
[0202] In some implementations, multiple broadcast receivers can be broadcast receivers with the same priority. The priority of a broadcast receiver can be specified by the first process during the broadcast receiver registration process. By packaging broadcast messages from broadcast receivers with the same priority, it can be ensured that broadcast messages are sent in priority order, which meets the requirements of the broadcast system for broadcast message delivery.
[0203] In some implementations, the second broadcast message may also include first indication information, which indicates the transmission method of the first broadcast message. This transmission method may include blocking transmission and non-blocking transmission. Blocking transmission is either ordered or sequential transmission, while non-blocking transmission is unordered transmission. By carrying the first indication information in the second broadcast message, the first application can explicitly specify the transmission method of the first broadcast message to multiple broadcast receivers, which helps ensure the correct transmission of the first broadcast message.
[0204] The method of sending the second broadcast message can be determined based on the application (hereinafter referred to as the second application) and / or the broadcast system that provided the first broadcast message. As an example, when the second application sends the first broadcast message to the broadcast system, it can specify that the first broadcast message is sent in a blocking or non-blocking manner. The broadcast system can determine the first indication information based on the sending method specified by the second application. For example, if the second application specifies a blocking sending method, then the first indication information also indicates a blocking sending method. Similarly, if the second application specifies a non-blocking sending method, then the first indication information also indicates a non-blocking sending method. Furthermore, if the second application specifies a non-blocking sending method but also indicates the need to obtain a delivery completion status, then the first indication information indicates a blocking sending method so that the broadcast system can obtain the delivery completion status of the broadcast message.
[0205] If the first broadcast message is sent in a blocking manner, the electronic device (such as the first process in the first application) can select a first broadcast receiver from multiple broadcast receivers and send the first broadcast message to the first broadcast receiver. The first broadcast receiver processes the first broadcast message, and only after processing the first broadcast message does it send it to the next broadcast receiver. For example, after the first broadcast receiver has finished processing the first broadcast message, a second broadcast receiver is selected from multiple broadcast receivers, and the first broadcast message is sent to the second broadcast receiver. After the second broadcast receiver has finished processing the first broadcast message, it sends the first broadcast message to the next broadcast receiver, and so on, until the first broadcast message has been sent to all broadcast receivers.
[0206] In some implementations, the order in which the first process sends the first broadcast message to multiple broadcast receivers can be random, or the first process can send the first broadcast message to multiple broadcast receivers in the order in which they registered. For example, the first process can first send the first broadcast message to the broadcast receiver that registered earliest among the multiple broadcast receivers, and after that broadcast receiver has processed the first broadcast message, it can then send the first broadcast message to the next broadcast receiver.
[0207] If a first broadcast message has been sent to multiple broadcast receivers and all of the multiple broadcast receivers have completed processing the first broadcast message, the first application may send a second instruction message (the first process in the first application may send the second instruction message to the broadcast system), which may be used to instruct the resumption of broadcast message dispatch.
[0208] If the broadcast system receives the second instruction information and still needs to send broadcast messages to the first process, it can continue to send broadcast messages to the first process in the first application.
[0209] As discussed earlier, in the blocking transmission mode, the higher-priority broadcast receiver can modify or truncate the broadcast message. Therefore, any one of the multiple receivers can modify or truncate the broadcast message. If one of the multiple broadcast receivers truncates the first broadcast message, the first process can stop sending the first broadcast message to subsequent broadcast receivers. Additionally, the first process can send an indication message to the broadcast system to instruct the transmission of the first broadcast message to be stopped.
[0210] If one of the multiple broadcast receivers modifies the first broadcast message, the first process can send the modified first broadcast message to subsequent broadcast receivers and to the broadcast system, so that the broadcast system can dispatch broadcast messages based on the modified first broadcast message.
[0211] In some implementations, if a second application needs to obtain the completion status of the first broadcast message, the broadcast system can send a third indication message to the second application to indicate that the first broadcast message has been successfully delivered.
[0212] If the first broadcast message is sent in a non-blocking manner, the electronic device (such as the first process in the first application) will asynchronously send the first broadcast message to each of the multiple broadcast receivers. These multiple broadcast receivers can receive the first broadcast message almost simultaneously. Because the first broadcast message is sent in a non-blocking manner, the first process also does not need to send an acknowledgment message to the broadcast system.
[0213] After sending a second broadcast message to the first process, if there are still broadcast messages for broadcast receivers in the first process, the broadcast system can continue to send broadcast messages to the first process.
[0214] As mentioned above, a broadcast system may include a process broadcast queue management object for managing broadcast receivers. In this embodiment, the process broadcast queue management object may add a new function: providing broadcast receivers with the same event and / or priority, so that the broadcast system can package and send broadcast messages according to the list.
[0215] In some implementations, upon receiving the first broadcast message, the broadcast system can obtain the first broadcast receiver from the process broadcast queue management object. The first broadcast receiver is for the first broadcast event; in other words, it is the broadcast receiver listening for the first broadcast message. The process broadcast queue management object can select the highest-priority broadcast receiver from among those listening for the first broadcast message as the first broadcast receiver.
[0216] The process broadcast queue management object can also determine whether there is a broadcast receiver with the same priority as the first broadcast receiver, and both of them are targeting the first broadcast event.
[0217] If there are broadcast receivers in the process broadcast queue management object that have the same priority as the first broadcast receiver and are all targeting the first broadcast event, the broadcast system can package the broadcast messages for these broadcast receivers into a second broadcast message and send the second broadcast message to the first application.
[0218] If there is no broadcast receiver in the process broadcast queue management object that has the same priority as the first broadcast receiver and is targeting the first broadcast event, the broadcast system can directly send the first broadcast message to the first broadcast receiver.
[0219] As mentioned above, the process broadcast queue management object does not need to directly maintain the list of broadcast receivers, but rather maintains a list of broadcast receiver proxy objects. Therefore, the process broadcast queue management object can package broadcast messages according to the priority of the proxy objects.
[0220] In some implementations, if the first broadcast message is sent in a blocking manner, the broadcast system can package the broadcast message according to the priority order of the proxy objects when sending the broadcast message to the first process.
[0221] For example, suppose the process broadcast queue management object maintains proxy objects including proxy object 1 to proxy object 10, and all of proxy objects 1 to 10 listen for the first broadcast message. The broadcast receivers corresponding to proxy objects 1 to 10 are broadcast receiver 1 to broadcast receiver 10, respectively. Proxy objects 1 to 5 have a priority of 1, and proxy objects 6 to 10 have a priority of 2. The broadcast system can first package the broadcast messages from proxy objects 1 to 5 and send the packaged broadcast message to the first process. If broadcast receivers 1 to 5 have all completed processing the broadcast message, the first process sends an acknowledgment message to the broadcast system.
[0222] After receiving the acknowledgment message, the broadcast system continues to traverse the list of proxy objects to determine the next priority proxy object, i.e., it queries the proxy objects with priority 2, identifying proxy objects 6 through 10. The broadcast system packages the broadcast messages of proxy objects 6 through 10 and sends the packaged broadcast message to the first process. If broadcast receivers 6 through 10 have all completed processing the broadcast message, the first process sends an acknowledgment message to the broadcast system.
[0223] As an example, when the broadcast system receives the first broadcast message, it retrieves the first proxy object from the process broadcast queue management object. The first proxy object targets the first broadcast event, and it corresponds to the first broadcast receiver mentioned above. The broadcast system then checks if there is a proxy object in the current process broadcast queue management object that targets the same broadcast event and has the same priority as the first proxy object. If such proxy objects exist, the broadcast message is packaged and sent to the multiple broadcast receivers corresponding to these proxy objects.
[0224] For example, if there are multiple proxy objects in the process broadcast queue management object that have the same priority as the first proxy object and all target the first broadcast event, then a second broadcast message is sent to the first process.
[0225] If there are no multiple proxy objects in the process broadcast queue management object that have the same priority as the first proxy object and are all targeting the first broadcast event, then the first broadcast message is sent to the broadcast receiver corresponding to the first proxy object. That is, the broadcast system can send the first broadcast message to the broadcast receiver corresponding to the first proxy object in the traditional way.
[0226] In some implementations, if the first broadcast message is sent in a non-blocking manner, since non-blocking transmission does not consider the priority of broadcast receivers, the broadcast system can asynchronously send the first broadcast message to all broadcast receivers listening for it. Therefore, when packaging the broadcast message, the broadcast system can also disregard the priority of the broadcast receivers and package the broadcast messages corresponding to all broadcast receivers listening for the first broadcast message into a single package and send it to the first process. In other words, if the first broadcast message is sent in a non-blocking manner, the multiple broadcast receivers mentioned above can include all broadcast receivers in the first process that are listening for the first broadcast event, which can further reduce CPU resource consumption.
[0227] If the first broadcast message is sent in a blocking manner, then because the blocking method requires broadcast messages to be sent in order of priority, the multiple broadcast receivers are broadcast receivers in the first process that are for the first broadcast event and have the same priority.
[0228] For example, when the first broadcast message arrives at the broadcast system, the broadcast system determines the sending method for the first broadcast message. If the first broadcast message is sent in a blocking manner, the process broadcast queue management object selects the highest-priority broadcast receiver (i.e., the first broadcast receiver) among the broadcast receivers listening for the first broadcast message, and identifies broadcast receivers that are all targeting the first broadcast event and have the same priority. The system then packages the broadcast messages for these broadcast receivers and sends them to the first application. If the first broadcast message is sent in a non-blocking manner, the process broadcast queue management object selects the highest-priority broadcast receiver (i.e., the first broadcast receiver) among the broadcast receivers listening for the first broadcast message, and identifies broadcast receivers that are all targeting the first broadcast event. The system then packages the broadcast messages for these broadcast receivers and sends them to the first application.
[0229] Therefore, the broadcast system can use different packetization strategies based on the sending method of the first broadcast message to package different broadcast messages, thereby achieving flexible sending of broadcast messages and minimizing CPU resource consumption.
[0230] The following is combined with Figure 12 and Figure 13The following is a detailed description of the broadcast message sending process provided in the embodiments of this application.
[0231] Figure 12 This is a schematic diagram of the broadcast message sending process for blocking transmission provided in the embodiments of this application.
[0232] exist Figure 12 In the scheme shown, the APP1 application process includes 6 broadcast receivers, namely screen-on broadcast receiver 1, screen-on broadcast receiver 2, screen-on broadcast receiver N, screen-on broadcast receiver N+1, screen-on broadcast receiver N+2, and other event broadcast receiver 1.
[0233] Correspondingly, the broadcast system can store proxy objects corresponding to the six on-screen broadcast receivers. The broadcast system includes an APP1 process broadcast queue management object, which can maintain information about the six proxy objects, each corresponding one-to-one with one of the six broadcast receivers. These six proxy objects are: APP1-On-Screen Broadcast Receiver Proxy Object 1, APP1-On-Screen Broadcast Receiver Proxy Object 2, APP1-On-Screen Broadcast Receiver Proxy Object N, APP1-On-Screen Broadcast Receiver Proxy Object N+1, APP1-On-Screen Broadcast Receiver Proxy Object N+2, and APP1-Other Event Type Broadcast Receiver Proxy Object 1.
[0234] After receiving the screen-on broadcast from the power management system, the broadcast queue management object of the APP1 process can obtain the screen-on broadcast receiver proxy objects with a priority of 11, and package the screen-on broadcasts for these proxy objects into a package and dispatch them to the APP1 application process at once, such as... Figure 12 The number ① in the text.
[0235] After receiving the packaged broadcast message, the APP1 application process can sequentially send the screen-on broadcast to multiple screen-on broadcast receivers. In some implementations, the APP1 application process can send the screen-on broadcast to multiple screen-on broadcast receivers sequentially according to the registration order of the broadcast receivers. After one screen-on broadcast receiver has finished processing the screen-on broadcast, it will then be sent to the next screen-on broadcast receiver.
[0236] For example, the APP1 application process can first send the screen-on broadcast to screen-on broadcast receiver 1; after screen-on broadcast receiver 1 has finished processing the screen-on broadcast, the APP1 application process sends the screen-on broadcast to screen-on broadcast receiver 2; after screen-on broadcast receiver 2 has finished processing the screen-on broadcast, the APP1 application process sends the screen-on broadcast to screen-on broadcast receiver N; after screen-on broadcast receiver N has finished processing the screen-on broadcast, the APP1 application process sends the screen-on broadcast to screen-on broadcast receiver N+1; after screen-on broadcast receiver N+1 has finished processing the screen-on broadcast, the APP1 application process sends the screen-on broadcast to screen-on broadcast receiver N+2.
[0237] After the screen-on broadcast receiver N+2 finishes processing the screen-on broadcast, the APP1 application process sends an acknowledgment message to the broadcast system, such as... Figure 12 Number ② in the text.
[0238] After receiving the acknowledgment message, if the broadcast system receives a broadcast message for a different event type, it can send that broadcast message to the APP1 application process, such as... Figure 12 The number ③ in the text.
[0239] The APP1 application process can send the broadcast message to another event broadcast receiver 1. After the other event broadcast receiver 1 processes the broadcast message, the APP1 application process can send an acknowledgment message to the broadcast system, such as... Figure 12 Number ④ in the text.
[0240] For screen-on broadcasts, Figure 12 In the proposed solution, the broadcast system and the APP1 application process only need to interact twice (i.e., Figure 12 (The numbers ① and ② in the text), however, in Figure 7 In the illustrated scheme, the broadcast system and the APP1 application process need to interact 10 times. Figure 7 Compared to the proposed solution, Figure 12 The proposed solution can significantly reduce the number of interactions between the broadcast system and application processes, thereby reducing the number of times application processes need to process broadcast messages and lowering CPU resource consumption.
[0241] Figure 13 This is a schematic diagram of the broadcast message sending process for non-blocking transmission provided in the embodiments of this application.
[0242] exist Figure 13 In the scheme shown, the APP1 application process includes 5 broadcast receivers, namely, a certain disordered broadcast receiver 1, a certain disordered broadcast receiver 2, a certain disordered broadcast receiver N, a certain disordered broadcast receiver N+1, and a certain disordered broadcast receiver N+2.
[0243] Correspondingly, the broadcast system can store proxy objects corresponding to the five unordered broadcast receivers. The broadcast system includes an APP1 process broadcast queue management object, which can maintain information about the five proxy objects, each corresponding one-to-one with one of the five broadcast receivers. These five proxy objects are: APP1-Unordered Broadcast Receiver Proxy Object 1, APP1-Unordered Broadcast Receiver Proxy Object 2, APP1-Unordered Broadcast Receiver Proxy Object N, APP1-Unordered Broadcast Receiver Proxy Object N+1, and APP1-Unordered Broadcast Receiver Proxy Object N+2.
[0244] After the broadcast system receives an out-of-order broadcast message, the broadcast queue management object of the APP1 process can obtain all the out-of-order broadcast receiver proxy objects, package the broadcast messages for these proxy objects, and dispatch them to the APP1 application process in one go, such as... Figure 13 The number ① in the text.
[0245] After receiving a packaged broadcast message, the APP1 application process can asynchronously send an out-of-order broadcast message to multiple out-of-order broadcast receivers.
[0246] exist Figure 13 In the scheme shown, the interaction between the broadcast system and the APP1 application process is 1 time; however, in Figure 8 In the illustrated scheme, the broadcast system interacts with the APP1 application process 5 times. Figure 8 Compared to the proposed solution, Figure 13 The proposed solution can significantly reduce the number of interactions between the broadcast system and application processes, thereby reducing the number of times application processes need to process broadcast messages and lowering CPU resource consumption.
[0247] In some implementations, after the broadcast system sends a second broadcast message to the first process, it can record the transmission status of the second broadcast message, including both normal and abnormal transmission situations. Abnormal transmission situations include application unresponsiveness.
[0248] Figure 14 This is a schematic flowchart illustrating another method of sending broadcast messages provided in the embodiments of this application.
[0249] See Figure 14 In step S1410, when the broadcast system receives a broadcast message, the broadcast system determines whether the process broadcast queue management object can dispatch a broadcast. For example, the broadcast system determines whether there is a broadcast receiver in the process broadcast queue management object that is listening for the broadcast message.
[0250] If the process broadcast queue management object can dispatch broadcasts, then proceed to step S1420; if the process broadcast queue management object cannot dispatch broadcasts, then the process ends.
[0251] In step S1420, the process broadcast queue management object acquires a broadcast receiver.
[0252] In step S1430, query whether there are several consecutive broadcast receivers with the same event and priority in the current process broadcast queue management object.
[0253] If there are several consecutive broadcast receivers with the same event and priority in the current process's broadcast queue management object, then execute steps S1440 and S1450; if there are no several consecutive broadcast receivers with the same event and priority in the current process's broadcast queue management object, then execute steps S1460 and S1470.
[0254] In step S1440, the broadcast message is packaged and dispatched to multiple broadcast receivers, which are consecutive broadcast receivers with the same event and priority.
[0255] In step S1450, the normal and abnormal transmission status of broadcast messages is recorded. For example, it is recorded whether the broadcast message triggers an ANR (Application Not Responding).
[0256] In step S1460, the broadcast message is dispatched to a broadcast receiver.
[0257] In step S1470, the normal and abnormal transmission status of broadcast messages is recorded. For example, it records whether the broadcast message triggers an ANR (Application Not Responding).
[0258] In step S1480, it is determined whether the broadcast message is sent in a blocking mode.
[0259] If the broadcast message is sent in a blocking manner, the process ends; if the broadcast message is not sent in a blocking manner, the process continues to loop through steps S1410 to S1480 until the broadcast message is sent to all broadcast receivers listening for the broadcast message.
[0260] In some implementations, in order to be compatible with traditional transmission methods and the transmission methods provided in this application embodiment, this application embodiment may add a transmission interface between the broadcast system and the first process to better implement different transmission methods.
[0261] For example, the transmission interface between the broadcast system and the first process may include a first interface and a second interface. The first interface is the existing interface, that is, the first interface is dedicated to sending broadcast messages to a single broadcast receiver. The second interface is a newly added interface, that is, the second interface is dedicated to sending broadcast messages to multiple broadcast receivers.
[0262] For example, if the broadcast system sends a second broadcast message to the first process, the broadcast system can send the second broadcast message to the first process through the second interface; if the broadcast system sends a first broadcast message to the broadcast receiver corresponding to the first proxy object, the broadcast system can send the first broadcast message to the broadcast receiver corresponding to the first proxy object through the first interface.
[0263] The first process can determine whether the broadcast message is targeted at one or multiple broadcast receivers based on the broadcast message's sending interface, thus ensuring the accurate transmission of the broadcast message.
[0264] Figure 15 This is a schematic diagram of the structure of the application process and broadcast system provided in the embodiments of this application.
[0265] exist Figure 15 In the scheme shown, the multiple broadcast list dispatch frameworks, multiple broadcast list dispatch interfaces, the function of dispatching broadcast lists of the same type to the same process in the broadcast dispatch management framework, and the function of providing broadcast lists of the same type and level in the process broadcast queue management object are new additions in this application embodiment.
[0266] If the broadcast system sends a broadcast message to a statically registered broadcast receiver, it can do so through interface 1; if the broadcast system sends a broadcast message to a dynamically registered broadcast receiver, it can do so through interface 2; and if the broadcast system sends a broadcast message to multiple broadcast receivers, it can do so through interface 3.
[0267] If a broadcast system sends broadcast messages to multiple broadcast receivers, the process broadcast queue management object can provide a list of broadcast receivers of the same type and level. The broadcast dispatch management framework can package the broadcast messages and send the packaged broadcast messages to the broadcast receivers in the list.
[0268] After the broadcast dispatch management framework dispatches a broadcast message, it can also start an ANR listening timeout mechanism to determine whether the broadcast message has triggered an ANR.
[0269] When an application process receives a broadcast message, if the broadcast message is for a single broadcast receiver (either statically registered or dynamically registered), the application process can use a broadcast dispatch procedure to send the broadcast message to the corresponding broadcast receiver. If the broadcast message is for a list of broadcast receivers, the application process can use multiple broadcast list dispatch frameworks to send the broadcast message to multiple broadcast receivers. For example, if the broadcast receiver list includes broadcast receiver 1 through broadcast receiver 4, the application process can send the broadcast message to broadcast receiver 1 through broadcast receiver 4.
[0270] The foregoing has detailed examples of the methods provided in this application. It is understood that the corresponding apparatus, in order to achieve the above functions, includes hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should readily recognize that, based on the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0271] This application can divide the broadcast message sending device into functional modules based on the above method example. For example, each function can be divided into its own functional module, or two or more functions can be integrated into one module. The integrated module can be implemented in hardware or as a software functional module. It should be noted that the module division in this application is illustrative and only represents one logical functional division; other division methods may be used in actual implementation.
[0272] The broadcast message sending device in the embodiments of this application can be an electronic device, or the broadcast message sending device can be a chip or the like used to implement the above method.
[0273] The following is combined with Figure 16 and Figure 17 The following describes the device embodiments of this application. It should be noted that the device embodiments correspond to the method embodiments, and any content not described in detail can be found in the method embodiments.
[0274] Figure 16 This is a schematic block diagram of an electronic device provided in an embodiment of this application. The electronic device 1600 includes a receiving module 1610, a first transmitting module 1620, and a second transmitting module 1630.
[0275] The receiving module 1610 is used to: receive a first broadcast message, wherein the first broadcast message is directed to a first broadcast event.
[0276] The first sending module 1620 is configured to: if the first application includes multiple broadcast receivers for the first broadcast event, send a second broadcast message to the first application, the second broadcast message including the first broadcast message and list information of the multiple broadcast receivers.
[0277] The second sending module 1630 is used to: send the first broadcast message in the second broadcast message to the plurality of broadcast receivers through the first application.
[0278] In some implementations, the second broadcast message further includes first indication information, which indicates the sending method of the first broadcast message, including blocking sending and non-blocking sending.
[0279] In some implementations, if the first broadcast message is sent in a blocking manner, the electronic device 1600 further includes a selection module, which is used to select a first broadcast receiver from the plurality of broadcast receivers; the second sending module 1630 is used to send the first broadcast message to the first broadcast receiver; when the first broadcast receiver has finished processing the first broadcast message, the selection module is used to select a second broadcast receiver from the plurality of broadcast receivers; the second sending module 1630 is used to send the first broadcast message to the second broadcast receiver.
[0280] In some implementations, the receiving module 1610 is further configured to: receive a second indication information sent by the first application, the second indication information being used to instruct the broadcast system to resume the dispatch of broadcast messages, the second indication information being sent when the first application has sent the first broadcast message to all of the plurality of broadcast receivers and all of the plurality of broadcast receivers have completed processing the first broadcast message.
[0281] In some implementations, if the first broadcast message is sent in a non-blocking manner, the second sending module 1630 is used to: asynchronously send the first broadcast message to each of the plurality of broadcast receivers.
[0282] In some implementations, the plurality of broadcast receivers have the same priority.
[0283] In some implementations, the electronic device 1600 further includes an acquisition module, which is used to acquire a first broadcast receiver from a process broadcast queue management object before the first sending module 1620 sends the second broadcast message to the first application. The first broadcast receiver is for the first broadcast event. The first sending module 1620 is used to send the second broadcast message to the first application if there is a broadcast receiver in the process broadcast queue management object with the same priority as the first broadcast receiver and both of them are for the first broadcast event.
[0284] In some implementations, the first sending module 1620 is further configured to: send the first broadcast message to the first broadcast receiver if there is no broadcast receiver in the process broadcast queue management object that has the same priority as the first broadcast receiver and is targeting the first broadcast event.
[0285] In some implementations, the second sending module 1630 is used to send the first broadcast message to the first broadcast receiver through a first interface, the first interface being an interface dedicated to dispatching broadcast messages to one broadcast receiver; and to send the second broadcast message to the first application through a second interface, the second interface being an interface dedicated to dispatching broadcast messages to multiple broadcast receivers.
[0286] In some implementations, the electronic device 1600 further includes a recording module, which is used to record the sending status of the second broadcast message after the first sending module 1620 sends the second broadcast message to the first application, including whether the application triggers an Application Not Responding (ANR).
[0287] Figure 17 This is a schematic structural diagram of the device according to an embodiment of this application. Figure 17 The dashed lines indicate that the unit or module is optional. The device 1700 can be used to implement the methods described in the above method embodiments. The device 1700 can be a chip or an electronic device.
[0288] Apparatus 1700 may include one or more processors 1710. The processor 1710 may support apparatus 1700 in implementing the methods described in the preceding method embodiments. The processor 1710 may be a general-purpose processor or a special-purpose processor. For example, the processor may be a central processing unit (CPU). Alternatively, the processor may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0289] The apparatus 1700 may further include one or more memories 1720. The memories 1720 store a program that can be executed by the processor 1710, causing the processor 1710 to perform the methods described in the preceding method embodiments. The memories 1720 may be independent of the processor 1710 or integrated within the processor 1710.
[0290] The device 1700 may also include a transceiver 1730. The processor 1710 can communicate with other devices or chips via the transceiver 1730. For example, the processor 1710 can send and receive data with other devices or chips via the transceiver 1730.
[0291] This application also provides a chip including a processor, which is used to read and execute a computer program stored in a memory to perform the broadcast message sending method described in any of the above embodiments.
[0292] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, causes the processor to perform the broadcast message sending method described in any of the above embodiments.
[0293] This application also provides a computer program product that, when run on a computer, causes the computer to perform the aforementioned steps to implement the broadcast message sending method described in the above embodiments.
[0294] In this embodiment, the electronic device, computer-readable storage medium, computer program product or chip are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can be referred to the beneficial effects of the corresponding methods provided above, and will not be repeated here.
[0295] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, indirect coupling or communication connection between devices or units. The replaced units may or may not be physically separate. The component shown as a unit may be one physical unit or multiple physical units, that is, it may be located in one place or distributed in multiple different places. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0296] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0297] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, in essence, or the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0298] It should be understood that in the various embodiments of this application, the order of the above-mentioned processes does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0299] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method for sending a broadcast message, characterized in that, include: Receive a first broadcast message, the broadcast event to which the first broadcast message is directed is the first broadcast event; If the first application includes multiple broadcast receivers for the first broadcast event, then a second broadcast message is sent to the first application, the second broadcast message including the first broadcast message and a list of the multiple broadcast receivers; The first application sends the first broadcast message in the second broadcast message to the plurality of broadcast receivers.
2. The method according to claim 1, characterized in that, The second broadcast message also includes first indication information, which indicates the sending method of the first broadcast message, including blocking sending and non-blocking sending.
3. The method according to claim 2, characterized in that, If the first broadcast message is sent in a blocking mode, then sending the first broadcast message in the second broadcast message to the plurality of broadcast receivers includes: Select a first broadcast receiver from the plurality of broadcast receivers; Send the first broadcast message to the first broadcast receiver; If the first broadcast receiver has finished processing the first broadcast message, a second broadcast receiver is selected from the plurality of broadcast receivers; The first broadcast message is sent to the second broadcast receiver.
4. The method according to claim 3, characterized in that, The method further includes: The system receives a second instruction message sent by the first application. The second instruction message is used to instruct the broadcast system to resume the dispatch of broadcast messages. The second instruction message is sent when the first application has sent the first broadcast message to all of the plurality of broadcast receivers and all of the plurality of broadcast receivers have completed processing the first broadcast message.
5. The method according to claim 2, characterized in that, If the first broadcast message is sent in a non-blocking manner, then sending the first broadcast message in the second broadcast message to the plurality of broadcast receivers includes: The first broadcast message is sent asynchronously to each of the plurality of broadcast receivers.
6. The method according to any one of claims 1-5, characterized in that, The multiple broadcast receivers have the same priority.
7. The method according to any one of claims 1-6, characterized in that, Before sending the second broadcast message to the first application, the method further includes: Obtain the first broadcast receiver from the process broadcast queue management object, wherein the first broadcast receiver is for the first broadcast event; Sending the second broadcast message to the first application includes: If the process broadcast queue management object contains a broadcast receiver with the same priority as the first broadcast receiver, and both are targeting the first broadcast event, then the second broadcast message is sent to the first application.
8. The method according to claim 7, characterized in that, The method further includes: If there is no broadcast receiver in the process broadcast queue management object that has the same priority as the first broadcast receiver and is targeting the first broadcast event, then the first broadcast message is sent to the first broadcast receiver.
9. The method according to claim 8, characterized in that, Sending the first broadcast message to the first broadcast receiver includes: The first broadcast message is sent to the first broadcast receiver through the first interface, wherein the first interface is an interface dedicated to dispatching broadcast messages to a single broadcast receiver; Sending the second broadcast message to the first application includes: The second broadcast message is sent to the first application through a second interface, which is an interface dedicated to distributing broadcast messages to multiple broadcast receivers.
10. The method according to any one of claims 1-9, characterized in that, After sending the second broadcast message to the first application, the method further includes: Record the sending status of the second broadcast message, including whether an application non-response (ANR) is triggered.
11. An electronic device, characterized in that, The electronic device includes a memory and a processor, the memory storing a computer program executable on the processor, the processor executing the computer program to implement the method as described in any one of claims 1 to 10.
12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, causes the processor to perform the method as described in any one of claims 1 to 10.
13. A computer program product, characterized in that, Includes a program that causes a computer to perform the method as described in any one of claims 1-10.