arc_util.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. // Copyright 2017 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. #ifndef ASH_COMPONENTS_ARC_ARC_UTIL_H_
  5. #define ASH_COMPONENTS_ARC_ARC_UTIL_H_
  6. // This file contains utility to see ARC functionality status controlled by
  7. // outside of ARC, e.g. CommandLine flag, attribute of global data/state,
  8. // users' preferences, and FeatureList.
  9. #include <stdint.h>
  10. #include <deque>
  11. #include <string>
  12. #include <vector>
  13. #include "chromeos/dbus/common/dbus_method_call_status.h"
  14. namespace aura {
  15. class Window;
  16. } // namespace aura
  17. namespace base {
  18. struct SystemMemoryInfoKB;
  19. } // namespace base
  20. namespace user_manager {
  21. class User;
  22. } // namespace user_manager
  23. namespace arc {
  24. // This enum should be synced with CpuRestrictionState in
  25. // src/third_party/cros_system_api/dbus/vm_concierge/concierge_service.proto
  26. enum class CpuRestrictionState {
  27. // The CPU usage is relaxed.
  28. CPU_RESTRICTION_FOREGROUND = 0,
  29. // The CPU usage is tightly restricted.
  30. CPU_RESTRICTION_BACKGROUND = 1,
  31. };
  32. enum class UpstartOperation {
  33. JOB_START = 0,
  34. JOB_STOP,
  35. // This sends STOP D-Bus message, then sends START. Unlike 'initctl restart',
  36. // this starts the job even when the job hasn't been started yet (and
  37. // therefore the stop operation fails.)
  38. JOB_STOP_AND_START,
  39. };
  40. // Enum for configuring ureadahead mode of operation during ARCVM boot process.
  41. enum class ArcVmUreadaheadMode {
  42. // ARCVM ureadahead is in readahead mode for normal user boot flow.
  43. READAHEAD = 0,
  44. // ARCVM ureadahead is turned on for generate mode in data collector flow.
  45. GENERATE,
  46. // ARCVM ureadahead is turned off for disabled mode.
  47. DISABLED,
  48. };
  49. using SystemMemoryInfoCallback =
  50. base::RepeatingCallback<bool(base::SystemMemoryInfoKB*)>;
  51. // Upstart Job Description
  52. struct JobDesc {
  53. // Explicit ctor/dtor declaration is necessary for complex struct. See
  54. // https://cs.chromium.org/chromium/src/tools/clang/plugins/FindBadConstructsConsumer.cpp
  55. JobDesc(const std::string& job_name,
  56. UpstartOperation operation,
  57. const std::vector<std::string>& environment);
  58. ~JobDesc();
  59. JobDesc(const JobDesc& other);
  60. std::string job_name;
  61. UpstartOperation operation;
  62. std::vector<std::string> environment;
  63. };
  64. // Name of the crosvm instance when ARCVM is enabled.
  65. constexpr char kArcVmName[] = "arcvm";
  66. // Returns true if ARC is installed and the current device is officially
  67. // supported to run ARC.
  68. // Note that, to run ARC practically, it is necessary to meet more conditions,
  69. // e.g., ARC supports only on Primary User Profile. To see if ARC can actually
  70. // run for the profile etc., arc::ArcSessionManager::IsAllowedForProfile() is
  71. // the function for that purpose. Please see also its comment, too.
  72. // Also note that, ARC singleton classes (e.g. ArcSessionManager,
  73. // ArcServiceManager, ArcServiceLauncher) are instantiated regardless of this
  74. // check, so it is ok to access them directly.
  75. bool IsArcAvailable();
  76. // Returns true if ARC VM is enabled.
  77. bool IsArcVmEnabled();
  78. // Returns true if ARC VM realtime VCPU is enabled.
  79. // |cpus| is the number of logical cores that are currently online on the
  80. // device.
  81. bool IsArcVmRtVcpuEnabled(uint32_t cpus);
  82. // Returns true if ARC VM advised to use Huge Pages for guest memory.
  83. bool IsArcVmUseHugePages();
  84. // Returns true if all development configuration directives in the
  85. // vm_tools/init/arcvm_dev.conf file are ignored during ARCVM start.
  86. bool IsArcVmDevConfIgnored();
  87. // Returns true if ureadahead is disabled completely, including host and guest
  88. // parts. See also |GetArcVmUreadaheadMode|.
  89. bool IsUreadaheadDisabled();
  90. // Returns mode of operation for ureadahead during the ARCVM boot flow.
  91. // Valid modes are readahead, generate, or disabled.
  92. ArcVmUreadaheadMode GetArcVmUreadaheadMode(SystemMemoryInfoCallback callback);
  93. // Returns true if ARC should always start within the primary user session
  94. // (opted in user or not), and other supported mode such as guest and Kiosk
  95. // mode.
  96. bool ShouldArcAlwaysStart();
  97. // Returns true if ARC should always start with no Play Store availability
  98. // within the primary user session (opted in user or not), and other supported
  99. // mode such as guest and Kiosk mode.
  100. bool ShouldArcAlwaysStartWithNoPlayStore();
  101. // Returns true if ARC should ignore Play Store preference and be started
  102. // manually in tests using autotest API |startArc|.
  103. bool ShouldArcStartManually();
  104. // Returns true if ARC OptIn ui needs to be shown for testing.
  105. bool ShouldShowOptInForTesting();
  106. // Returns true if ARC is installed and running ARC kiosk apps on the current
  107. // device is officially supported.
  108. // It doesn't follow that ARC is available for user sessions and
  109. // IsArcAvailable() will return true, although the reverse should be.
  110. // This is used to distinguish special cases when ARC kiosk is available on
  111. // the device, but is not yet supported for regular user sessions.
  112. // In most cases, IsArcAvailable() check should be used instead of this.
  113. // Also not that this function may return true when ARC is not running in
  114. // Kiosk mode, it checks only ARC Kiosk availability.
  115. bool IsArcKioskAvailable();
  116. // Returns true if ARC should run under Kiosk mode for the current profile.
  117. // As it can return true only when user is already initialized, it implies
  118. // that ARC availability was checked before and IsArcKioskAvailable()
  119. // should also return true in that case.
  120. bool IsArcKioskMode();
  121. // Returns true if current user is a robot account user, or offline demo mode
  122. // user.
  123. // These are Public Session and ARC Kiosk users. Note that demo mode, including
  124. // offline demo mode, is implemented as a Public Session - offline demo mode
  125. // is setup offline and it isn't associated with a working robot account.
  126. // As it can return true only when user is already initialized, it implies
  127. // that ARC availability was checked before.
  128. // The check is basically IsArcKioskMode() | IsLoggedInAsPublicSession().
  129. bool IsRobotOrOfflineDemoAccountMode();
  130. // Returns true if ARC is allowed for the given user. Note this should not be
  131. // used as a signal of whether ARC is allowed alone because it only considers
  132. // user meta data. e.g. a user could be allowed for ARC but if the user signs in
  133. // as a secondary user or signs in to create a supervised user, ARC should be
  134. // disabled for such cases.
  135. bool IsArcAllowedForUser(const user_manager::User* user);
  136. // Checks if opt-in verification was disabled by switch in command line.
  137. // In most cases, it is disabled for testing purpose.
  138. bool IsArcOptInVerificationDisabled();
  139. constexpr int kNoTaskId = -1;
  140. constexpr int kSystemWindowTaskId = 0;
  141. // Returns the task id given by the exo shell's application id, or
  142. // absl::nullopt if not an ARC window.
  143. absl::optional<int> GetWindowTaskId(const aura::Window* window);
  144. absl::optional<int> GetTaskIdFromWindowAppId(const std::string& window_app_id);
  145. absl::optional<int> GetWindowSessionId(const aura::Window* window);
  146. absl::optional<int> GetSessionIdFromWindowAppId(
  147. const std::string& window_app_id);
  148. absl::optional<int> GetWindowTaskOrSessionId(const aura::Window* window);
  149. // Returns true if ARC app icons are forced to cache.
  150. bool IsArcForceCacheAppIcon();
  151. // Returns true if data clean up is requested for each ARC start.
  152. bool IsArcDataCleanupOnStartRequested();
  153. // Returns true in case ARC app sync flow is disabled.
  154. bool IsArcAppSyncFlowDisabled();
  155. // Returns true in case ARC locale sync is disabled.
  156. bool IsArcLocaleSyncDisabled();
  157. // Returns true in case ARC Play Auto Install flow is disabled.
  158. bool IsArcPlayAutoInstallDisabled();
  159. // Returns the Android density that should be used for the given device scale
  160. // factor used on chrome.
  161. int32_t GetLcdDensityForDeviceScaleFactor(float device_scale_factor);
  162. // Gets a system property managed by crossystem. This function can be called
  163. // only with base::MayBlock().
  164. int GetSystemPropertyInt(const std::string& property);
  165. // Starts or stops a job in |jobs| one by one. If starting a job fails, the
  166. // whole operation is aborted and the |callback| is immediately called with
  167. // false. Errors on stopping a job is just ignored with some logs. Once all jobs
  168. // are successfully processed, |callback| is called with true.
  169. void ConfigureUpstartJobs(std::deque<JobDesc> jobs,
  170. chromeos::VoidDBusMethodCallback callback);
  171. } // namespace arc
  172. #endif // ASH_COMPONENTS_ARC_ARC_UTIL_H_