hardware_android.cc 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. #include "update_engine/hardware_android.h"
  17. #include <sys/types.h>
  18. #include <memory>
  19. #include <android-base/properties.h>
  20. #include <base/files/file_util.h>
  21. #include <bootloader_message/bootloader_message.h>
  22. #include "update_engine/common/hardware.h"
  23. #include "update_engine/common/platform_constants.h"
  24. using android::base::GetBoolProperty;
  25. using android::base::GetIntProperty;
  26. using android::base::GetProperty;
  27. using std::string;
  28. namespace chromeos_update_engine {
  29. namespace {
  30. // Android properties that identify the hardware and potentially non-updatable
  31. // parts of the bootloader (such as the bootloader version and the baseband
  32. // version).
  33. const char kPropBootBootloader[] = "ro.boot.bootloader";
  34. const char kPropBootBaseband[] = "ro.boot.baseband";
  35. const char kPropProductManufacturer[] = "ro.product.manufacturer";
  36. const char kPropBootHardwareSKU[] = "ro.boot.hardware.sku";
  37. const char kPropBootRevision[] = "ro.boot.revision";
  38. const char kPropBuildDateUTC[] = "ro.build.date.utc";
  39. } // namespace
  40. namespace hardware {
  41. // Factory defined in hardware.h.
  42. std::unique_ptr<HardwareInterface> CreateHardware() {
  43. return std::make_unique<HardwareAndroid>();
  44. }
  45. } // namespace hardware
  46. // In Android there are normally three kinds of builds: eng, userdebug and user.
  47. // These builds target respectively a developer build, a debuggable version of
  48. // the final product and the pristine final product the end user will run.
  49. // Apart from the ro.build.type property name, they differ in the following
  50. // properties that characterize the builds:
  51. // * eng builds: ro.secure=0 and ro.debuggable=1
  52. // * userdebug builds: ro.secure=1 and ro.debuggable=1
  53. // * user builds: ro.secure=1 and ro.debuggable=0
  54. //
  55. // See IsOfficialBuild() and IsNormalMode() for the meaning of these options in
  56. // Android.
  57. bool HardwareAndroid::IsOfficialBuild() const {
  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 GetBoolProperty("ro.secure", true);
  67. }
  68. bool HardwareAndroid::IsNormalBootMode() const {
  69. // We are running in "dev-mode" iff ro.debuggable == 1. In dev-mode the
  70. // update_engine will allow extra developers options, such as providing a
  71. // different update URL. In case of error, we assume the build is in
  72. // normal-mode.
  73. return !GetBoolProperty("ro.debuggable", false);
  74. }
  75. bool HardwareAndroid::AreDevFeaturesEnabled() const {
  76. return !IsNormalBootMode();
  77. }
  78. bool HardwareAndroid::IsOOBEEnabled() const {
  79. // No OOBE flow blocking updates for Android-based boards.
  80. return false;
  81. }
  82. bool HardwareAndroid::IsOOBEComplete(base::Time* out_time_of_oobe) const {
  83. LOG(WARNING) << "OOBE is not enabled but IsOOBEComplete() called.";
  84. if (out_time_of_oobe)
  85. *out_time_of_oobe = base::Time();
  86. return true;
  87. }
  88. string HardwareAndroid::GetHardwareClass() const {
  89. auto manufacturer = GetProperty(kPropProductManufacturer, "");
  90. auto sku = GetProperty(kPropBootHardwareSKU, "");
  91. auto revision = GetProperty(kPropBootRevision, "");
  92. return manufacturer + ":" + sku + ":" + revision;
  93. }
  94. string HardwareAndroid::GetFirmwareVersion() const {
  95. return GetProperty(kPropBootBootloader, "");
  96. }
  97. string HardwareAndroid::GetECVersion() const {
  98. return GetProperty(kPropBootBaseband, "");
  99. }
  100. int HardwareAndroid::GetMinKernelKeyVersion() const {
  101. LOG(WARNING) << "STUB: No Kernel key version is available.";
  102. return -1;
  103. }
  104. int HardwareAndroid::GetMinFirmwareKeyVersion() const {
  105. LOG(WARNING) << "STUB: No Firmware key version is available.";
  106. return -1;
  107. }
  108. int HardwareAndroid::GetMaxFirmwareKeyRollforward() const {
  109. LOG(WARNING) << "STUB: Getting firmware_max_rollforward is not supported.";
  110. return -1;
  111. }
  112. bool HardwareAndroid::SetMaxFirmwareKeyRollforward(
  113. int firmware_max_rollforward) {
  114. LOG(WARNING) << "STUB: Setting firmware_max_rollforward is not supported.";
  115. return false;
  116. }
  117. bool HardwareAndroid::SetMaxKernelKeyRollforward(int kernel_max_rollforward) {
  118. LOG(WARNING) << "STUB: Setting kernel_max_rollforward is not supported.";
  119. return false;
  120. }
  121. int HardwareAndroid::GetPowerwashCount() const {
  122. LOG(WARNING) << "STUB: Assuming no factory reset was performed.";
  123. return 0;
  124. }
  125. bool HardwareAndroid::SchedulePowerwash(bool is_rollback) {
  126. LOG(INFO) << "Scheduling a powerwash to BCB.";
  127. LOG_IF(WARNING, is_rollback) << "is_rollback was true but isn't supported.";
  128. string err;
  129. if (!update_bootloader_message({"--wipe_data", "--reason=wipe_data_from_ota"},
  130. &err)) {
  131. LOG(ERROR) << "Failed to update bootloader message: " << err;
  132. return false;
  133. }
  134. return true;
  135. }
  136. bool HardwareAndroid::CancelPowerwash() {
  137. string err;
  138. if (!clear_bootloader_message(&err)) {
  139. LOG(ERROR) << "Failed to clear bootloader message: " << err;
  140. return false;
  141. }
  142. return true;
  143. }
  144. bool HardwareAndroid::GetNonVolatileDirectory(base::FilePath* path) const {
  145. base::FilePath local_path(constants::kNonVolatileDirectory);
  146. if (!base::PathExists(local_path)) {
  147. LOG(ERROR) << "Non-volatile directory not found: " << local_path.value();
  148. return false;
  149. }
  150. *path = local_path;
  151. return true;
  152. }
  153. bool HardwareAndroid::GetPowerwashSafeDirectory(base::FilePath* path) const {
  154. // On Android, we don't have a directory persisted across powerwash.
  155. return false;
  156. }
  157. int64_t HardwareAndroid::GetBuildTimestamp() const {
  158. return GetIntProperty<int64_t>(kPropBuildDateUTC, 0);
  159. }
  160. bool HardwareAndroid::GetFirstActiveOmahaPingSent() const {
  161. LOG(WARNING) << "STUB: Assuming first active omaha was never set.";
  162. return false;
  163. }
  164. bool HardwareAndroid::SetFirstActiveOmahaPingSent() {
  165. LOG(WARNING) << "STUB: Assuming first active omaha is set.";
  166. // We will set it true, so its failure doesn't cause escalation.
  167. return true;
  168. }
  169. } // namespace chromeos_update_engine