TECHNICAL FIELD

This application relates to the field of terminals, and more specifically, to a method for managing a trigger on a terminal device, and a terminal device.

BACKGROUND

A terminal device usually senses a change and elapsing of time according to a requirement of an application program, to trigger a corresponding task. For example, the terminal device may trigger a corresponding task at a specified time by using a trigger such as an alarm, a job information (JobInfo) object, or a timer. Triggers may be set to trigger tasks at specified times for a plurality of reasons. Some triggers are set according to an actual requirement of a user, while some triggers are autonomously set by an application program.

A good-will trigger can improve user experience. For example, a user operates in an alarm, and sets the alarm to ring at 7:00 tomorrow morning, to wake up the user to work. Alternatively, a user performs a setting in a shopping application program to snap up an item, and the shopping application program accordingly sets a reminder alarm with a corresponding time. Alternatively, a system application program or a common application program needs to complete a particular task. For example, a news application program may set a JobInfo object that is triggered once an hour to obtain and cache news on the Internet, so that a user waits less time.

However, from a perspective of an application program, to ensure a target quantity of daily active users, ensure advertising revenue, increase a quantity of users online at the same time, decrease a cold start rate, or the like, the application program may apply some special mechanisms for malicious keepalive, to ensure that the application program resides in background and a resource is not cleaned up by a system. Currently, a most widely used means is: The application program automatically starts at a specified time or periodically by setting a trigger without knowledge of a user. In this way, even though the application program is closed by the user, the application program can still be pulled up in background by the trigger. It is found through testing and analysis that, many common application programs on the terminal device automatically start at specified times or periodically by using triggers, for example, alarms or JobInfo objects, of an operating system, to achieve keepalive. Such a trigger that is set to keep an application program alive does not match a true will or intention of a user, and usually is not perceived by the user, and therefore may also be referred to as a malicious trigger. The malicious trigger causes the system to repeatedly pull up, in background, the application program that has been closed by the user. This leads to additional resource overheads (CPU, memory, battery, and the like), degrades foreground performance, and increases power consumption. In addition, when the terminal device is in a sleep state, the malicious trigger that is set by the application program repeatedly wakes up the system from the sleep state, leading to additional power consumption, and affecting battery endurance of the terminal device.

SUMMARY

This application provides a method for managing a trigger, and a related apparatus, to differently manage and control triggers on a terminal device based on information in one or more dimensions, to change a timing for an application program to execute a corresponding task based on a trigger, prevent behavior of setting the trigger by the application program to frequently trigger the task, and reduce resource consumption.

According to a first aspect, an embodiment of this application provides a method for managing a trigger, including: obtaining a trigger that is set by an application program on a terminal device, where the trigger is set to trigger a scheduled task at a specified triggering time; determining an attribute of the trigger based on at least one of characteristic information of historical behavior of a user, characteristic information of the application program, or characteristic information of the trigger; and delaying or stopping the trigger based on the attribute of the trigger, so that the scheduled task is triggered at a time later than the triggering time that is set by the application program, where the characteristic information of the historical behavior of the user is used to determine a use habit of the user. In this solution, a trigger that does not match a will of the user or the use habit of the user and that has a particular attribute, for example, a malicious trigger configured to keep an application alive (periodically start a process or a service), is identified based on the use habit of the user, a characteristic of the application program, and a characteristic of the trigger, and the trigger is delayed or stopped. This reduces impact on foreground available resources, and reduces power consumption.

The trigger is an alarm, a timer, or a job information (JobInfo) object.

In one embodiment, when it is determined, based on at least one of the characteristic information of the historical behavior of the user, the characteristic information of the application program, or the characteristic information of the trigger, that the trigger is a trigger that is configured to trigger a task specified by the user or beneficial to user experience and that has a particular attribute, the trigger is accelerated to trigger the corresponding task earlier or in an unstopped manner, to improve user experience.

In one embodiment, when the triggering time of the trigger arrives, before the trigger is delivered, whether a delivering condition is met is further determined based on at least one of a status of the terminal device or a current operation status of the user. If the delivering condition is not met, delivering the trigger to the application program is delayed. In this way, triggering behavior of the trigger can be managed and controlled better, to reduce impact on foreground performance and improve user experience.

In one embodiment, a plurality of different types of trigger queues may be set, including: a normal trigger queue, a delayed trigger queue, and an accelerated trigger queue. Correspondingly, a trigger whose triggering policy is delaying triggering is added to the delayed trigger queue, a trigger whose triggering policy is normal triggering is added to the normal trigger queue, and a trigger whose triggering policy is accelerating triggering is added to the accelerated trigger queue. A plurality of trigger queues corresponding to a plurality of triggering policies are set to facilitate logical management on triggers and improve system performance.

In one embodiment, the trigger may be migrated between different trigger queues based on a delivering timing of the trigger.

According to a second aspect, an embodiment of this application provides another method for managing a trigger, including: determining a trigger that is set by a first application program on a terminal device, where the trigger is configured to: when a specified triggering condition is met, trigger the first application program to execute a scheduled task; determining a triggering policy of the trigger based on at least one of characteristic information of historical behavior of a user, characteristic information of the application program, or characteristic information of the trigger; and if the triggering policy of the trigger is normal triggering, when the specified triggering condition is met, executing the trigger to trigger the application program to execute the scheduled task; or if the triggering policy of the trigger is delaying triggering, delaying the trigger to trigger the application program later to execute the scheduled task. In this solution, the triggering policy of the trigger that is set by the application program is dynamically determined based on a use habit of the user, a characteristic of the application program, and a characteristic of the trigger, and a trigger having a particular attribute, for example, a malicious trigger, is delayed or stopped. This reduces impact of the malicious trigger on foreground available resources, and reduces power consumption.

In one embodiment, a trigger that is configured to trigger a task specified by the user or beneficial to user experience and that has a particular attribute may be identified based on at least one of the characteristic information of the historical behavior of the user, the characteristic information of the application program, or the characteristic information of the trigger, and the trigger is accelerated to trigger the corresponding task earlier or in an unstopped manner, to improve user experience.

In one embodiment, when the triggering condition of the trigger is met, whether a delivering condition is met is further determined based on at least one of a status of the terminal device or a current operation status of the user. If the delivering condition is met, the trigger is delivered to the first application program. If the delivering condition is not met, delivering the trigger to the application program is delayed. In this way, triggering behavior of the trigger can be managed and controlled better, to reduce impact on foreground performance and improve user experience.

In one embodiment, the trigger may be delayed and accelerated by modifying the triggering condition of the trigger.

The triggering condition of the trigger includes a condition in a time dimension and/or a condition in the terminal device status dimension. The condition in the time dimension includes, but is not limited to, a time for triggering the scheduled task, a time interval for triggering the scheduled task, or a maximum triggering delay of the scheduled task. The condition in the terminal device status dimension includes, but is not limited to, a battery level of the terminal device is not lower than a specified first threshold, available storage space of the terminal device is not less than a specified second threshold, the terminal device is in a charging state, the terminal device is in an idle mode, or a network connection type of the terminal device is a specified type.

In one embodiment, the delaying the trigger includes: when the triggering condition that is set by the application program is met, waiting preset duration and then determining again whether the specified triggering condition is met, and if the specified triggering condition is met, executing the trigger to trigger the application program to execute the scheduled task. The preset duration may be flexibly set based on a status of a system or a specific application scenario.

In one embodiment, a plurality of different types of trigger queues may be set, including: a normal trigger queue, a delayed trigger queue, and an accelerated trigger queue. Correspondingly, a trigger whose triggering policy is delaying triggering is added to the delayed trigger queue, a trigger whose triggering policy is normal triggering is added to the normal trigger queue, and a trigger whose triggering policy is accelerating triggering is added to the accelerated trigger queue. A plurality of trigger queues corresponding to a plurality of triggering policies are set to facilitate logical management on triggers and improve system performance.

According to a third aspect, an embodiment of this application provides another method for managing a trigger, including: determining a trigger that is set by an application program on a terminal device, where the trigger is configured to: when a specified triggering condition is met, trigger the application program to execute a scheduled task; and when the triggering condition of the trigger is met, delaying, based on at least one of a status of the terminal device or a current operation status of a user, delivering the trigger to the application program, so that the scheduled task is executed later. In this solution, a delivering timing of the trigger is flexibly managed and controlled based on the status of the terminal device and/or the current operation status of the user, to reduce impact of the trigger on foreground performance and improve user experience.

The triggering condition of the trigger includes a condition in a time dimension and/or a condition in the terminal device status dimension. The condition in the time dimension includes, but is not limited to, a time for triggering the scheduled task, a time interval for triggering the scheduled task, or a maximum triggering delay of the scheduled task. The condition in the terminal device status dimension includes, but is not limited to, a battery level of the terminal device is not lower than a specified first threshold, available storage space of the terminal device is not less than a specified second threshold, the terminal device is in a charging state, the terminal device is in an idle mode, or a network connection type of the terminal device is a specified type.

In one embodiment, when resource usage of the terminal device exceeds a specified threshold, delivering the trigger to the application program is delayed.

In one embodiment, when the terminal device is in a sleep mode, delivering the trigger to the application program is delayed.

In one embodiment, when a battery level of the terminal device is lower than a predetermined threshold, delivering the trigger to the application program is delayed.

In one embodiment, when a foreground application currently operated by the user is a high-resource-consumption application, in other words, consumed resources exceed a preset threshold, for example, the application is a large-scale game, delivering the trigger to the application program is delayed.

According to a fourth aspect, an embodiment of this application provides another method for managing a trigger, including: obtaining a parameter of a trigger, where the trigger is set by an application program on a terminal device to trigger, when a specified triggering condition is met, a scheduled task to be executed; determining a triggering policy of the trigger based on at least one of the parameter of the trigger, characteristic information of historical behavior of a user, or characteristic information of the application program; and if the triggering policy of the trigger is normal triggering, when the specified triggering condition is met, executing the trigger to trigger the application program to execute the scheduled task; or if the triggering policy of the trigger is delaying triggering, delaying the trigger to trigger the application program later to execute the scheduled task. In this solution, the triggering policy of the trigger that is set by the application program is dynamically determined based on a use habit of the user, a characteristic of the application program, and a characteristic of the trigger, and a trigger having a particular attribute, for example, a malicious trigger, is delayed or stopped. This reduces impact of the malicious trigger on foreground available resources, and reduces power consumption.

The parameter of the trigger includes: a type, the triggering condition, the to-be-triggered scheduled task (scheduled task), and the like of the trigger.

In one embodiment, a trigger that is configured to trigger a task specified by the user or beneficial to user experience and that has a particular attribute may be identified based on at least one of the parameter of the trigger, the characteristic information of the historical behavior of the user, or the characteristic information of the application program, and the trigger is accelerated to trigger the corresponding task earlier or in an unstopped manner, to improve user experience.

In one embodiment, when the triggering condition of the trigger is met, whether a delivering condition is met is further determined based on at least one of a status of the terminal device or a current operation status of the user. If the delivering condition is met, the trigger is delivered to the application program. If the delivering condition is not met, delivering the trigger to the application program is delayed. In this way, triggering behavior of the trigger can be managed and controlled better, to reduce impact on foreground performance and improve user experience.

In one embodiment, the trigger may be delayed and accelerated by modifying the triggering condition of the trigger.

In one embodiment, the delaying the trigger includes: when the triggering condition that is set by the application program is met, waiting preset duration and then determining again whether the specified triggering condition is met, and if the specified triggering condition is met, executing the trigger to trigger the application program to execute the scheduled task. The preset duration may be flexibly set based on a status of a system or a specific application scenario.

In one embodiment, a plurality of different types of trigger queues may be set, including: a normal trigger queue, a delayed trigger queue, and an accelerated trigger queue. Correspondingly, a trigger whose triggering policy is delaying triggering is added to the delayed trigger queue, a trigger whose triggering policy is normal triggering is added to the normal trigger queue, and a trigger whose triggering policy is accelerating triggering is added to the accelerated trigger queue. A plurality of trigger queues corresponding to a plurality of triggering policies are set to facilitate logical management on triggers and improve system performance.

According to a fifth aspect, an embodiment of this application provides a terminal device, including one or more functional units configured to perform the method described in any one of the first aspect to the fourth aspect. These functional units may be implemented by software, or implemented by hardware, for example, a processor, or implemented by software and necessary hardware.

According to a sixth aspect, an embodiment of this application provides a terminal device, including: a memory, a processor, and a computer program that is stored in the memory. When the processor executes the computer program, operations of the method described in any one of the first aspect to the fourth aspect are implemented.

According to a seventh aspect, an embodiment of this application provides a computer-readable storage medium, storing a computer program (an instruction). When the program is executed by a processor, operations of the method described in any one of the first aspect to the fourth aspect are implemented.

In any one of the foregoing aspects or the possible implementations of the foregoing aspects, the characteristic information of the application program includes at least one of characteristic information of historical behavior, an identifier, or a type of the application program; and the characteristic information of the historical behavior of the user includes an operation record of the user and/or a whitelist that is set by the user, and the whitelist records an identifier, set by the user, of a trusted application program.

In any one of the foregoing aspects or the possible implementations of the foregoing aspects, the status of the terminal device includes at least one of resource usage, a battery level, a work mode, a network connection status, a data transmission status, a name of a foreground application program, a type of the foreground application program, a name of a background application program, or a type of the background application program of the terminal device; and the work mode of the terminal device includes a sleep mode and a wakeup mode.

In any one of the foregoing aspects or the possible implementations of the foregoing aspects, the scheduled task that the trigger triggers to be executed includes at least one of the following: starting an activity, sending a broadcast, starting a service, or initiating network communication.

In any one of the foregoing aspects or the possible implementations of the foregoing aspects, the characteristic information of the trigger includes at least one of a type (for example, a one-time trigger or a repeating trigger), a triggering condition, or a to-be-triggered task of the trigger; the characteristic information of the application program includes at least one of a name/an identifier of the application program, a type of the application program, or characteristic information of historical behavior of the application program; and the characteristic information of the historical behavior of the user includes at least one of a frequency, a time, a location, or a motion status when the user uses each application.

