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/callback.h" |
| 11 #include "base/files/file_path.h" |
7 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/sys_info.h" |
| 14 #include "base/task_scheduler/post_task.h" |
| 15 #include "base/threading/thread_restrictions.h" |
8 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | 16 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
9 #include "chrome/browser/chromeos/login/user_flow.h" | 17 #include "chrome/browser/chromeos/login/user_flow.h" |
10 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" | 18 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
11 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 19 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
12 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
14 #include "components/arc/arc_util.h" | 22 #include "components/arc/arc_util.h" |
15 #include "components/prefs/pref_service.h" | 23 #include "components/prefs/pref_service.h" |
| 24 #include "components/user_manager/known_user.h" |
16 #include "components/user_manager/user.h" | 25 #include "components/user_manager/user.h" |
17 #include "components/user_manager/user_manager.h" | 26 #include "components/user_manager/user_manager.h" |
18 | 27 |
19 namespace arc { | 28 namespace arc { |
20 | 29 |
21 namespace { | 30 namespace { |
22 | 31 |
| 32 constexpr char kLsbReleaseArcVersionKey[] = "CHROMEOS_ARC_ANDROID_SDK_VERSION"; |
| 33 constexpr char kAndroidMSdkVersion[] = "23"; |
| 34 |
23 // Let IsAllowedForProfile() return "false" for any profile. | 35 // Let IsAllowedForProfile() return "false" for any profile. |
24 bool g_disallow_for_testing = false; | 36 bool g_disallow_for_testing = false; |
25 | 37 |
| 38 // Returns whether ARC can run on the filesystem mounted at |path|. |
| 39 // This function should run only on threads where IO operations are allowed. |
| 40 bool IsArcCompatibleFilesystem(const base::FilePath& path) { |
| 41 base::ThreadRestrictions::AssertIOAllowed(); |
| 42 |
| 43 // If it can be verified it is not on ecryptfs, then it is ok. |
| 44 struct statfs statfs_buf; |
| 45 if (statfs(path.value().c_str(), &statfs_buf) < 0) |
| 46 return false; |
| 47 return statfs_buf.f_type != ECRYPTFS_SUPER_MAGIC; |
| 48 } |
| 49 |
| 50 // Stores the result of IsArcCompatibleFilesystem posted back from the blocking |
| 51 // task runner. |
| 52 void StoreCompatibilityCheckResult(const AccountId& account_id, |
| 53 const base::Closure& callback, |
| 54 bool is_compatible) { |
| 55 if (is_compatible) { |
| 56 user_manager::known_user::SetIntegerPref( |
| 57 account_id, prefs::kArcCompatibleFilesystemChosen, |
| 58 arc::kFileSystemCompatible); |
| 59 } |
| 60 callback.Run(); |
| 61 } |
| 62 |
| 63 FileSystemCompatibilityState GetFileSystemCompatibilityPref( |
| 64 const AccountId& account_id) { |
| 65 int pref_value = kFileSystemIncompatible; |
| 66 user_manager::known_user::GetIntegerPref( |
| 67 account_id, prefs::kArcCompatibleFilesystemChosen, &pref_value); |
| 68 return static_cast<FileSystemCompatibilityState>(pref_value); |
| 69 } |
| 70 |
26 } // namespace | 71 } // namespace |
27 | 72 |
28 bool IsArcAllowedForProfile(const Profile* profile) { | 73 bool IsArcAllowedForProfile(const Profile* profile) { |
29 if (g_disallow_for_testing) { | 74 if (g_disallow_for_testing) { |
30 VLOG(1) << "ARC is disallowed for testing."; | 75 VLOG(1) << "ARC is disallowed for testing."; |
31 return false; | 76 return false; |
32 } | 77 } |
33 | 78 |
34 // ARC Kiosk can be enabled even if ARC is not yet supported on the device. | 79 // ARC Kiosk can be enabled even if ARC is not yet supported on the device. |
35 // In that case IsArcKioskMode() should return true as profile is already | 80 // In that case IsArcKioskMode() should return true as profile is already |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 return; | 172 return; |
128 if (enabled) | 173 if (enabled) |
129 arc_session_manager->RequestEnable(); | 174 arc_session_manager->RequestEnable(); |
130 else | 175 else |
131 arc_session_manager->RequestDisable(); | 176 arc_session_manager->RequestDisable(); |
132 return; | 177 return; |
133 } | 178 } |
134 profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, enabled); | 179 profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, enabled); |
135 } | 180 } |
136 | 181 |
| 182 void UpdateArcFileSystemCompatibilityPrefIfNeeded( |
| 183 const AccountId& account_id, |
| 184 const base::FilePath& profile_path, |
| 185 const base::Closure& callback) { |
| 186 DCHECK(!callback.is_null()); |
| 187 |
| 188 // If ARC is not available, skip the check. |
| 189 if (!IsArcAvailable()) { |
| 190 callback.Run(); |
| 191 return; |
| 192 } |
| 193 |
| 194 // If the compatibility has been already confirmed, skip the check. |
| 195 if (GetFileSystemCompatibilityPref(account_id) != kFileSystemIncompatible) { |
| 196 callback.Run(); |
| 197 return; |
| 198 } |
| 199 |
| 200 // Otherwise, check the underlying filesystem. |
| 201 base::PostTaskWithTraitsAndReplyWithResult( |
| 202 FROM_HERE, |
| 203 base::TaskTraits() |
| 204 .WithShutdownBehavior( |
| 205 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
| 206 .WithPriority(base::TaskPriority::USER_BLOCKING) |
| 207 .MayBlock(), |
| 208 base::Bind(&IsArcCompatibleFilesystem, profile_path), |
| 209 base::Bind(&StoreCompatibilityCheckResult, account_id, callback)); |
| 210 } |
| 211 |
137 } // namespace arc | 212 } // namespace arc |
OLD | NEW |