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 
5 #ifndef COMPONENTS_ARC_ARC_UTIL_H_
6 #define COMPONENTS_ARC_ARC_UTIL_H_
7 
8 // This file contains utility to see ARC functionality status controlled by
9 // outside of ARC, e.g. CommandLine flag, attribute of global data/state,
10 // users' preferences, and FeatureList.
11 
12 #include <stdint.h>
13 #include <string>
14 
15 namespace aura {
16 class Window;
17 }  // namespace aura
18 
19 namespace base {
20 class CommandLine;
21 }  // namespace base
22 
23 namespace user_manager {
24 class User;
25 }  // namespace user_manager
26 
27 namespace arc {
28 
29 // This enum should be synced with CpuRestrictionState in
30 // src/third_party/cros_system_api/dbus/vm_concierge/concierge_service.proto
31 enum class CpuRestrictionState {
32   // The CPU usage is relaxed.
33   CPU_RESTRICTION_FOREGROUND = 0,
34   // The CPU usage is tightly restricted.
35   CPU_RESTRICTION_BACKGROUND = 1,
36 };
37 
38 // Name of the crosvm instance when ARCVM is enabled.
39 constexpr char kArcVmName[] = "arcvm";
40 
41 // Returns true if ARC is installed and the current device is officially
42 // supported to run ARC.
43 // Note that, to run ARC practically, it is necessary to meet more conditions,
44 // e.g., ARC supports only on Primary User Profile. To see if ARC can actually
45 // run for the profile etc., arc::ArcSessionManager::IsAllowedForProfile() is
46 // the function for that purpose. Please see also its comment, too.
47 // Also note that, ARC singleton classes (e.g. ArcSessionManager,
48 // ArcServiceManager, ArcServiceLauncher) are instantiated regardless of this
49 // check, so it is ok to access them directly.
50 bool IsArcAvailable();
51 
52 // Returns true if ARC VM is enabled.
53 bool IsArcVmEnabled();
54 
55 // Returns true if ARC should always start within the primary user session
56 // (opted in user or not), and other supported mode such as guest and Kiosk
57 // mode.
58 bool ShouldArcAlwaysStart();
59 
60 // Returns true if ARC should always start with no Play Store availability
61 // within the primary user session (opted in user or not), and other supported
62 // mode such as guest and Kiosk mode.
63 bool ShouldArcAlwaysStartWithNoPlayStore();
64 
65 // Returns true if ARC OptIn ui needs to be shown for testing.
66 bool ShouldShowOptInForTesting();
67 
68 // Enables to always start ARC without Play Store for testing, by appending the
69 // command line flag.
70 void SetArcAlwaysStartWithoutPlayStoreForTesting();
71 
72 // Returns true if ARC is installed and running ARC kiosk apps on the current
73 // device is officially supported.
74 // It doesn't follow that ARC is available for user sessions and
75 // IsArcAvailable() will return true, although the reverse should be.
76 // This is used to distinguish special cases when ARC kiosk is available on
77 // the device, but is not yet supported for regular user sessions.
78 // In most cases, IsArcAvailable() check should be used instead of this.
79 // Also not that this function may return true when ARC is not running in
80 // Kiosk mode, it checks only ARC Kiosk availability.
81 bool IsArcKioskAvailable();
82 
83 // For testing ARC in browser tests, this function should be called in
84 // SetUpCommandLine(), and its argument should be passed to this function.
85 // Also, in unittests, this can be called in SetUp() with
86 // base::CommandLine::ForCurrentProcess().
87 // |command_line| must not be nullptr.
88 void SetArcAvailableCommandLineForTesting(base::CommandLine* command_line);
89 
90 // Returns true if ARC should run under Kiosk mode for the current profile.
91 // As it can return true only when user is already initialized, it implies
92 // that ARC availability was checked before and IsArcKioskAvailable()
93 // should also return true in that case.
94 bool IsArcKioskMode();
95 
96 // Returns true if current user is a robot account user, or offline demo mode
97 // user.
98 // These are Public Session and ARC Kiosk users. Note that demo mode, including
99 // offline demo mode, is implemented as a Public Session - offline demo mode
100 // is setup offline and it isn't associated with a working robot account.
101 // As it can return true only when user is already initialized, it implies
102 // that ARC availability was checked before.
103 // The check is basically IsArcKioskMode() | IsLoggedInAsPublicSession().
104 bool IsRobotOrOfflineDemoAccountMode();
105 
106 // Returns true if ARC is allowed for the given user. Note this should not be
107 // used as a signal of whether ARC is allowed alone because it only considers
108 // user meta data. e.g. a user could be allowed for ARC but if the user signs in
109 // as a secondary user or signs in to create a supervised user, ARC should be
110 // disabled for such cases.
111 bool IsArcAllowedForUser(const user_manager::User* user);
112 
113 // Checks if opt-in verification was disabled by switch in command line.
114 // In most cases, it is disabled for testing purpose.
115 bool IsArcOptInVerificationDisabled();
116 
117 // Returns true if the |window|'s aura::client::kAppType is ARC_APP. When
118 // |window| is nullptr, returns false.
119 bool IsArcAppWindow(const aura::Window* window);
120 
121 constexpr int kNoTaskId = -1;
122 constexpr int kSystemWindowTaskId = 0;
123 // Returns the task id given by the exo shell's application id, or |kNoTaskId|
124 // if not an ARC window.
125 int GetWindowTaskId(const aura::Window* window);
126 int GetTaskIdFromWindowAppId(const std::string& app_id);
127 
128 // Returns true if ARC app icons are forced to cache.
129 bool IsArcForceCacheAppIcon();
130 
131 // Returns true if data clean up is requested for each ARC start.
132 bool IsArcDataCleanupOnStartRequested();
133 
134 // Returns true in case ARC app sync flow is disabled.
135 bool IsArcAppSyncFlowDisabled();
136 
137 // Returns true in case ARC locale sync is disabled.
138 bool IsArcLocaleSyncDisabled();
139 
140 // Returns true in case ARC Play Auto Install flow is disabled.
141 bool IsArcPlayAutoInstallDisabled();
142 
143 // Adjusts the amount of CPU the ARC instance is allowed to use. When
144 // |cpu_restriction_state| is CPU_RESTRICTION_BACKGROUND, the limit is adjusted
145 // so ARC can only use tightly restricted CPU resources.
146 void SetArcCpuRestriction(CpuRestrictionState cpu_restriction_state);
147 
148 // Returns the Android density that should be used for the given device scale
149 // factor used on chrome.
150 int32_t GetLcdDensityForDeviceScaleFactor(float device_scale_factor);
151 
152 }  // namespace arc
153 
154 #endif  // COMPONENTS_ARC_ARC_UTIL_H_
155