Commit c02f2451 authored by khmel@chromium.org's avatar khmel@chromium.org Committed by Commit Bot

arc: Add concept of system default apps.

These apps exist on system image and available for all users. This also
moves custom Play Store case handled separately before to system app.

TEST=unit test
BUG=1013730

Change-Id: Iaf63d52c38c376b6b07930bc8ec88e5b9de4bb58
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1865472Reviewed-by: default avatarJosh Horwich <jhorwich@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Yury Khmel <khmel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706920}
parent 12f38923
......@@ -733,6 +733,7 @@ class ArcDefaultAppForManagedUserTest : public ArcPlayStoreAppTest {
bool IsEnabledByPolicy() const {
switch (GetParam()) {
case ArcState::ARC_PLAY_STORE_MANAGED_AND_ENABLED:
return true;
case ArcState::ARC_PLAY_STORE_MANAGED_AND_DISABLED:
case ArcState::ARC_WITHOUT_PLAY_STORE:
return false;
......@@ -2833,8 +2834,20 @@ TEST_P(ArcDefaultAppForManagedUserTest, DefaultAppsForManagedUser) {
// There is no default app for managed users except Play Store
for (const auto& app : fake_default_apps()) {
const std::string app_id = ArcAppTest::GetAppId(app);
EXPECT_FALSE(prefs->IsRegistered(app_id));
EXPECT_FALSE(prefs->GetApp(app_id));
if (IsEnabledByPolicy()) {
// Only system apps are allowed. App from package test.app2 is declared as
// a system app.
auto app = prefs->GetApp(app_id);
if (app) {
EXPECT_EQ("test.app2", app->package_name);
EXPECT_TRUE(prefs->IsRegistered(app_id));
} else {
EXPECT_FALSE(prefs->IsRegistered(app_id));
}
} else {
EXPECT_FALSE(prefs->IsRegistered(app_id));
EXPECT_FALSE(prefs->GetApp(app_id));
}
}
// PlayStor exists for managed and enabled state.
......
......@@ -28,6 +28,7 @@ constexpr char kAppPath[] = "app_path";
constexpr char kName[] = "name";
constexpr char kOem[] = "oem";
constexpr char kPackageName[] = "package_name";
constexpr char kSystem[] = "system";
constexpr char kDefaultApps[] = "arc.apps.default";
constexpr char kHidden[] = "hidden";
......@@ -86,12 +87,14 @@ std::unique_ptr<ArcDefaultAppList::AppInfoMap> ReadAppsFromFileThread(
std::string activity;
std::string app_path;
bool oem = false;
bool system = false;
app_info_dictionary->GetString(kName, &name);
app_info_dictionary->GetString(kPackageName, &package_name);
app_info_dictionary->GetString(kActivity, &activity);
app_info_dictionary->GetString(kAppPath, &app_path);
app_info_dictionary->GetBoolean(kOem, &oem);
app_info_dictionary->GetBoolean(kSystem, &system);
if (name.empty() || package_name.empty() || activity.empty() ||
app_path.empty()) {
......@@ -103,8 +106,9 @@ std::unique_ptr<ArcDefaultAppList::AppInfoMap> ReadAppsFromFileThread(
const std::string app_id =
ArcAppListPrefs::GetAppId(package_name, activity);
std::unique_ptr<ArcDefaultAppList::AppInfo> app =
std::make_unique<ArcDefaultAppList::AppInfo>(
name, package_name, activity, oem, root_dir.Append(app_path));
std::make_unique<ArcDefaultAppList::AppInfo>(name, package_name,
activity, oem, system,
root_dir.Append(app_path));
apps.get()->insert(
std::pair<std::string, std::unique_ptr<ArcDefaultAppList::AppInfo>>(
app_id, std::move(app)));
......@@ -206,11 +210,10 @@ void ArcDefaultAppList::OnAppsReady() {
registry->GetInstalledExtension(arc::kPlayStoreAppId);
if (arc_host && arc::IsPlayStoreAvailable()) {
std::unique_ptr<ArcDefaultAppList::AppInfo> play_store_app =
std::make_unique<ArcDefaultAppList::AppInfo>(arc_host->name(),
arc::kPlayStorePackage,
arc::kPlayStoreActivity,
false /* oem */,
base::FilePath() /* app_path */);
std::make_unique<ArcDefaultAppList::AppInfo>(
arc_host->name(), arc::kPlayStorePackage, arc::kPlayStoreActivity,
false /* oem */, true /* system */,
base::FilePath() /* app_path */);
AppInfoMap& app_map =
IsAppHidden(prefs, arc::kPlayStoreAppId) ? hidden_apps_ : visible_apps_;
app_map.insert(
......@@ -223,14 +226,16 @@ void ArcDefaultAppList::OnAppsReady() {
const ArcDefaultAppList::AppInfo* ArcDefaultAppList::GetApp(
const std::string& app_id) const {
if ((filter_level_ == FilterLevel::ALL) ||
(filter_level_ == FilterLevel::OPTIONAL_APPS &&
app_id != arc::kPlayStoreAppId)) {
if (filter_level_ == FilterLevel::ALL)
return nullptr;
}
const auto it = visible_apps_.find(app_id);
if (it == visible_apps_.end())
return nullptr;
if (filter_level_ == FilterLevel::OPTIONAL_APPS && !it->second->system)
return nullptr;
return it->second.get();
}
......@@ -294,11 +299,13 @@ ArcDefaultAppList::AppInfo::AppInfo(const std::string& name,
const std::string& package_name,
const std::string& activity,
bool oem,
bool system,
const base::FilePath app_path)
: name(name),
package_name(package_name),
activity(activity),
oem(oem),
system(system),
app_path(app_path) {}
ArcDefaultAppList::AppInfo::~AppInfo() {}
......@@ -29,24 +29,26 @@ class ArcDefaultAppList {
public:
struct AppInfo {
AppInfo(const std::string& name,
const std::string& package_name,
const std::string& activity,
bool oem,
const base::FilePath app_path);
const std::string& package_name,
const std::string& activity,
bool oem,
bool system,
const base::FilePath app_path);
~AppInfo();
std::string name;
std::string package_name;
std::string activity;
bool oem;
bool system;
base::FilePath app_path; // App folder that contains pre-installed icons.
};
enum class FilterLevel {
// Filter nothing.
NOTHING,
// Filter out only optional apps, excluding Play Store for example. Used in
// case when Play Store is managed and enabled.
// Filter out only optional apps, leaving system apps available, Play Store
// is also system app.
OPTIONAL_APPS,
// Filter out everything. Used in case when Play Store is managed and
// disabled.
......
{
"name": "TestApp2",
"package_name": "test.app2",
"activity": "test.app2.activity",
"system": true,
"app_path": "test_app2"
}
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