Index: components/proximity_auth/messenger_impl.cc |
diff --git a/components/proximity_auth/messenger_impl.cc b/components/proximity_auth/messenger_impl.cc |
index 13bfac7a4e36a1f1b707508fdd62690d4d7c3ed7..aab4adee94b075eb0c7d274a2d639fb1fa854058 100644 |
--- a/components/proximity_auth/messenger_impl.cc |
+++ b/components/proximity_auth/messenger_impl.cc |
@@ -7,6 +7,8 @@ |
#include "base/bind.h" |
#include "base/json/json_reader.h" |
#include "base/json/json_writer.h" |
+#include "base/location.h" |
+#include "base/thread_task_runner_handle.h" |
#include "base/values.h" |
#include "components/proximity_auth/connection.h" |
#include "components/proximity_auth/cryptauth/base64url.h" |
@@ -36,6 +38,15 @@ const char kMessageTypeUnlockResponse[] = "unlock_response"; |
// The name for an unlock event originating from the local device. |
const char kUnlockEventName[] = "easy_unlock"; |
+// Messages sent and received from the iOS app when polling for it's lock screen |
+// status. |
+// TODO(tengs): Unify the iOS status update protocol with the existing Android |
+// protocol, so we don't have this special case. |
+const char kPollScreenState[] = "PollScreenState"; |
+const char kScreenUnlocked[] = "Screen Unlocked"; |
+const char kScreenLocked[] = "Screen Locked"; |
+const int kIOSPollingIntervalSeconds = 5; |
+ |
// Serializes the |value| to a JSON string and returns the result. |
std::string SerializeValueToJson(const base::Value& value) { |
std::string json; |
@@ -61,6 +72,11 @@ MessengerImpl::MessengerImpl(scoped_ptr<Connection> connection, |
weak_ptr_factory_(this) { |
DCHECK(connection_->IsConnected()); |
connection_->AddObserver(this); |
+ |
+ // TODO(tengs): We need CryptAuth to report if the phone runs iOS or Android, |
+ // rather than relying on this heuristic. |
+ if (connection_->remote_device().bluetooth_type == RemoteDevice::BLUETOOTH_LE) |
+ PollScreenStateForIOS(); |
} |
MessengerImpl::~MessengerImpl() { |
@@ -243,6 +259,20 @@ void MessengerImpl::HandleUnlockResponseMessage( |
FOR_EACH_OBSERVER(MessengerObserver, observers_, OnUnlockResponse(true)); |
} |
+void MessengerImpl::PollScreenStateForIOS() { |
+ if (!connection_->IsConnected()) |
+ return; |
+ |
+ // Sends message requesting screen state. |
+ connection_->SendMessage(make_scoped_ptr(new WireMessage(kPollScreenState))); |
sacomoto
2015/10/01 16:09:08
We should encrypt the messages to iOS too.
|
+ |
+ // Schedules the next message in |kPollingIntervalSeconds|. |
+ base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
+ FROM_HERE, base::Bind(&MessengerImpl::PollScreenStateForIOS, |
+ weak_ptr_factory_.GetWeakPtr()), |
+ base::TimeDelta::FromSeconds(kIOSPollingIntervalSeconds)); |
+} |
+ |
void MessengerImpl::OnConnectionStatusChanged(Connection* connection, |
Connection::Status old_status, |
Connection::Status new_status) { |
@@ -250,7 +280,6 @@ void MessengerImpl::OnConnectionStatusChanged(Connection* connection, |
if (new_status == Connection::DISCONNECTED) { |
PA_LOG(INFO) << "Secure channel disconnected..."; |
connection_->RemoveObserver(this); |
- connection_.reset(); |
FOR_EACH_OBSERVER(MessengerObserver, observers_, OnDisconnected()); |
// TODO(isherman): Determine whether it's also necessary/appropriate to fire |
// this notification from the destructor. |
@@ -259,6 +288,20 @@ void MessengerImpl::OnConnectionStatusChanged(Connection* connection, |
void MessengerImpl::OnMessageReceived(const Connection& connection, |
const WireMessage& wire_message) { |
+ // TODO(tengs): Unify the iOS status update protocol with the existing Android |
+ // protocol, so we don't have this special case. |
+ std::string payload = wire_message.payload(); |
sacomoto
2015/10/01 16:09:08
This message should be encrypted too.
|
+ if (payload == kScreenUnlocked || payload == kScreenLocked) { |
+ RemoteStatusUpdate update; |
+ update.user_presence = |
+ (payload == kScreenUnlocked ? USER_PRESENT : USER_ABSENT); |
+ update.secure_screen_lock_state = SECURE_SCREEN_LOCK_ENABLED; |
+ update.trust_agent_state = TRUST_AGENT_ENABLED; |
+ FOR_EACH_OBSERVER(MessengerObserver, observers_, |
+ OnRemoteStatusUpdate(update)); |
+ return; |
+ } |
+ |
secure_context_->Decode(wire_message.payload(), |
base::Bind(&MessengerImpl::OnMessageDecoded, |
weak_ptr_factory_.GetWeakPtr())); |