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 the first time the check if migration to ext4 is allowed, | |
| 48 // and remains unchanged after that. | |
| 49 // TODO(igorcov): Remove this after migration. crbug.com/725493 | |
| 50 base::Optional<bool> g_is_arc_migration_allowed; | |
|
bartfab (slow)
2017/06/12 12:49:03
Nit: #include "base/optional.h"
igorcov
2017/06/12 16:50:09
Done.
| |
| 51 | |
| 42 // Returns whether ARC can run on the filesystem mounted at |path|. | 52 // Returns whether ARC can run on the filesystem mounted at |path|. |
| 43 // This function should run only on threads where IO operations are allowed. | 53 // This function should run only on threads where IO operations are allowed. |
| 44 bool IsArcCompatibleFilesystem(const base::FilePath& path) { | 54 bool IsArcCompatibleFilesystem(const base::FilePath& path) { |
| 45 base::ThreadRestrictions::AssertIOAllowed(); | 55 base::ThreadRestrictions::AssertIOAllowed(); |
| 46 | 56 |
| 47 // If it can be verified it is not on ecryptfs, then it is ok. | 57 // If it can be verified it is not on ecryptfs, then it is ok. |
| 48 struct statfs statfs_buf; | 58 struct statfs statfs_buf; |
| 49 if (statfs(path.value().c_str(), &statfs_buf) < 0) | 59 if (statfs(path.value().c_str(), &statfs_buf) < 0) |
| 50 return false; | 60 return false; |
| 51 return statfs_buf.f_type != ECRYPTFS_SUPER_MAGIC; | 61 return statfs_buf.f_type != ECRYPTFS_SUPER_MAGIC; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 65 } | 75 } |
| 66 | 76 |
| 67 FileSystemCompatibilityState GetFileSystemCompatibilityPref( | 77 FileSystemCompatibilityState GetFileSystemCompatibilityPref( |
| 68 const AccountId& account_id) { | 78 const AccountId& account_id) { |
| 69 int pref_value = kFileSystemIncompatible; | 79 int pref_value = kFileSystemIncompatible; |
| 70 user_manager::known_user::GetIntegerPref( | 80 user_manager::known_user::GetIntegerPref( |
| 71 account_id, prefs::kArcCompatibleFilesystemChosen, &pref_value); | 81 account_id, prefs::kArcCompatibleFilesystemChosen, &pref_value); |
| 72 return static_cast<FileSystemCompatibilityState>(pref_value); | 82 return static_cast<FileSystemCompatibilityState>(pref_value); |
| 73 } | 83 } |
| 74 | 84 |
| 85 bool IsArcMigrationAllowedInternal() { | |
| 86 // If the device is not managed, then the migration allowed. | |
| 87 if (!g_browser_process->platform_part() | |
|
bartfab (slow)
2017/06/12 12:49:03
Nit: #include "chrome/browser/browser_process_plat
igorcov
2017/06/12 16:50:09
Done.
| |
| 88 ->browser_policy_connector_chromeos() | |
| 89 ->IsEnterpriseManaged()) { | |
| 90 return true; | |
| 91 } | |
| 92 | |
| 93 const auto* command_line = base::CommandLine::ForCurrentProcess(); | |
|
bartfab (slow)
2017/06/12 12:49:04
Nit: const pointer to const
igorcov
2017/06/12 16:50:09
Done.
| |
| 94 // If the command line flag is missing, the migration for this type of | |
| 95 // device is allowed regardless of the policy data. | |
| 96 if (!command_line->HasSwitch( | |
| 97 chromeos::switches::kNeedArcMigrationPolicyCheck)) { | |
| 98 return true; | |
| 99 } | |
| 100 | |
| 101 const PrefService* pref_service = | |
|
bartfab (slow)
2017/06/12 12:49:03
Nit: const pointer to const
igorcov
2017/06/12 16:50:09
Done.
| |
| 102 user_manager::UserManager::Get()->GetLocalState(); | |
| 103 const PrefService::Preference* pref = | |
|
bartfab (slow)
2017/06/12 12:49:04
Nit: const pointer to const
igorcov
2017/06/12 16:50:09
Done.
| |
| 104 pref_service->FindPreference(prefs::kDeviceEcryptfsMigrationStrategy); | |
| 105 | |
| 106 return pref && pref->GetValue() && | |
| 107 pref->GetValue()->GetInt() == | |
|
bartfab (slow)
2017/06/12 12:49:03
Nit: #include "base/values.h"
igorcov
2017/06/12 16:50:09
Done.
| |
| 108 enterprise_management::DeviceEcryptfsMigrationStrategyProto:: | |
| 109 ALLOW_MIGRATION; | |
| 110 } | |
| 111 | |
| 75 } // namespace | 112 } // namespace |
| 76 | 113 |
| 77 bool IsArcAllowedForProfile(const Profile* profile) { | 114 bool IsArcAllowedForProfile(const Profile* profile) { |
|
kinaba
2017/06/12 00:22:07
Returning false from this utility method does not
igorcov
2017/06/12 16:50:09
Added additional checks for migration UI. Thank yo
| |
| 78 if (g_disallow_for_testing) { | 115 if (g_disallow_for_testing) { |
| 79 VLOG(1) << "ARC is disallowed for testing."; | 116 VLOG(1) << "ARC is disallowed for testing."; |
| 80 return false; | 117 return false; |
| 81 } | 118 } |
| 82 | 119 |
| 83 // ARC Kiosk can be enabled even if ARC is not yet supported on the device. | 120 // 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 | 121 // In that case IsArcKioskMode() should return true as profile is already |
| 85 // created. | 122 // created. |
| 86 if (!IsArcAvailable() && !(IsArcKioskMode() && IsArcKioskAvailable())) { | 123 if (!IsArcAvailable() && !(IsArcKioskMode() && IsArcKioskAvailable())) { |
| 87 VLOG(1) << "ARC is not available."; | 124 VLOG(1) << "ARC is not available."; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 114 // users do this through GAIA, but Kiosk and Active Directory users use | 151 // users do this through GAIA, but Kiosk and Active Directory users use |
| 115 // different application install mechanism. ARC is not allowed otherwise | 152 // different application install mechanism. ARC is not allowed otherwise |
| 116 // (e.g. in public sessions). cf) crbug.com/605545 | 153 // (e.g. in public sessions). cf) crbug.com/605545 |
| 117 const user_manager::User* user = | 154 const user_manager::User* user = |
| 118 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); | 155 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); |
| 119 if (!IsArcAllowedForUser(user)) { | 156 if (!IsArcAllowedForUser(user)) { |
| 120 VLOG(1) << "ARC is not allowed for the user."; | 157 VLOG(1) << "ARC is not allowed for the user."; |
| 121 return false; | 158 return false; |
| 122 } | 159 } |
| 123 | 160 |
| 161 // If migration policy check is needed (specified by commandline flag), check | |
| 162 // the policy, which should be already available here. If policy says | |
| 163 // migration is not allowed, do not run ARC, regardless whether file system | |
| 164 // migration is actually needed. For example, even if file system is still | |
| 165 // ecryptfs and ARC version is M, or file system is already migrated into ext4 | |
| 166 // crypt and ARC version is N or later, if policy says migration is not | |
| 167 // allowed, ARC will never run. Practically, in the former example case, | |
| 168 // --need-arc-migration-policy-check is not set, so this check passes and user | |
| 169 // can use ARC. In latter case, policy should say migration is allowed, so | |
| 170 // also user can use ARC then. | |
| 171 // TODO(igorcov): Remove this after migration. crbug.com/725493 | |
| 172 if (!IsArcMigrationAllowed()) { | |
| 173 VLOG(1) << "ARC requires migration, but is not allowed by the policy."; | |
|
bartfab (slow)
2017/06/12 12:49:04
Nit: The log statement contradicts the comment abo
igorcov
2017/06/12 16:50:09
Fixed the log statement.
| |
| 174 return false; | |
| 175 } | |
| 176 | |
| 124 // Do not run ARC instance when supervised user is being created. | 177 // Do not run ARC instance when supervised user is being created. |
| 125 // Otherwise noisy notification may be displayed. | 178 // Otherwise noisy notification may be displayed. |
| 126 chromeos::UserFlow* user_flow = | 179 chromeos::UserFlow* user_flow = |
| 127 chromeos::ChromeUserManager::Get()->GetUserFlow(user->GetAccountId()); | 180 chromeos::ChromeUserManager::Get()->GetUserFlow(user->GetAccountId()); |
| 128 if (!user_flow || !user_flow->CanStartArc()) { | 181 if (!user_flow || !user_flow->CanStartArc()) { |
| 129 VLOG(1) << "ARC is not allowed in the current user flow."; | 182 VLOG(1) << "ARC is not allowed in the current user flow."; |
| 130 return false; | 183 return false; |
| 131 } | 184 } |
| 132 | 185 |
| 133 return true; | 186 return true; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 | 307 |
| 255 // Otherwise, check the underlying filesystem. | 308 // Otherwise, check the underlying filesystem. |
| 256 base::PostTaskWithTraitsAndReplyWithResult( | 309 base::PostTaskWithTraitsAndReplyWithResult( |
| 257 FROM_HERE, | 310 FROM_HERE, |
| 258 {base::MayBlock(), base::TaskPriority::USER_BLOCKING, | 311 {base::MayBlock(), base::TaskPriority::USER_BLOCKING, |
| 259 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}, | 312 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}, |
| 260 base::Bind(&IsArcCompatibleFilesystem, profile_path), | 313 base::Bind(&IsArcCompatibleFilesystem, profile_path), |
| 261 base::Bind(&StoreCompatibilityCheckResult, account_id, callback)); | 314 base::Bind(&StoreCompatibilityCheckResult, account_id, callback)); |
| 262 } | 315 } |
| 263 | 316 |
| 317 bool IsArcMigrationAllowed() { | |
| 318 if (!g_is_arc_migration_allowed.has_value()) | |
| 319 g_is_arc_migration_allowed = IsArcMigrationAllowedInternal(); | |
| 320 return g_is_arc_migration_allowed.value(); | |
| 321 } | |
| 322 | |
| 323 void ResetArcMigrationAllowedForTesting() { | |
| 324 g_is_arc_migration_allowed.reset(); | |
| 325 } | |
| 326 | |
| 264 } // namespace arc | 327 } // namespace arc |
| OLD | NEW |