Commit 23998bf2 authored by yilkal's avatar yilkal Committed by Commit Bot

Sends hidden ARC++ applications in ChildStatusReport.

Send ARC++ applications that should be hidden from
the family link app through ChildStatusReport.
Example of these apps are the new ARC++ TWAs
installed through playstore. The user is not able
to launch these applications from the launcher and
hence they shouldn't be added to AppActivityRegistry.

Bug: 1093072
Change-Id: I0b6bd2016cf5c00bf5096d90d88c0ebbf500cecb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2252919Reviewed-by: default avatarJeevan Shikaram <jshikaram@chromium.org>
Reviewed-by: default avatarAga Wronska <agawronska@chromium.org>
Reviewed-by: default avatarSergey Poromov <poromov@chromium.org>
Commit-Queue: Yilkal Abe <yilkal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#782025}
parent ea45d4f3
...@@ -96,6 +96,7 @@ app_time::AppActivityReportInterface::ReportParams ...@@ -96,6 +96,7 @@ app_time::AppActivityReportInterface::ReportParams
ChildUserService::GenerateAppActivityReport( ChildUserService::GenerateAppActivityReport(
enterprise_management::ChildStatusReportRequest* report) { enterprise_management::ChildStatusReportRequest* report) {
DCHECK(app_time_controller_); DCHECK(app_time_controller_);
app_time_controller_->app_registry()->GenerateHiddenApps(report);
return app_time_controller_->app_registry()->GenerateAppActivityReport( return app_time_controller_->app_registry()->GenerateAppActivityReport(
report); report);
} }
......
...@@ -34,26 +34,6 @@ constexpr base::TimeDelta kFiveMinutes = base::TimeDelta::FromMinutes(5); ...@@ -34,26 +34,6 @@ constexpr base::TimeDelta kFiveMinutes = base::TimeDelta::FromMinutes(5);
constexpr base::TimeDelta kOneMinute = base::TimeDelta::FromMinutes(1); constexpr base::TimeDelta kOneMinute = base::TimeDelta::FromMinutes(1);
constexpr base::TimeDelta kZeroMinutes = base::TimeDelta::FromMinutes(0); constexpr base::TimeDelta kZeroMinutes = base::TimeDelta::FromMinutes(0);
enterprise_management::App::AppType AppTypeForReporting(
apps::mojom::AppType type) {
switch (type) {
case apps::mojom::AppType::kArc:
return enterprise_management::App::ARC;
case apps::mojom::AppType::kBuiltIn:
return enterprise_management::App::BUILT_IN;
case apps::mojom::AppType::kCrostini:
return enterprise_management::App::CROSTINI;
case apps::mojom::AppType::kExtension:
return enterprise_management::App::EXTENSION;
case apps::mojom::AppType::kPluginVm:
return enterprise_management::App::PLUGIN_VM;
case apps::mojom::AppType::kWeb:
return enterprise_management::App::WEB;
default:
return enterprise_management::App::UNKNOWN;
}
}
enterprise_management::AppActivity::AppState AppStateForReporting( enterprise_management::AppActivity::AppState AppStateForReporting(
AppState state) { AppState state) {
switch (state) { switch (state) {
...@@ -395,6 +375,21 @@ void AppActivityRegistry::SetReportingEnabled(base::Optional<bool> value) { ...@@ -395,6 +375,21 @@ void AppActivityRegistry::SetReportingEnabled(base::Optional<bool> value) {
activity_reporting_enabled_ = value.value(); activity_reporting_enabled_ = value.value();
} }
void AppActivityRegistry::GenerateHiddenApps(
enterprise_management::ChildStatusReportRequest* report) {
const std::vector<AppId> hidden_arc_apps =
app_service_wrapper_->GetHiddenArcApps();
for (const auto& app_id : hidden_arc_apps) {
enterprise_management::App* app_info = report->add_hidden_app();
app_info->set_app_id(app_id.app_id());
app_info->set_app_type(AppTypeForReporting(app_id.app_type()));
if (app_id.app_type() == apps::mojom::AppType::kArc) {
app_info->add_additional_app_id(
app_service_wrapper_->GetAppServiceId(app_id));
}
}
}
AppActivityReportInterface::ReportParams AppActivityReportInterface::ReportParams
AppActivityRegistry::GenerateAppActivityReport( AppActivityRegistry::GenerateAppActivityReport(
enterprise_management::ChildStatusReportRequest* report) { enterprise_management::ChildStatusReportRequest* report) {
......
...@@ -134,6 +134,9 @@ class AppActivityRegistry : public AppServiceWrapper::EventListener { ...@@ -134,6 +134,9 @@ class AppActivityRegistry : public AppServiceWrapper::EventListener {
// Reporting enablement is set if |enabled| has value. // Reporting enablement is set if |enabled| has value.
void SetReportingEnabled(base::Optional<bool> enabled); void SetReportingEnabled(base::Optional<bool> enabled);
void GenerateHiddenApps(
enterprise_management::ChildStatusReportRequest* report);
// Populates |report| with collected app activity. Returns whether any data // Populates |report| with collected app activity. Returns whether any data
// were reported. // were reported.
AppActivityReportInterface::ReportParams GenerateAppActivityReport( AppActivityReportInterface::ReportParams GenerateAppActivityReport(
......
...@@ -30,28 +30,6 @@ namespace app_time { ...@@ -30,28 +30,6 @@ namespace app_time {
namespace { namespace {
// Return whether app with |app_id| should be included for per-app time
// limits.
bool ShouldIncludeApp(const AppId& app_id, Profile* profile) {
if (app_id.app_type() == apps::mojom::AppType::kExtension) {
const extensions::Extension* extension =
extensions::ExtensionRegistry::Get(profile)->GetExtensionById(
app_id.app_id(),
extensions::ExtensionRegistry::IncludeFlag::EVERYTHING);
// If we are not able to find the extension, return false.
if (!extension)
return false;
// Some preinstalled apps that open in browser window are legacy packaged
// apps. Example Google Slides app.
return extension->is_hosted_app() || extension->is_legacy_packaged_app();
}
return app_id.app_type() == apps::mojom::AppType::kArc ||
app_id.app_type() == apps::mojom::AppType::kWeb;
}
// Gets AppId from |update|. // Gets AppId from |update|.
AppId AppIdFromAppUpdate(const apps::AppUpdate& update) { AppId AppIdFromAppUpdate(const apps::AppUpdate& update) {
bool is_arc = update.AppType() == apps::mojom::AppType::kArc; bool is_arc = update.AppType() == apps::mojom::AppType::kArc;
...@@ -123,14 +101,13 @@ void AppServiceWrapper::LaunchApp(const std::string& app_service_id) { ...@@ -123,14 +101,13 @@ void AppServiceWrapper::LaunchApp(const std::string& app_service_id) {
std::vector<AppId> AppServiceWrapper::GetInstalledApps() const { std::vector<AppId> AppServiceWrapper::GetInstalledApps() const {
std::vector<AppId> installed_apps; std::vector<AppId> installed_apps;
Profile* profile = profile_;
GetAppCache().ForEachApp( GetAppCache().ForEachApp(
[&installed_apps, &profile](const apps::AppUpdate& update) { [&installed_apps, this](const apps::AppUpdate& update) {
if (update.Readiness() == apps::mojom::Readiness::kUninstalledByUser) if (update.Readiness() == apps::mojom::Readiness::kUninstalledByUser)
return; return;
const AppId app_id = AppIdFromAppUpdate(update); const AppId app_id = AppIdFromAppUpdate(update);
if (!ShouldIncludeApp(app_id, profile)) if (!ShouldIncludeApp(app_id))
return; return;
installed_apps.push_back(app_id); installed_apps.push_back(app_id);
...@@ -138,6 +115,40 @@ std::vector<AppId> AppServiceWrapper::GetInstalledApps() const { ...@@ -138,6 +115,40 @@ std::vector<AppId> AppServiceWrapper::GetInstalledApps() const {
return installed_apps; return installed_apps;
} }
bool AppServiceWrapper::IsHiddenArcApp(const AppId& app_id) const {
if (app_id.app_type() != apps::mojom::AppType::kArc)
return false;
bool is_hidden = false;
const std::string app_service_id = AppServiceIdFromAppId(app_id, profile_);
GetAppCache().ForEachApp([&is_hidden](const apps::AppUpdate& update) {
if (update.Readiness() == apps::mojom::Readiness::kUninstalledByUser)
return;
is_hidden = update.ShowInLauncher() == apps::mojom::OptionalBool::kFalse;
});
return is_hidden;
}
std::vector<AppId> AppServiceWrapper::GetHiddenArcApps() const {
std::vector<AppId> hidden_arc_apps;
GetAppCache().ForEachApp([&hidden_arc_apps](const apps::AppUpdate& update) {
if (update.Readiness() == apps::mojom::Readiness::kUninstalledByUser)
return;
const AppId app_id = AppIdFromAppUpdate(update);
if (app_id.app_type() != apps::mojom::AppType::kArc ||
update.ShowInLauncher() != apps::mojom::OptionalBool::kFalse) {
return;
}
hidden_arc_apps.push_back(app_id);
});
return hidden_arc_apps;
}
std::string AppServiceWrapper::GetAppName(const AppId& app_id) const { std::string AppServiceWrapper::GetAppName(const AppId& app_id) const {
const std::string app_service_id = AppServiceIdFromAppId(app_id, profile_); const std::string app_service_id = AppServiceIdFromAppId(app_id, profile_);
DCHECK(!app_service_id.empty()); DCHECK(!app_service_id.empty());
...@@ -213,7 +224,7 @@ void AppServiceWrapper::OnAppUpdate(const apps::AppUpdate& update) { ...@@ -213,7 +224,7 @@ void AppServiceWrapper::OnAppUpdate(const apps::AppUpdate& update) {
return; return;
const AppId app_id = AppIdFromAppUpdate(update); const AppId app_id = AppIdFromAppUpdate(update);
if (!ShouldIncludeApp(app_id, profile_)) if (!ShouldIncludeApp(app_id))
return; return;
switch (update.Readiness()) { switch (update.Readiness()) {
...@@ -253,7 +264,7 @@ void AppServiceWrapper::OnInstanceUpdate(const apps::InstanceUpdate& update) { ...@@ -253,7 +264,7 @@ void AppServiceWrapper::OnInstanceUpdate(const apps::InstanceUpdate& update) {
return; return;
const AppId app_id = AppIdFromInstanceUpdate(update, &GetAppCache()); const AppId app_id = AppIdFromInstanceUpdate(update, &GetAppCache());
if (!ShouldIncludeApp(app_id, profile_)) if (!ShouldIncludeApp(app_id))
return; return;
bool is_active = update.State() & apps::InstanceState::kActive; bool is_active = update.State() & apps::InstanceState::kActive;
...@@ -298,5 +309,28 @@ apps::InstanceRegistry& AppServiceWrapper::GetInstanceRegistry() const { ...@@ -298,5 +309,28 @@ apps::InstanceRegistry& AppServiceWrapper::GetInstanceRegistry() const {
return proxy->InstanceRegistry(); return proxy->InstanceRegistry();
} }
bool AppServiceWrapper::ShouldIncludeApp(const AppId& app_id) const {
if (IsHiddenArcApp(app_id))
return false;
if (app_id.app_type() == apps::mojom::AppType::kExtension) {
const extensions::Extension* extension =
extensions::ExtensionRegistry::Get(profile_)->GetExtensionById(
app_id.app_id(),
extensions::ExtensionRegistry::IncludeFlag::EVERYTHING);
// If we are not able to find the extension, return false.
if (!extension)
return false;
// Some preinstalled apps that open in browser window are legacy packaged
// apps. Example Google Slides app.
return extension->is_hosted_app() || extension->is_legacy_packaged_app();
}
return app_id.app_type() == apps::mojom::AppType::kArc ||
app_id.app_type() == apps::mojom::AppType::kWeb;
}
} // namespace app_time } // namespace app_time
} // namespace chromeos } // namespace chromeos
...@@ -114,6 +114,12 @@ class AppServiceWrapper : public apps::AppRegistryCache::Observer, ...@@ -114,6 +114,12 @@ class AppServiceWrapper : public apps::AppRegistryCache::Observer,
// Installed apps of unsupported types will not be included. // Installed apps of unsupported types will not be included.
std::vector<AppId> GetInstalledApps() const; std::vector<AppId> GetInstalledApps() const;
// Returns true if the application is a hidden arc++ app.
bool IsHiddenArcApp(const AppId& app_id) const;
// Returns the list of arc++ apps hidden from user.
std::vector<AppId> GetHiddenArcApps() const;
// Returns short name of the app identified by |app_id|. // Returns short name of the app identified by |app_id|.
// Might return empty string. // Might return empty string.
std::string GetAppName(const AppId& app_id) const; std::string GetAppName(const AppId& app_id) const;
...@@ -155,6 +161,10 @@ class AppServiceWrapper : public apps::AppRegistryCache::Observer, ...@@ -155,6 +161,10 @@ class AppServiceWrapper : public apps::AppRegistryCache::Observer,
apps::AppRegistryCache& GetAppCache() const; apps::AppRegistryCache& GetAppCache() const;
apps::InstanceRegistry& GetInstanceRegistry() const; apps::InstanceRegistry& GetInstanceRegistry() const;
// Return whether app with |app_id| should be included for per-app time
// limits.
bool ShouldIncludeApp(const AppId& app_id) const;
base::ObserverList<EventListener> listeners_; base::ObserverList<EventListener> listeners_;
Profile* const profile_; Profile* const profile_;
......
...@@ -12,6 +12,26 @@ ...@@ -12,6 +12,26 @@
namespace chromeos { namespace chromeos {
namespace app_time { namespace app_time {
enterprise_management::App::AppType AppTypeForReporting(
apps::mojom::AppType type) {
switch (type) {
case apps::mojom::AppType::kArc:
return enterprise_management::App::ARC;
case apps::mojom::AppType::kBuiltIn:
return enterprise_management::App::BUILT_IN;
case apps::mojom::AppType::kCrostini:
return enterprise_management::App::CROSTINI;
case apps::mojom::AppType::kExtension:
return enterprise_management::App::EXTENSION;
case apps::mojom::AppType::kPluginVm:
return enterprise_management::App::PLUGIN_VM;
case apps::mojom::AppType::kWeb:
return enterprise_management::App::WEB;
default:
return enterprise_management::App::UNKNOWN;
}
}
AppId GetChromeAppId() { AppId GetChromeAppId() {
return AppId(apps::mojom::AppType::kExtension, extension_misc::kChromeAppId); return AppId(apps::mojom::AppType::kExtension, extension_misc::kChromeAppId);
} }
......
...@@ -5,12 +5,23 @@ ...@@ -5,12 +5,23 @@
#ifndef CHROME_BROWSER_CHROMEOS_CHILD_ACCOUNTS_TIME_LIMITS_APP_TIME_LIMIT_UTILS_H_ #ifndef CHROME_BROWSER_CHROMEOS_CHILD_ACCOUNTS_TIME_LIMITS_APP_TIME_LIMIT_UTILS_H_
#define CHROME_BROWSER_CHROMEOS_CHILD_ACCOUNTS_TIME_LIMITS_APP_TIME_LIMIT_UTILS_H_ #define CHROME_BROWSER_CHROMEOS_CHILD_ACCOUNTS_TIME_LIMITS_APP_TIME_LIMIT_UTILS_H_
#include "components/policy/proto/device_management_backend.pb.h"
namespace apps {
namespace mojom {
enum class AppType;
}
} // namespace apps
namespace chromeos { namespace chromeos {
namespace app_time { namespace app_time {
class AppId; class AppId;
enum class AppState; enum class AppState;
enterprise_management::App::AppType AppTypeForReporting(
apps::mojom::AppType type);
AppId GetChromeAppId(); AppId GetChromeAppId();
bool IsWebAppOrExtension(const AppId& app_id); bool IsWebAppOrExtension(const AppId& app_id);
......
...@@ -3007,7 +3007,10 @@ message ChildStatusReportRequest { ...@@ -3007,7 +3007,10 @@ message ChildStatusReportRequest {
// It might not be sent in every report. // It might not be sent in every report.
repeated AppActivity app_activity = 8; repeated AppActivity app_activity = 8;
// Next id: 9. // A list of applications which are hidden from the user.
repeated App hidden_app = 9;
// Next id: 10.
} }
// Response from DMServer to update user devices' status. // Response from DMServer to update user devices' status.
......
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