0

Produce version and CPU answer card result in System Info Provider

Low-Coverage-Reason: Answer ranker priority is not yet confirmed. Tests will be complete once this is set.

Bug: b/263994165
Change-Id: I33c9b91122b80cc29d8cda3112465003b9bff0e1

Change-Id: I33c9b91122b80cc29d8cda3112465003b9bff0e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4230235
Commit-Queue: Lauren Commeignes <laurencom@chromium.org>
Reviewed-by: Rachel Wong <wrong@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1104366}
This commit is contained in:
Lauren Commeignes
2023-02-13 06:28:34 +00:00
committed by Chromium LUCI CQ
parent 4eb1aea4db
commit 187f3734c2
12 changed files with 148 additions and 22 deletions

@ -1843,6 +1843,15 @@ Style notes:
<message name="IDS_ASH_ASSISTANT_QUERY_ACCESSIBILITY_ANNOUNCEMENT" desc="The accessibility announcement that notifies users that the UI is focusing on an assistant query">
<ph name="QUERY_NAME">$1<ex>Harry Potter</ex></ph>, Google Assistant
</message>
<message name="IDS_ASH_VERSION_IN_LAUNCHER_MESSAGE" desc="Message content for the title of the answer card with the current version in the launcher">
Version <ph name="VERSION_NAME">$1<ex>109.0.5414.125</ex></ph> (<ph name="OFFICIAL_STATUS">$2<ex>Official Build</ex></ph>) <ph name="CHANNEL_NAME">$3<ex>Beta</ex></ph> <ph name="PROCESSOR_VARIATION">$4<ex>(64-bit)</ex></ph>
</message>
<message name="IDS_ASH_CPU_IN_LAUNCHER_TITLE" desc="Message content for the title of the answer card with the current CPU system information in the launcher">
CPU current usage: <ph name="CPU_USEAGE">$1<ex>89</ex></ph>%
</message>
<message name="IDS_ASH_CPU_IN_LAUNCHER_DESCRIPTION" desc="Message content for the description of the answer card with the current CPU system information in the launcher">
Temperature: <ph name="TEMPERATURE">$1<ex>34</ex></ph>°C - Current speed: <ph name="CPU_AVERAGE_CURRENT_FREQUENCY_GHZ">$2<ex>1.52</ex></ph>GHz
</message>
<message name="IDS_ASH_TOAST_DISMISS_BUTTON" desc="The text button shown in toasts to close the toast immediately without waiting timeout.">
DISMISS

@ -0,0 +1 @@
29a96f73916543be23bbd10d0a4dd284f2f1b173

@ -0,0 +1 @@
29a96f73916543be23bbd10d0a4dd284f2f1b173

@ -0,0 +1 @@
e65c801b2c0cc5def2209e2185b136918c8c98e7

@ -89,8 +89,9 @@ absl::optional<std::pair<std::u16string, std::u16string>> GetTemperature(
void AppendTextItem(const std::u16string& line,
const CrosApiSearchResult::TextType type,
std::vector<TextItem>& text_vector) {
if (line.empty())
if (line.empty()) {
return;
}
if (!text_vector.empty()) {
text_vector.push_back(CreateStringTextItem(u" "));

@ -7,17 +7,21 @@
#include "ash/public/cpp/app_list/app_list_types.h"
#include "chrome/browser/ash/app_list/search/chrome_search_result.h"
#include "chrome/browser/ash/app_list/search/common/icon_constants.h"
#include "chrome/browser/ash/app_list/search/types.h"
namespace app_list {
namespace {
// Returns the provider type's priority. A higher value indicates higher
// priority. Providers that are never used for answers will have 0 priority.
bool GetPriority(ProviderType type) {
int GetPriority(ProviderType type) {
switch (type) {
case ProviderType::kOmnibox:
return 2;
return 3;
case ProviderType::kKeyboardShortcut:
return 2;
// TODO(b/263994165): Check if this is the correct priority.
case ProviderType::kSystemInfo:
return 1;
default:
return 0;
@ -42,6 +46,26 @@ ChromeSearchResult* GetOmniboxCandidate(Results& results) {
return top_answer;
}
// If there are any best match SystemInfo answers, returns the highest scoring
// one. If not, returns nullptr.
ChromeSearchResult* GetSystemInfoCandidate(Results& results) {
ChromeSearchResult* top_answer = nullptr;
double top_score = 0.0;
for (const auto& result : results) {
if (result->display_type() != DisplayType::kAnswerCard ||
!result->best_match()) {
continue;
}
const double score = result->relevance();
if (!top_answer || score > top_score) {
top_answer = result.get();
top_score = score;
}
}
return top_answer;
}
// Returns the Shortcut best match as long as there is only one. Otherwise,
// returns nullptr.
ChromeSearchResult* GetShortcutCandidate(Results& results) {
@ -118,6 +142,9 @@ void AnswerRanker::UpdateResultRanks(ResultsMap& results,
case ProviderType::kKeyboardShortcut:
new_answer = GetShortcutCandidate(new_results);
break;
case ProviderType::kSystemInfo:
new_answer = GetSystemInfoCandidate(new_results);
break;
default:
return;
}

@ -5,6 +5,10 @@
#ifndef CHROME_BROWSER_ASH_APP_LIST_SEARCH_SYSTEM_INFO_CPU_DATA_H_
#define CHROME_BROWSER_ASH_APP_LIST_SEARCH_SYSTEM_INFO_CPU_DATA_H_
#include <string>
#include "base/strings/string_number_conversions.h"
namespace app_list {
/* This class is used to store the final CPU usage and health data for the
@ -34,8 +38,8 @@ class CpuData {
int GetPercentUsageUser() const { return percent_usage_user_; }
int GetPercentUsageSystem() const { return percent_usage_system_; }
int GetPercentUsageFree() const { return percent_usage_free_; }
int GetPercentUsageTotal() const {
return percent_usage_user_ + percent_usage_system_;
std::u16string GetPercentUsageTotalString() const {
return base::NumberToString16(percent_usage_user_ + percent_usage_system_);
}
int GetAverageCpuTempCelsius() const { return average_cpu_temp_celsius_; }
int GetScalingAverageCurrentFrequencyKhz() const {

@ -8,6 +8,7 @@
#include "ash/webui/diagnostics_ui/url_constants.h"
#include "base/strings/strcat.h"
#include "chrome/browser/ash/app_list/search/common/icon_constants.h"
#include "chrome/browser/ash/app_list/search/common/search_result_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ash/system_web_apps/system_web_app_ui_utils.h"
#include "chrome/browser/ui/settings_window_manager_chromeos.h"
@ -43,6 +44,7 @@ SystemInfoAnswerResult::SystemInfoAnswerResult(
SetTitle(title);
SetCategory(Category::kSettings);
SetResultType(ResultType::kSystemInfo);
UpdateTitleAndDetails(title, description);
SetMetricsType(ash::SYSTEM_INFO);
std::string id =
system_info_category_ == SystemInfoCategory::kSettings
@ -53,6 +55,18 @@ SystemInfoAnswerResult::SystemInfoAnswerResult(
SystemInfoAnswerResult::~SystemInfoAnswerResult() = default;
void SystemInfoAnswerResult::UpdateTitleAndDetails(
const std::u16string& title,
const std::u16string& description) {
std::vector<TextItem> title_vector;
title_vector.push_back(CreateStringTextItem(title));
SetTitleTextVector(title_vector);
std::vector<TextItem> details_vector;
details_vector.push_back(CreateStringTextItem(description));
SetDetailsTextVector(details_vector);
}
void SystemInfoAnswerResult::Open(int event_flags) {
if (system_info_category_ == SystemInfoCategory::kSettings) {
chrome::SettingsWindowManager::GetInstance()->ShowOSSettings(profile_,

@ -43,10 +43,14 @@ class SystemInfoAnswerResult : public ChromeSearchResult {
void Open(int event_flags) override;
void UpdateTitleAndDetails(const std::u16string& title,
const std::u16string& description);
private:
SystemInfoCategory const system_info_category_;
Profile* const profile_;
const std::u16string query_;
const std::string url_path_;
};

@ -59,6 +59,19 @@ TEST_F(SystemInfoAnswerResultTest, Settings) {
EXPECT_EQ(result.icon().shape, ash::SearchResultIconShape::kDefault);
EXPECT_TRUE(gfx::BitmapsAreEqual(*result.icon().icon.bitmap(),
*GetTestIcon().bitmap()));
ASSERT_EQ(result.title_text_vector().size(), 1u);
const auto& title = result.title_text_vector()[0];
ASSERT_EQ(title.GetType(), ash::SearchResultTextItemType::kString);
EXPECT_EQ(title.GetText(),
u"Version 108.0.5359.37 (Official Build) beta (64-bit)");
EXPECT_TRUE(title.GetTextTags().empty());
ASSERT_EQ(result.details_text_vector().size(), 1u);
const auto& details = result.details_text_vector()[0];
ASSERT_EQ(details.GetType(), ash::SearchResultTextItemType::kString);
EXPECT_EQ(details.GetText(), u"Click here to check for updates");
EXPECT_TRUE(details.GetTextTags().empty());
}
} // namespace app_list::test

@ -8,15 +8,20 @@
#include <optional>
#include <string>
#include "ash/strings/grit/ash_strings.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/ash/app_list/search/system_info/cpu_data.h"
#include "chrome/browser/ash/app_list/search/system_info/cpu_usage_data.h"
#include "chrome/browser/ash/app_list/search/system_info/system_info_answer_result.h"
#include "chrome/browser/ash/app_list/search/system_info/system_info_util.h"
#include "chrome/browser/ui/webui/settings/ash/device_storage_util.h"
#include "chrome/browser/ui/webui/settings/chromeos/constants/routes.mojom-forward.h"
#include "chrome/common/channel_info.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/ash/components/string_matching/fuzzy_tokenized_string_match.h"
#include "chromeos/ash/services/cros_healthd/public/cpp/service_connection.h"
#include "chromeos/ash/services/cros_healthd/public/mojom/cros_healthd_probe.mojom-shared.h"
@ -38,9 +43,20 @@ using ::ash::cros_healthd::mojom::PhysicalCpuInfoPtr;
using ::ash::cros_healthd::mojom::TelemetryInfoPtr;
using ::ash::string_matching::FuzzyTokenizedStringMatch;
using ::ash::string_matching::TokenizedString;
using ::chromeos::settings::mojom::kAboutChromeOsSectionPath;
constexpr double kRelevanceThreshold = 0.64;
// TODO(b/263994165): Replace with actual icon before feature is released. This
// is currently blocked by b/267948410, to manually load the settings and
// diagnostics icons in search.
gfx::ImageSkia GetTestIcon() {
SkBitmap bitmap;
bitmap.allocN32Pixels(50, 50);
bitmap.eraseColor(SK_ColorYELLOW);
return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
}
} // namespace
SystemInfoCardProvider::SystemInfoCardProvider(Profile* profile)
@ -58,6 +74,7 @@ SystemInfoCardProvider::SystemInfoCardProvider(Profile* profile)
base::BindOnce(&SystemInfoCardProvider::OnProbeServiceDisconnect,
weak_factory_.GetWeakPtr()));
StartObservingCalculators();
chromeos::PowerManagerClient::Get()->AddObserver(this);
}
SystemInfoCardProvider::~SystemInfoCardProvider() {
@ -71,7 +88,9 @@ void SystemInfoCardProvider::Start(const std::u16string& query) {
std::vector<std::u16string> memory_keywords = {
u"memory", u"memory usage", u"ram", u"ram usage", u"activity monitor"};
for (const std::u16string& keyword : memory_keywords) {
if (CalculateRelevance(query, keyword) > kRelevanceThreshold) {
double relevance = CalculateRelevance(query, keyword);
if (relevance > kRelevanceThreshold) {
relevance_ = relevance;
UpdateMemoryUsage();
break;
}
@ -80,7 +99,9 @@ void SystemInfoCardProvider::Start(const std::u16string& query) {
std::vector<std::u16string> cpu_keywords = {
u"cpu", u"cpu usage", u"device slow", u"why is my device slow"};
for (const std::u16string& keyword : cpu_keywords) {
if (CalculateRelevance(query, keyword) > kRelevanceThreshold) {
double relevance = CalculateRelevance(query, keyword);
if (relevance > kRelevanceThreshold) {
relevance_ = relevance;
UpdateCpuUsage();
break;
}
@ -89,10 +110,9 @@ void SystemInfoCardProvider::Start(const std::u16string& query) {
std::vector<std::u16string> battery_keywords = {u"battery", u"battery life",
u"battery health"};
for (const std::u16string& keyword : battery_keywords) {
if (CalculateRelevance(query, keyword) > kRelevanceThreshold) {
if (!chromeos::PowerManagerClient::Get()->HasObserver(this)) {
chromeos::PowerManagerClient::Get()->AddObserver(this);
}
double relevance = CalculateRelevance(query, keyword);
if (relevance > kRelevanceThreshold) {
relevance_ = relevance;
UpdateBatteryInfo(absl::nullopt);
break;
}
@ -101,7 +121,9 @@ void SystemInfoCardProvider::Start(const std::u16string& query) {
std::vector<std::u16string> version_keywords = {u"version", u"my device",
u"about"};
for (const std::u16string& keyword : version_keywords) {
if (CalculateRelevance(query, keyword) > kRelevanceThreshold) {
double relevance = CalculateRelevance(query, keyword);
if (relevance > kRelevanceThreshold) {
relevance_ = relevance;
UpdateChromeOsVersion();
break;
}
@ -110,9 +132,11 @@ void SystemInfoCardProvider::Start(const std::u16string& query) {
std::vector<std::u16string> storage_keywords = {u"storage", u"storage use",
u"storage management"};
for (const std::u16string& keyword : storage_keywords) {
if (CalculateRelevance(query, keyword) > kRelevanceThreshold) {
double relevance = CalculateRelevance(query, keyword);
if (relevance > kRelevanceThreshold) {
// Do not calculate the storage size again if already calculated recently.
// TODO(b/263994165): Add in a refresh period here.
relevance_ = relevance;
if (!calculation_state_.all()) {
UpdateStorageInfo();
}
@ -221,6 +245,22 @@ void SystemInfoCardProvider::OnCpuUsageUpdated(TelemetryInfoPtr info_ptr) {
previous_cpu_usage_data_ = new_cpu_usage_data;
cpu_usage_ = std::move(new_cpu_usage);
std::u16string title = l10n_util::GetStringFUTF16(
IDS_ASH_CPU_IN_LAUNCHER_TITLE, cpu_usage_->GetPercentUsageTotalString());
std::u16string description = l10n_util::GetStringFUTF16(
IDS_ASH_CPU_IN_LAUNCHER_DESCRIPTION,
base::NumberToString16(cpu_usage_->GetAverageCpuTempCelsius()),
// Provide the frequency in GHz and round the value to 2 decimal places.
base::NumberToString16(
static_cast<double>(
cpu_usage_->GetScalingAverageCurrentFrequencyKhz() / 10000) /
100));
SearchProvider::Results new_results;
new_results.emplace_back(std::make_unique<SystemInfoAnswerResult>(
profile_, last_query_, /*url_path=*/"", GetTestIcon(), relevance_, title,
description, SystemInfoAnswerResult::AnswerCardDisplayType::kTextCard,
SystemInfoAnswerResult::SystemInfoCategory::kDiagnostics));
SwapResults(&new_results);
}
void SystemInfoCardProvider::UpdateCpuUsage() {
@ -281,18 +321,28 @@ void SystemInfoCardProvider::PowerChanged(
}
void SystemInfoCardProvider::UpdateChromeOsVersion() {
std::string version = version_info::GetVersionStringWithModifier("");
std::string official = l10n_util::GetStringUTF8(
std::u16string version =
base::UTF8ToUTF16(version_info::GetVersionStringWithModifier(""));
std::u16string is_official = l10n_util::GetStringUTF16(
version_info::IsOfficialBuild() ? IDS_VERSION_UI_OFFICIAL
: IDS_VERSION_UI_UNOFFICIAL);
std::string processorVariation = l10n_util::GetStringUTF8(
std::u16string processor_variation = l10n_util::GetStringUTF16(
sizeof(void*) == 8 ? IDS_VERSION_UI_64BIT : IDS_VERSION_UI_32BIT);
// TODO(b/263994165): Replace this with the correct translation string.
chromeOS_version_ =
base::StrCat({"Version ", version, " (", official, ") ",
chrome::GetChannelName(chrome::WithExtendedStable(true)),
" ", processorVariation});
std::u16string version_string = l10n_util::GetStringFUTF16(
IDS_ASH_VERSION_IN_LAUNCHER_MESSAGE, version, is_official,
base::UTF8ToUTF16(
chrome::GetChannelName(chrome::WithExtendedStable(true))),
processor_variation);
std::u16string description =
l10n_util::GetStringUTF16(IDS_SETTINGS_ABOUT_PAGE_CHECK_FOR_UPDATES);
SearchProvider::Results new_results;
new_results.emplace_back(std::make_unique<SystemInfoAnswerResult>(
profile_, last_query_, kAboutChromeOsSectionPath, GetTestIcon(),
relevance_, version_string, description,
SystemInfoAnswerResult::AnswerCardDisplayType::kTextCard,
SystemInfoAnswerResult::SystemInfoCategory::kSettings));
SwapResults(&new_results);
}
void SystemInfoCardProvider::UpdateStorageInfo() {

@ -38,11 +38,11 @@ class SystemInfoCardProvider : public SearchProvider,
SystemInfoCardProvider(const SystemInfoCardProvider&) = delete;
SystemInfoCardProvider& operator=(const SystemInfoCardProvider&) = delete;
ash::AppListSearchResultType ResultType() const override;
// SearchProvider:
void Start(const std::u16string& query) override;
void StopQuery() override;
ash::AppListSearchResultType ResultType() const override;
// SizeCalculator::Observer:
void OnSizeCalculated(
@ -102,6 +102,7 @@ class SystemInfoCardProvider : public SearchProvider,
std::u16string last_query_;
Profile* const profile_;
double relevance_;
mojo::Remote<ash::cros_healthd::mojom::CrosHealthdProbeService>
probe_service_;
std::string chromeOS_version_{""};