Broadcast processing method and apparatus
By performing deadlock detection on the broadcast process queue, the out-of-order problem caused by conflicts in priority and order attributes during broadcast distribution is resolved, thereby improving the security and reliability of broadcast distribution.
Patent Information
- Application Number
- CN202311848628.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-28
- Publication Date
- 2026-08-25
- Estimated Expiration
- 2043-12-28
AI Technical Summary
During broadcast distribution, anomaly detection in the broadcast process queue is difficult to implement effectively, causing broadcast receivers to be unable to receive broadcasts normally, thus affecting the security and efficiency of broadcast distribution.
By performing deadlock detection on the broadcast process queue, out-of-order phenomena caused by conflicts in priority and order attributes are identified and resolved. A periodic detection mechanism is adopted to improve the security of broadcast distribution, including monitoring the priority, index order, and queue status of broadcast receivers in the group.
Deadlock detection in the broadcast process queue is implemented, which improves the security and reliability of the broadcast distribution process and avoids the problem that broadcast receivers cannot distribute normally due to deadlock.
Smart Images

Figure CN120856486B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of terminal technology, and in particular to a broadcast processing method and apparatus. Background Technology
[0002] As one of the four major components of the Android system, broadcast is a mechanism for message passing (e.g., passing data, sending notifications) between components. These components can be in the same process or different processes. In other words, the broadcast mechanism can be understood as an inter-process communication mechanism. The broadcast mechanism utilizes the observer pattern and is based on a message publish / subscribe event model. This model includes message publishers, message subscribers, and a message center. The message publisher, message subscriber, and message center correspond to the sender (broadcast sender), receiver (broadcast receiver), and Activity Manager Service (AMS) in the broadcast mechanism, respectively.
[0003] The sender sends a broadcast (i.e., a broadcast message) to AMS. AMS determines the broadcast receivers corresponding to the broadcast message and assigns them to groups in the broadcast process queue. AMS then distributes the broadcast to the corresponding broadcast receivers according to the order of the groups. In essence, AMS can use the binder mechanism to distribute broadcasts to receivers.
[0004] When an anomaly occurs during broadcast distribution, broadcast receivers in the broadcast process queue will fail to receive the broadcast. Therefore, how to implement anomaly detection in the broadcast process queue is a problem that urgently needs to be solved. Summary of the Invention
[0005] This application provides a broadcast processing method and apparatus, which are applied in the field of terminal technology and can realize deadlock detection in the broadcast process queue.
[0006] In a first aspect, embodiments of this application propose a broadcast processing method. The method includes: receiving a first broadcast sent by a broadcast sender, wherein the broadcast receivers corresponding to the first broadcast include a first broadcast receiver and a second broadcast receiver; assigning the first broadcast receiver and the second broadcast receiver to a first group of a first broadcast process queue, wherein the first broadcast receiver is located at a first position in the first group and the second broadcast receiver is located at a second position in the first group, the second position being after the first position; and performing deadlock detection on the first broadcast process queue when the first broadcast process queue is in a blocked state.
[0007] The broadcast receiver corresponding to the first broadcast can be the target broadcast receiver described in the embodiments of this application, and the number of broadcast receivers corresponding to the first broadcast can be N, where N is greater than or equal to 2. The first group can be a group determined based on the attributes of the first broadcast.
[0008] When there is no deadlock detection process during broadcast distribution, the first broadcast process queue can be blocked for an extended period during a deadlock, causing a chain reaction that prevents subsequent broadcast process queues from performing broadcast distribution. Therefore, embodiments of this application can perform deadlock detection on any group in the broadcast process queue before broadcast distribution, thereby improving the security of the broadcast distribution process.
[0009] In one possible implementation, deadlock detection of the first broadcast process queue includes: determining that a deadlock exists in the first broadcast process queue when the priority of the first broadcast receiver is lower than the priority of the second broadcast receiver.
[0010] Because the first-in, first-out (FIFO) principle followed by each group in the broadcast process queue conflicts with the priority attributes of each broadcast receiver within the group, two or more broadcast receivers in the group may be waiting for each other due to out-of-order delivery. Therefore, when an electronic device detects that a low-priority broadcast receiver is ahead of a high-priority broadcast receiver in the same group, it determines that a deadlock exists in the broadcast process queue containing that group, thus achieving accurate deadlock detection.
[0011] In one possible implementation, deadlock detection of the first broadcast process queue includes: determining that a deadlock exists in the first broadcast process queue when the application process corresponding to the first broadcast receiver is in a non-frozen state and the duration of the first broadcast receiver being blocked is longer than a preset duration, wherein the first position is the head position in the first group.
[0012] Electronic devices can determine that a deadlock exists in the broadcast process queue of any packet when they detect that the broadcast receiver at the head of the queue is blocked for an extended period of time, thus achieving accurate deadlock detection.
[0013] In one possible implementation, the application process in a non-frozen state includes one or more of the following: foreground process, visible process, or resident process, etc.
[0014] In one possible implementation, the first broadcast is an ordered broadcast. In the broadcast receiver queue corresponding to the first broadcast, the first broadcast receiver corresponds to the first index value, and the second broadcast receiver corresponds to the second index value. Deadlock detection is performed on the first broadcast process queue, including: when the first index value is greater than the second index value, it is determined that there is a deadlock in the first broadcast process queue. The first index value or the second index value is used to characterize the distribution order of the broadcast receivers.
[0015] Because the first-in, first-out (FIFO) principle followed by each group in the broadcast process queue conflicts with the ordered nature of the broadcast receivers within each group, two or more broadcast receivers in a group may experience mutual waiting due to out-of-order delivery. Therefore, when an electronic device detects that a broadcast receiver with a larger index value is ahead of a broadcast receiver with a smaller index value in the same group, it determines that a deadlock exists in the broadcast process queue containing that group, thus achieving accurate deadlock detection.
[0016] In one possible implementation, deadlock detection of the first broadcast process queue includes: determining to perform deadlock detection on the first broadcast process queue every first duration when the first broadcast is an ordered broadcast, the first broadcast carries a priority attribute, the first broadcast carries a substitution attribute, and the number of broadcast receivers corresponding to the first broadcast is greater than a first threshold; or, determining to perform deadlock detection on the first broadcast process queue every second duration when the first broadcast satisfies at least one of the following: the first broadcast is an ordered broadcast, the first broadcast carries a priority attribute, or the first broadcast carries a substitution attribute; the second duration is greater than the first duration.
[0017] Both the first duration and the second duration can be the first timing detection duration described in the embodiments of this application.
[0018] Electronic devices can identify the risks of broadcasts by recognizing their attributes and set shorter durations for broadcasts with higher risks. This allows electronic devices to periodically perform deadlock checks, thereby improving the security of broadcast distribution.
[0019] In one possible implementation, any broadcast receiver corresponding to a broadcast is in a first broadcast queue, which includes a temporary queue and a ready queue. The temporary queue is used to store fourth broadcast receivers who have not yet received a broadcast, and the ready queue is used to store third broadcast receivers who are about to receive a broadcast. Deadlock detection is performed on the first broadcast process queue, including: obtaining the ratio of the third broadcast receiver to the fourth broadcast receiver; when the ratio is greater than a second threshold, determining to perform deadlock detection on the first broadcast process queue every third time interval.
[0020] The first broadcast queue can be a modern broadcast queue as described in the embodiments of this application.
[0021] The third duration can be the second timing detection duration described in the embodiments of this application.
[0022] When the number of broadcast receivers in the temporary queue is large, while the number of broadcast receivers in the ready queue is small, it indicates a potential deadlock in the temporary queue, preventing broadcasts from being sent to the appropriate receivers. Therefore, electronic devices can identify queue anomalies by monitoring queue status and setting periodic deadlock checks to improve the security of the broadcast distribution process.
[0023] In one possible implementation, the hash code of the first broadcast received by the first broadcast receiver is the same as the hash code of the first broadcast received by the second broadcast receiver, and the first broadcast receiver and the second broadcast receiver are on the same electronic device.
[0024] Electronic devices can identify the first and second broadcast receivers as registered recipients of the same broadcast by listening to the hash code of the broadcast.
[0025] Secondly, embodiments of this application provide a broadcast processing apparatus, which may be an electronic device, or a chip or chip system within an electronic device. The broadcast processing apparatus may include a receiving unit and a processing unit. When the broadcast processing apparatus is an electronic device, the receiving unit is used to perform a data receiving step to enable the electronic device to implement a broadcast processing method described in the first aspect or any possible implementation of the first aspect. When the broadcast processing apparatus is an electronic device, the processing unit may be a processor. The broadcast processing apparatus may further include a storage unit, which may be a memory. The storage unit is used to store instructions, and the processing unit executes the instructions stored in the storage unit to enable the electronic device to implement a broadcast processing method described in the first aspect or any possible implementation of the first aspect. When the broadcast processing apparatus is a chip or chip system within an electronic device, the processing unit may be a processor. The processing unit executes the instructions stored in the storage unit to enable the electronic device to implement a broadcast processing method described in the first aspect or any possible implementation of the first aspect. The storage unit may be a storage unit within the chip (e.g., a register, cache, etc.), or a storage unit located outside the chip within the electronic device (e.g., a read-only memory, random access memory, etc.).
[0026] For example, the receiving unit is used to receive a first broadcast sent by a broadcast sender, and the broadcast receivers corresponding to the first broadcast include a first broadcast receiver and a second broadcast receiver; the processing unit is used to allocate the first broadcast receiver and the second broadcast receiver to a first group of the first broadcast process queue; the processing unit is further used to position the first broadcast receiver at a first position in the first group and the second broadcast receiver at a second position in the first group, the second position being after the first position; when the first broadcast process queue is in a blocked state, the processing unit is further used to perform deadlock detection on the first broadcast process queue.
[0027] In one possible implementation, when the priority of the first broadcast receiver is lower than the priority of the second broadcast receiver, the processing unit is specifically used to determine that there is a deadlock in the first broadcast process queue.
[0028] In one possible implementation, when the application process corresponding to the first broadcast receiver is in a non-frozen state and the duration of the first broadcast receiver being blocked is longer than a preset duration, the processing unit is specifically used to determine that there is a deadlock in the queue of the first broadcast process, and the first position is the head position in the first group.
[0029] In one possible implementation, the application process in a non-frozen state includes one or more of the following: foreground process, visible process, or resident process, etc.
[0030] In one possible implementation, the first broadcast is an ordered broadcast. In the broadcast receiver queue corresponding to the first broadcast, the first broadcast receiver corresponds to the first index value, and the second broadcast receiver corresponds to the second index value. When the first index value is greater than the second index value, the processing unit is also used to determine that there is a deadlock in the first broadcast process queue. The first index value or the second index value is used to characterize the distribution order of the broadcast receivers.
[0031] In one possible implementation, when the first broadcast is an ordered broadcast, the first broadcast carries a priority attribute, the first broadcast carries a substitution attribute, and the number of broadcast receivers corresponding to the first broadcast is greater than a first threshold, the processing unit is specifically used to determine to perform deadlock detection on the first broadcast process queue every first duration; or, when the first broadcast satisfies at least one of the following: the first broadcast is an ordered broadcast, the first broadcast carries a priority attribute, or the first broadcast carries a substitution attribute, the processing unit is further specifically used to determine to perform deadlock detection on the first broadcast process queue every second duration; the second duration is greater than the first duration.
[0032] In one possible implementation, any broadcast receiver corresponding to a broadcast is in a first broadcast queue, which includes a temporary queue and a ready queue. The temporary queue is used to store fourth broadcast receivers who have not yet received a broadcast, and the ready queue is used to store third broadcast receivers who are about to receive a broadcast. The processing unit is specifically used to: obtain the ratio of the third broadcast receiver to the fourth broadcast receiver; and when the ratio is greater than a second threshold, determine to perform deadlock detection on the first broadcast process queue every third time interval.
[0033] In one possible implementation, the hash code of the first broadcast received by the first broadcast receiver is the same as the hash code of the first broadcast received by the second broadcast receiver, and the first broadcast receiver and the second broadcast receiver are on the same electronic device.
[0034] Thirdly, embodiments of this application provide an electronic device including a processor and a memory, the memory for storing code instructions, and the processor for running the code instructions to perform the methods described in the first aspect or any possible implementation of the first aspect.
[0035] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program or instructions that, when executed on a computer, cause the computer to perform the methods described in the first aspect or any possible implementation thereof.
[0036] Fifthly, embodiments of this application provide a computer program product including a computer program, which, when run on a computer, causes the computer to perform the methods described in the first aspect or any possible implementation thereof.
[0037] Sixthly, this application provides a chip or chip system including at least one processor and a communication interface. The communication interface and the at least one processor are interconnected via a circuit. The at least one processor is used to run computer programs or instructions to perform the methods described in the first aspect or any possible implementation of the first aspect. The communication interface in the chip can be an input / output interface, pins, or circuits, etc.
[0038] In one possible implementation, the chip or chip system described above in this application further includes at least one memory storing instructions. The memory can be an internal storage unit of the chip, such as a register or cache, or it can be a storage unit of the chip itself (e.g., read-only memory, random access memory, etc.).
[0039] It should be understood that the second to sixth aspects of this application correspond to the technical solutions of the first aspect of this application, and the beneficial effects achieved by each aspect and the corresponding feasible implementation are similar, and will not be repeated here. Attached Figure Description
[0040] Figure 1 A schematic diagram illustrating a process for managing broadcast receivers, provided as an embodiment of this application;
[0041] Figure 2 A schematic diagram of a modern broadcast queue provided for an embodiment of this application;
[0042] Figure 3 A schematic diagram of a broadcast process queue provided in an embodiment of this application;
[0043] Figure 4 A schematic diagram of another broadcast process queue provided in an embodiment of this application;
[0044] Figure 5 A scenario diagram provided for an embodiment of this application;
[0045] Figure 6 This is a schematic diagram of the structure of a terminal device provided in an embodiment of this application;
[0046] Figure 7 A schematic diagram of the software structure of an electronic device provided in an embodiment of this application;
[0047] Figure 8 A flowchart illustrating a broadcast processing method provided in an embodiment of this application;
[0048] Figure 9 A schematic diagram illustrating the steps of another broadcast processing method provided in this application embodiment;
[0049] Figure 10 This is a schematic diagram of the structure of a broadcast processing device provided in an embodiment of this application;
[0050] Figure 11 This is a schematic diagram of the hardware structure of another electronic device provided in an embodiment of this application. Detailed Implementation
[0051] To facilitate a clear description of the technical solutions in the embodiments of this application, some terms and technologies involved in the embodiments of this application will be briefly introduced below:
[0052] 1. Broadcasting and types of broadcasting
[0053] As described above, the broadcast mechanism involves a broadcast sender, a broadcast receiver, and an AMS (Advanced Management System). A broadcast sender can send a broadcast to the AMS. The AMS can find the corresponding broadcast receiver and assign that receiver to a group in the broadcast process queue for processing. It can be understood that a broadcast can correspond to multiple broadcast receivers. During processing, the AMS can send the broadcast to its corresponding broadcast receivers sequentially, thus achieving broadcast distribution.
[0054] Generally, both the broadcast sender sending a broadcast to AMS and the AMS sending a broadcast to the broadcast receiver are implemented based on the binder mechanism. The binder mechanism is an inter-process communication (IPC) mechanism, and its specific meaning can be found in relevant technical documents, which will not be elaborated here.
[0055] Broadcasts can be categorized by type, including general broadcasts and scheduled broadcasts.
[0056] Regular broadcast: All registered broadcast receivers can listen to the broadcast. Regular broadcast can be understood as an unordered broadcast, meaning that the broadcast does not need to be distributed to broadcast receivers in a specific order.
[0057] Ordered broadcasting: Broadcasts are distributed sequentially to receivers according to their index values in the receiver queue. Each receiver corresponds to an index value; the smaller the index value, the earlier the broadcast will be distributed to that receiver. It's understandable that each receiver has the opportunity to influence the broadcast distribution outcome, such as by terminating delivery to other undistributed receivers.
[0058] 2. Broadcast registration
[0059] Broadcast registration includes two methods: static registration and dynamic registration.
[0060] Static registration refers to registering broadcast receiver information in the application's manifest file, and then parsing this file during application installation to complete the registration. The static registration process can be performed within the Product Management System (PMS), which stores the mapping between broadcasts and broadcast receivers during static registration.
[0061] Dynamic registration refers to registering the relevant information of a broadcast receiver with the AMS by calling a function method (e.g., by calling Context.registerReceiver()). Since the dynamic registration process can take place within the AMS, the AMS can store the mapping between broadcasts and broadcast receivers during dynamic registration.
[0062] The method of broadcast registration is not specifically limited in the embodiments of this application.
[0063] 3. Broadcast process queue (BPQ)
[0064] The broadcast process queue can be used to manage the order in which broadcast receivers receive broadcasts. The broadcast process queue can be internally divided into three groups based on broadcast attributes: normal group, urgent group, and offload group.
[0065] After AMS receives a broadcast from the broadcast sender, it creates a broadcast process queue for each application process based on the user identification (UID) of the application process corresponding to the broadcast receiver. Then, it assigns the broadcast receivers to the corresponding groups within the broadcast process queues according to the broadcast attributes. The following section combines... Figure 1 The corresponding implementation example illustrates the queuing process. Figure 1 This is a schematic diagram illustrating a process for managing broadcast receivers, as provided in an embodiment of this application.
[0066] like Figure 1 As shown, AMS receives broadcast A and determines that broadcast A can correspond to 8 broadcast receivers. These 8 broadcast receivers are then sorted according to their priority. The broadcast receiver queue corresponding to broadcast A can include: broadcast receiver 1 at index 0, broadcast receiver 2 at index 1, broadcast receiver 3 at index 2, broadcast receiver 4 at index 3, broadcast receiver 5 at index 4, broadcast receiver 6 at index 5, broadcast receiver 7 at index 6, and broadcast receiver 8 at index 7, etc.
[0067] In this context, the priority values for broadcast receivers 1, 2, and 3 can all be 1000. The priority values for broadcast receivers 4 and 5 can all be 100. The priority values for broadcast receivers 6, 7, and 8 can all be 0. Broadcast receivers with a priority value of 1000 have higher priority, while those with a priority value of 0 have lower priority. In other words, a higher priority value indicates that the broadcast can be sent to the broadcast receiver earlier.
[0068] The blocking status flags for broadcast receivers 1, 2, and 3 can all be 0, meaning they do not need to wait for other broadcast receivers. The blocking status flags for broadcast receivers 4 and 5 can both be 3, meaning they need to wait for the distribution from three other broadcast receivers to complete. The blocking status flags for broadcast receivers 6, 7, and 8 can be 5, meaning they need to wait for the distribution from all five other broadcast receivers to complete.
[0069] During the process of broadcast A entering the modern broadcast queue of AMS, each broadcast receiver is encapsulated into a separate set of args. For example, some args A1 may include: arg1 = the index of broadcast A (marked as arg1), argi1 = the index of broadcast receiver 1 (e.g., index 0), that is, some args A1 can be understood as the broadcast receiver with receiver index 1 in broadcast A. The contents of some args A2 and some args A8 are similar to those in some args A1, and will not be elaborated here.
[0070] AMS matches the broadcast receiver to the corresponding broadcast process queue based on the application process to which the broadcast receiver belongs. For example, if AMS determines that broadcast receiver 1 and broadcast receiver 2 both come from application process 1, it creates broadcast process queue 1 for application process 1 and assigns some args A1 for broadcast receiver 1 and some args A2 for broadcast receiver 2 to broadcast process queue 1. If AMS determines that broadcast receiver 3, broadcast receiver 4, and broadcast receiver 5 all come from application process 2, it creates broadcast process queue 2 for application process 2 and assigns some args A3 for broadcast receiver 3, some args A4 for broadcast receiver 4, and some args A5 for broadcast receiver 5 to broadcast process queue 2. If AMS determines that broadcast receiver 6, broadcast receiver 7, and broadcast receiver 8 all come from application process 3, it creates broadcast process queue 3 for application process 3 and assigns some args A6 for broadcast receiver 6, some args A7 for broadcast receiver 7, and some args A8 for broadcast receiver 8 to broadcast process queue 3.
[0071] It is understandable that, since broadcast A does not have an urgent or load attribute, the above 8 broadcast receivers corresponding to broadcast A can all be assigned to the normal group in the broadcast process queue.
[0072] Similarly, when AMS receives broadcasts B, C, and D, it can retrieve the broadcast receiver corresponding to any broadcast and set that receiver in the appropriate broadcast process queue group. For example, AMS sets some args B1 corresponding to broadcast B in the normal group of broadcast process queue 1, some args C5 corresponding to broadcast C in the urgent group of broadcast process queue 1, and some args D8 corresponding to broadcast D in the load group of broadcast process queue 1. AMS sets some args C6 corresponding to broadcast C in the urgent group of broadcast process queue 2, and some args D4 corresponding to broadcast D in the load group of broadcast process queue 2. AMS sets some args D6 corresponding to broadcast D in the load group of broadcast process queue 3, and so on.
[0073] After broadcast receivers are assigned to the broadcast process queue, AMS can distribute broadcasts to the corresponding broadcast receivers in the order of the broadcast receivers in the broadcast process queue and the grouping order.
[0074] 4. Modern Broadcast Queue (BQMI)
[0075] The latest version of the Android native system (Android 14) uses a modern broadcast queue to replace the original broadcast queue as the caching and scheduling mechanism for the entire broadcast system. The modern broadcast queue provides a separate broadcast queue for each process, represented by a broadcast process queue instance. This allows the modern broadcast queue to schedule broadcasts sent by applications / systems according to their recipient processes. Furthermore, the modern broadcast queue can also control each broadcast process queue to pause, delay, or deliver broadcasts to their respective receivers ahead of schedule.
[0076] The following is combined Figure 2 The corresponding embodiment illustrates the broadcast distribution process under modern broadcast queues. Figure 2 This is a schematic diagram illustrating a broadcast distribution process based on a modern broadcast queue, provided as an embodiment of this application.
[0077] like Figure 2 As shown, the broadcast distribution process is divided into three stages: the queuing stage, the delivery stage, and the distribution stage.
[0078] The queuing phase includes: when a broadcast enters the modern broadcast queue in the Activity Manager service, AMS encapsulates each broadcast receiver into a separate args, matches the broadcast receiver to the corresponding broadcast process queue based on the application process of the broadcast receiver, and then matches the broadcast receiver to the corresponding group in the broadcast process queue based on the broadcast attributes.
[0079] The delivery phase includes: AMS determining the ready time, delivering the broadcast process queue to the runnable queue according to the ready time, obtaining a broadcast process queue from the runnable queue, and obtaining a running resource from the running queue for broadcast distribution.
[0080] Dispatch phase: AMS dispatches the broadcast to the specified broadcast receiver in the broadcast process queue based on the acquired running resources.
[0081] like Figure 2 As shown, modern broadcast queues include: temporary queues, ready queues, and running queues.
[0082] The temporary queue includes: the queue of broadcast processes that have already been created in the modern broadcast queue.
[0083] like Figure 2 The temporary storage queues shown indicate that application 1, identified by UID1, can have three broadcast process queues: broadcast process queue 1 corresponding to application process 1, broadcast process queue 2 corresponding to application process 2, and broadcast process queue 3 corresponding to application process 3. Application 2, identified by UID2, can have two broadcast process queues: broadcast process queue 4 corresponding to application process 4 and broadcast process queue 5 corresponding to application process 5. Application 3, identified by UID3, can have one broadcast process queue: broadcast process queue 6 corresponding to application process 6.
[0084] During the process of a broadcast entering AMS's modern broadcast queue, AMS can create a broadcast process queue based on the application process in which the broadcast receiver resides. AMS can encapsulate each broadcast receiver into individual args and assign them to the appropriate group within the broadcast process queue according to their broadcast attributes. See details... Figure 1 The corresponding description.
[0085] Figure 2 The contents of the broadcast process queue 1 and some args A1 can be found in [link to relevant documentation]. Figure 1 The description in the text will not be repeated here.
[0086] The ready queue includes a queue of broadcast processes arranged according to their ready time. Ready time can be understood as the time allotted for distributing the broadcast to receivers.
[0087] AMS can determine the ready time of each broadcast process queue based on broadcast type, application process status, etc., and arrange the broadcast process queues according to their ready time to obtain the ready queue. For example Figure 2As shown in the ready queue, AMS can determine the order of broadcast distribution to broadcast receivers in broadcast process queue 1, broadcast distribution to broadcast receivers in broadcast process queue 2, and then broadcast distribution to broadcast receivers in broadcast process queue 3, etc., according to the order of ready time.
[0088] The run queue contains multiple running resources; the dispatching and processing of a broadcast process queue can occupy one running resource. For example... Figure 2 As shown, AMS obtains broadcast process queue 1 from the ready queue. When distributing the broadcast to the broadcast receiver in broadcast process queue 1, it needs to obtain a running resource from the running queue and occupy a running resource for broadcast distribution. When the broadcast distribution is completed, the occupied running resource can be released. Figure 2 The run queue shown can provide 5 running resources, including 4 normal running resources and 1 expedited running resource.
[0089] Understandable Figure 2 The temporary queue, ready queue, running queue, and the contents of each queue described herein are merely examples and do not constitute a limitation on the modern broadcast queues described in the embodiments of this application.
[0090] 5. Deadlock
[0091] Deadlock can be understood as an abnormal situation in the broadcast distribution process. Deadlock occurs when the first-in-first-out (FIFO) principle followed by each group in the broadcast process queue conflicts with the priority / order attributes of the broadcast receivers within those groups, causing two or more broadcast receivers in a group to wait for each other due to out-of-order delivery.
[0092] In one implementation, combined Figure 3 The description of the broadcast process queue illustrates the deadlock situation. Figure 3 This is a schematic diagram of a broadcast process queue provided in an embodiment of this application.
[0093] like Figure 3As shown, the ordinary packets in broadcast process queue 2 can include, in sequence, some args A4, some args A3, and some args A5, etc. Some args A4 can be understood as the broadcast receiver with receiver index 4 in broadcast A (i.e., broadcast receiver 4), some args A3 can be understood as the broadcast receiver with receiver index 3 in broadcast A (i.e., broadcast receiver 3), and some args A5 can be understood as the broadcast receiver with receiver index 5 in broadcast A (i.e., broadcast receiver 5). The contents of other packets in broadcast process queue 2 besides ordinary packets, and the contents of broadcast process queue 3, can be found in [reference needed]. Figure 1 As shown, it will not be elaborated further here.
[0094] See Figure 1 The document describes the priorities of broadcast receiver 4 and broadcast receiver 3, with broadcast receiver 3 having a higher priority than broadcast receiver 4. Therefore, when AMS distributes broadcasts according to the priority order of the broadcast receivers, AMS can determine to distribute broadcast A to broadcast receiver 3 first, and then distribute broadcast A to broadcast receiver 4.
[0095] See Figure 1 The text describes the ordered descriptions of broadcast receivers 4 and 3, with the index of broadcast receiver 3 preceding that of broadcast receiver 4. Therefore, when AMS distributes broadcasts according to the order of the broadcast receivers, AMS can determine to distribute broadcast A to broadcast receiver 3 first, and then to broadcast receiver 4.
[0096] And in Figure 3 In the ordinary packets of broadcast process queue 2 described in the description, broadcast receiver 4 is enqueued into the ordinary packet first, and broadcast receiver 3 is enqueued into the ordinary packet later. Therefore, when AMS follows the first-in-first-out principle in the broadcast process queue packets to distribute broadcasts, AMS can determine that broadcast A is distributed to broadcast receiver 4 first, and then broadcast A is distributed to broadcast receiver 3.
[0097] However, in reality, when AMS distributes broadcast A to broadcast receiver 4, because there are higher-priority broadcast receivers or earlier-ordered broadcast receivers (such as broadcast receiver 3) in the same group that have not yet been distributed, AMS determines that broadcast receiver 4 needs to wait for the higher-priority broadcast receivers or earlier-ordered broadcast receivers to finish distributing. Similarly, when AMS distributes broadcast A to broadcast receiver 3, because there are earlier-ordered broadcast receivers (such as broadcast receiver 4) in the same group that have not yet been distributed, AMS determines that broadcast receiver 3 needs to wait for the earlier-ordered broadcast receivers in the group to finish distributing. Both broadcast receivers 3 and 4 are in a mutual waiting state, preventing any broadcast receiver in the group from distributing normally, causing a deadlock. This deadlock in the group will have a chain reaction, preventing other broadcast receivers in broadcast process queue 2, as well as broadcast receivers in broadcast process queue 3 located after broadcast process queue 2, from distributing broadcasts, thus affecting the entire broadcast distribution mechanism.
[0098] Combination Figure 3 The description states that the reasons for broadcast receivers being out of order can include one or more of the following: the priority of the broadcast receiver is temporarily adjusted, a low-priority broadcast receiver is directly added to the head of the queue, or the broadcast receiver carries a replace attribute, causing the broadcast receiver to be replaced, etc.
[0099] Deadlock can also be understood as a phenomenon in which, in the broadcast process queue corresponding to an application process that is not in a frozen state, the broadcast receiver at the head of any group is in a blocked state for a long time, causing other broadcast receivers in the group to be unable to distribute their broadcasts normally.
[0100] Processes in a frozen state: Background processes that cannot access CPU resources; frozen processes may carry a cached flag. Processes in a non-frozen state can include one or more of the following: foreground processes, visible processes, or resident processes, etc.
[0101] The situations in which the broadcast receiver at the head of the queue is in a blocked state include: the broadcast receiver at the head of the queue has a higher priority broadcast receiver that has not yet finished distributing; the ordered broadcast receiver at the head of the queue has a broadcast receiver with a higher index that has not yet finished distributing; or the process corresponding to a deferred broadcast receiver is in a frozen state. It can be understood that when a broadcast is ordered, the broadcast receiver corresponding to that broadcast can be called an ordered broadcast receiver.
[0102] In another implementation, combined Figure 4 The description of the broadcast process queue illustrates the deadlock situation. Figure 4 This is a schematic diagram of another broadcast process queue provided in an embodiment of this application.
[0103] like Figure 4 As shown, the ordinary packets in broadcast process queue 1 can include, in sequence, some args A1, some args A2, and some args B1, etc. some args A1 can be understood as the broadcast receiver with receiver index 1 in broadcast A (i.e., broadcast receiver 1), some args A2 can be understood as the broadcast receiver with receiver index 2 in broadcast A (i.e., broadcast receiver 2), and some args B1 can be understood as the broadcast receiver with receiver index 1 in broadcast B. The contents of other packets in broadcast process queue 1 besides ordinary packets, and the contents of broadcast process queue 2, can be found in [reference needed]. Figure 1 As shown, it will not be elaborated further here.
[0104] If application process 1 is not in a frozen state, and the time that broadcast receiver 1 at the head of the ordinary packet in broadcast process queue 1 is in a blocked state exceeds a time threshold, a deadlock will occur in the ordinary packet. This deadlock in the ordinary packet will have a cascading effect, preventing other broadcast receivers in broadcast process queue 1, as well as broadcast receivers in broadcast process queue 2 following broadcast process queue 1, from delivering broadcasts, thus affecting the entire broadcast delivery mechanism.
[0105] 6. Other terms
[0106] In the embodiments of this application, terms such as "first" and "second" are used to distinguish identical or similar items with substantially the same function and purpose. For example, "first chip" and "second chip" are used only to distinguish different chips and do not limit their order of execution. Those skilled in the art will understand that terms such as "first" and "second" do not limit the quantity or execution order, and that "first" and "second" do not necessarily imply that they are different.
[0107] It should be noted that, in the embodiments of this application, the terms "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design scheme described as "exemplary" or "for example" in this application should not be construed as being more preferred or advantageous than other embodiments or design schemes. Specifically, the use of terms such as "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.
[0108] In this application embodiment, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c can represent: a, b, c, ab, a--c, bc, or abc, where a, b, and c can be single or multiple.
[0109] 7. Electronic equipment
[0110] The electronic devices in this application embodiment may include handheld devices, vehicle-mounted devices, etc., with broadcast processing functions. For example, some electronic devices include: mobile phones, tablets, PDAs, laptops, mobile internet devices (MIDs), wearable devices, virtual reality (VR) devices, augmented reality (AR) devices, wireless terminals in industrial control, wireless terminals in self-driving vehicles, wireless terminals in remote medical surgery, wireless terminals in smart grids, wireless terminals in transportation safety, wireless terminals in smart cities, wireless terminals in smart homes, cellular phones, cordless phones, session initiation protocol (SIP) phones, wireless local loop (WLL) stations, personal digital assistants (PDAs), handheld devices with wireless communication capabilities, computing devices or other processing devices connected to wireless modems, in-vehicle devices, wearable devices, terminal devices in 5G networks, or future evolution of public land mobile communication networks. Terminal devices in a network (PLMN), etc., are not limited to this in the embodiments of this application.
[0111] The electronic devices in the embodiments of this application may also be referred to as: terminal equipment, user equipment (UE), mobile station (MS), mobile terminal (MT), access terminal, user unit, user station, mobile station, mobile station, remote station, remote terminal, mobile device, user terminal, terminal, wireless communication equipment, user agent, or user device, etc.
[0112] In this embodiment, the electronic device or various network devices include a hardware layer, an operating system layer running on top of the hardware layer, and an application layer running on top of the operating system layer. The hardware layer includes hardware such as a central processing unit (CPU), a memory management unit (MMU), and memory (also called main memory). The operating system can be any one or more computer operating systems that implement business processing through processes, such as Linux, Unix, Android, iOS, or Windows. The application layer includes applications such as browsers, address books, word processing software, and instant messaging software.
[0113] Based on the description of deadlock at the end of the title, deadlock can occur in various broadcast distribution scenarios. For example, deadlock during broadcast distribution can lead to application / functional failures such as Wi-Fi network connection failure, instant messaging message delays, and alarm clock delays, reducing the efficiency of modern broadcast mechanisms or even causing them to fail completely.
[0114] Combination Figure 5 The corresponding implementation example illustrates the deadlock situation using a failed Wi-Fi network connection as an example. Figure 5 This is a schematic diagram of a scenario provided for an embodiment of this application.
[0115] When an electronic device receives a message indicating that the user has enabled the WLAN settings, it displays something like this. Figure 5 The image shows the Wi-Fi settings interface (point 'a'). The Wi-Fi settings interface can display at least one available Wi-Fi network, such as Wi-Fi1, Wi-Fi2, and Wi-Fi3.
[0116] In response to a user's triggering action on button 501 for connecting to WIFI1, the electronic device generates a WIFI status change broadcast, and the electronic device obtains the broadcast receiver corresponding to the WIFI status change broadcast. The broadcast receiver corresponding to the WIFI status change broadcast can include one or more of the following, such as: the user interface (UI) process corresponding to the WIFI settings interface, the process corresponding to system applications (such as app stores), or the process corresponding to third-party applications (such as social applications), etc.
[0117] Electronic devices assign broadcast receivers, such as UI processes and system applications (e.g., app stores), to a broadcast process queue. If a deadlock occurs in any group of the broadcast process queue, Wi-Fi status change broadcasts will fail to reach UI processes and other broadcast receivers, and the electronic device will be unable to connect to Wi-Fi1.
[0118] Understandably, when a deadlock occurs, electronic devices cannot detect deadlock anomalies in the broadcast process queue in a timely manner. As a result, the system cannot detect the deadlock situation immediately when the problem occurs, and the broadcast distribution process continues to run in an incorrect deadlock state until all functions fail.
[0119] In view of this, embodiments of this application provide a broadcast processing method that enables an electronic device to determine the existence of deadlock when identifying one or more of the following situations: a low-priority broadcast receiver is located ahead of a high-priority broadcast receiver in any group of the broadcast process queue; a later-indexed ordered broadcast receiver is located ahead of a earlier-indexed ordered broadcast receiver in any group of the broadcast process queue; or, in the broadcast process queue corresponding to a non-frozen application process, a broadcast receiver at the head of any group is blocked for an extended period. This achieves accurate detection of deadlock. Here, "later-indexed" can be understood as having a larger index value, and "earlier-indexed" can be understood as having a smaller index value.
[0120] To better understand the embodiments of this application, the structure of the terminal device of this application embodiment is described below. For example, Figure 6 This is a schematic diagram of the structure of a terminal device provided in an embodiment of this application.
[0121] The terminal device 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, 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, an indicator 192, a camera 193, and a display screen 194, etc.
[0122] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the terminal device. In other embodiments of this application, the terminal device 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.
[0123] Processor 110 may include one or more processing units. These processing units may be independent devices or integrated within one or more processors. Processor 110 may also include memory for storing instructions and data. For example, processor 110 may be used to execute data processing steps in a broadcast processing method.
[0124] The wireless communication function of the terminal device can be implemented through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor, and baseband processor.
[0125] The wireless communication module 160 can provide solutions for wireless communication applications on terminal devices, including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks).
[0126] The terminal device implements display functions through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor that performs broadcast processing, connecting the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations and for graphics rendering.
[0127] Display screen 194 is used to display images, videos, etc. Display screen 194 includes a display panel. In some embodiments, the terminal device may include one or N displays screens 194, where N is a positive integer greater than 1. For example, display screen 194 can be used to display, for example... Figure 4 The WIFI settings interface or other interfaces described in the document.
[0128] Terminal devices can achieve shooting functions through ISP, camera 193, video codec, GPU, display 194 and application processor.
[0129] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the terminal device. The internal memory 121 can be used to store executable program code, including instructions. The internal memory 121 may include a program storage area and a data storage area. For example, the internal memory 121 can be used to store executable program code in a broadcast processing method.
[0130] The terminal device can implement audio functions such as music playback and recording through an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, and an application processor.
[0131] The sensor module 180 may include a touch sensor ( Figure 6 (Not shown in the image). A touch sensor can be located on the display screen 194, and the touch sensor and the display screen 194 together form a touch screen, or "touchscreen". The touch sensor is used to receive any touch operation from the user on the display screen 194.
[0132] The software system of terminal devices can adopt layered architecture, event-driven architecture, microkernel architecture, microservice architecture, or cloud architecture, etc., which will not be elaborated here.
[0133] For example, Figure 7 This is a schematic diagram of the software structure of an electronic device provided in an embodiment of this application. Figure 6 As shown, the layered architecture divides the software into several layers, each with a clear role and function. Layers communicate with each other through software interfaces.
[0134] In some embodiments, the Android system is divided into multiple layers, from top to bottom: the application (APP) layer, the application framework (FWK) layer, and the kernel layer, etc. This application embodiment does not limit this.
[0135] The application layer can include a series of application packages. The application layer can include at least one application, such as a system application or a third-party application. Figure 7 (not shown in the text), etc., are not limited in this application embodiment.
[0136] Both the application layer and the application framework layer can implement broadcast event triggering. Taking broadcast event triggering at the application layer as an example, the application layer can notify the AMS that a broadcast needs to be distributed through the application context (contextimpl) interface. The communication method between the application layer and the AMS can be through methods such as binder calls; this embodiment is not limited to this.
[0137] The application framework layer provides application programming interfaces (APIs) and a programming framework for applications in the application layer. The application framework layer includes a set of predefined interfaces. It may also include a series of system services. System services are modular components focused on specific functionalities. The functionality provided by the application framework API allows communication with these system services to access the underlying hardware.
[0138] The application framework layer may include: system server processes and configuration management modules.
[0139] The system service process is responsible for starting and managing the entire application framework layer. After the system service process is created, it can mainly handle the following: (1) initialize some system settings, virtual machine configuration, etc.; (2) start the binder thread pool so that it can communicate with other processes through binder cross-process communication; (3) create the system service manager, which is used to create, start and manage the life cycle of system services; (4) create the main thread looper and enter the loop to wait for messages; (5) start various system services, such as AMS, PMS, etc.
[0140] The system service process can run AMS and PMS. AMS manages all activities and processes within an application. It can start, pause, stop, and destroy activities, as well as manage the application's lifecycle. AMS can also allocate system resources such as memory, processes, and threads to different applications. PMS is primarily responsible for the installation, management, and uninstallation of applications. When a new application is installed, PMS identifies all components of the application (e.g., services, broadcast receivers, etc.) and assigns appropriate permissions to these components. PMS can also view the status of installed applications, ensuring their integrity and security.
[0141] In this embodiment of the application, the PMS may include the correspondence between broadcasts and broadcast receivers generated during static broadcast registration; the AMS may include the correspondence between broadcasts and broadcast receivers generated during dynamic broadcast registration.
[0142] It is understood that the system service process may also include other services, which will not be elaborated in this application.
[0143] The configuration management module can be used for configuration initialization at boot time (e.g., initializing the initial mapping in the configuration file), and for storing and processing maintenance information transmitted by system service processes. It also enables maintenance and testing of deadlock issues that occur during the management of the system service process application framework layer.
[0144] AMS can run modern broadcast queues and deadlock detection modules. The process of broadcast distribution based on modern broadcast queues can be found in sections ①-⑧ below. The process of deadlock detection based on the deadlock detection module can be found in the following sections. The description in the text.
[0145] like Figure 7 As shown, the process of broadcast distribution based on modern broadcast queues can be described as follows:
[0146] ① Broadcast events are triggered at the application layer or application framework layer.
[0147] ② The application layer or application framework layer sends broadcasts to AMS for scheduling and management.
[0148] ③ AMS collects broadcast receivers. For example, AMS can collect broadcast receivers that are dynamically registered for broadcasts from AMS, and broadcast receivers that are statically registered for broadcasts from PMS. AMS sorts all collected broadcast receivers according to their priority.
[0149] ④ AMS assigns broadcast receivers to broadcast process queues. For example, AMS assigns broadcast receivers to groups within the broadcast process queue based on the application process corresponding to the broadcast receiver and the broadcast attributes. For details on the distribution process, please refer to [link to relevant documentation]. Figure 1 as well as Figure 2 The description in the text will not be repeated here.
[0150] ⑤ AMS schedules broadcast delivery from the broadcast process queue. For example, AMS determines the delivery order of broadcasts according to the group order in the broadcast process queue.
[0151] ⑥AMS determines whether to cold start or warm start the application process corresponding to the broadcast receiver. If the application process is not closed, AMS warm starts the application process and then executes ⑦. Alternatively, if the application is not started, AMS can create the application process by executing ⑧ and then execute ⑦.
[0152] ⑦ AMS distributes broadcasts to broadcast receivers. For example, a broadcast can be passed to a broadcast receiver in the application layer via a binder call.
[0153] ⑧AMS instructs the zygote process to create the application process.
[0154] ⑨ AMS performs broadcast risk identification. For example, AMS can determine the broadcast risk level based on broadcast attributes and determine the timed detection duration under the broadcast risk level based on the configuration file. The process of AMS determining the broadcast risk level based on broadcast attributes and determining the timed detection duration under the broadcast risk level based on the configuration file can be found in the description in S804, and will not be repeated here.
[0155] ⑩ The AMS performs queue status identification. For example, the AMS can determine the risk level of potential deadlock in the queue based on the number of broadcast receivers in the temporary queue and the number of broadcast receivers in the ready queue. When the risk level is determined to meet preset conditions, a timed detection duration is set. The process of determining the risk level based on the number of broadcast receivers in the temporary queue and the ready queue can be found in the description in S810, and will not be repeated here.
[0156] AMS performs timed polling. For example, AMS can perform deadlock detection when the scheduled monitoring period has elapsed.
[0157] AMS performs deadlock detection. Specifically, AMS can execute [specific actions] when a deadlock is detected. Alternatively, the current deadlock detection process can be terminated if no deadlock is detected. The deadlock detection process can be found in the description in S806, and will not be repeated here.
[0158] An Application Not Responding (ANR) triggered by Android System Management (AMS) refers to an application failing to respond. Specifically, the Android system requires certain events to be completed within a specific timeframe. If a valid response is not received within the predetermined time or the response time is excessively long, an ANR will occur.
[0159] In possible implementations, the application framework layer may also include one or more of the following: a display compositor, a window manager, a content provider, a resource manager, a view system, or a notification manager, etc. Figure 7 (Not shown in the image).
[0160] The kernel layer can create application processes. The kernel layer can include the zygote process. The zygote process is started by the init process, the first process in user space, and is the first Android runtime process running in the Android operating system. The zygote process's main functions include creating system service processes and other application processes.
[0161] In possible implementations, the electronic device may also include a hardware abstraction layer, a driver layer, and other software layers. This application does not specifically limit the software layers involved in the software architecture, the modules contained within those layers, or the functions of those modules.
[0162] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be implemented independently or in combination with each other. The same or similar concepts or processes may not be described again in some embodiments.
[0163] For example, Figure 8 This is a schematic flowchart illustrating a broadcast processing method provided in an embodiment of this application. Figure 8 In a corresponding embodiment, the electronic device may include one or more of the following: AMS, modern broadcast queue, worker thread, or broadcast process queue.
[0164] In this context, AMS, the modern broadcast queue, and the broadcast process queue can all run in the same thread, which can be the main thread in the AMS thread pool. Worker threads can be child threads within the AMS thread pool. The main thread and worker threads are distinct; their names are merely illustrative and do not constitute a limitation on the embodiments of this application.
[0165] like Figure 8 As shown, the broadcast processing method may include: the enqueue phase described in S802-S812, the delivery phase described in S813-S817, and the dispatch phase described in S818.
[0166] S801. When the electronic device is detected to be powered on, AMS parses the configuration file and saves the first correspondence.
[0167] The configuration file can be pre-set in the configuration management module. The configuration file includes: the first correspondence between broadcast risk level and timed detection duration, for example, the contents of the first correspondence can be as shown in Table 1 below.
[0168] Table 1. Schematic diagram of the first correspondence.
[0169] Serial Number Broadcast risk level Periodic detection duration 1 high 3 minutes 2 middle 5 minutes 3 Low 0 minutes
[0170] Broadcast risk level can be understood as the level of risk of deadlock occurring during the broadcast distribution process. The higher the broadcast risk level, the more likely a deadlock is to occur during the broadcast distribution process.
[0171] The timed detection duration can be understood as the periodic duration for deadlock detection. When the timed detection duration is 3 minutes, the electronic device can perform a deadlock detection every 3 minutes. When the timed detection duration is 0 minutes, the electronic device can determine that deadlock detection is not necessary. The shorter the timed detection duration, the more deadlock checks are performed within the fixed duration.
[0172] As shown in Table 1, the higher the broadcast risk level, the shorter the timed detection duration. Electronic devices can improve the security of broadcast distribution by setting different timed detection durations for different broadcast risk levels and performing multiple deadlock checks on broadcasts with high risk levels.
[0173] It is understood that the broadcast risk level and the value of the timed monitoring duration described in Table 1 are only examples and do not constitute a limitation on the embodiments of this application.
[0174] For example, in response to user operations such as powering on or restarting, the Linux kernel starts. The kernel can notify the system service process and service devices such as the configuration management module to power on by starting init(). The AMS in the system service process can obtain the configuration file from the configuration management module. The AMS parses the configuration file and saves the first correspondence in the configuration file.
[0175] S802. When AMS receives the first broadcast, AMS obtains the target broadcast receiver corresponding to the first broadcast.
[0176] The first broadcast can be sent to the AMS by a broadcaster. Correspondingly, the AMS can receive the first broadcast sent to the AMS by the broadcaster. It is understood that the broadcaster can be the operating system in the electronic device, or it can be an application, component, etc., in the electronic device; this application does not limit this.
[0177] There is a second correspondence between the first broadcast and the target broadcast receiver. This second correspondence can be obtained from the AMS and PMS. The number of target broadcast receivers can be one or more, and this is not limited in the embodiments of this application.
[0178] In one implementation, when an electronic device performs static broadcast registration in a PMS, it can store a second correspondence in the PMS when registering the first broadcast. In this case, after the AMS receives the first broadcast from the broadcast sender, it can perform scheduling management and retrieve the target broadcast receiver corresponding to the first broadcast from the PMS based on the second correspondence.
[0179] In another implementation, when an electronic device performs dynamic broadcast registration in the AMS, it can store a second correspondence in the AMS when registering for the first broadcast. In this case, after receiving the first broadcast from the broadcast sender, the AMS can retrieve the target broadcast receiver corresponding to the first broadcast from the AMS based on the second correspondence.
[0180] In possible implementations, this second correspondence can also be stored in other modules. In this case, AMS can obtain the second correspondence based on the corresponding interface or a specific storage address, which is not limited in this embodiment.
[0181] For example, the broadcast sender passes the first broadcast and its broadcast properties to the AMS by calling the contextimpl interface, using instructions for sending the broadcast. The AMS can then collect target broadcast receivers from either the AMS or PMS using instructions for collecting broadcast receivers when it detects the first broadcast. The instructions for sending the broadcast can include: broadcastIntentWithFeature(), and the instructions for collecting broadcast receivers can include: collectReceiverComponents().
[0182] The broadcast attributes of a first broadcast may include: attributes indicating whether the first broadcast is an ordered broadcast or a normal broadcast, attributes indicating whether the first broadcast has priority, and attributes indicating whether the first broadcast allows replacement. Specifically, if, during the broadcast registration process, it is determined that the broadcast receiver registering the first broadcast has priority, then a priority attribute can be added to that first broadcast.
[0183] In a possible implementation, when AMS receives the first broadcast, AMS can first perform broadcast verification and assign values to default broadcast attributes using instructions for broadcast verification. Instructions for broadcast verification may include: broadcastIntentLockedTraced().
[0184] After S802, AMS can prioritize target broadcast receivers according to their priority to obtain the broadcast receiver queue corresponding to the target broadcast receiver.
[0185] S803 and AMS send enqueue commands to the modern broadcast queue.
[0186] The enqueue instruction is used to instruct modern broadcast queues to assign a target broadcast receiver to a group within the broadcast process queue. The enqueue instruction can carry: the broadcast attributes of the first broadcast, and information about the target broadcast receiver. This information may include: the application process the target broadcast receiver is running in, and the target broadcast receiver's status information. The target broadcast receiver's status information may include: the number of target broadcast receivers.
[0187] For example, AMS can instruct the modern broadcast queue to enqueue the target broadcast receiver by invoking an enqueue instruction. The enqueue instruction can include: `enqueueBroadcastLocked()`.
[0188] It is understood that AMS can perform deadlock detection on the broadcast process queue in the temporary storage queue based on the steps shown in S804-S806 and / or the steps shown in S810-812. The temporary storage queue may include the first broadcast process queue described below, or it may include other broadcast process queues, that is, AMS can perform risk detection on the first broadcast process queue and other broadcast process queues. The following is an illustrative description of the deadlock detection process using the example of the temporary storage queue including the first broadcast process queue. This illustration does not constitute a limitation on the embodiments of this application.
[0189] S804. The modern broadcast queue determines the broadcast risk level of the first broadcast and the first timing detection duration of the first broadcast based on the broadcast attributes and the first correspondence of the first broadcast.
[0190] The process by which a modern broadcast queue determines the broadcast risk level and the first timing detection duration of a first broadcast based on broadcast attributes and a first correspondence can include the following three scenarios:
[0191] Case 1: If the first broadcast contains the attributes of order, priority, and replace, and the number of target broadcast receivers is greater than the first threshold, the broadcast risk level of the first broadcast is determined to be high.
[0192] The first threshold can be a value such as 30, and this application embodiment does not limit it. When the broadcast receiver corresponding to the first broadcast has a priority, the first broadcast is a broadcast with a priority attribute.
[0193] Understandably, the more target broadcast receivers there are, the more likely a deadlock will occur during the first broadcast distribution process.
[0194] When the risk level of the first broadcast is high, the duration of the first timed check is 3 minutes. This is understandable because a high risk level in the first broadcast increases the likelihood of deadlock during its distribution; therefore, a shorter timed check duration can be set to enable multiple deadlock checks.
[0195] Scenario 2: If the first broadcast contains at least one of the following attributes: ordered, priority, or replace, and the number of target broadcast recipients is less than or equal to the first threshold, the risk level of the first broadcast is determined to be medium. Alternatively, if the first broadcast contains at least one of the following attributes: ordered, priority, or replace, and the number of target broadcast recipients is greater than the first threshold, the risk level of the first broadcast is determined to be medium.
[0196] When the risk level of the first broadcast is medium, the duration of the first timed detection is 5 minutes. This is because, with a medium risk level, there is a relatively low probability of deadlock during the distribution of the first broadcast; therefore, a longer timed detection duration can be set to achieve timed deadlock detection without consuming excessive device power.
[0197] Case 3: If the first broadcast does not contain the attributes of ordered, priority, or replace, the risk level of the first broadcast is determined to be low.
[0198] When the risk level of the first broadcast is low, the duration of the first timed check is 0 minutes. This is understandable because when the risk level of the first broadcast is low, there is almost no possibility of deadlock during the distribution process, therefore timed deadlock detection is unnecessary.
[0199] In the above risk identification process, the method by which AMS determines the first broadcast risk level may not be limited to the above description, and will not be elaborated here.
[0200] Understandably, inserting the broadcast risk identification process into the broadcast queuing process can maintain the consistency of broadcast risk information updates. When a risk broadcast enters the modern broadcast queue, subsequent periodic polling checks will be initiated, avoiding situations where the check timing is not synchronized with the current queue risk updates.
[0201] In a possible implementation, AMS could also immediately initiate deadlock detection when it detects that the risk level of the broadcast is high or medium, and then perform deadlock detection again when the first timed detection period expires.
[0202] S805, the modern broadcast queue sends the first delayed message to the worker thread.
[0203] The first delay message is used to notify worker threads to perform deadlock detection after the corresponding timeout period has elapsed. For example, the first delay message can carry the first timeout period, and the first delay message can be MSG_BR_BLOCK_CHECK.
[0204] S806. When the worker thread reaches the first timer detection duration, it performs deadlock detection.
[0205] based on Figure 3 as well as Figure 4 The description of deadlock in broadcast mechanisms in the text includes two deadlock detection methods:
[0206] In one implementation, the worker thread traverses the broadcast process queue in the temporary storage queue that is in a blocked state. When a low-priority broadcast receiver is located in front of a high-priority broadcast receiver or a broadcast receiver with a larger index value is located in front of a broadcast receiver with a smaller index value in any group of the broadcast process queue in a blocked state, a deadlock is determined and AMS is notified to take termination / rollback measures.
[0207] The target broadcast receivers include both high-priority and low-priority broadcast receivers. Determining whether two broadcast receivers are receiving the same broadcast can be based on the hash code of the broadcast being listened to by each receiver. For example, if the hash code of a high-priority broadcast receiver is the same as the hash code of a low-priority broadcast receiver, and both receivers are on the same electronic device.
[0208] In another implementation, the worker thread iterates through the blocked broadcast process queue in the temporary storage queue. When the worker thread detects that in the broadcast process queue corresponding to an application process in a non-frozen state, there exists a queue where the difference between the enqueue time of the head broadcast receiver and the current time is greater than a third threshold, a deadlock is determined, and AMS is notified to take termination / rollback measures. Here, the enqueue time can be understood as the time when the first broadcast enters the modern broadcast queue.
[0209] Understandably, when a worker thread determines that one of the packets in the broadcast process queue is normal during deadlock detection, it can mark that packet as safe and perform deadlock detection on the other packets in the broadcast process queue until all broadcast process queues in the temporary queue are marked as safe.
[0210] Alternatively, when a worker thread determines that a deadlock exists in one of the packets of the broadcast process queue during deadlock detection, it can mark the broadcast process queue as abnormal and then notify AMS to take termination / rollback measures.
[0211] It is understandable that before the worker thread performs deadlock detection on the distribution process of the first broadcast based on S806, the target broadcast receiver has already been enqueued into the first broadcast process queue based on S807-S809, so that the worker thread can determine whether deadlock detection has occurred based on the state of the first broadcast process queue.
[0212] Alternatively, if the target broadcast receiver is not enqueued in the first broadcast process queue, the worker thread can determine whether a deadlock exists in the broadcast process queue in the temporary queue by performing deadlock detection. In this scenario, since the worker thread has started a timed polling function, it can perform deadlock detection on the first broadcast process queue when the next timed detection period expires.
[0213] Alternatively, even if the target broadcast receiver is not yet enqueued in the first broadcast process queue, AMS determines the first timed detection duration. Before the first timed detection duration expires, the target broadcast receiver can be enqueued in the first broadcast process queue. At this time, the worker thread can determine whether there is a deadlock in the first broadcast process queue through deadlock detection.
[0214] In this embodiment of the application, AMS can perform deadlock detection on the distribution process of the first broadcast after the target broadcast receiver is enqueued into the first broadcast process queue.
[0215] S807. The modern broadcast queue determines the first broadcast process queue and the grouping of the target broadcast receiver in the first broadcast process queue based on the application process in which the target broadcast receiver is located.
[0216] Understandably, the process by which modern broadcast queues determine the first broadcast process queue and the grouping of target broadcast receivers within that queue can be found in [reference needed]. Figures 1-2 The description in the text will not be repeated here.
[0217] S808, Modern Broadcast Queue Notifies Broadcast Process Queue, Target Broadcast Receiver in the First Broadcast Process Queue Group.
[0218] For example, a modern broadcast queue can notify the broadcast process queue by calling enqueueorplaceBroadcast().
[0219] S809, The broadcast process queue adds the target broadcast receiver to the group in the first broadcast process queue.
[0220] For example, the broadcast process queue can add the target broadcast receiver to the group in the first broadcast process queue by calling addLast().
[0221] S810, the modern broadcast queue determines the second timing detection duration based on the number of broadcast receivers in the temporary queue and the number of broadcast receivers in the ready queue.
[0222] For the meanings of the temporary queue and the ready queue, please refer to [link / reference]. Figure 2 The description in the text will not be repeated here.
[0223] For example, a modern broadcast queue can calculate the ratio between the number of broadcast receivers in the ready queue (or third broadcast receivers) and the number of broadcast receivers in the temporary queue (or fourth broadcast receivers). This ratio can be obtained by dividing the number of broadcast receivers in the ready queue by the number of broadcast receivers in the temporary queue.
[0224] When the ratio is greater than the second threshold, the modern broadcast queue can determine that the second timing detection duration is set to a duration of 3 minutes or similar. Alternatively, when the ratio is less than or equal to the second threshold, the modern broadcast queue can normally execute the steps shown in S813-S818. The second threshold can be set to a value such as 90%.
[0225] It is understandable that when there are many broadcast receivers in the temporary queue and few broadcast receivers in the ready queue, it indicates that there may be a deadlock in the temporary queue, which prevents the broadcast from being sent to the corresponding broadcast receiver.
[0226] In a possible implementation, AMS could also immediately initiate deadlock detection when the detection ratio is greater than the second threshold, and then perform deadlock detection again when the second timed detection period expires.
[0227] S811, Modern broadcast queues send a second delayed message to worker threads.
[0228] The second delay message is used to notify worker threads to perform deadlock detection after the corresponding timeout period has elapsed. For example, the second delay message can carry a second timeout period, and the second delay message can also be MSG_BR_BLOCK_CHECK.
[0229] S812. When the worker thread meets the second timer detection duration, it performs deadlock detection.
[0230] The method for deadlock detection in worker threads in S812 can be found in the description in S806, and will not be repeated here.
[0231] Understandably, the electronic device can perform deadlock detection based on the steps shown in S801-S812. When no deadlock is detected, the electronic device can normally distribute the first broadcast to the corresponding target broadcast receiver based on the steps shown in S813-S818 below.
[0232] Understandably, AMS can update the ready queue during the delivery phase. For example, modern broadcast queues can update the ready queue by calling instructions to update the ready queue. These instructions can include: updaterunableList().
[0233] S813, Modern Broadcast Queue notifies worker threads to perform preparation work for entering the run queue.
[0234] The preparation work for entering the run queue may include: worker threads determining whether broadcast distribution can be performed at the ready time, and whether there are sufficient running resources in the run queue for broadcast distribution. Modern broadcast queues notify worker threads to perform the preparation work for entering the run queue by invoking instructions to update the run queue. Instructions for updating the run queue may include: MSG_UPDATE_RUNNING_LIST.
[0235] S814, The worker thread performs preparation work for entering the run queue.
[0236] When a worker thread determines that it can broadcast the process when the ready time arrives and that there are sufficient running resources in the running queue for broadcasting, it can allocate the first broadcast process queue to the running queue and execute the steps shown in S815.
[0237] S815, The worker thread notifies the broadcast process queue to update the ready time.
[0238] For example, worker threads can notify the broadcast process queue to update its ready time by calling getrunnableAt().
[0239] S816, Broadcast process queue calculates ready time.
[0240] The steps for calculating the ready time of the broadcast process queue can be found in [link to relevant documentation]. Figure 2 The descriptions in the corresponding embodiments will not be repeated here.
[0241] The broadcast process queue can be updated with its ready time by calling updaterunnableAt().
[0242] S817, the broadcast process queue sends the ready time to the worker thread.
[0243] S818. When the ready time arrives, the worker thread will distribute the first broadcast to the target broadcast receiver.
[0244] Worker threads can distribute the first broadcast sequentially to the corresponding target broadcast receivers according to the ready time of each broadcast process queue. Specifically, worker threads can distribute the first broadcast by calling `dispatchReceivers()`.
[0245] Understandable Figure 8 The steps described herein are merely examples and do not constitute a limitation on the embodiments of this application.
[0246] Therefore, electronic devices can not only perform risk detection for broadcasting and queuing, but also deadlock detection based on the state of broadcast receivers, thus providing security for the broadcast distribution process. Furthermore, the deadlock detection process does not affect the normal broadcast distribution process.
[0247] In the above Figure 8 Based on the corresponding embodiments, the broadcast processing method described in the embodiments of this application is explained more clearly. Figure 9 This is a schematic diagram illustrating the steps of another broadcast processing method provided in an embodiment of this application.
[0248] S901. Electronic devices calculate the timing detection duration based on broadcast risk identification and / or queue status identification.
[0249] The risk broadcast identification process can be found in step S804, and the queue idle state identification process can be found in step S810, which will not be repeated here.
[0250] S902, Electronic devices can send delayed messages with timed detection durations to worker threads.
[0251] The delayed message may include the duration of the timed detection. When the worker thread determines the duration of the timed detection in the delayed message, it can perform deadlock detection based on the steps shown in 903-S905.
[0252] S903. When the electronic device reaches the timed detection duration, it traverses the broadcast process queue in the temporary storage queue that is in the blocked state.
[0253] S904. Does the electronic device traverse any group of the broadcast process queue and find a low-priority broadcast receiver preceding a high-priority broadcast receiver?
[0254] The hash code generated when a low-priority broadcast receiver listens for a broadcast is the same as the hash code generated when a high-priority broadcast receiver listens for a broadcast, and the two broadcast receivers are on the same electronic device.
[0255] If the electronic device determines that in any group of the broadcast process queue, there exists a low-priority broadcast receiver preceding a high-priority broadcast receiver, the electronic device may execute the step shown in S906. Alternatively, if the electronic device determines that in any group of the broadcast process queue, there is no low-priority broadcast receiver preceding a high-priority broadcast receiver, the electronic device may execute the step shown in S907.
[0256] In a possible implementation, the electronic device may also confirm the existence of a deadlock and execute the steps shown in S906 when it detects a conflict between the ordered attribute of the broadcast and the first-in-first-out principle of the broadcast process queue. The specific deadlock detection process will not be described in detail here.
[0257] S905. Traverse the broadcast process queues corresponding to application processes that are not in a frozen state to see if there is a broadcast receiver at the head of the queue that has been in a blocked state for a long time.
[0258] When the electronic device determines that in the broadcast process queue corresponding to an application process that is not in a frozen state, there is a broadcast receiver at the head of the queue that has been in a blocked state for a long time, the electronic device executes the step shown in S906. Alternatively, when the electronic device determines that in the broadcast process queue corresponding to an application process that is not in a frozen state, there is no broadcast receiver at the head of the queue that has been in a blocked state for a long time, the electronic device executes the step shown in S907.
[0259] S906, Electronic equipment reports ANR.
[0260] S907. The electronic device determines that there is no out-of-order packet and marks it as safe. It continues to detect unmarked broadcast process queues until all broadcast process queues in the temporary storage queue are marked as safe.
[0261] Based on this, electronic devices can not only perform risk detection for broadcasts and queues, but also perform deadlock detection based on the state of broadcast receivers, so as to recover from deadlocks in a timely manner if deadlocks are accurately detected.
[0262] Understandably, in traditional broadcast detection mechanisms, electronic devices cannot identify the current operating status of the broadcast queue, and periodic detection is still required even if the broadcast queue is risk-free. The broadcast processing method provided in this application is a broadcast detection mechanism with lower performance overhead. Unlike traditional broadcast detection mechanisms, this invention can identify broadcast risks and only perform detection when there is a deadlock risk in the modern broadcast queue, thereby reducing the detection overhead in empty queue scenarios; the detection efficiency of the broadcast mechanism is further improved.
[0263] This application also provides a broadcast processing method, the method comprising: receiving a first broadcast sent by a broadcast sender, wherein the broadcast receivers corresponding to the first broadcast include a first broadcast receiver and a second broadcast receiver; assigning the first broadcast receiver and the second broadcast receiver to a first group of a first broadcast process queue, wherein the first broadcast receiver is located at a first position in the first group, and the second broadcast receiver is located at a second position in the first group, the second position being after the first position; and performing deadlock detection on the first broadcast process queue when the first broadcast process queue is in a blocked state.
[0264] The broadcast receiver corresponding to the first broadcast can be the target broadcast receiver described in the embodiments of this application. The first broadcast receiver and the second broadcast receiver can be two receivers among the target broadcast receivers.
[0265] The first group can be one of the groups in the broadcast process queue.
[0266] The order of the first and second positions can be used to represent the order in which two broadcast receivers are located within the first packet. The first packet can follow a first-in, first-out (FIFO) principle.
[0267] It is understood that the sequential relationship between the steps described in the embodiments of this application is only an example and does not constitute a limitation on the embodiments of this application.
[0268] It should be noted that the module names involved in the embodiments of this application can all be defined as other names, as long as they can achieve the function of each module, and no specific restrictions are placed on the module names.
[0269] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in the embodiments of this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0270] The above combination Figures 4-9 The broadcast processing method of the embodiments of this application has been described. The apparatus for performing the above method provided in the embodiments of this application is described below. Those skilled in the art will understand that the methods and apparatus can be combined with and referenced by each other, and the related apparatus provided in the embodiments of this application can perform the steps in the above list sorting method.
[0271] Figure 10This is a schematic diagram of a broadcast processing device provided in an embodiment of this application. The broadcast processing device may be an electronic device in the embodiment of this application, or it may be a chip or chip system within an electronic device.
[0272] like Figure 10 As shown, the broadcast processing apparatus 1000 can be used in communication equipment, circuits, hardware components, or chips. The broadcast processing apparatus 1000 includes a receiving unit 1001 and a processing unit 1002. The receiving unit 1001 supports the data receiving step of the broadcast processing method; the processing unit 1002 supports the information processing step of the broadcast processing apparatus 1000.
[0273] In one possible implementation, the broadcast processing device 1000 may further include a communication unit 1003, which supports the broadcast processing device 1000 in performing steps such as receiving or sending messages.
[0274] The broadcast processing apparatus described in the embodiments of this application may include all of the following: Figure 10 The units described in the corresponding embodiments.
[0275] Specifically, the processing unit 1002 and the receiving unit 1001 can be integrated together, and the processing unit 1002 and the receiving unit 1001 may communicate.
[0276] In one possible implementation, the broadcast processing apparatus 1000 may further include a storage unit 1004. The storage unit 1004 may include one or more memories, which may be devices in one or more devices or circuits used to store programs or data.
[0277] The storage unit 1004 can exist independently or be connected to the processing unit 1002 via a communication bus. Alternatively, the storage unit 1004 can be integrated with the processing unit 1002.
[0278] Taking the broadcast processing device 1000 as an example, which may be a chip or chip system of the electronic device in the embodiments of this application, the storage unit 1004 may store computer-executable instructions of the electronic device method, so that the processing unit 1002 executes the electronic device method in the above embodiments. The storage unit 1004 may be a register, cache, or random access memory (RAM), etc., and the storage unit 1004 may be integrated with the processing unit 1002. The storage unit 1004 may be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, and the storage unit 1004 may be independent of the processing unit 1002.
[0279] In one possible implementation, the broadcast processing device 1000 may further include a communication unit 1003. The communication unit 1003 supports interaction between the broadcast processing device 1000 and other devices. For example, when the broadcast processing device 1000 is an electronic device, the communication unit 1003 may be a communication interface or interface circuit. When the broadcast processing device 1000 is a chip or chip system within an electronic device, the communication unit 1003 may be a communication interface. For example, the communication interface may be an input / output interface, pins, or circuits.
[0280] The apparatus in this embodiment can be used to execute the steps performed in the above method embodiments, and its implementation principle and technical effect are similar, so they will not be described again here.
[0281] Figure 11 This is a schematic diagram of the hardware structure of another electronic device provided in an embodiment of this application.
[0282] The electronic device includes a processor 1101, a communication line 1104, and at least one communication interface. Figure 11 (The example is illustrated using communication interface 1103).
[0283] The processor 1101 may be a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits used to control the execution of the program of the present application.
[0284] Communication line 1104 may include circuitry for transmitting information between the aforementioned components.
[0285] Communication interface 1103 uses any transceiver-like device for communicating with other devices or communication networks, such as Ethernet, wireless local area networks (WLAN), etc.
[0286] Possibly, the electronic device may also include a memory 1102.
[0287] The memory 1102 may be a read-only memory (ROM) or other type of static storage device capable of storing static information and instructions, random access memory (RAM) or other type of dynamic storage device capable of storing information and instructions, or electrically erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed discs, laser discs, optical discs, digital universal discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto. The memory may exist independently and be connected to the processor via communication line 1104. The memory may also be integrated with the processor.
[0288] The memory 1102 stores computer execution instructions for implementing the scheme of this application, and the processor 1101 controls the execution. The processor 1101 executes the computer execution instructions stored in the memory 1102 to implement the method provided in the embodiments of this application.
[0289] It is possible that the computer execution instructions in the embodiments of this application may also be referred to as application code, and the embodiments of this application do not specifically limit this.
[0290] In a specific implementation, as one example, the processor 1101 may include one or more CPUs, for example... Figure 11 CPU0 and CPU1 in the CPU.
[0291] In a specific implementation, as one example, an electronic device may include multiple processors, for example... Figure 11 Processors 1101 and 1105 are mentioned. Each of these processors can be a single-core (single-CPU) processor or a multi-core (multi-CPU) processor. A processor here can refer to one or more devices, circuits, and / or processing cores used to process data (e.g., computer program instructions).
[0292] The broadcast processing method provided in this application can be applied to electronic devices with communication functions. Electronic devices include terminal devices, and the specific device form of the terminal device can be referred to the above-mentioned descriptions, which will not be repeated here.
[0293] This application provides a terminal device, which includes a processor and a memory; the memory stores computer execution instructions; the processor executes the computer execution instructions stored in the memory, causing the terminal device to perform the above-described method.
[0294] This application provides a chip. The chip includes a processor, which is used to call a computer program in memory to execute the technical solutions in the above embodiments. Its implementation principle and technical effects are similar to those in the related embodiments described above, and will not be repeated here.
[0295] This application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program. When the computer program is executed by a processor, it implements the methods described above. The methods described in the above embodiments can be implemented wholly or partially by software, hardware, firmware, or any combination thereof. If implemented in software, the functionality can be stored as one or more instructions or code on or transmitted over the computer-readable medium. The computer-readable medium can include computer storage media and communication media, and can also include any medium that can transfer a computer program from one place to another. The storage medium can be any target medium accessible by a computer.
[0296] In one possible implementation, a computer-readable medium may include RAM, ROM, compact disc read-only memory (CD-ROM) or other optical disc storage, disk storage or other magnetic storage devices, or any other medium targeted to carry or to store the required program code in the form of instructions or data structures, and accessible by a computer. Furthermore, any connection is appropriately referred to as a computer-readable medium. For example, if software is transmitted from a website, server, or other remote source using coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave, then coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave are included in the definition of medium. As used herein, disks and optical discs include optical discs, laser discs, optical discs, Digital Versatile Discs (DVDs), floppy disks, and Blu-ray discs, where disks typically reproduce data magnetically, while optical discs optically reproduce data using lasers. Combinations of the above should also be included within the scope of computer-readable media.
[0297] This application provides a computer program product, which includes a computer program that, when run, causes a computer to perform the above-described method.
[0298] This application describes embodiments of methods, apparatus (systems), and computer program products according to embodiments of this application with reference to flowchart illustrations and / or block diagrams. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processing unit of a general-purpose computer, special-purpose computer, embedded processor, or other programmable device to produce a machine, such that the instructions, which execute via the processing unit of the computer or other programmable data processing device, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0299] The above specific embodiments further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made on the basis of the technical solution of the present invention should be included within the scope of protection of the present invention.
Claims
1. A broadcast processing method, characterized in that, include: Receive a first broadcast sent by a broadcast sender, and the broadcast receivers corresponding to the first broadcast include a first broadcast receiver and a second broadcast receiver; Based on the broadcast attributes of the first broadcast, determine the broadcast risk level of the first broadcast; Based on the broadcast risk level, determine the first timing detection duration of the first broadcast; Receive the first delay message, and perform deadlock detection when the first timed detection duration is reached; The first broadcast receiver and the second broadcast receiver are assigned to a first group of the first broadcast process queue, with the first broadcast receiver located at a first position in the first group and the second broadcast receiver located at a second position in the first group, the second position being after the first position; The second timing detection duration is determined based on the number of broadcast receivers in the temporary queue of the first broadcast process queue and the number of broadcast receivers in the ready queue. Receive the second delay message and perform deadlock detection when the second timed detection duration is met.
2. The method according to claim 1, characterized in that, The deadlock detection of the first broadcast process queue includes: When the priority of the first broadcast receiver is lower than the priority of the second broadcast receiver, a deadlock is determined to exist in the first broadcast process queue.
3. The method according to claim 1 or 2, characterized in that, The deadlock detection of the first broadcast process queue includes: When the application process corresponding to the first broadcast receiver is in a non-frozen state and the duration of the first broadcast receiver being blocked is longer than a preset duration, it is determined that there is a deadlock in the first broadcast process queue, and the first position is the head position in the first group.
4. The method according to claim 3, characterized in that, Application processes in the non-frozen state include one or more of the following: foreground processes, visible processes, or resident processes.
5. The method according to any one of claims 1-4, characterized in that, The first broadcast is an ordered broadcast. In the broadcast receiver queue corresponding to the first broadcast, the first broadcast receiver corresponds to a first index value, and the second broadcast receiver corresponds to a second index value. The deadlock detection of the first broadcast process queue includes: When the first index value is greater than the second index value, it is determined that there is a deadlock in the first broadcast process queue. The first index value or the second index value is used to characterize the distribution order of the broadcast receivers.
6. The method according to any one of claims 1-5, characterized in that, Determining the broadcast risk level of the first broadcast based on its broadcast attributes includes: When the first broadcast is an ordered broadcast, the first broadcast carries a priority attribute, the first broadcast carries a substitution attribute, and the number of broadcast receivers corresponding to the first broadcast is greater than a first threshold, the broadcast risk level of the first broadcast is determined to be high. Alternatively, the broadcast risk level of the first broadcast is determined to be medium when the first broadcast satisfies at least one of the following: the first broadcast is an ordered broadcast, the first broadcast carries the priority attribute, or the first broadcast carries the alternative attribute. The step of determining the first timing detection duration of the first broadcast based on the broadcast risk level includes: When the broadcast risk level of the first broadcast is high, the first timing detection duration of the first broadcast is determined to be the first duration; or, When the broadcast risk level of the first broadcast is medium, the first timing detection duration of the first broadcast is determined to be the second duration; The step of performing deadlock detection upon reaching the first timed detection duration includes: Deadlock detection is performed on the first broadcast process queue every first duration. Alternatively, deadlock detection may be performed on the first broadcast process queue at intervals of the second duration; the second duration is longer than the first duration.
7. The method according to any one of claims 1-6, characterized in that, Each broadcast receiver corresponding to a broadcast is in a first broadcast queue, which includes a temporary queue and a ready queue. The temporary queue stores fourth broadcast receivers whose broadcasts have not yet been distributed, and the ready queue stores third broadcast receivers whose broadcasts are about to be distributed. The determination of the second timing detection duration based on the number of broadcast receivers in the temporary queue and the number of broadcast receivers in the ready queue of the first broadcast process queue includes: Obtain the ratio of the third broadcast receiver to the fourth broadcast receiver; When the ratio is greater than the second threshold, the second timing detection duration is determined to be the third duration; The step of performing deadlock detection when the second timing detection duration is met includes: Deadlock detection is performed on the first broadcast process queue every third time interval.
8. The method according to any one of claims 1-7, characterized in that, The hash code of the first broadcast received by the first broadcast receiver is the same as the hash code of the first broadcast received by the second broadcast receiver, and the first broadcast receiver and the second broadcast receiver are on the same electronic device.
9. An electronic device, characterized in that, include: Processor and memory; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory, causing the electronic device to perform the method as described in any one of claims 1-8.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by an electronic device, it implements the method as described in any one of claims 1-8.
11. A chip system, characterized in that, It includes at least one processor and a communication interface, the communication interface and the at least one processor being interconnected via a line, the at least one processor being configured to run a computer program or instructions to perform the method as described in any one of claims 1-8.
12. A computer program product, characterized in that, Includes a computer program that, when run, causes a computer to perform the method as described in any one of claims 1-8.
Citation Information
Patent Citations
Broadcast distribution processing method and related equipment
CN117076158A