Skip to content

Commit

Permalink
Merge pull request #497 from doronz88/feature/restore_service
Browse files Browse the repository at this point in the history
services: add `RestoreService`
  • Loading branch information
doronz88 authored Jul 23, 2023
2 parents c60e053 + 7e14708 commit 03880b5
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions pymobiledevice3/services/restore_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from typing import Mapping

from pymobiledevice3.exceptions import PyMobileDevice3Exception
from pymobiledevice3.remote.remote_service import RemoteService
from pymobiledevice3.remote.remote_service_discovery import RemoteServiceDiscoveryService


class RestoreService(RemoteService):
SERVICE_NAME = 'com.apple.RestoreRemoteServices.restoreserviced'

def __init__(self, lockdown: RemoteServiceDiscoveryService):
super().__init__(lockdown, self.SERVICE_NAME)

def delay_recovery_image(self) -> None:
"""
Set `delay-recovery-image` on devices of ProductType 0x1677b394. Otherwise, fail
"""
self.validate_command('delayrecoveryimage')

def enter_recovery(self) -> None:
""" Enter recovery """
self.validate_command('recovery')

def reboot(self) -> None:
""" Reboot device """
self.validate_command('reboot')

def get_preflightinfo(self) -> Mapping:
""" Get preflight info """
return self.service.send_receive_request({'command': 'getpreflightinfo'})

def get_nonces(self) -> Mapping:
""" Get ApNonce and SEPNonce """
return self.service.send_receive_request({'command': 'getnonces'})

def validate_command(self, command: str) -> Mapping:
""" Execute command and validate result is `success` """
response = self.service.send_receive_request({'command': command})
if response.get('result') != 'success':
raise PyMobileDevice3Exception(f'request command: {command} failed with error: {response}')
return response

0 comments on commit 03880b5

Please sign in to comment.