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> |
| 8 #include <sys/statfs.h> |
| 9 |
| 10 #include "base/files/file_path.h" |
7 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/sys_info.h" |
| 13 #include "base/threading/thread_restrictions.h" |
8 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | 14 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
9 #include "chrome/browser/chromeos/login/user_flow.h" | 15 #include "chrome/browser/chromeos/login/user_flow.h" |
10 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" | 16 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
11 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 17 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
12 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
14 #include "components/arc/arc_util.h" | 20 #include "components/arc/arc_util.h" |
15 #include "components/prefs/pref_service.h" | 21 #include "components/prefs/pref_service.h" |
16 #include "components/user_manager/user.h" | 22 #include "components/user_manager/user.h" |
17 #include "components/user_manager/user_manager.h" | 23 #include "components/user_manager/user_manager.h" |
18 | 24 |
19 namespace arc { | 25 namespace arc { |
20 | 26 |
21 namespace { | 27 namespace { |
22 | 28 |
| 29 constexpr char kLsbReleaseArcVersionKey[] = "CHROMEOS_ARC_ANDROID_SDK_VERSION"; |
| 30 constexpr char kAndroidMSdkVersion[] = "23"; |
| 31 |
23 // Let IsAllowedForProfile() return "false" for any profile. | 32 // Let IsAllowedForProfile() return "false" for any profile. |
24 bool g_disallow_for_testing = false; | 33 bool g_disallow_for_testing = false; |
25 | 34 |
26 } // namespace | 35 } // namespace |
27 | 36 |
28 bool IsArcAllowedForProfile(const Profile* profile) { | 37 bool IsArcAllowedForProfile(const Profile* profile) { |
29 if (g_disallow_for_testing) { | 38 if (g_disallow_for_testing) { |
30 VLOG(1) << "ARC is disallowed for testing."; | 39 VLOG(1) << "ARC is disallowed for testing."; |
31 return false; | 40 return false; |
32 } | 41 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 return false; | 94 return false; |
86 } | 95 } |
87 | 96 |
88 // Do not allow for Ephemeral data user. cf) b/26402681 | 97 // Do not allow for Ephemeral data user. cf) b/26402681 |
89 if (user_manager::UserManager::Get() | 98 if (user_manager::UserManager::Get() |
90 ->IsCurrentUserCryptohomeDataEphemeral()) { | 99 ->IsCurrentUserCryptohomeDataEphemeral()) { |
91 VLOG(1) << "Users with ephemeral data are not supported in ARC."; | 100 VLOG(1) << "Users with ephemeral data are not supported in ARC."; |
92 return false; | 101 return false; |
93 } | 102 } |
94 | 103 |
| 104 // Do not allow newer version of ARC on old filesystem. |
| 105 // Check this condition only on real Chrome OS devices. Test runs on Linux |
| 106 // workstation does not have expected /etc/lsb-release field nor profile |
| 107 // creation step. |
| 108 if (base::SysInfo::IsRunningOnChromeOS()) { |
| 109 // chromeos::UserSessionManager::PrepareProfile does the actual file system |
| 110 // check and stores the result to prefs, so that it survives crash-restart. |
| 111 const bool is_filesystem_compatible = |
| 112 profile->GetPrefs()->GetBoolean(prefs::kArcCompatibleFilesystemChosen); |
| 113 std::string arc_sdk_version; |
| 114 const bool is_M = base::SysInfo::GetLsbReleaseValue( |
| 115 kLsbReleaseArcVersionKey, &arc_sdk_version) && |
| 116 arc_sdk_version == kAndroidMSdkVersion; |
| 117 // To run ARC we want to make sure either |
| 118 // - Underlying file system is compatible with ARC, or |
| 119 // - SDK version is M. |
| 120 if (!is_filesystem_compatible && !is_M) { |
| 121 VLOG(1) |
| 122 << "Users with SDK version (" << arc_sdk_version |
| 123 << ") are not supported when they postponed to migrate to dircrypto."; |
| 124 return false; |
| 125 } |
| 126 } |
| 127 |
95 return true; | 128 return true; |
96 } | 129 } |
97 | 130 |
98 void DisallowArcForTesting() { | 131 void DisallowArcForTesting() { |
99 g_disallow_for_testing = true; | 132 g_disallow_for_testing = true; |
100 } | 133 } |
101 | 134 |
102 bool IsArcPlayStoreEnabledForProfile(const Profile* profile) { | 135 bool IsArcPlayStoreEnabledForProfile(const Profile* profile) { |
103 return IsArcAllowedForProfile(profile) && | 136 return IsArcAllowedForProfile(profile) && |
104 profile->GetPrefs()->GetBoolean(prefs::kArcEnabled); | 137 profile->GetPrefs()->GetBoolean(prefs::kArcEnabled); |
(...skipping 29 matching lines...) Expand all Loading... |
134 profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, enabled); | 167 profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, enabled); |
135 } | 168 } |
136 | 169 |
137 bool AreArcAllOptInPreferencesManagedForProfile(const Profile* profile) { | 170 bool AreArcAllOptInPreferencesManagedForProfile(const Profile* profile) { |
138 return profile->GetPrefs()->IsManagedPreference( | 171 return profile->GetPrefs()->IsManagedPreference( |
139 prefs::kArcBackupRestoreEnabled) && | 172 prefs::kArcBackupRestoreEnabled) && |
140 profile->GetPrefs()->IsManagedPreference( | 173 profile->GetPrefs()->IsManagedPreference( |
141 prefs::kArcLocationServiceEnabled); | 174 prefs::kArcLocationServiceEnabled); |
142 } | 175 } |
143 | 176 |
| 177 bool IsArcCompatibleFilesystem(const base::FilePath& path) { |
| 178 base::ThreadRestrictions::AssertIOAllowed(); |
| 179 |
| 180 // If it can be verified it is not on ecryptfs, then it is ok. |
| 181 struct statfs statfs_buf; |
| 182 if (statfs(path.value().c_str(), &statfs_buf) < 0) |
| 183 return false; |
| 184 return statfs_buf.f_type != ECRYPTFS_SUPER_MAGIC; |
| 185 } |
| 186 |
144 } // namespace arc | 187 } // namespace arc |
OLD | NEW |