mirror of
https://github.com/bitwarden/mobile.git
synced 2024-09-27 03:52:57 +02:00
e72932cbaa
* EC-835 Added in the Watch app keychain accessible when passcode set this device only and when the passcode is set to signal the iPhone to trigger a sync on opening the watch app * EC-835 Embed LocalAuthentication framework into the watch app to fix no such module when importing it * EC-835 Changed approach to check if Watch has passcode enabled by using Keychain accessible kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly instead of LAContext * EC-835 Fix weird error saying unassigned local variable on the CI compiler. It seems it doesn't realize of the full condition
66 lines
2.3 KiB
C#
66 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Bit.App.Services;
|
|
using Bit.Core.Abstractions;
|
|
using Bit.Core.Models;
|
|
using Bit.Core.Utilities;
|
|
using Newtonsoft.Json;
|
|
using WatchConnectivity;
|
|
|
|
namespace Bit.iOS.Core.Services
|
|
{
|
|
public class WatchDeviceService : BaseWatchDeviceService
|
|
{
|
|
const string ACTION_MESSAGE_KEY = "actionMessage";
|
|
const string TRIGGER_SYNC_ACTION_KEY = "triggerSync";
|
|
|
|
public WatchDeviceService(ICipherService cipherService,
|
|
IEnvironmentService environmentService,
|
|
IStateService stateService,
|
|
IVaultTimeoutService vaultTimeoutService)
|
|
: base(cipherService, environmentService, stateService, vaultTimeoutService)
|
|
{
|
|
WCSessionManager.SharedManager.OnMessagedReceived += OnMessagedReceived;
|
|
}
|
|
|
|
public override bool IsConnected => WCSessionManager.SharedManager.IsSessionActivated;
|
|
|
|
protected override bool CanSendData => WCSessionManager.SharedManager.IsValidSession;
|
|
|
|
protected override bool IsSupported => WCSession.IsSupported;
|
|
|
|
protected override Task SendDataToWatchAsync(WatchDTO watchDto)
|
|
{
|
|
var serializedData = JsonConvert.SerializeObject(watchDto);
|
|
|
|
// Add time to the key to make it change on every message sent so it's delivered faster.
|
|
// If we use the same key then the OS may defer the delivery of the message because of
|
|
// resources, reachability and other stuff
|
|
WCSessionManager.SharedManager.SendBackgroundHighPriorityMessage(new Dictionary<string, object>
|
|
{
|
|
[$"watchDto-{DateTime.UtcNow.ToLongTimeString()}"] = serializedData
|
|
});
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
protected override void ConnectToWatch()
|
|
{
|
|
WCSessionManager.SharedManager.StartSession();
|
|
}
|
|
|
|
private void OnMessagedReceived(WCSession session, Dictionary<string, object> data)
|
|
{
|
|
if (data != null
|
|
&&
|
|
data.TryGetValue(ACTION_MESSAGE_KEY, out var action)
|
|
&&
|
|
action as string == TRIGGER_SYNC_ACTION_KEY)
|
|
{
|
|
SyncDataToWatchAsync().FireAndForget();
|
|
}
|
|
}
|
|
}
|
|
}
|