Background task scheduling method and electronic equipment

By predicting the charging time and battery level of electronic devices and dynamically adjusting the task start conditions, the problem of poor flexibility in the JobScheduler mechanism is solved, improving the flexibility of background task scheduling and user experience.

CN121742980APending Publication Date: 2026-03-27HONOR DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-18
Publication Date
2026-03-27

AI Technical Summary

Technical Problem

In the existing technology, the task startup time of the background task scheduling mechanism JobScheduler of electronic devices is 31 minutes and cannot be modified, resulting in poor flexibility, inability to adapt to fast charging and different user behaviors, and affecting device performance and power consumption.

Method used

By predicting the screen-off time and battery level during the next charging of electronic devices based on charging data, the system dynamically adjusts the task startup time and battery threshold to ensure that background tasks are scheduled in advance when the device is in an idle state, thus avoiding impact on performance and power consumption.

Benefits of technology

It improves the flexibility of background task scheduling, reduces heat generation and power consumption during fast charging, and enhances the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121742980A_ABST
    Figure CN121742980A_ABST
Patent Text Reader

Abstract

The invention provides a background task scheduling method and electronic equipment, and is applied to the technical field of electronics, and the method comprises the steps: predicting the screen turn-off duration when the electronic equipment is charged next time according to charging data, and the charging data comprises the screen turn-off duration data of each time of charging of the electronic equipment in a preset period; the task starting duration is determined within the range of a first duration threshold value and a second duration threshold value, the first duration threshold value represents the minimum screen turn-off duration needed by the electronic device to enter the idle state, and the second duration threshold value is the difference value between the screen turn-off duration and the predicted time used for completing the background task; and when the screen turn-off duration of the electronic equipment in next charging reaches the task starting duration, scheduling and executing the background task. In this way, the task starting duration can be dynamically adjusted according to the first duration threshold and the second duration threshold, and then the problems in the prior art are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of electronic technology, and in particular to a background task scheduling method and an electronic device. Background Technology

[0002] In certain situations, the operating system of an electronic device may need to schedule and execute background tasks, such as updating the operating system, synchronizing data, clearing memory, and running system maintenance programs. These tasks aim to improve the performance of the electronic device, provide more efficient service to users, and enhance its security.

[0003] Since scheduling and executing background tasks on electronic devices consumes CPU resources and power, current technologies typically use charging conditions and screen-off duration as criteria for determining whether an electronic device is idle. That is, an electronic device can only be considered idle if it is charging and its screen remains off for a certain period (e.g., the screen-off duration equals the task startup duration). Background tasks can only be scheduled and executed when the electronic device is idle, thus reducing the impact on its performance and conserving power.

[0004] Furthermore, the scheduling of background tasks in electronic devices generally adopts the JobScheduler mechanism. The execution condition parameters of the JobScheduler mechanism cannot be modified. That is, the task start time under charging conditions is 31 minutes and cannot be modified. This mechanism has poor flexibility. Summary of the Invention

[0005] The background task scheduling method and electronic device provided in this application solve the problem of poor flexibility of the JobScheduler mechanism in the prior art.

[0006] To achieve the above objectives, this application adopts the following technical solution:

[0007] Firstly, this application provides a background task scheduling method, which can be applied to electronic devices, including...

[0008] The screen-off duration for the next charging cycle of the electronic device is predicted based on charging data, which includes the screen-off duration data for each charging cycle within a preset period. A task startup duration is determined within a range of a first duration threshold and a second duration threshold. The first duration threshold represents the minimum screen-off duration required for the electronic device to enter an idle state, and the second duration threshold is the difference between the screen-off duration and the estimated time to complete the background task. When the screen-off duration for the next charging cycle reaches the task startup duration, the background task is scheduled for execution. Thus, since the task startup duration for determining whether the electronic device has entered an idle state is determined by the first and second duration thresholds, the determined task startup duration will always be less than or equal to the difference between the predicted screen-off duration for the next charging cycle and the estimated time to complete the background task, ensuring that the electronic device can enter an idle state. Therefore, there is no issue where the screen-off duration is insufficient to reach the task startup duration, preventing the background task from being scheduled for execution. Furthermore, the screen-off duration determined in this application may be longer than 31 minutes. The longer the screen-off duration of the electronic device, the more thoroughly the electronic device may enter an idle state (the fewer application tasks may be running in the foreground of the electronic device), thereby avoiding impacting the performance of the electronic device. Therefore, compared with the mechanism of the prior art, it improves the flexibility of scheduling background tasks.

[0009] In some possible implementations, the task start-up duration is determined within the range of a first duration threshold and a second duration threshold. Specifically, this can be achieved by:

[0010] By setting the second duration threshold as the task startup duration, background tasks can be scheduled and executed a certain amount of time before the electronic device ends its screen-off state to avoid affecting the performance of the electronic device. This also allows the electronic device to enter an idle state more thoroughly, thereby further avoiding any impact on its performance.

[0011] In some possible implementations, the screen-off duration during the next charging cycle of the electronic device can be predicted based on charging data. Specifically, this could include:

[0012] Determine the average screen-off duration during the current charging of the electronic device and the screen-off duration during the previous charging of the electronic device.

[0013] Determine the product of a first weighting coefficient and the variance of the screen-off duration recorded for each charging session since the electronic device was activated, wherein the first weighting coefficient is less than 1;

[0014] Predict the screen-off duration during the next charging of the electronic device based on the average value and the sum of the products.

[0015] The specific formula can be as follows:

[0016]

[0017] Where σ is the variance of the screen-off duration recorded for each charging cycle from the start of activation of the electronic device, α is the weighting coefficient, and Q is the screen-off duration for each charging cycle. t+1 Q is the screen-off duration for the next time an electronic device is charged. t The screen-off duration during charging of this electronic device, Q t-1 The screen-off duration during the last charging session of the electronic device is used. Here, a second-order moving average method is used to predict the screen-off duration during the next charging session. Because this prediction is based on the screen-off durations of the last two charging sessions, it is more accurate than using overall charging data for each charging session.

[0018] In some possible implementations, the charging data may also include the charge level at the end of each charge cycle of the electronic device within a preset period. This application may also:

[0019] Based on the charging data, predict the battery level at the end of the next charging cycle of the electronic device, and determine the task start battery level within the range of a first battery level threshold and a second battery level threshold. The first battery level threshold is a pre-set cached battery level, and the second battery level threshold is the difference between the battery level at the end of the charging cycle of the electronic device and the pre-set cached battery level.

[0020] The corresponding background task can be scheduled and executed, specifically:

[0021] When the screen-off time before the next charge of the electronic device meets the task startup time, and the battery level before the next charge meets the task startup charge level, the corresponding background task will be scheduled and executed. This allows the electronic device to schedule background tasks when the battery level is high, thereby reducing the heat generated by the electronic device and thus reducing the impact on charging speed.

[0022] In some possible implementations, the task startup power level is determined within the range of a first power threshold and a second power threshold. Specifically, this can be achieved by:

[0023] By setting the second power threshold as the power level for task initiation, the electronic device can schedule and execute background tasks a certain amount of time before the charging process ends, thus reducing the power consumption of the electronic device and reducing its heat generation. This may further reduce the impact on the charging speed of the electronic device.

[0024] In some possible implementations, predicting the remaining charge level of the electronic device at the end of the next charging cycle based on charging data can be specifically:

[0025] Determine the average charge level of the electronic device at the end of this charging cycle and the charge level of the previous charging cycle;

[0026] The second weighting coefficient is determined to be the product of the variance of the charge level recorded by the electronic device at the end of each charge since activation, and the second weighting coefficient is less than 1.

[0027] Predict the remaining charge level of the electronic device at the end of the next charging cycle based on the average value and the sum of the products.

[0028] The specific formula is as follows:

[0029]

[0030] Where σ is the variance of the charge level recorded by the electronic device at the end of each charge cycle from activation, α is the weighting coefficient, and P... t+1 P is the predicted charge level for the next time an electronic device finishes charging. t The remaining charge level of this electronic device is P. t-1 The battery level at the end of the last charging session for the electronic device is used. Here, a second-order moving average method is used to predict the battery level at the end of the next charging session. Because this prediction is based on the battery levels at the two most recent charging points, the result is more accurate than using overall charging data for each charging session.

[0031] In some possible implementations, since users' charging needs for electronic devices may vary at different times of the day—for example, the screen-off time of electronic devices during charging may be longer at night than during the day, and the screen-off time of electronic devices during charging may be longer on weekdays than on weekends—it is possible to predict and determine whether background tasks can be scheduled based on the user's target charging scenario.

[0032] Specifically, charging data can include charging data for each time the electronic device is charged in the target charging scenario within a preset period. When the screen-off duration for the next charge of the electronic device meets the task startup duration and the battery level for the next charge meets the task startup battery level, the corresponding background task is scheduled and executed. Specifically, this can be:

[0033] When an electronic device is in a target charging scenario, and the screen-off duration for the next charging session meets the task startup duration for the next charging session in the target charging scenario, and the battery level for the next charging session meets the task startup battery level for the next charging session in the target charging scenario, the corresponding background task is scheduled and executed. It should be noted that the screen-off duration for the next charging session refers to the screen-off duration predicted for the next charging session in the target charging scenario based on the charging data of each charging session in the target charging scenario within a preset period. The task startup duration for the next charging session in the target charging scenario is determined within the range of a first duration threshold and a second duration threshold. The second duration threshold can be the difference between the screen-off duration for the next charging session in the target charging scenario and the estimated time for completing the background task.

[0034] In some possible implementations, the charging data includes charging data for each time the electronic device is charged in the target charging scenario within a preset period. When the screen-off duration for the next charging session of the electronic device meets the task startup duration, the corresponding background task is scheduled and executed. Specifically, this can be:

[0035] When an electronic device is in the target charging scenario and the screen-off duration for the next charging session meets the task startup duration for the next charging session in the target charging scenario, the corresponding background task is scheduled and executed.

[0036] Secondly, this application also provides a background task scheduling method, which can be applied to electronic devices, including:

[0037] The screen-off duration during this charging session is predicted based on charging data. The charging data includes the screen-off duration data for each charging session of the electronic device within a preset period. The task start duration is determined within the range of a first duration threshold and a second duration threshold. The first duration threshold represents the minimum screen-off duration required for the electronic device to enter an idle state. The second duration threshold is the difference between the screen-off duration and the estimated time to complete the background task. When the screen-off duration of the electronic device during this charging session reaches the task start duration, the background task is scheduled and executed.

[0038] In some possible implementations, the task start-up duration is determined within the range of a first duration threshold and a second duration threshold. Specifically, this can be achieved by:

[0039] The second duration threshold is determined as the task startup duration.

[0040] The specific formula can be as follows:

[0041] Q threshold =Max(Q) min Q t -q)

[0042] Among them, Q t -q can also be called the second duration threshold.

[0043] In some possible implementations, the charging data also includes the charge level at the end of each charge cycle of the electronic device within a preset period. This application may also include:

[0044] Based on the charging data, predict the battery level at which the electronic device will finish charging. Determine the battery level at which the task will start within the range of a first battery level threshold and a second battery level threshold. The second battery level threshold is the difference between the battery level at which the electronic device finishes charging and the preset cached battery level.

[0045] Schedule and execute the corresponding background tasks, including:

[0046] If the screen-off duration during this charging period of the electronic device meets the task startup duration and the battery level of the electronic device during this charging period meets the task startup battery level, the corresponding background task will be scheduled and executed.

[0047] In some possible implementations, the task startup power level is determined within the range of a first power threshold and a second power threshold. Specifically, this can be achieved by:

[0048] The second power threshold is determined as the power required to start the task.

[0049] The specific formula can be as follows:

[0050] P threshold =Max(P min ,P t -p)

[0051] Among them, P t -p can also be called the second threshold power.

[0052] In some possible implementations, the charging data includes charging data for each time the electronic device is charged in the target charging scenario within a preset period. When the screen-off duration of the electronic device during this charging period meets the task startup duration and the battery level of the electronic device during this charging period meets the task startup battery level, the corresponding background task is scheduled and executed. Specifically, this can be:

[0053] When an electronic device is in the target charging scenario, the screen-off duration of the current charging session meets the task startup duration for the current charging session in the target charging scenario, and the current charge level of the electronic device meets the task startup charge level for the current charging session in the target charging scenario, the corresponding background task is scheduled and executed.

[0054] In some possible implementations, the charging data includes charging data for each time the electronic device is charged in the target charging scenario within a preset period. When the screen-off duration of the electronic device during this charging session meets the task startup duration, the corresponding background task is scheduled and executed. Specifically, this can be:

[0055] When an electronic device is in the target charging scenario and the screen-off duration of the current charging session meets the task startup duration for the current charging session, the corresponding background task is scheduled and executed.

[0056] The implementation principle of the second aspect is similar to that of the first aspect, so it will not be described in detail here. The difference is that the first aspect predicts the screen-off duration and charging end power of the next electronic device charging, the task start duration and task start power of the next electronic device charging, and determines whether the background task can be scheduled to be executed when the next electronic device is charging. The second aspect, on the other hand, predicts the screen-off duration and charging end power of the current electronic device charging, predicts the task start duration and task start power of the current electronic device charging, and determines whether the background task can be scheduled to be executed when the current electronic device is charging.

[0057] Thirdly, this application provides an electronic device, including: a processor and a memory;

[0058] The memory stores one or more computer programs, the one or more computer programs including instructions; when the instructions are executed by the processor, the electronic device performs the method as described in any one of the first or second aspects.

[0059] Fourthly, this application provides a computer storage medium including computer instructions that, when executed on a mobile terminal, cause the electronic device to perform the method as described in any one of the first or second aspects. Attached Figure Description

[0060] Figure 1 A schematic diagram illustrating an application scenario provided in an embodiment of this application;

[0061] Figure 2 A flowchart of a background task scheduling method provided in an embodiment of this application;

[0062] Figure 3 A flowchart illustrating yet another background task scheduling method provided in this application embodiment;

[0063] Figure 4 A flowchart of another background task scheduling method provided in the embodiments of this application;

[0064] Figure 5A schematic diagram of a module structure provided in an embodiment of this application;

[0065] Figure 6 A flowchart illustrating a background task scheduling method in the form of inter-module interaction, provided for embodiments of this application;

[0066] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application;

[0067] Figure 8 This is a software architecture diagram of an electronic device provided in an embodiment of this application. Detailed Implementation

[0068] The terms "first," "second," and "third," etc., used in this application specification, claims, and drawings are used to distinguish different objects, not to limit a specific order.

[0069] In the embodiments of this application, the terms "exemplary" or "for example" are used to indicate that something is an example, illustration, or description. Any embodiment or design that is described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design. Specifically, the use of the terms "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.

[0070] To ensure clarity and conciseness in the description of the following embodiments, a brief introduction to the related technologies is given first:

[0071] In certain situations, the operating system of an electronic device may need to schedule and execute background tasks, such as updating the operating system, synchronizing data, clearing memory, and running system maintenance programs. These tasks are necessary to ensure the electronic device functions properly, serves users more efficiently, and improves the device's security.

[0072] Since electronic devices consume CPU resources to schedule and execute background tasks, if no idle condition is set to determine when the electronic device is in an idle state (meaning that the user has not performed any user interaction or the foreground application is not executing any application tasks) before scheduling and executing background tasks, the electronic device can schedule and execute background tasks at any time, which may affect the performance of the electronic device and thus result in a poor user experience.

[0073] If the idle condition is determined solely by the duration the screen is off (the time the screen display is turned off), for example, considering the device as idle if the screen remains off for a certain period, then when the device schedules background tasks, the increased CPU resource consumption will lead to higher power consumption, especially for high-load and long-duration tasks. Therefore, current technologies typically use both charging conditions and screen-off duration as conditions for determining idle status.

[0074] For example, such as Figure 1 As shown, electronic device 1 may include a USB interface, such as a USB Type-C interface. Electronic device 1 can be connected to charger 2 via the USB Type-C interface for charging. Electronic device 1 can only be considered idle if it is charging and its display screen remains off for a certain period (e.g., the screen-off time equals the task startup time). Background tasks can only be scheduled and executed when electronic device 1 is in an idle state.

[0075] Specifically, the scheduling of background tasks on electronic devices generally uses the JobScheduler mechanism. The execution condition parameters of the JobScheduler mechanism cannot be modified; that is, the task start time is 31 minutes. The JobScheduler mechanism is an API used to schedule jobs when electronic devices are idle.

[0076] On the one hand, since most electronic devices now use fast charging technology, the charging speed is relatively fast. Therefore, the screen-off time may not reach 31 minutes before the electronic device stops charging. As a result, the electronic device cannot simultaneously meet the conditions of charging and screen-off time reaching the 31-minute idle time required for task startup, which may result in the expected background tasks not being scheduled and executed.

[0077] On the other hand, when the screen-off time of an electronic device reaches 31 minutes, although it can be determined that the electronic device has entered an idle state, there may still be some application tasks running in the foreground of the electronic device, which may affect the performance of the electronic device.

[0078] In summary, it can be seen that the JobScheduler mechanism in the existing technology has a fixed task startup time of 31 minutes, which is not modifiable and has poor flexibility.

[0079] In this application, the electronic device can predict the screen-off duration during the next charging phase based on charging data. The charging data includes the screen-off duration data for each charging cycle of the electronic device within a preset period. The screen-off duration during the next charging phase can be the screen-off duration during the current charging phase or the screen-off duration for the next charging phase. The task start duration is determined within the range of a first duration threshold and a second duration threshold. The first duration threshold represents the minimum screen-off duration required for the electronic device to enter an idle state. The second duration threshold can be the difference between the current screen-off duration and the estimated time for completing the background task, or the difference between the next screen-off duration and the estimated time for completing the background task. When the screen-off duration during charging reaches the task start duration, the background task is scheduled and executed. Since the task startup duration for determining whether an electronic device has entered an idle state is determined by a first and a second time threshold, the determined task startup duration will always be less than or equal to the difference between the predicted screen-off duration during the next charging phase and the estimated time for completing the background task, while ensuring that the electronic device can enter an idle state. This solves the problem that when the device is charging, the screen-off duration may not be as long as the task startup duration, resulting in the expected background task not being scheduled for execution. Furthermore, the screen-off duration determined in this application may be longer than 31 minutes. The longer the screen-off duration, the more thoroughly the electronic device may enter an idle state (reducing the number of application tasks that may be running in the foreground), thus avoiding impacting the performance of the electronic device. Therefore, compared to existing technologies, this mechanism improves the flexibility of scheduling and executing background tasks.

[0080] To make the technical solution of this application clearer and easier to understand, the background task scheduling method provided by the embodiments of this application will be described below with reference to the above embodiments and corresponding drawings, taking an electronic device as the execution subject. Figure 2 As shown, the background task scheduling method provided in this application embodiment may include:

[0081] S201. Obtain charging data.

[0082] Electronic devices can acquire charging data for each charge within a preset period. The preset period can be set according to actual needs, such as one week or one month, and is not limited here. The charging data may include the screen-off duration data of the electronic device during each charging cycle within the preset period.

[0083] S202. Based on charging data, predict the screen-off time during the next stage of electronic device charging.

[0084] Electronic devices can predict the screen-off duration during the next charging phase based on charging data. It should be noted that the screen-off duration here refers to the continuous screen-off duration of the electronic device. If the electronic device triggers a screen-on event, the accumulation of screen-off duration will restart. In some cases, there may be multiple screen-off durations during the next charging phase of the electronic device. The predicted screen-off duration here refers to the longest screen-off duration.

[0085] In some possible implementations, step S202 can be executed at the end of each charging cycle of the electronic device. When step S202 is executed at the end of charging of the electronic device, the screen-off duration during the next charging cycle of the electronic device can be the screen-off duration during the next charging cycle of the electronic device (i.e., the screen-off duration that the electronic device maintains at the end of the next charging cycle).

[0086] The following description uses step S202, which is executed at the end of each charging cycle of the electronic device, as an example.

[0087] Using charging data, the formula for predicting the screen-off duration during the next charging of an electronic device can be shown in (1):

[0088]

[0089] Where σ is the variance of the screen-off duration recorded for each charging cycle of the electronic device from activation onwards, α is the weighting coefficient (which can be called the first weighting coefficient), and Q1+Q2+…Q t-1 +Q t Let Q be the screen-off duration recorded in the charging data for each instance of the electronic device charging, and t be the number of times the screen-off duration was recorded during charging. t+1 The screen-off duration for the next charging of the electronic device. It should be noted that α here can be a number less than 1, such as a negative value. The specific value can be set according to the requirements, such as -1, -2, etc. When the variance value is large (for example, greater than or equal to the variance threshold), it can be said that the screen-off duration for each charging of the electronic device is unstable. In this case, it is desirable to execute the background task scheduling a certain time in advance, and then calculate Q as in formula (1). t+1 The value is less than the actual predicted Q. t+1 The value of Q is therefore calculated using formula (1) when the task startup duration is taken. t+1 In this case, the background task can be executed a certain time in advance. When the variance value is small (e.g., less than the variance threshold), it indicates that the screen-off time during each charging of the electronic device is relatively stable, and Q in formula (1) is... t+1 No calculations are needed based on α and σ.

[0090] In some possible implementations, this application can also use a second-order moving average method to predict the screen-off duration during the next charging of the electronic device, as shown in formula (2):

[0091]

[0092] Where σ is the variance of the screen-off duration recorded for each charging cycle from the start of activation of the electronic device, α is the weighting coefficient, and Q is the screen-off duration for each charging cycle. t+1 Q is the screen-off duration for the next time an electronic device is charged. t The screen-off duration during charging of this electronic device, Q t-1 The screen-off duration during the last charging of the electronic device is given. Here, the second-order moving average method is used to predict the screen-off duration during the next charging of the electronic device. Since the screen-off duration during the charging of the electronic device is predicted based on the screen-off duration during the charging of the electronic device at the two most recent time points, it is more accurate than the prediction based on the overall data of each time in formula (1).

[0093] In some possible implementations, this application can also use an incremental calculation method to evaluate the variance σ, as shown in formula (3):

[0094]

[0095] Where N is the number of times the electronic device has been charged since activation, and σ H 2 It is the variance of the screen-off duration during the charging history of electronic devices (excluding the current charging time). It is the average screen-off time during charging in the past (excluding this time). This is the average screen-off time during charging (including this time). The variance σ is evaluated using an incremental calculation method; simply add N and σ... H as well as These few data points are saved, and each time the variance is calculated, it can be updated only based on the charging data of the current electronic device charging. This eliminates the need to store the charging data for each charging session, thereby reducing the amount of charging data stored.

[0096] In some possible implementations, step S202 can also be executed each time the electronic device starts charging. When step S202 is executed when the electronic device starts charging, the screen-off duration during the next stage of electronic device charging can be the screen-off duration during the current electronic device charging.

[0097] Specifically, the following description will take step S202, which is executed at the end of each charging of the electronic device, as an example.

[0098] Using charging data, the formula for predicting the screen-off time during charging of the electronic device can be shown in (4):

[0099]

[0100] Where σ is the variance of the screen-off duration during each charging session of the electronic device, and α is the weighting coefficient.

[0101] Q1+Q2+…Q t-1 Let t-1 be the duration of screen-off during each charging session of the electronic device, and Q be the number of times the screen-off duration during charging is recorded. t The screen-off duration while charging this electronic device.

[0102] In some possible implementations, this application can also use a second-order moving average method to predict the screen-off duration during the next charging of the electronic device, as shown in formula (5):

[0103]

[0104] Where σ is the variance of the screen-off duration recorded for each charging cycle from the start of activation of the electronic device, α is the weighting coefficient, and Q is the screen-off duration. t The screen-off duration during charging of this electronic device, Q t-1 The duration the screen remained off while the electronic device was last charged. Q t-2 For Q t-1 The screen-off time during the last charging of the electronic device is used to predict the screen-off time during the next charging of the electronic device using the second-order moving average method. Since the screen-off time during the charging of the electronic device is predicted by the screen-off time during the charging of the electronic device at the two most recent time points, it is more accurate than the prediction using the overall data of each time in formula (4).

[0105] In some possible implementations, this application can also utilize an incremental calculation method to evaluate the variance σ, as shown in formula (6):

[0106]

[0107] Where N is the number of times the electronic device has been charged since activation, and σ H 2 It is the variance of the screen-off duration during the electronic device's historical charging (excluding the last charging time t-1). It is the average screen-off time during historical charging (excluding the previous t-1). It is the average screen-off time during historical charging (including the last t-1). To evaluate the variance σ using an incremental calculation method, simply add N and σ... H as well as These few data points are saved, and each time the variance is calculated, it can be updated only based on the charging data of the current electronic device charging. This eliminates the need to store the charging data for each charging session, thereby reducing the amount of charging data stored.

[0108] S203. Determine the task start duration based on the screen-off duration during the next stage of electronic device charging.

[0109] Once the electronic device predicts the screen-off duration during the next charging phase, it can adjust the task startup duration based on that duration.

[0110] For example, let's take the screen-off time during the next charging cycle of the electronic device as an example.

[0111] When the predicted screen-off duration Q for the next electronic device charge t+1 The minimum condition Q for screen-off time during charging is less than the minimum condition Q for charging. min (Also called the first duration threshold, used to characterize the minimum screen-off time required for an electronic device to enter an idle state) At this time, if Q t+1 The value is the task startup time Q during charging. threshold If the screen-off time of an electronic device reaches this value, it cannot be determined that the electronic device has entered an idle state. Therefore, Q threshold The value can be Q. min , where Q min The value can be set according to actual needs, but it needs to be less than the task startup time of the JobScheduler mechanism. For example, it can be set to 10 minutes, meaning that if the screen is off for 10 minutes while the electronic device is charging, the electronic device is considered to be in an idle state. When Q t+1 Greater than or equal to Q min At that time, because the screen-off time is greater than Q t+1 This confirms that the electronic device has entered an idle state, at which point Q... threshold The value can be Q. min To Q t+1 Any value within the range.

[0112] In some possible implementations, the screen-off duration of the electronic device satisfies Q. t+1 Even though it can be determined that the electronic device has entered an idle state, there may still be some application tasks running in the foreground of the electronic device at this time.

[0113] Therefore, Q in this application threshold You can get Q min and Q t+1 The maximum value in can be specifically shown in formula (7):

[0114] Qthreshold =Max(Q) min Q t+1 (7)

[0115] When Q t+1 Greater than Q min At this time, Q threshold The value can be Q. t+1 In other words, the longer the screen is off on an electronic device, the more thoroughly the device may enter an idle state (the fewer application tasks may be running in the foreground), which can further avoid affecting the performance of the electronic device.

[0116] In some possible implementations, when Q t+1 -q is greater than Q min In order for the electronic device to complete the background task before ending its idle state (i.e., before the electronic device transitions from an idle state to an active state), Q... threshold The value can be Q. min To Q t+1 -q(Q t+1 -q (also called the second duration threshold) is any value within the range, where q is the estimated time to complete the background task, and Q is the time to complete the background task. t+1 -q can also be called the second duration threshold.

[0117] For example, Q threshold The value can be Q. t+1 Taking -q as an example, the screen-off time of the electronic device under charging conditions reaches Q. t+1 When -q is selected, the electronic device can schedule and execute background tasks. For example, if q is 30 seconds, the screen-off time of the electronic device reaches Q. t+1 When -q is selected, background tasks are scheduled and executed. After time q, the electronic device completes the background task, and the screen-off time of the electronic device reaches Q. t+1 If the screen of an electronic device is turned off, the device will exit its idle state and enter a working state to perform tasks or user operations. By scheduling background tasks a certain amount of time in advance before the device exits its screen-off state, the device can avoid scheduling background tasks while it is in a working state, thus avoiding impacting the device's performance and preventing a poor user experience.

[0118] In some possible implementations, the formula for determining the task start-up duration based on the screen-off duration during the next stage of electronic device charging in this application can also be as shown in (8):

[0119] Q threshold =Max(Q) min Q t+1 -q)(8)

[0120] That is, the value Q min and Q t+1 The maximum value in -q ensures that background tasks are scheduled and executed a certain amount of time before the electronic device ends its screen-off state to avoid affecting the device's performance. This also allows the electronic device to enter an idle state more thoroughly (with fewer application tasks running in the foreground), further preventing any impact on the device's performance.

[0121] In some possible implementations, Q threshold The value can also be directly taken as Q. min This could make it easier for electronic devices to achieve the Q standard screen-off duration. threshold This can improve the speed at which electronic devices schedule and execute background tasks.

[0122] It should be noted that Formulas (7) and (8) are specific implementation methods for determining the task start time based on the screen-off time during the next charging of the electronic device. The specific implementation method for determining the task start time based on the screen-off time during the current charging of the electronic device is similar and will not be explained in detail here.

[0123] S204. When the electronic device is charging and the screen-off time meets the task startup time, schedule and execute the background task.

[0124] After determining the task start duration, when the electronic device is under charging conditions, it can determine whether the screen-off duration (here, screen-off duration refers to continuous screen-off duration, that is, no interruption during the screen-off process; if interrupted, the screen-off duration will restart) meets the task start duration.

[0125] When the electronic device is determined to be charging and the screen-off duration meets the task startup duration, a background task can be scheduled and executed. This background task can include updating the operating system, synchronizing data, clearing memory, and running system maintenance programs, etc. Those skilled in the art can set the specific requirements according to their needs, and no limitations are imposed here. The second duration threshold can be the difference between the screen-off duration during the next charging of the electronic device and the estimated time for completing the background task, or it can be the difference between the screen-off duration during the current charging of the electronic device and the estimated time for completing the background task.

[0126] In Embodiment 1 of this application, the electronic device can predict the screen-off duration during the next stage of charging based on charging data. The charging data includes the screen-off duration data for each charging cycle of the electronic device within a preset period. The screen-off duration during the next stage of charging can be the screen-off duration during the current charging cycle or the screen-off duration for the next charging cycle. The task start duration is determined within the range of a first duration threshold and a second duration threshold. The first duration threshold represents the minimum screen-off duration required for the electronic device to enter an idle state. The second duration threshold can be the difference between the current screen-off duration and the estimated time for completing the background task, or the difference between the next screen-off duration and the estimated time for completing the background task. When the screen-off duration during charging reaches the task start duration, the background task is scheduled and executed. Since the task startup duration for determining whether an electronic device has entered an idle state is determined by a first and a second time threshold, the determined task startup duration will always be less than or equal to the difference between the predicted screen-off duration during the next charging phase and the estimated time for completing the background task, provided that the electronic device can enter an idle state. This solves the problem that when the device is charging, the screen-off duration may not be as long as the task startup duration, resulting in the expected background task not being scheduled for execution. Furthermore, the screen-off duration determined in this application may be longer than 31 minutes. The longer the screen-off duration of the electronic device, the more thoroughly the electronic device may enter an idle state (and the fewer application tasks may be running in the foreground), thus avoiding impacting the performance of the electronic device. Therefore, compared to existing technologies, this mechanism improves the flexibility of scheduling and executing background tasks.

[0127] The above embodiment can be referred to as Embodiment 1. In some cases, such as when the electronic device has low battery power and is in the fast charging phase (using a fast charging protocol), the chemical reaction inside the battery is more active, which may generate more heat. Fast charging also charges the battery with a larger current, which will also cause the battery and charger of the electronic device to generate more heat. If background tasks are performed under these circumstances, especially high-load and long-duration tasks, the heat of the electronic device will be further increased, which may seriously affect the current charging speed of the electronic device.

[0128] To address this issue, this application also provides another embodiment, referred to here as Embodiment Two. The difference between Embodiment Two and Embodiment One is that in Embodiment One, it is only necessary to determine whether to schedule and execute a background task based on the determined task startup duration. In Embodiment Two, it is necessary to consider the battery level of the electronic device in conjunction with the battery level, and thus predict the battery level at which the electronic device will finish charging in the next stage. The battery level at which the electronic device will finish charging in the next stage can be either the battery level at which the electronic device finishes charging in the current stage or the battery level at which the electronic device will finish charging in the next stage. The task startup battery level is determined within the range of a first battery level threshold and a second battery level threshold. The second battery level threshold can be either the difference between the battery level at which the electronic device finishes charging in the current stage and a preset cached battery level, or the difference between the battery level at which the electronic device will finish charging in the next stage and a preset cached battery level. When the battery level of the electronic device meets the task startup battery level and the screen-off duration under charging conditions meets the task startup duration, the background task can be scheduled and executed. This allows the electronic device to schedule and execute background tasks when the battery level is high, thereby reducing the heat of the electronic device and thus reducing the impact on the charging speed.

[0129] To make the technical solution of this application clearer and easier to understand, the background task scheduling method provided by the embodiments of this application will be described below with reference to the above embodiments and corresponding drawings, taking an electronic device as the execution subject. Figure 3 As shown in the embodiments of this application, another background task scheduling method may include:

[0130] S301. Obtain charging data.

[0131] Electronic devices can acquire charging data for each charge within a preset period. This preset period can be set according to actual needs, such as one week or one month, and is not limited here. The charging data can include the screen-off time during each charging process within the preset period and the remaining battery level at the end of each charge.

[0132] After acquiring charging data, electronic devices can store the charging data in a database.

[0133] In some possible implementations, since users' charging needs for electronic devices may vary at different times—for example, the screen-off time of electronic devices during charging may be longer at night than during the day, and the screen-off time of electronic devices during charging may be longer on weekdays than on weekends—the acquired charging data can be categorized by time period and stored according to the categorization results.

[0134] For example, charging data can be categorized into nighttime, daytime, weekdays, and rest days. When acquiring charging data, the corresponding timestamp can be obtained simultaneously. For instance, if the timestamp indicates a time between 6:00 AM and 6:00 PM, the charging data can be categorized as daytime; if the timestamp indicates a time between 6:01 PM and 5:59 AM, it can be categorized as nighttime; if the timestamp indicates a time between Monday and Friday, it can be categorized as weekday; and if the timestamp indicates a time between Saturday and Sunday, it can be categorized as rest day. It should be noted that the above are merely illustrative examples, and those skilled in the art can set other methods and conditions to classify charging data according to actual circumstances; this is not limited here.

[0135] In some possible implementations, the charging data of the electronic device may also include the battery level of the electronic device at the start of charging and the charging time of the electronic device. The electronic device may also filter the acquired charging data to filter some temporary charging data, such as data where the charging time of the electronic device is less than a first threshold (indicating a short charging time) or the screen-off time during charging is less than a second threshold (indicating a short screen-off time during charging) or the battery level of the electronic device at the start of charging is greater than a third threshold (indicating a high battery level of the electronic device at the start of charging). The first and second thresholds may be set to, for example, 3s, 5s, etc., and the third threshold may be set to, for example, 80%. Of course, this is just an example, and those skilled in the art can set it according to actual needs, and it is not limited here.

[0136] S302. Based on the charging data, predict the screen-off time and the final charge level of the electronic device during the next charging phase.

[0137] After acquiring charging data, electronic devices can predict the screen-off time and the remaining charge level during the next charging phase based on the charging data.

[0138] Specifically, the electronic device can predict the screen-off time during the next stage of charging based on the charging data. The specific principle and implementation method are similar to step S202. For details, please refer to the description of step S202. It will not be described in detail here.

[0139] Electronic devices can predict the end of the next charging phase based on the end of each charging phase.

[0140] In some possible implementations, step S302 can be performed at the end of each charging cycle of the electronic device. When step S302 is performed at the end of charging of the electronic device, the charge level at the end of the next charging cycle of the electronic device can be the charge level at the end of the next charging cycle of the electronic device.

[0141] The following description uses step S302, which is executed at the end of each charging cycle of the electronic device, as an example.

[0142] Using charging data, the formula for predicting the remaining charge level of the electronic device at the end of the next charging cycle can be shown in (9):

[0143]

[0144] Where σ is the variance of the battery level at the end of each charging cycle in the charging data, α is the weighting coefficient (which can be called the second weighting coefficient), and P1+P2+…P t-1 +P t The charging data t represents the number of times the charging power of the electronic device is recorded at the end of each charging cycle, and P represents the total charge level at the end of each charging cycle. t+1 The predicted charge level for the next charging cycle of the electronic device. It should be noted that α here can be a negative value, which can be set according to the requirements, such as -1%, -2%, etc. When the variance value is large (e.g., greater than or equal to the variance threshold), it indicates that the charge level of the electronic device is unstable each time it is charged. In this case, it is desirable to execute the background task of execution scheduling a certain time in advance, and then calculate P as shown in formula (9). t+1 The value is less than the actual predicted P. t+1 The value of P is therefore calculated using formula (9) when the task starts. t+1 In this case, the background task can be executed a certain time in advance. When the variance value is small (e.g., less than the variance threshold), it indicates that the charge level of the electronic device at the end of each charge is relatively stable, and P in formula (9) will be more stable. t+1 No calculations are needed based on α and σ.

[0145] In some possible implementations, this application can also use a second-order moving average method to predict the charge level at the end of the next charging cycle of the electronic device, as shown in formula (10):

[0146]

[0147] Where σ is the variance of the charge level recorded by the electronic device at the end of each charge cycle from activation, α is the weighting coefficient, and P... t+1 P is the predicted charge level for the next time an electronic device finishes charging. t The remaining charge level of this electronic device is P. t-1 The charge level at the end of the last charging session of the electronic device is given. Here, the second-order moving average method is used to predict the charge level at the end of the next charging session of the electronic device. Since the charge level at the end of the next charging session of the electronic device is predicted based on the charge levels at the two most recent time points, it is more accurate than the prediction based on the overall data of each time in formula (9).

[0148] In some possible implementations, this application can also utilize an incremental calculation method to evaluate the variance σ, as shown in formula (11):

[0149]

[0150] Where N is the number of times the electronic device has been charged since activation, and σ H It is the variance of the charge level at the end of charging for the electronic device throughout its history (excluding the current charge). It is the average screen-off time during charging in the past (excluding this time). This is the average charge level at the end of each charge (including the current one). To evaluate the variance σ using an incremental calculation method, simply add N and σ... H as well as These few data points are saved, and each time the variance is calculated, it can be updated only based on the charging data of the current electronic device charging. This eliminates the need to store the charging data for each charging session, thereby reducing the amount of charging data stored.

[0151] In some possible implementations, step S302 can also be executed at the start of each charging of the electronic device. When step S302 is executed at the start of charging of the electronic device, the charge level of the electronic device at the end of the next charging stage can be the charge level at the end of the current charging of the electronic device.

[0152] Specifically, the following description will take step S302, which is executed at the end of each charging of the electronic device, as an example.

[0153] Using charging data, the formula for predicting the screen-off time during charging of the electronic device can be shown in (12):

[0154]

[0155] Where σ is the variance of the charge level at the end of each charging cycle in the charging data, α is the weighting coefficient, and P1+P2+…P t-1 P represents the total charge level recorded at the end of each charging session for the electronic device, t-1 represents the number of times the charge level at the end of each charging session for the electronic device was recorded in the charging data. t The charging power of this electronic device has ended.

[0156] In some possible implementations, this application can also use a second-order moving average method to predict the screen-off duration during the next charging of the electronic device, as shown in formula (13):

[0157]

[0158] Where σ is the variance of the charge level recorded by the electronic device at the end of each charge cycle from activation, α is the weighting coefficient, and P... t The electronic device's charge level at the end of this charging process, P t-1 The last charge of the electronic device has ended. (P) t-2 For P t-1 The battery level at the end of the last charging session of the electronic device is used to predict the battery level at the end of the next charging session of the electronic device. Since the battery level at the end of the last charging session of the electronic device is predicted based on the battery level at the end of the last charging session of the electronic device at the two most recent time points, it is more accurate than the prediction based on the overall data of each time in formula (12).

[0159] In some possible implementations, this application can also use an incremental calculation method to evaluate the variance σ, as shown in formula (14):

[0160]

[0161] Where N is the number of times the electronic device has been charged since activation, and σ H 2 It is the variance of the screen-off duration during charging of electronic devices throughout history (excluding the previous t-1). It is the average screen-off time during historical charging (excluding the previous t-1). It is the average screen-off time during historical charging (including the last t-1). To evaluate the variance σ using an incremental calculation method, simply add N and σ... H as well as These few data points are saved, and each time the variance is calculated, it can be updated only based on the charging data of the current electronic device charging. This eliminates the need to store the charging data for each charging session, thereby reducing the amount of charging data stored.

[0162] In some possible implementations, this application can also identify the target charging scenario for this charging (the target charging scenario can be, for example, night, day, weekday, and rest day, etc.), and then match the charging data of the corresponding classification result from the database according to the identified target charging scenario. Based on the charging data (which may include the charging data of each time the electronic device is charged in the target charging scenario within a preset period), the screen-off time and the charging end power of the electronic device during the next stage of charging can be predicted.

[0163] For example, taking the next stage as the next charging of an electronic device as an example, and taking the identified target charging scenario as a weekday as an example, the charging data classified as a weekday can be matched from the database, that is, the charging data of each weekday charging within the preset cycle of the electronic device. Then, based on the charging data, the screen-off time and the charging end level of the electronic device when charging in the next charging scenario (e.g., a weekday) can be predicted. Based on the predicted screen-off time of the next charging in the target charging scenario, the task start time of the next charging in the target charging scenario can be determined, and based on the charging end level of the next charging in the target charging scenario, the task start level of the next charging in the target charging scenario can be determined. Then, when the electronic device is charged on a weekday, it can be determined whether to schedule and execute a background task based on the task start time and the task start level.

[0164] S303. Determine the task start duration based on the screen-off duration during the next stage of electronic device charging, and determine the task start power level based on the power level after the next stage of electronic device charging ends.

[0165] After predicting the screen-off duration during the next charging phase and the battery level at the end of the next charging phase, the electronic device can determine the task startup duration based on the screen-off duration during the next charging phase and the task startup battery level based on the battery level at the end of the next charging phase.

[0166] Specifically, the principle and implementation method of determining the task start time based on the screen-off time during the next stage of electronic device charging are similar to step S202. For details, please refer to the description of step S202. No further description will be given here.

[0167] The electronic device determines the task startup duration based on the screen-off time during the next stage of charging and the task startup battery level based on the battery level after the next stage of charging. Specifically, it can be as follows:

[0168] For example, let's take the example of the electronic device ending its charging in the next stage as the end of the next charging cycle.

[0169] When the predicted next charge end time P of the electronic device t+1 The minimum charge level P required to start the task after charging is completed min At this time, if P t+1 The value is the task startup power P during charging. threshold P threshold If the power consumption of the electronic device is relatively small, then the power consumption of the electronic device will meet the requirement of P. threshold Under certain circumstances, scheduling background tasks may increase the heat of electronic devices, which could severely impact their charging speed. Therefore, Pthreshold The value of P is taken min , where P threshold The starting power level for tasks during charging; that is, the corresponding background tasks can only be scheduled when the electronic device's battery level reaches this value during charging. min The value of P can be set according to actual needs. For example, if an electronic device needs to perform a high-load background task (a background task whose completion time is greater than a threshold), in order to ensure that the charging speed is not affected, then P... min This can be set to a relatively large value, for example, 80%. If the electronic device needs to perform low-load tasks (background tasks whose completion time is less than a threshold), then P... min It can be set to a relatively small value, such as P. min Setting the value to 60% allows electronic devices to perform background tasks in advance.

[0170] When P t+1 Greater than or equal to P min At that time, P threshold The value can be P min To P t+1 Any value within the range.

[0171] In some possible implementations, P threshold The larger the value of P, the less heat is generated when the electronic device schedules and executes background tasks. Therefore, in this application, P... threshold The value can be P min and P t+1 The maximum value in can be specifically shown in formula (15):

[0172] P threshold =Max(P min ,P t+1 (15)

[0173] According to formula (15), when P t+1 Greater than P min When P (also called the first energy threshold) is reached, threshold The value can be P t+1 P threshold If the power consumption of the electronic device is relatively large, then the power consumption of the electronic device will meet the requirement of P. threshold In certain situations, scheduling background tasks can reduce the heat generated by electronic devices, potentially minimizing the impact on charging speed. It should be noted that...

[0174] In some possible implementations, if a background task, especially a high-load background task, is scheduled to execute shortly after the electronic device stops charging, and the background task continues to run in the background, it can also cause power consumption issues for the electronic device. To ensure that the electronic device completes its background task before charging ends, when P...t+1 -P is greater than P min At this time, P threshold The value can be P min To P t+1 -P (also called the second threshold power) is any value within the range where p is the cached power. The value of the cached power can be set according to actual needs, such as 4%, 5%, 6%, etc., and is not limited here.

[0175] With P threshold The value of P is taken t+1 Taking -P as an example, the amount of charge an electronic device receives during charging satisfies P. t+1 When -p is used, the electronic device may schedule and execute background tasks. For example, if p is 5%, the electronic device's battery level reaches P. t+1 When set to -p, background tasks may be scheduled and executed, allowing the electronic device to schedule and execute these tasks a certain amount of time before the charging process ends. This ensures that when the electronic device's battery level reaches P, the background tasks will be executed. t+1 When an electronic device finishes charging, it may have already completed background tasks, which may reduce its power consumption.

[0176] In some possible implementations, the formula for determining the task start-up charge based on the charge level of the electronic device at the end of the next stage of charging can also be as shown in (16):

[0177] P threshold =Max(P min ,P t+1 -p)(16)

[0178] That is, the value P min and P t+1 The maximum value in -p allows the electronic device to schedule background tasks to be executed a certain amount of time before the charging is finished, thus reducing the power consumption of the electronic device and also reducing the heat of the electronic device, which may further reduce the impact on the charging speed of the electronic device.

[0179] It should be noted that formulas (15) and (16) are specific implementation methods for determining the task start-up power based on the power level at the end of the next electronic device charging cycle. The specific implementation method for determining the task start-up power level based on the power level at the end of the current electronic device charging cycle is similar and will not be explained in detail here. It should also be noted that the second power threshold can be the difference between the power level at the end of the next electronic device charging cycle and the preset cached power level, or it can be the difference between the power level at the end of the current electronic device charging cycle and the preset cached power level.

[0180] S304. When the screen-off time of the electronic device is in the charging condition meets the task start time and the battery level meets the task start power requirements, the background task is scheduled to be executed.

[0181] After determining the screen-off duration and the battery level required to start a task, an electronic device, while charging, can determine whether the screen-off duration meets the task start-up duration and whether the battery level meets the task start-up requirements.

[0182] Specifically, such as Figure 4 As shown, the electronic device can execute step S401 to detect whether the electronic device is in a charging environment. If not, i.e., it is determined that it is not in a charging environment, step S401 can be executed again for detection. If yes, i.e. the electronic device is determined to be in a charging environment, step S402 can be executed to detect the change in charging power, and then step S403 can be executed to detect whether the electronic device is in a screen-off state. If not, step S403 can be executed again for detection. If yes, step S404 can be executed to detect the screen-off duration of the electronic device and send a delayed Handler message with a preset time (i.e., the message can only be sent after a preset time). The preset time can be set to be the same as the screen-off threshold.

[0183] If the electronic device interrupts the screen-off state within the preset time, the electronic device executes step S405 to cancel sending the delayed Handler message. In other words, the screen-off time of the electronic device does not meet the task start time, and the electronic device can re-execute step S403 for detection.

[0184] If the electronic device does not interrupt the screen-off state within the preset time, it is determined that the delayed message was successfully sent. At this time, the screen-off duration of the electronic device meets the task start duration, and the electronic device can execute step S406 to determine that the electronic device has entered the idle state and set the idle flag bit for the electronic device.

[0185] After step S406 is completed, the electronic device can proceed to step S407 to determine whether it is still in a charging environment and whether its battery level is sufficient for task startup. If it is determined that the electronic device is not in a charging environment, step S401 is re-executed to check whether the electronic device is in a charging environment. If it is determined that the electronic device's battery level is insufficient for task startup, the determination is re-executed to check whether the electronic device is still in a charging environment, whether the screen is still off, and whether its battery level is sufficient for task startup. If yes, step S409 is executed; otherwise, step S408 is re-executed.

[0186] If so, i.e., the electronic device is determined to still be in a charging environment and the power is sufficient to start the task, then step 409 can be executed to schedule the background task.

[0187] In some possible implementations, Pthreshold The value of P is taken t+1 -p, Q threshold The value of Q is taken t+1 -q, when the electronic device is charging, the screen-off duration of the electronic device meets the task startup duration Q. threshold And the battery level meets the task startup battery level P. threshold In this case, the electronic device can schedule and execute background tasks a certain amount of time before ending its idle state and charging, thus avoiding the need to schedule and execute background tasks while the device is in operation, thereby preventing performance impact and a poor user experience. Furthermore, the background tasks may have already been completed by the time the device finishes charging, potentially reducing power consumption. Embodiment 2 of this application, based on Embodiment 1, considers the electronic device's battery level and can predict the next stage's charging end level based on charging data. The task start level is then determined within a first and second battery threshold, where the second battery threshold is the difference between the charging end level and a pre-set cached battery level. When the electronic device's battery level meets the task start level requirement and the screen-off duration under charging conditions meets the task start duration, background tasks can be scheduled and executed. This allows the electronic device to schedule and execute background tasks when the battery level is high, further reducing heat generation and impacting charging speed, building upon Embodiment 1.

[0188] In addition to Embodiments 1 and 2, this application also provides Embodiment 3. In Embodiment 3, the electronic device of this application may include a user charging habit learning module and a background task scheduling module, such as... Figure 5 As shown, the background task scheduling module may include an information collection module and a scheduling strategy module, while the user charging learning module includes a charging data recording module and a user habit learning module. The information collection module detects whether the electronic device is in a charging environment, detects changes in the device's battery level, and detects the screen-off duration. The charging data recording module acquires charging data for each charge. The user habit module determines the task startup duration and battery level based on the charging data. The scheduling strategy module schedules and executes background tasks based on the detection results from the information collection module.

[0189] The following is combined Figure 6 The scheduling method for background tasks provided in this application is described in the form of interactions between modules, including:

[0190] S61. The charging data recording module acquires charging data.

[0191] The specific principle and implementation method are similar to step S301. For details, please refer to the description of step S301. No further details will be provided here.

[0192] S62. The user habit module determines the task start time and task start power based on charging data.

[0193] The specific principles and implementation methods are similar to those in steps S302 and S303. For details, please refer to the descriptions in steps S302 and S303. No further details will be provided here.

[0194] S63. The information acquisition module detects whether the electronic device is in a charging environment, detects changes in the charging power of the electronic device, and detects the screen-off time of the electronic device.

[0195] S64. If the information acquisition module determines that the electronic device is in a charging environment and in a screen-off state, it sends a delayed Handler message for a preset time.

[0196] S65. If the information acquisition module determines that the electronic device will interrupt the screen-off state within a preset time, it will cancel sending the delayed Handler message.

[0197] S66. After receiving the delayed Handler message, the task scheduling module determines that the electronic device has entered an idle state and sets the idle flag for the electronic device.

[0198] S67. The task scheduling module determines whether the electronic device is still in a charging environment and whether the electronic device's power level is sufficient to start the task.

[0199] S68. If the electronic device is determined to be still in a charging environment and the power level is sufficient to start the task, the task scheduling module can schedule the execution of background tasks.

[0200] The specific principles and implementation methods of steps S64 to S68 are similar to those of step S304. For details, please refer to the description of step S304. No further details will be provided here.

[0201] In some embodiments, the electronic device may be a mobile phone, tablet computer, desktop computer, laptop computer, ultra-mobile personal computer (UMPC), handheld computer, netbook, personal digital assistant (PDA), wearable electronic device, smartwatch, etc. This application does not impose any special limitations on the specific form of the aforementioned electronic device. In this embodiment, the structure of the electronic device may be as follows: Figure 7 As shown, Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.

[0202] like Figure 7 As shown, the electronic device may include a processor 710, a power management module 720, a charging management module 730, etc. It is understood that the structure illustrated in this embodiment does not constitute a specific limitation on the electronic device. In other embodiments, the electronic 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.

[0203] The processor 710 can acquire charging data for each charge within a preset cycle. Based on the charging data, it predicts the screen-off duration during the next charging phase of the electronic device. It then determines the task startup duration based on the minimum of the screen-off duration for the next charging phase and the preset screen-off duration for the electronic device to enter an idle state. The processor 710 can also determine whether the electronic device is charging and whether the screen-off duration meets the task startup duration. When it is determined that the electronic device is charging and the screen-off duration meets the task startup duration, it can schedule and execute background tasks.

[0204] Electronic devices can also be used to predict the next stage of charging completion based on charging data, and determine the task startup battery level based on the next stage's charging completion battery level and a preset minimum charging completion battery level. It can also determine whether the electronic device is currently charging and whether its battery level meets the task startup battery requirement. If it is determined that the electronic device's battery level meets the task startup battery requirement and the screen-off duration while charging meets the task startup duration, a background task can be scheduled and executed.

[0205] In some embodiments, the processor 710 may include one or more interfaces. Interfaces may include power management IC (PMIC) interfaces, etc.

[0206] A power management IC (PMIC), also known as a power management module (720), is a purpose-specific integrated circuit whose function is to manage power for the main system. The charging management module (730) is used to control this. PMICs are commonly used in battery-powered devices, such as mobile phones or portable media players. Since these devices typically have more than one power source (e.g., battery and USB power), and the system requires multiple power sources with different voltages, plus the need to control battery charging and discharging, traditional methods would consume considerable space and increase product development time, thus leading to the development of PMICs.

[0207] The power management module 720 can be connected to the battery 140, the charging management module 730, and the processor 710. It receives input from the battery 140 and / or the charging management module 730 to power the processor 710, etc. The power management module 720 can also be used to monitor parameters such as battery capacity. In some other embodiments, the power management module 720 can be located within the processor 710. In other embodiments, the power management module 720 and the charging management module 730 can also be located in the same device.

[0208] The charging management module 730 receives charging input from the charger according to instructions from the PMIC. The charger can be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 730 receives charging input from the wired charger via USB. In some wireless charging embodiments, the charging management module 730 receives wireless charging input via the wireless charging coil of the electronic device. While charging the battery 140, the charging management module 730 can also supply power to the electronic device via the power management module 720.

[0209] In some possible implementations, the electronic device may also include a USB interface 150, which is a USB standard-compliant interface for connecting a USB plug. This USB interface is a reserved interface on the electronic device, which may be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc.

[0210] For example, the USB interface can be a Mini USB interface, which is widely used in media players, external hard drives, and other digital devices. The USB interface can also be a Micro USB interface, which can only be inserted from one side. It is the next generation of Mini USB, smaller, with a longer lifespan and greater strength, and is mainly used for connecting or transferring data to various USB flash drives or mobile devices. Compared to Mini USB, it offers faster transfer speeds. The USB interface can also be a USB Type-C interface: this is a connection interface based on the USB 3.1 standard, featuring reversible insertion and high transfer speeds.

[0211] USB port 150 can be used to connect a charger to charge electronic devices, and it can also be used for data transfer between electronic devices and peripheral devices. For example, when the device connected to this USB port is a charger, the USB port receives current; when the device connected to this USB port is a computer, the USB port receives / outputs data. It can also be used to connect headphones for audio playback. This port can also be used to connect other electronic devices, such as AR devices.

[0212] It is understood that the interface connection relationships between the modules illustrated in this embodiment are merely illustrative and do not constitute a limitation on the structure of the electronic device. In other embodiments of this application, the electronic device may also employ different interface connection methods or combinations of multiple interface connection methods as described in the above embodiments.

[0213] The software architecture of the electronic device described in this application can adopt a layered architecture, event-driven architecture, microkernel architecture, microservice architecture, or cloud architecture. This embodiment of the invention uses the layered architecture Android system as an example for illustrative explanation. Figure 8 As shown:

[0214] A layered architecture divides software into several layers, each with a clear role and function. Layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into five layers, from top to bottom: the application layer, the application framework layer, the Android runtime, the system libraries, and the kernel layer.

[0215] The application layer may include a series of application packages. For example, it may include camera, gallery, calendar, calling, map, navigation, WLAN, Bluetooth, music, video, SMS, etc.

[0216] The application framework layer provides the application with an application programming interface (API) and a programming framework. The application framework layer includes predefined functions and modules. In this embodiment, the application framework may include an information acquisition module, a scheduling strategy module, a charging data recording module, and a user habit learning module.

[0217] The system comprises the following modules: an information acquisition module to detect whether the electronic device is in a charging environment, to detect changes in the charging level, and to detect the screen-off duration; a charging data recording module to acquire charging data for each charge; a user habit module to determine task startup duration and battery level based on the charging data; and a scheduling strategy module to schedule and execute background tasks based on the detection results from the information acquisition module.

[0218] The application layer and framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and framework layer as binary files. The virtual machine is used to perform functions such as object lifecycle management, stack management, thread management, security and exception management, and garbage collection.

[0219] The kernel layer is the layer between hardware and software. The kernel layer provided in this application embodiment includes a display driver, an audio driver, and a sensor driver.

[0220] The technical solution of this embodiment, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments. The aforementioned storage medium includes various media capable of storing program code, such as flash memory, portable hard disk, read-only memory, random access memory, magnetic disk, or optical disk.

[0221] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A background task scheduling method, characterized in that, include: The screen-off duration for the next charging of an electronic device is predicted based on charging data, wherein the charging data includes the screen-off duration data for each charging of the electronic device within a preset period. The task start time is determined within the range of a first time threshold and a second time threshold. The first time threshold represents the minimum screen-off time required for the electronic device to enter an idle state, and the second time threshold is the difference between the screen-off time and the estimated time to complete the background task. When the screen-off time of the electronic device during the next charging period reaches the task startup time, the background task is scheduled to be executed.

2. The method according to claim 1, characterized in that, Determining the task start duration within the range of the first duration threshold and the second duration threshold includes: The second duration threshold is determined as the task startup duration.

3. The method according to claim 1, characterized in that, The step of predicting the screen-off duration during the next charging of the electronic device based on the charging data includes: Determine the average screen-off duration during the current charging of the electronic device and the screen-off duration during the previous charging of the electronic device. Determine the product of a first weighting coefficient and the variance of the screen-off duration recorded for each charging session since the electronic device was activated, wherein the first weighting coefficient is less than 1; The screen-off duration during the next charging of the electronic device is predicted based on the sum of the average value and the product.

4. The method according to claim 1, characterized in that, The charging data also includes the charge level at the end of each charge cycle for the electronic device within a preset period, and the method further includes: Predict the remaining charge level of the electronic device at the end of the next charging cycle based on the charging data; The task start-up battery level is determined within the range of a first battery threshold and a second battery threshold, where the second battery threshold is the difference between the battery level at the end of charging of the electronic device and the preset cached battery level. The background task to be scheduled and executed includes: When the screen-off duration of the electronic device during its next charge meets the task startup duration, and the battery level of the electronic device during its next charge meets the task startup battery level, the corresponding background task is scheduled and executed.

5. The method according to claim 4, characterized in that, Determining the task startup power level within the range of a first power threshold and a second power threshold includes: The second power threshold is determined as the power required to start the task.

6. The method according to claim 4, characterized in that, The step of predicting the remaining charge level of the electronic device at the end of the next charging cycle based on the charging data includes: Determine the average charge level of the electronic device at the end of this charging cycle and the charge level of the previous charging cycle; Determine the product of the second weighting coefficient and the variance of the charge level recorded by the electronic device each time it is activated, wherein the second weighting coefficient is less than 1; The sum of the average value and the product is used to predict the remaining charge level of the electronic device at the end of the next charging cycle.

7. The method according to claim 4, characterized in that, The charging data includes charging data for each time the electronic device is charged in the target charging scenario within the preset period. When the screen-off duration of the next charging of the electronic device meets the task startup duration and the battery level of the electronic device's next charge meets the task startup battery level, the corresponding background task is scheduled and executed, including: When the electronic device is in the target charging scenario, the screen-off duration of the next charging session of the electronic device meets the task startup duration of the next charging session of the electronic device in the target charging scenario, and the battery level of the next charging session of the electronic device meets the task startup battery level of the next charging session of the electronic device in the target charging scenario, the corresponding background task is scheduled and executed.

8. The method according to claim 1, characterized in that, The charging data includes charging data for each time the electronic device is charged in the target charging scenario within the preset period. When the screen-off duration of the next charging of the electronic device meets the task startup duration, the corresponding background task is scheduled and executed, including: When the electronic device is in the target charging scenario and the screen-off duration of the next charging session of the electronic device meets the task start duration when the electronic device is charging in the target charging scenario, the corresponding background task is scheduled and executed.

9. A background task scheduling method, characterized in that, include: The screen-off time during this charging of the electronic device is predicted based on the charging data, wherein the charging data includes the screen-off time data of each charging of the electronic device within a preset period; The task start time is determined within the range of a first time threshold and a second time threshold. The first time threshold represents the minimum screen-off time required for the electronic device to enter an idle state, and the second time threshold is the difference between the screen-off time and the estimated time to complete the background task. When the screen-off time of the electronic device during this charging period reaches the task startup time, the background task is scheduled and executed.

10. The method according to claim 9, characterized in that, Determining the task start duration within the range of the first duration threshold and the second duration threshold includes: The second duration threshold is determined as the task startup duration.

11. The method according to claim 9, characterized in that, The charging data also includes the charge level at the end of each charge cycle for the electronic device within a preset period, and the method further includes: Predict the remaining charge level of the electronic device based on the charging data. The task start-up battery level is determined within the range of a first battery threshold and a second battery threshold, where the second battery threshold is the difference between the battery level at the end of charging of the electronic device and the preset cached battery level. The background task to be scheduled and executed includes: When the screen-off duration of the electronic device during this charging period meets the task startup duration and the battery level of the electronic device during this charging period meets the task startup battery level, the corresponding background task is scheduled and executed.

12. The method according to claim 11, characterized in that, Determining the task startup power level within the range of the first power threshold and the second power threshold includes: The second power threshold is determined as the power required to start the task.

13. The method according to claim 12, characterized in that, The charging data includes charging data for each time the electronic device is charged in the target charging scenario within the preset period. When the screen-off duration of the electronic device during this charging session meets the task startup duration and the battery level of the electronic device during this charging session meets the task startup battery level, the corresponding background task is scheduled and executed, including: When the electronic device is in the target charging scenario, the screen-off duration of the electronic device during this charging session meets the task startup duration of the electronic device during the charging session in the target charging scenario, and the charge level of the electronic device during this charging session meets the task startup charge level of the electronic device during the charging session in the target charging scenario, the corresponding background task is scheduled and executed.

14. The method according to claim 9, characterized in that, The charging data includes charging data for each time the electronic device charges in the target charging scenario within the preset period. When the screen-off duration of the electronic device during this charging session meets the task startup duration, the corresponding background task is scheduled and executed, including: When the electronic device is in the target charging scenario and the screen-off duration of the electronic device during this charging session meets the task startup duration of the electronic device during the charging session in the target charging scenario, the corresponding background task is scheduled and executed.

15. An electronic device, characterized in that, include: Processor and memory; The memory stores one or more computer programs, the one or more computer programs including instructions; when the instructions are executed by the processor, the electronic device performs the method as described in any one of claims 1-8 or 9-14.

16. A computer storage medium, characterized in that, Includes computer instructions, which, when executed on an electronic device, cause the electronic device to perform the method as described in any one of claims 1-8 or 9-14.