Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/arc/arc_util.h" | 5 #include "chrome/browser/chromeos/arc/arc_util.h" |
| 6 | 6 |
| 7 #include <linux/magic.h> | 7 #include <linux/magic.h> |
| 8 #include <sys/statfs.h> | 8 #include <sys/statfs.h> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/command_line.h" | |
| 11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/sys_info.h" | 14 #include "base/sys_info.h" |
| 14 #include "base/task_scheduler/post_task.h" | 15 #include "base/task_scheduler/post_task.h" |
| 15 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
| 17 #include "chrome/browser/browser_process.h" | |
| 16 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | 18 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
| 17 #include "chrome/browser/chromeos/login/user_flow.h" | 19 #include "chrome/browser/chromeos/login/user_flow.h" |
| 18 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" | 20 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
| 21 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | |
| 22 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | |
| 19 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 23 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 26 #include "chromeos/chromeos_switches.h" | |
| 22 #include "components/arc/arc_util.h" | 27 #include "components/arc/arc_util.h" |
| 23 #include "components/prefs/pref_service.h" | 28 #include "components/prefs/pref_service.h" |
| 24 #include "components/user_manager/known_user.h" | 29 #include "components/user_manager/known_user.h" |
| 25 #include "components/user_manager/user.h" | 30 #include "components/user_manager/user.h" |
| 26 #include "components/user_manager/user_manager.h" | 31 #include "components/user_manager/user_manager.h" |
| 27 | 32 |
| 28 namespace arc { | 33 namespace arc { |
| 29 | 34 |
| 30 namespace { | 35 namespace { |
| 31 | 36 |
| 32 constexpr char kLsbReleaseArcVersionKey[] = "CHROMEOS_ARC_ANDROID_SDK_VERSION"; | 37 constexpr char kLsbReleaseArcVersionKey[] = "CHROMEOS_ARC_ANDROID_SDK_VERSION"; |
| 33 constexpr char kAndroidMSdkVersion[] = "23"; | 38 constexpr char kAndroidMSdkVersion[] = "23"; |
| 34 | 39 |
| 35 // Let IsAllowedForProfile() return "false" for any profile. | 40 // Let IsAllowedForProfile() return "false" for any profile. |
| 36 bool g_disallow_for_testing = false; | 41 bool g_disallow_for_testing = false; |
| 37 | 42 |
| 38 // Let IsArcBlockedDueToIncompatibleFileSystem() return the specified value | 43 // Let IsArcBlockedDueToIncompatibleFileSystem() return the specified value |
| 39 // during test runs. | 44 // during test runs. |
| 40 bool g_arc_blocked_due_to_incomaptible_filesystem_for_testing = false; | 45 bool g_arc_blocked_due_to_incomaptible_filesystem_for_testing = false; |
| 41 | 46 |
| 47 // This flag is set only in case the command line flag is set to mark the device | |
| 48 // as requiring the migration. The value is set the first time the policy fetch | |
| 49 // is done, and remains unchanged after that. | |
| 50 // TODO(igorcov): Remove this after migration. crbug.com/725493 | |
| 51 ArcAvailabilityPolicyStatus g_arc_availability_policy_status = | |
| 52 ArcAvailabilityPolicyStatus::UNKNOWN; | |
| 53 | |
| 42 // Returns whether ARC can run on the filesystem mounted at |path|. | 54 // Returns whether ARC can run on the filesystem mounted at |path|. |
| 43 // This function should run only on threads where IO operations are allowed. | 55 // This function should run only on threads where IO operations are allowed. |
| 44 bool IsArcCompatibleFilesystem(const base::FilePath& path) { | 56 bool IsArcCompatibleFilesystem(const base::FilePath& path) { |
| 45 base::ThreadRestrictions::AssertIOAllowed(); | 57 base::ThreadRestrictions::AssertIOAllowed(); |
| 46 | 58 |
| 47 // If it can be verified it is not on ecryptfs, then it is ok. | 59 // If it can be verified it is not on ecryptfs, then it is ok. |
| 48 struct statfs statfs_buf; | 60 struct statfs statfs_buf; |
| 49 if (statfs(path.value().c_str(), &statfs_buf) < 0) | 61 if (statfs(path.value().c_str(), &statfs_buf) < 0) |
| 50 return false; | 62 return false; |
| 51 return statfs_buf.f_type != ECRYPTFS_SUPER_MAGIC; | 63 return statfs_buf.f_type != ECRYPTFS_SUPER_MAGIC; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 65 } | 77 } |
| 66 | 78 |
| 67 FileSystemCompatibilityState GetFileSystemCompatibilityPref( | 79 FileSystemCompatibilityState GetFileSystemCompatibilityPref( |
| 68 const AccountId& account_id) { | 80 const AccountId& account_id) { |
| 69 int pref_value = kFileSystemIncompatible; | 81 int pref_value = kFileSystemIncompatible; |
| 70 user_manager::known_user::GetIntegerPref( | 82 user_manager::known_user::GetIntegerPref( |
| 71 account_id, prefs::kArcCompatibleFilesystemChosen, &pref_value); | 83 account_id, prefs::kArcCompatibleFilesystemChosen, &pref_value); |
| 72 return static_cast<FileSystemCompatibilityState>(pref_value); | 84 return static_cast<FileSystemCompatibilityState>(pref_value); |
| 73 } | 85 } |
| 74 | 86 |
| 87 // Returns if the migration from ecryptfs to ext4 is allowed. It is true if it | |
| 88 // is known that the device is consumer owned, or if the device policy is | |
| 89 // present and has the value |kAllowMigration|. The response is cached the first | |
| 90 // time the function is used, and the policy update won't change the return | |
| 91 // value after that. | |
| 92 bool IsMigrationAllowed() { | |
| 93 if (g_arc_availability_policy_status == | |
|
hidehiko
2017/06/07 12:22:20
nit/optional: How about using base::Optional<bool>
igorcov
2017/06/08 10:42:25
Done.
| |
| 94 ArcAvailabilityPolicyStatus::UNKNOWN) { | |
| 95 // If the device is not managed, then the migration allowed. | |
| 96 if (!g_browser_process->platform_part() | |
| 97 ->browser_policy_connector_chromeos() | |
| 98 ->IsEnterpriseManaged()) { | |
| 99 g_arc_availability_policy_status = ArcAvailabilityPolicyStatus::AVAILABLE; | |
| 100 return true; | |
| 101 } | |
| 102 | |
| 103 const PrefService* pref_service = | |
| 104 user_manager::UserManager::Get()->GetLocalState(); | |
| 105 const PrefService::Preference* pref = | |
| 106 pref_service->FindPreference(prefs::kDeviceEcryptfsMigrationStrategy); | |
| 107 | |
| 108 if (pref && pref->GetValue() && | |
| 109 pref->GetValue()->GetInt() == | |
| 110 enterprise_management::DeviceEcryptfsMigrationStrategyProto:: | |
| 111 ALLOW_MIGRATION) | |
| 112 g_arc_availability_policy_status = ArcAvailabilityPolicyStatus::AVAILABLE; | |
| 113 else | |
| 114 g_arc_availability_policy_status = ArcAvailabilityPolicyStatus::DISABLED; | |
| 115 } | |
| 116 | |
| 117 return g_arc_availability_policy_status == | |
| 118 ArcAvailabilityPolicyStatus::AVAILABLE; | |
| 119 } | |
| 120 | |
| 75 } // namespace | 121 } // namespace |
| 76 | 122 |
| 77 bool IsArcAllowedForProfile(const Profile* profile) { | 123 bool IsArcAllowedForProfile(const Profile* profile) { |
| 78 if (g_disallow_for_testing) { | 124 if (g_disallow_for_testing) { |
| 79 VLOG(1) << "ARC is disallowed for testing."; | 125 VLOG(1) << "ARC is disallowed for testing."; |
| 80 return false; | 126 return false; |
| 81 } | 127 } |
| 82 | 128 |
| 83 // ARC Kiosk can be enabled even if ARC is not yet supported on the device. | 129 // ARC Kiosk can be enabled even if ARC is not yet supported on the device. |
| 84 // In that case IsArcKioskMode() should return true as profile is already | 130 // In that case IsArcKioskMode() should return true as profile is already |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 114 // users do this through GAIA, but Kiosk and Active Directory users use | 160 // users do this through GAIA, but Kiosk and Active Directory users use |
| 115 // different application install mechanism. ARC is not allowed otherwise | 161 // different application install mechanism. ARC is not allowed otherwise |
| 116 // (e.g. in public sessions). cf) crbug.com/605545 | 162 // (e.g. in public sessions). cf) crbug.com/605545 |
| 117 const user_manager::User* user = | 163 const user_manager::User* user = |
| 118 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); | 164 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); |
| 119 if (!IsArcAllowedForUser(user)) { | 165 if (!IsArcAllowedForUser(user)) { |
| 120 VLOG(1) << "ARC is not allowed for the user."; | 166 VLOG(1) << "ARC is not allowed for the user."; |
| 121 return false; | 167 return false; |
| 122 } | 168 } |
| 123 | 169 |
| 170 const auto* command_line = base::CommandLine::ForCurrentProcess(); | |
| 171 // In the case the initial encryption was ecryptfs, the user data require | |
| 172 // migration to ext4 in order to have ARC available. The migration is | |
| 173 // forbidden if the device is managed and the policy is set to disable | |
| 174 // migration. This makes the ARC unavailable too. | |
| 175 // TODO(igorcov): Remove this after migration. crbug.com/725493 | |
| 176 if (command_line->HasSwitch(chromeos::switches::kInitialEncryptionEcryptfs) && | |
|
hidehiko
2017/06/07 12:22:20
IIUC, This won't work as expected if;
- FS is curr
igorcov
2017/06/07 13:45:18
Do you mean the case when user had ARC M, had ecry
| |
| 177 !IsMigrationAllowed()) { | |
| 178 VLOG(1) << "ARC requires migration, but is not allowed by the policy."; | |
| 179 return false; | |
| 180 } | |
| 181 | |
| 124 // Do not run ARC instance when supervised user is being created. | 182 // Do not run ARC instance when supervised user is being created. |
| 125 // Otherwise noisy notification may be displayed. | 183 // Otherwise noisy notification may be displayed. |
| 126 chromeos::UserFlow* user_flow = | 184 chromeos::UserFlow* user_flow = |
| 127 chromeos::ChromeUserManager::Get()->GetUserFlow(user->GetAccountId()); | 185 chromeos::ChromeUserManager::Get()->GetUserFlow(user->GetAccountId()); |
| 128 if (!user_flow || !user_flow->CanStartArc()) { | 186 if (!user_flow || !user_flow->CanStartArc()) { |
| 129 VLOG(1) << "ARC is not allowed in the current user flow."; | 187 VLOG(1) << "ARC is not allowed in the current user flow."; |
| 130 return false; | 188 return false; |
| 131 } | 189 } |
| 132 | 190 |
| 133 return true; | 191 return true; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 | 312 |
| 255 // Otherwise, check the underlying filesystem. | 313 // Otherwise, check the underlying filesystem. |
| 256 base::PostTaskWithTraitsAndReplyWithResult( | 314 base::PostTaskWithTraitsAndReplyWithResult( |
| 257 FROM_HERE, | 315 FROM_HERE, |
| 258 {base::MayBlock(), base::TaskPriority::USER_BLOCKING, | 316 {base::MayBlock(), base::TaskPriority::USER_BLOCKING, |
| 259 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}, | 317 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}, |
| 260 base::Bind(&IsArcCompatibleFilesystem, profile_path), | 318 base::Bind(&IsArcCompatibleFilesystem, profile_path), |
| 261 base::Bind(&StoreCompatibilityCheckResult, account_id, callback)); | 319 base::Bind(&StoreCompatibilityCheckResult, account_id, callback)); |
| 262 } | 320 } |
| 263 | 321 |
| 322 ArcAvailabilityPolicyStatus GetArcAvailabilityPolicyStatus() { | |
| 323 return g_arc_availability_policy_status; | |
| 324 } | |
| 325 | |
| 326 void ResetGlobalDataForTesting() { | |
| 327 g_arc_availability_policy_status = ArcAvailabilityPolicyStatus::UNKNOWN; | |
| 328 } | |
| 329 | |
| 264 } // namespace arc | 330 } // namespace arc |
| OLD | NEW |