Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2015 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
| 16 | |
Alex Deymo | 1b03f9f | 2015-12-09 00:38:36 -0800 | [diff] [blame] | 17 | #include "update_engine/hardware_android.h" |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 18 | |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 19 | #include <base/files/file_util.h> |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 20 | #include <brillo/make_unique_ptr.h> |
Alex Deymo | 1c4e84a | 2015-09-22 16:58:10 -0700 | [diff] [blame] | 21 | #include <cutils/properties.h> |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 22 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 23 | #include "update_engine/common/hardware.h" |
Sen Jiang | 9c12346 | 2015-11-19 13:16:23 -0800 | [diff] [blame] | 24 | #include "update_engine/common/platform_constants.h" |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 25 | |
| 26 | using std::string; |
| 27 | |
| 28 | namespace chromeos_update_engine { |
| 29 | |
| 30 | namespace hardware { |
| 31 | |
| 32 | // Factory defined in hardware.h. |
| 33 | std::unique_ptr<HardwareInterface> CreateHardware() { |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 34 | return brillo::make_unique_ptr(new HardwareAndroid()); |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | } // namespace hardware |
| 38 | |
Alex Deymo | 1c4e84a | 2015-09-22 16:58:10 -0700 | [diff] [blame] | 39 | // In Android there are normally three kinds of builds: eng, userdebug and user. |
| 40 | // These builds target respectively a developer build, a debuggable version of |
| 41 | // the final product and the pristine final product the end user will run. |
| 42 | // Apart from the ro.build.type property name, they differ in the following |
| 43 | // properties that characterize the builds: |
| 44 | // * eng builds: ro.secure=0 and ro.debuggable=1 |
| 45 | // * userdebug builds: ro.secure=1 and ro.debuggable=1 |
| 46 | // * user builds: ro.secure=1 and ro.debuggable=0 |
| 47 | // |
| 48 | // See IsOfficialBuild() and IsNormalMode() for the meaning of these options in |
| 49 | // Android. |
| 50 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 51 | bool HardwareAndroid::IsOfficialBuild() const { |
Alex Deymo | 1c4e84a | 2015-09-22 16:58:10 -0700 | [diff] [blame] | 52 | // We run an official build iff ro.secure == 1, because we expect the build to |
| 53 | // behave like the end user product and check for updates. Note that while |
| 54 | // developers are able to build "official builds" by just running "make user", |
| 55 | // that will only result in a more restrictive environment. The important part |
| 56 | // is that we don't produce and push "non-official" builds to the end user. |
| 57 | // |
| 58 | // In case of a non-bool value, we take the most restrictive option and |
| 59 | // assume we are in an official-build. |
| 60 | return property_get_bool("ro.secure", 1) != 0; |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | bool HardwareAndroid::IsNormalBootMode() const { |
Alex Deymo | 1c4e84a | 2015-09-22 16:58:10 -0700 | [diff] [blame] | 64 | // We are running in "dev-mode" iff ro.debuggable == 1. In dev-mode the |
| 65 | // update_engine will allow extra developers options, such as providing a |
| 66 | // different update URL. In case of error, we assume the build is in |
| 67 | // normal-mode. |
| 68 | return property_get_bool("ro.debuggable", 0) != 1; |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 71 | bool HardwareAndroid::IsOOBEEnabled() const { |
| 72 | // No OOBE flow blocking updates for Android-based boards. |
| 73 | return false; |
| 74 | } |
| 75 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 76 | bool HardwareAndroid::IsOOBEComplete(base::Time* out_time_of_oobe) const { |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 77 | LOG(WARNING) << "OOBE is not enabled but IsOOBEComplete() called."; |
Alex Deymo | 4d2990d | 2015-09-15 12:11:26 -0700 | [diff] [blame] | 78 | if (out_time_of_oobe) |
| 79 | *out_time_of_oobe = base::Time(); |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 80 | return true; |
| 81 | } |
| 82 | |
| 83 | string HardwareAndroid::GetHardwareClass() const { |
| 84 | LOG(WARNING) << "STUB: GetHardwareClass()."; |
| 85 | return "ANDROID"; |
| 86 | } |
| 87 | |
| 88 | string HardwareAndroid::GetFirmwareVersion() const { |
| 89 | LOG(WARNING) << "STUB: GetFirmwareVersion()."; |
| 90 | return "0"; |
| 91 | } |
| 92 | |
| 93 | string HardwareAndroid::GetECVersion() const { |
| 94 | LOG(WARNING) << "STUB: GetECVersion()."; |
| 95 | return "0"; |
| 96 | } |
| 97 | |
| 98 | int HardwareAndroid::GetPowerwashCount() const { |
| 99 | LOG(WARNING) << "STUB: Assuming no factory reset was performed."; |
| 100 | return 0; |
| 101 | } |
| 102 | |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 103 | bool HardwareAndroid::GetNonVolatileDirectory(base::FilePath* path) const { |
Sen Jiang | 9c12346 | 2015-11-19 13:16:23 -0800 | [diff] [blame] | 104 | base::FilePath local_path(constants::kNonVolatileDirectory); |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 105 | if (!base::PathExists(local_path)) { |
| 106 | LOG(ERROR) << "Non-volatile directory not found: " << local_path.value(); |
| 107 | return false; |
| 108 | } |
| 109 | *path = local_path; |
| 110 | return true; |
| 111 | } |
| 112 | |
| 113 | bool HardwareAndroid::GetPowerwashSafeDirectory(base::FilePath* path) const { |
| 114 | // On Android, we don't have a directory persisted across powerwash. |
| 115 | return false; |
| 116 | } |
| 117 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 118 | } // namespace chromeos_update_engine |