Commit d367e8d6 authored by wutao's avatar wutao Committed by Commit Bot

Assistant: Update device id and type

We need to update device_settings_update's device id and type.
We update them when the assistant service starts.

Bug: b/110094434
Test: manual. Can see updated id and type in log.
Change-Id: I1c85828482be49fb0e879cb233160236d0a676e1
Reviewed-on: https://chromium-review.googlesource.com/1099965Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: Tao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567345}
parent f2bbbf41
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include "build/util/webkit_version.h" #include "build/util/webkit_version.h"
#include "chromeos/assistant/internal/internal_constants.h" #include "chromeos/assistant/internal/internal_constants.h"
#include "chromeos/assistant/internal/internal_util.h" #include "chromeos/assistant/internal/internal_util.h"
#include "chromeos/services/assistant/public/proto/assistant_device_settings_ui.pb.h"
#include "chromeos/services/assistant/public/proto/settings_ui.pb.h"
#include "chromeos/services/assistant/service.h" #include "chromeos/services/assistant/service.h"
#include "chromeos/services/assistant/utils.h" #include "chromeos/services/assistant/utils.h"
#include "chromeos/system/version_loader.h" #include "chromeos/system/version_loader.h"
...@@ -266,9 +268,14 @@ void AssistantManagerServiceImpl::StartAssistantInternal( ...@@ -266,9 +268,14 @@ void AssistantManagerServiceImpl::StartAssistantInternal(
SetAccessToken(access_token); SetAccessToken(access_token);
assistant_client::Callback0 assistant_callback([callback = std::move( assistant_client::Callback0 assistant_callback([
callback)]() mutable { callback = std::move(callback),
update_settings_callback =
base::BindOnce(&AssistantManagerServiceImpl::UpdateDeviceIdAndType,
weak_factory_.GetWeakPtr())
]() mutable {
std::move(callback).Run(); std::move(callback).Run();
std::move(update_settings_callback).Run();
}); });
assistant_manager_->Start(std::move(assistant_callback)); assistant_manager_->Start(std::move(assistant_callback));
...@@ -299,6 +306,26 @@ std::string AssistantManagerServiceImpl::BuildUserAgent( ...@@ -299,6 +306,26 @@ std::string AssistantManagerServiceImpl::BuildUserAgent(
return user_agent; return user_agent;
} }
void AssistantManagerServiceImpl::UpdateDeviceIdAndType() {
const std::string device_id = assistant_manager_->GetDeviceId();
if (device_id.empty())
return;
// Update device id and device type.
assistant::SettingsUiUpdate update;
assistant::AssistantDeviceSettingsUpdate* device_settings_update =
update.mutable_assistant_device_settings_update()
->add_assistant_device_settings_update();
device_settings_update->set_device_id(device_id);
device_settings_update->set_assistant_device_type(
assistant::AssistantDevice::CROS);
// Device settings update result is not handled because it is not included in
// the SettingsUiUpdateResult.
SendUpdateSettingsUiRequest(update.SerializeAsString(),
UpdateSettingsUiResponseCallback());
}
void AssistantManagerServiceImpl::HandleGetSettingsResponse( void AssistantManagerServiceImpl::HandleGetSettingsResponse(
base::RepeatingCallback<void(const std::string&)> callback, base::RepeatingCallback<void(const std::string&)> callback,
const std::string& settings) { const std::string& settings) {
......
...@@ -102,6 +102,9 @@ class AssistantManagerServiceImpl ...@@ -102,6 +102,9 @@ class AssistantManagerServiceImpl
assistant_client::AssistantManager* assistant_manager); assistant_client::AssistantManager* assistant_manager);
std::string BuildUserAgent(const std::string& arc_version) const; std::string BuildUserAgent(const std::string& arc_version) const;
// Update device id and type when assistant service starts.
void UpdateDeviceIdAndType();
void HandleGetSettingsResponse( void HandleGetSettingsResponse(
base::RepeatingCallback<void(const std::string&)> callback, base::RepeatingCallback<void(const std::string&)> callback,
const std::string& settings); const std::string& settings);
......
# Copyright 2018 Google Inc. All Rights Reserved. # Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//third_party/protobuf/proto_library.gni") import("//third_party/protobuf/proto_library.gni")
...@@ -7,6 +9,7 @@ proto_library("proto") { ...@@ -7,6 +9,7 @@ proto_library("proto") {
"about_me_settings_ui.proto", "about_me_settings_ui.proto",
"activity_control_settings_common.proto", "activity_control_settings_common.proto",
"activity_control_settings_ui.proto", "activity_control_settings_ui.proto",
"assistant_device_settings_ui.proto",
"consent_flow_ui.proto", "consent_flow_ui.proto",
"email_opt_in_ui.proto", "email_opt_in_ui.proto",
"get_settings_ui.proto", "get_settings_ui.proto",
......
// Copyright 2018 The Chromium Authors. All rights reserved. // Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is govered by a BSD-style // Use of this source code is governed by a BSD-style license that can be
// license that can be found in the LICENSE file or at // found in the LICENSE file.
// https://developers.google.com/open-source/licenses/bsd
syntax = "proto2"; syntax = "proto2";
......
// Copyright 2018 The Chromium Authors. All rights reserved. // Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is govered by a BSD-style // Use of this source code is governed by a BSD-style license that can be
// license that can be found in the LICENSE file or at // found in the LICENSE file.
// https://developers.google.com/open-source/licenses/bsd
syntax = "proto2"; syntax = "proto2";
......
// Copyright 2018 The Chromium Authors. All rights reserved. // Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is govered by a BSD-style // Use of this source code is governed by a BSD-style license that can be
// license that can be found in the LICENSE file or at // found in the LICENSE file.
// https://developers.google.com/open-source/licenses/bsd
syntax = "proto2"; syntax = "proto2";
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
syntax = "proto2";
option optimize_for = LITE_RUNTIME;
package chromeos.assistant;
message AssistantDevice {
// The type of assistant device.
enum Type { CROS = 17; }
}
message AssistantDeviceSettingsUiUpdate {
// A list of assistant device settings update.
repeated AssistantDeviceSettingsUpdate assistant_device_settings_update = 1;
}
// Write only fields should go into AssistantDeviceSettingsUpdate.
message AssistantDeviceSettingsUpdate {
optional string device_id = 1;
optional AssistantDevice.Type assistant_device_type = 3 [default = CROS];
optional AssistantDeviceSettings device_settings = 2;
}
message AssistantDeviceSettings {
optional string locale = 5;
}
// Copyright 2018 The Chromium Authors. All rights reserved. // Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is govered by a BSD-style // Use of this source code is governed by a BSD-style license that can be
// license that can be found in the LICENSE file or at // found in the LICENSE file.
// https://developers.google.com/open-source/licenses/bsd
syntax = "proto2"; syntax = "proto2";
......
// Copyright 2018 The Chromium Authors. All rights reserved. // Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is govered by a BSD-style // Use of this source code is governed by a BSD-style license that can be
// license that can be found in the LICENSE file or at // found in the LICENSE file.
// https://developers.google.com/open-source/licenses/bsd
syntax = "proto2"; syntax = "proto2";
......
// Copyright 2018 The Chromium Authors. All rights reserved. // Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is govered by a BSD-style // Use of this source code is governed by a BSD-style license that can be
// license that can be found in the LICENSE file or at // found in the LICENSE file.
// https://developers.google.com/open-source/licenses/bsd
syntax = "proto2"; syntax = "proto2";
...@@ -10,6 +9,7 @@ option optimize_for = LITE_RUNTIME; ...@@ -10,6 +9,7 @@ option optimize_for = LITE_RUNTIME;
package chromeos.assistant; package chromeos.assistant;
import "about_me_settings_ui.proto"; import "about_me_settings_ui.proto";
import "assistant_device_settings_ui.proto";
import "consent_flow_ui.proto"; import "consent_flow_ui.proto";
import "email_opt_in_ui.proto"; import "email_opt_in_ui.proto";
...@@ -21,6 +21,7 @@ message SettingsUi { ...@@ -21,6 +21,7 @@ message SettingsUi {
message SettingsUiUpdate { message SettingsUiUpdate {
optional AboutMeSettingsUiUpdate about_me_settings_update = 4; optional AboutMeSettingsUiUpdate about_me_settings_update = 4;
optional AssistantDeviceSettingsUiUpdate assistant_device_settings_update = 6;
optional ConsentFlowUiUpdate consent_flow_ui_update = 21; optional ConsentFlowUiUpdate consent_flow_ui_update = 21;
optional EmailOptInUpdate email_opt_in_update = 26; optional EmailOptInUpdate email_opt_in_update = 26;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment