예제 #1
0
def manage(foregroundTasks, backgroundTasks):
    for task in foregroundTasks:
        if not process.is_system_process(task.pid):
            resume_process(task.pid)
    if not process.on_battery():
        suspended_pids = [pid for pid,_ in suspended_tasks]
        for pid in filter(lambda pid: get_suspend_preference(pid) == SUSPEND_ON_BATTERY, suspended_pids):
            resume_process(pid)
    for task in filter(lambda task: get_suspend_preference(task.pid), backgroundTasks):
        if process.is_system_process(task.pid):
            continue
        suspend_task_on_battery = get_suspend_preference(task.pid) == SUSPEND_ON_BATTERY
        if suspend_task_on_battery and not process.on_battery():
            continue
        suspend_process(task.pid, battery=suspend_task_on_battery)
예제 #2
0
def suspend_process(pid, manual=False, battery=False):
    name = process.get_name(pid)
    if manual:
        set_suspend_preference(name, SUSPEND_ON_BATTERY if battery else SUSPEND_ALWAYS)
    if battery and not process.on_battery():
        return
    if process.suspend_pid(pid):
        suspended_tasks.add((pid, name))
    else:
        set_suspend_preference(name, "")