1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/chromeos/crostini/crostini_pref_names.h"
6 
7 #include <memory>
8 #include <utility>
9 
10 #include "base/values.h"
11 #include "chrome/browser/chromeos/crostini/crostini_simple_types.h"
12 #include "chrome/browser/chromeos/crostini/crostini_util.h"
13 #include "components/pref_registry/pref_registry_syncable.h"
14 #include "components/prefs/pref_registry_simple.h"
15 
16 namespace crostini {
17 namespace prefs {
18 
19 // A boolean preference representing whether a user has opted in to use
20 // Crostini (Called "Linux Apps" in UI).
21 const char kCrostiniEnabled[] = "crostini.enabled";
22 const char kCrostiniMimeTypes[] = "crostini.mime_types";
23 // List of USB devices with their system guid, a name/description and their
24 // enabled state for use with Crostini.
25 const char kCrostiniSharedUsbDevices[] = "crostini.shared_usb_devices";
26 const char kCrostiniContainers[] = "crostini.containers";
27 // Dictionary of terminal UI settings such as font style, colors, etc.
28 const char kCrostiniTerminalSettings[] = "crostini.terminal_settings";
29 const char kVmKey[] = "vm_name";
30 const char kContainerKey[] = "container_name";
31 const char kContainerOsVersionKey[] = "container_os_version";
32 
33 // A boolean preference representing a user level enterprise policy to enable
34 // Crostini use.
35 const char kUserCrostiniAllowedByPolicy[] = "crostini.user_allowed_by_policy";
36 // A boolean preference representing a user level enterprise policy to enable
37 // the crostini export / import UI.
38 const char kUserCrostiniExportImportUIAllowedByPolicy[] =
39     "crostini.user_export_import_ui_allowed_by_policy";
40 // A boolean preference representing a user level enterprise policy to enable
41 // VM management CLI.
42 const char kVmManagementCliAllowedByPolicy[] =
43     "crostini.vm_management_cli_allowed_by_policy";
44 // A boolean preference representing a user level enterprise policy to allow
45 // Crostini root access in the default Crostini VM.
46 // TODO(https://crbug.com/983998): The features that have to be implemented.
47 const char kUserCrostiniRootAccessAllowedByPolicy[] =
48     "crostini.user_root_access_allowed_by_policy";
49 // A file path preference representing a user level enterprise policy that
50 // specifies Ansible playbook to be applied to the default Crostini container.
51 // Value is empty when there is no playbook to be applied specified though
52 // policy.
53 const char kCrostiniAnsiblePlaybookFilePath[] =
54     "crostini.ansible_playbook_file_path";
55 // A boolean preference representing whether default Crostini container is
56 // successfully configured by kCrostiniAnsiblePlaybook user policy.
57 const char kCrostiniDefaultContainerConfigured[] =
58     "crostini.default_container_configured";
59 // A boolean preference representing a user level enterprise policy to allow
60 // port forwarding into Crostini.
61 const char kCrostiniPortForwardingAllowedByPolicy[] =
62     "crostini.port_forwarding_allowed_by_policy";
63 
64 // A boolean preference controlling Crostini usage reporting.
65 const char kReportCrostiniUsageEnabled[] = "crostini.usage_reporting_enabled";
66 // Preferences used to store last launch information for reporting:
67 // Last launch Termina component version.
68 const char kCrostiniLastLaunchTerminaComponentVersion[] =
69     "crostini.last_launch.version";
70 // Last launch Termina kernel version.
71 const char kCrostiniLastLaunchTerminaKernelVersion[] =
72     "crostini.last_launch.vm_kernel_version";
73 // The start of a three day window of the last app launch
74 // stored as Java time (ms since epoch).
75 const char kCrostiniLastLaunchTimeWindowStart[] =
76     "crostini.last_launch.time_window_start";
77 // The value of the last sample of the disk space used by Crostini.
78 const char kCrostiniLastDiskSize[] = "crostini.last_disk_size";
79 // A dictionary preference representing a user's settings of forwarded ports
80 // to Crostini.
81 const char kCrostiniPortForwarding[] = "crostini.port_forwarding.ports";
82 
83 // An integer preference indicating the allowance policy for ADB sideloading,
84 // with 0 meaning disallowed and 1 meaning allowed
85 const char kCrostiniArcAdbSideloadingUserPref[] =
86     "crostini.arc_adb_sideloading.user_pref";
87 
RegisterProfilePrefs(PrefRegistrySimple * registry)88 void RegisterProfilePrefs(PrefRegistrySimple* registry) {
89   registry->RegisterBooleanPref(kCrostiniEnabled, false);
90   registry->RegisterDictionaryPref(kCrostiniMimeTypes);
91   registry->RegisterListPref(kCrostiniPortForwarding);
92   registry->RegisterListPref(kCrostiniSharedUsbDevices);
93 
94   // Set a default value for crostini.containers to ensure that we track the
95   // default container even if its creation predates this preference. This
96   // preference should not be accessed unless crostini is installed
97   // (i.e. kCrostiniEnabled is true).
98   base::Value default_container(base::Value::Type::DICTIONARY);
99   default_container.SetKey(kVmKey, base::Value(kCrostiniDefaultVmName));
100   default_container.SetKey(kContainerKey,
101                            base::Value(kCrostiniDefaultContainerName));
102 
103   base::Value::ListStorage default_containers_list;
104   default_containers_list.push_back(std::move(default_container));
105   registry->RegisterListPref(kCrostiniContainers,
106                              base::Value(std::move(default_containers_list)));
107 
108   registry->RegisterBooleanPref(crostini::prefs::kReportCrostiniUsageEnabled,
109                                 false);
110   registry->RegisterStringPref(kCrostiniLastLaunchTerminaComponentVersion,
111                                std::string());
112   registry->RegisterStringPref(kCrostiniLastLaunchTerminaKernelVersion,
113                                std::string());
114   registry->RegisterInt64Pref(kCrostiniLastLaunchTimeWindowStart, 0u);
115   registry->RegisterInt64Pref(kCrostiniLastDiskSize, 0u);
116   registry->RegisterBooleanPref(kUserCrostiniAllowedByPolicy, true);
117   registry->RegisterBooleanPref(kUserCrostiniExportImportUIAllowedByPolicy,
118                                 true);
119   registry->RegisterBooleanPref(kVmManagementCliAllowedByPolicy, true);
120   registry->RegisterBooleanPref(kUserCrostiniRootAccessAllowedByPolicy, true);
121   registry->RegisterBooleanPref(kCrostiniPortForwardingAllowedByPolicy, true);
122   registry->RegisterFilePathPref(kCrostiniAnsiblePlaybookFilePath,
123                                  base::FilePath());
124   registry->RegisterBooleanPref(kCrostiniDefaultContainerConfigured, false);
125   registry->RegisterDictionaryPref(
126       kCrostiniTerminalSettings, base::DictionaryValue(),
127       user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
128 
129   registry->RegisterIntegerPref(
130       kCrostiniArcAdbSideloadingUserPref,
131       static_cast<int>(CrostiniArcAdbSideloadingUserAllowanceMode::kDisallow));
132 }
133 
134 }  // namespace prefs
135 }  // namespace crostini
136