1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ash/policy/status_collector/status_collector.h"
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/logging.h"
#include "base/time/clock.h"
#include "base/time/time.h"
#include "chrome/browser/ash/app_mode/isolated_web_app/kiosk_iwa_manager.h"
#include "chrome/browser/ash/app_mode/kiosk_chrome_app_manager.h"
#include "chrome/browser/ash/app_mode/web_app/kiosk_web_app_manager.h"
#include "chrome/browser/ash/policy/core/device_local_account.h"
#include "chrome/browser/ash/policy/core/user_cloud_policy_manager_ash.h"
#include "chrome/browser/ash/policy/status_collector/app_info_generator.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "chromeos/ash/components/system/statistics_provider.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h"
#include "device_management_backend.pb.h"
namespace policy {
namespace {
namespace ent_mgmt = ::enterprise_management;
// Returns the DeviceLocalAccount associated with the current kiosk session.
// Returns nullptr if there is no active kiosk session, or if that kiosk
// session has been removed from policy since the session started, in which
// case we won't report its status).
std::unique_ptr<DeviceLocalAccount> GetCurrentKioskDeviceLocalAccount(
ash::CrosSettings* settings) {
if (!user_manager::UserManager::Get()->IsLoggedInAsAnyKioskApp()) {
return nullptr;
}
const user_manager::User* const user =
user_manager::UserManager::Get()->GetActiveUser();
const std::vector<DeviceLocalAccount> accounts =
GetDeviceLocalAccounts(settings);
for (const auto& device_local_account : accounts) {
if (AccountId::FromUserEmail(device_local_account.user_id) ==
user->GetAccountId()) {
return std::make_unique<DeviceLocalAccount>(device_local_account);
}
}
LOG(WARNING) << "Kiosk app not found in list of device-local accounts";
return nullptr;
}
} // namespace
// -----------------------------------------------------------------------------
// StatusCollectorParams.
// -----------------------------------------------------------------------------
StatusCollectorParams::StatusCollectorParams() {
device_status = std::make_unique<ent_mgmt::DeviceStatusReportRequest>();
session_status = std::make_unique<ent_mgmt::SessionStatusReportRequest>();
child_status = std::make_unique<ent_mgmt::ChildStatusReportRequest>();
}
StatusCollectorParams::~StatusCollectorParams() = default;
// Move only.
StatusCollectorParams::StatusCollectorParams(StatusCollectorParams&&) = default;
StatusCollectorParams& StatusCollectorParams::operator=(
StatusCollectorParams&&) = default;
// -----------------------------------------------------------------------------
// StatusCollector.
// -----------------------------------------------------------------------------
// static
void StatusCollector::RegisterProfilePrefs(PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(prefs::kReportArcStatusEnabled, false);
// TODO(crbug.com/40569404): move to ChildStatusCollector after migration.
registry->RegisterDictionaryPref(prefs::kUserActivityTimes);
registry->RegisterTimePref(prefs::kLastChildScreenTimeReset, base::Time());
registry->RegisterTimePref(prefs::kLastChildScreenTimeSaved, base::Time());
registry->RegisterIntegerPref(prefs::kChildScreenTimeMilliseconds, 0);
AppInfoGenerator::RegisterProfilePrefs(registry);
}
// static
std::optional<std::string> StatusCollector::GetBootMode(
ash::system::StatisticsProvider* statistics_provider) {
const std::optional<std::string_view> dev_switch_mode =
statistics_provider->GetMachineStatistic(ash::system::kDevSwitchBootKey);
if (!dev_switch_mode) {
return std::nullopt;
}
if (dev_switch_mode == ash::system::kDevSwitchBootValueDev) {
return std::string("Dev");
}
if (dev_switch_mode == ash::system::kDevSwitchBootValueVerified) {
return std::string("Verified");
}
return std::nullopt;
}
StatusCollector::StatusCollector(ash::system::StatisticsProvider* provider,
ash::CrosSettings* cros_settings,
base::Clock* clock)
: statistics_provider_(provider),
cros_settings_(cros_settings),
clock_(clock) {}
StatusCollector::~StatusCollector() = default;
std::unique_ptr<DeviceLocalAccount>
StatusCollector::GetAutoLaunchedKioskSessionInfo() {
std::unique_ptr<DeviceLocalAccount> account =
GetCurrentKioskDeviceLocalAccount(ash::CrosSettings::Get());
if (!account) {
// No auto-launched kiosk session active.
return nullptr;
}
auto app = ash::KioskChromeAppManager::Get()->GetApp(account->kiosk_app_id);
const bool chrome_app_auto_launched_with_zero_delay =
app.has_value() && app->was_auto_launched_with_zero_delay;
const bool web_app_auto_launched_with_zero_delay =
ash::KioskWebAppManager::Get()
->current_app_was_auto_launched_with_zero_delay();
const bool iwa_auto_launched_with_zero_delay =
ash::KioskIwaManager::Get()
->current_app_was_auto_launched_with_zero_delay();
const bool kiosk_auto_launched_with_zero_delay =
chrome_app_auto_launched_with_zero_delay ||
web_app_auto_launched_with_zero_delay ||
iwa_auto_launched_with_zero_delay;
return kiosk_auto_launched_with_zero_delay ? std::move(account) : nullptr;
}
std::string StatusCollector::GetDMTokenForProfile(Profile* profile) const {
CloudPolicyManager* user_cloud_policy_manager =
profile->GetUserCloudPolicyManagerAsh();
DCHECK(user_cloud_policy_manager != nullptr);
return user_cloud_policy_manager->core()->client()->dm_token();
}
} // namespace policy
|