forked from doronz88/pymobiledevice3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
power_assertion.py
executable file
·32 lines (25 loc) · 1.1 KB
/
power_assertion.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
import contextlib
from pymobiledevice3.lockdown import LockdownClient
from pymobiledevice3.lockdown_service_provider import LockdownServiceProvider
from pymobiledevice3.services.lockdown_service import LockdownService
class PowerAssertionService(LockdownService):
RSD_SERVICE_NAME = 'com.apple.mobile.assertion_agent.shim.remote'
SERVICE_NAME = 'com.apple.mobile.assertion_agent'
def __init__(self, lockdown: LockdownServiceProvider):
if isinstance(lockdown, LockdownClient):
super().__init__(lockdown, self.SERVICE_NAME)
else:
super().__init__(lockdown, self.RSD_SERVICE_NAME)
@contextlib.contextmanager
def create_power_assertion(self, type_: str, name: str, timeout: float, details: str = None):
msg = {
'CommandKey': 'CommandCreateAssertion',
'AssertionTypeKey': type_,
'AssertionNameKey': name,
'AssertionTimeoutKey': timeout,
}
if details is not None:
msg['AssertionDetailKey'] = details
self.service.send_recv_plist(msg)
yield