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 | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame^] | 17 | #include "update_engine/common/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" |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 24 | |
| 25 | using std::string; |
| 26 | |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 27 | namespace { |
| 28 | |
| 29 | // The stateful directory used by update_engine. |
| 30 | const char kNonVolatileDirectory[] = "/data/misc/update_engine"; |
| 31 | |
| 32 | } // namespace |
| 33 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 34 | namespace chromeos_update_engine { |
| 35 | |
| 36 | namespace hardware { |
| 37 | |
| 38 | // Factory defined in hardware.h. |
| 39 | std::unique_ptr<HardwareInterface> CreateHardware() { |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 40 | return brillo::make_unique_ptr(new HardwareAndroid()); |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | } // namespace hardware |
| 44 | |
Alex Deymo | 1c4e84a | 2015-09-22 16:58:10 -0700 | [diff] [blame] | 45 | // In Android there are normally three kinds of builds: eng, userdebug and user. |
| 46 | // These builds target respectively a developer build, a debuggable version of |
| 47 | // the final product and the pristine final product the end user will run. |
| 48 | // Apart from the ro.build.type property name, they differ in the following |
| 49 | // properties that characterize the builds: |
| 50 | // * eng builds: ro.secure=0 and ro.debuggable=1 |
| 51 | // * userdebug builds: ro.secure=1 and ro.debuggable=1 |
| 52 | // * user builds: ro.secure=1 and ro.debuggable=0 |
| 53 | // |
| 54 | // See IsOfficialBuild() and IsNormalMode() for the meaning of these options in |
| 55 | // Android. |
| 56 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 57 | bool HardwareAndroid::IsOfficialBuild() const { |
Alex Deymo | 1c4e84a | 2015-09-22 16:58:10 -0700 | [diff] [blame] | 58 | // We run an official build iff ro.secure == 1, because we expect the build to |
| 59 | // behave like the end user product and check for updates. Note that while |
| 60 | // developers are able to build "official builds" by just running "make user", |
| 61 | // that will only result in a more restrictive environment. The important part |
| 62 | // is that we don't produce and push "non-official" builds to the end user. |
| 63 | // |
| 64 | // In case of a non-bool value, we take the most restrictive option and |
| 65 | // assume we are in an official-build. |
| 66 | return property_get_bool("ro.secure", 1) != 0; |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | bool HardwareAndroid::IsNormalBootMode() const { |
Alex Deymo | 1c4e84a | 2015-09-22 16:58:10 -0700 | [diff] [blame] | 70 | // We are running in "dev-mode" iff ro.debuggable == 1. In dev-mode the |
| 71 | // update_engine will allow extra developers options, such as providing a |
| 72 | // different update URL. In case of error, we assume the build is in |
| 73 | // normal-mode. |
| 74 | return property_get_bool("ro.debuggable", 0) != 1; |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | bool HardwareAndroid::IsOOBEComplete(base::Time* out_time_of_oobe) const { |
| 78 | LOG(WARNING) << "STUB: Assuming OOBE is complete."; |
Alex Deymo | 4d2990d | 2015-09-15 12:11:26 -0700 | [diff] [blame] | 79 | if (out_time_of_oobe) |
| 80 | *out_time_of_oobe = base::Time(); |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 81 | return true; |
| 82 | } |
| 83 | |
| 84 | string HardwareAndroid::GetHardwareClass() const { |
| 85 | LOG(WARNING) << "STUB: GetHardwareClass()."; |
| 86 | return "ANDROID"; |
| 87 | } |
| 88 | |
| 89 | string HardwareAndroid::GetFirmwareVersion() const { |
| 90 | LOG(WARNING) << "STUB: GetFirmwareVersion()."; |
| 91 | return "0"; |
| 92 | } |
| 93 | |
| 94 | string HardwareAndroid::GetECVersion() const { |
| 95 | LOG(WARNING) << "STUB: GetECVersion()."; |
| 96 | return "0"; |
| 97 | } |
| 98 | |
| 99 | int HardwareAndroid::GetPowerwashCount() const { |
| 100 | LOG(WARNING) << "STUB: Assuming no factory reset was performed."; |
| 101 | return 0; |
| 102 | } |
| 103 | |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 104 | bool HardwareAndroid::GetNonVolatileDirectory(base::FilePath* path) const { |
| 105 | base::FilePath local_path(kNonVolatileDirectory); |
| 106 | if (!base::PathExists(local_path)) { |
| 107 | LOG(ERROR) << "Non-volatile directory not found: " << local_path.value(); |
| 108 | return false; |
| 109 | } |
| 110 | *path = local_path; |
| 111 | return true; |
| 112 | } |
| 113 | |
| 114 | bool HardwareAndroid::GetPowerwashSafeDirectory(base::FilePath* path) const { |
| 115 | // On Android, we don't have a directory persisted across powerwash. |
| 116 | return false; |
| 117 | } |
| 118 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 119 | } // namespace chromeos_update_engine |