-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework DeviceLink and Mobilebackup2Service
- Loading branch information
Showing
8 changed files
with
207 additions
and
610 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using Netimobiledevice.Plist; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Netimobiledevice.Lockdown.Services | ||
{ | ||
internal class DeviceLink : IDisposable | ||
{ | ||
private const int SERVICE_TIMEOUT = 60 * 1000; | ||
|
||
private readonly ServiceConnection _service; | ||
|
||
public DeviceLink(ServiceConnection service) | ||
{ | ||
_service = service; | ||
_service.SetTimeout(SERVICE_TIMEOUT); | ||
} | ||
|
||
private void Disconnect() | ||
{ | ||
ArrayNode message = new ArrayNode { | ||
new StringNode("DLMessageDisconnect"), | ||
new StringNode("___EmptyParameterString___") | ||
}; | ||
_service.SendPlist(message, PlistFormat.Binary); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Disconnect(); | ||
} | ||
|
||
public async Task<ArrayNode> ReceiveMessage() | ||
{ | ||
PropertyNode? message = await _service.ReceivePlist(); | ||
if (message == null) { | ||
return new ArrayNode(); | ||
} | ||
return message.AsArrayNode(); | ||
} | ||
|
||
public void Send(PropertyNode message) | ||
{ | ||
_service.SendPlist(message, PlistFormat.Binary); | ||
} | ||
|
||
public void SendProcessMessage(PropertyNode message) | ||
{ | ||
_service.SendPlist(new ArrayNode() { | ||
new StringNode("DLMessageProcessMessage"), | ||
message | ||
}, PlistFormat.Binary); | ||
} | ||
|
||
public async Task VersionExchange() | ||
{ | ||
ArrayNode versionExchangeMessage = await ReceiveMessage(); | ||
PropertyNode versionMajor = versionExchangeMessage[1]; | ||
_service.SendPlist(new ArrayNode { | ||
new StringNode("DLMessageVersionExchange"), | ||
new StringNode("DLVersionsOk"), | ||
versionMajor | ||
}); | ||
ArrayNode messageDeviceReady = await ReceiveMessage(); | ||
if (messageDeviceReady[0].AsStringNode().Value != "DLMessageDeviceReady") { | ||
throw new Exception("Device link didn't return ready state"); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.