Skip to content

Commit

Permalink
human_presence_internals: Display firmware manifest
Browse files Browse the repository at this point in the history
Add a dialog for displaying the firmware manifest data, i.e., which
model revisions are used by the device. This lets us verify we are
testing the correct firmware image.

(cherry picked from commit 659ee25)

Bug: b:231393337
Change-Id: Ic44f7ff47b6b7a9c1fb10237f6ae41fdea589236
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3641198
Reviewed-by: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: Guoxing Zhao <charleszhao@chromium.org>
Auto-Submit: Sami Kyöstilä <skyostil@chromium.org>
Commit-Queue: Sami Kyöstilä <skyostil@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1004001}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3659826
Cr-Commit-Position: refs/branch-heads/5060@{#259}
Cr-Branched-From: b83393d-refs/heads/main@{#1002911}
  • Loading branch information
skyostil authored and Chromium LUCI CQ committed May 26, 2022
1 parent 0e6e05e commit b042f8f
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 2 deletions.
34 changes: 34 additions & 0 deletions chrome/browser/ui/webui/chromeos/human_presence_internals_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/files/file_util.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observation.h"
#include "base/task/thread_pool.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/url_constants.h"
Expand Down Expand Up @@ -62,6 +64,8 @@ class HumanPresenceInternalsUIMessageHandler
void OnConnected(bool connected);
void OnLockOnLeaveResult(absl::optional<hps::HpsResultProto>);
void OnSnoopingProtectionResult(absl::optional<hps::HpsResultProto>);
static absl::optional<std::string> ReadManifest();
void UpdateManifest(absl::optional<std::string> manifest);

base::ScopedObservation<chromeos::HumanPresenceDBusClient,
chromeos::HumanPresenceDBusClient::Observer>
Expand Down Expand Up @@ -139,6 +143,36 @@ void HumanPresenceInternalsUIMessageHandler::OnConnected(bool connected) {
base::DictionaryValue value;
value.SetBoolean("connected", connected);
FireWebUIListener(hps::kHumanPresenceInternalsConnectedEvent, value);

if (connected) {
base::ThreadPool::PostTaskAndReplyWithResult(
FROM_HERE, {base::MayBlock()},
base::BindOnce(&HumanPresenceInternalsUIMessageHandler::ReadManifest),
base::BindOnce(&HumanPresenceInternalsUIMessageHandler::UpdateManifest,
weak_ptr_factory_.GetWeakPtr()));
}
}

// static
absl::optional<std::string>
HumanPresenceInternalsUIMessageHandler::ReadManifest() {
std::string manifest;
static const base::FilePath::CharType kManifestPath[] =
FILE_PATH_LITERAL("/usr/lib/firmware/hps/manifest.txt");
if (!base::ReadFileToString(base::FilePath(kManifestPath), &manifest))
return absl::nullopt;
return manifest;
}

void HumanPresenceInternalsUIMessageHandler::UpdateManifest(
absl::optional<std::string> manifest) {
if (!manifest.has_value()) {
FireWebUIListener(hps::kHumanPresenceInternalsManifestEvent,
base::Value("(Failed to read manifest)"));
return;
}
FireWebUIListener(hps::kHumanPresenceInternalsManifestEvent,
base::Value(*manifest));
}

void HumanPresenceInternalsUIMessageHandler::EnableLockOnLeave(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ const char kHumanPresenceInternalsLockOnLeaveChangedEvent[] = "sense_changed";
const char kHumanPresenceInternalsSnoopingProtectionChangedEvent[] =
"notify_changed";
const char kHumanPresenceInternalsEnableErrorEvent[] = "enable_error";
const char kHumanPresenceInternalsManifestEvent[] = "manifest";

} // namespace hps
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extern const char kHumanPresenceInternalsConnectedEvent[];
extern const char kHumanPresenceInternalsLockOnLeaveChangedEvent[];
extern const char kHumanPresenceInternalsSnoopingProtectionChangedEvent[];
extern const char kHumanPresenceInternalsEnableErrorEvent[];
extern const char kHumanPresenceInternalsManifestEvent[];

} // namespace hps

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,27 @@ h2 {
margin-top: 0;
}

a, button {
cursor: pointer;
}

dialog {
filter: drop-shadow(0px 16px 16px rgba(0, 0, 0, 0.2));
border-color: var(--cros-color-prominent-inverted);
border-radius: 8px;
}

.flexbar {
display: flex;
flex-direction: row;
align-items: flex-start;
margin: 5px 0px;
}

.flexbar-wrap {
flex-wrap: wrap;
}

.flexbar button {
padding: 0px 4px;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</head>

<body id="root">
<h1>HPS Internals</h1>
<h1>HPS Internals <a id="show-info"></a></h1>

<div id="connection-error" style="display: none">
Unable to connect to HPS. Are the screen privacy settings enabled?
Expand All @@ -24,7 +24,15 @@ <h1>HPS Internals</h1>
Failed to enable feature.
</div>

<div class="flexbar">
<dialog id="info-dialog">
<label for="manifest">Firmware manifest</label>
<pre id="manifest"></pre>
<form method="dialog">
<button>Close</button>
</form>
</dialog>

<div class="flexbar flexbar-wrap">
<div class="feature-panel">
<h2>👤 Sense feature</h2>
<div class="flexbar">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ function onEnableError() {
$('enable-error').style.display = 'block';
}

function onManifest(manifest: string) {
$('manifest').textContent = manifest;
}

function onSenseChanged(value: IncomingHpsResult) {
if (value.disabled) {
enableButton('enable-sense', true);
Expand Down Expand Up @@ -124,10 +128,12 @@ function initialize() {
addWebUIListener('sense_changed', onSenseChanged);
addWebUIListener('notify_changed', onNotifyChanged);
addWebUIListener('enable_error', onEnableError);
addWebUIListener('manifest', onManifest);
$('enable-sense').onclick = enableSense;
$('disable-sense').onclick = disableSense;
$('enable-notify').onclick = enableNotify;
$('disable-notify').onclick = disableNotify;
$('show-info').onclick = showInfo;
onConnected({connected: false});
chrome.send('connect');
}
Expand Down Expand Up @@ -158,6 +164,10 @@ function disableNotify() {
chrome.send('query_notify');
}

function showInfo() {
($('info-dialog') as any).showModal();
}

function updatePolling() {
const shouldPoll =
g_notifyState.result !== HpsResult.DISABLED ||
Expand Down

0 comments on commit b042f8f

Please sign in to comment.