140d86b22363fd9461e67ad288e0273bed509937bAlex Deymo// 240d86b22363fd9461e67ad288e0273bed509937bAlex Deymo// Copyright (C) 2015 The Android Open Source Project 340d86b22363fd9461e67ad288e0273bed509937bAlex Deymo// 440d86b22363fd9461e67ad288e0273bed509937bAlex Deymo// Licensed under the Apache License, Version 2.0 (the "License"); 540d86b22363fd9461e67ad288e0273bed509937bAlex Deymo// you may not use this file except in compliance with the License. 640d86b22363fd9461e67ad288e0273bed509937bAlex Deymo// You may obtain a copy of the License at 740d86b22363fd9461e67ad288e0273bed509937bAlex Deymo// 840d86b22363fd9461e67ad288e0273bed509937bAlex Deymo// http://www.apache.org/licenses/LICENSE-2.0 940d86b22363fd9461e67ad288e0273bed509937bAlex Deymo// 1040d86b22363fd9461e67ad288e0273bed509937bAlex Deymo// Unless required by applicable law or agreed to in writing, software 1140d86b22363fd9461e67ad288e0273bed509937bAlex Deymo// distributed under the License is distributed on an "AS IS" BASIS, 1240d86b22363fd9461e67ad288e0273bed509937bAlex Deymo// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1340d86b22363fd9461e67ad288e0273bed509937bAlex Deymo// See the License for the specific language governing permissions and 1440d86b22363fd9461e67ad288e0273bed509937bAlex Deymo// limitations under the License. 1540d86b22363fd9461e67ad288e0273bed509937bAlex Deymo// 1640d86b22363fd9461e67ad288e0273bed509937bAlex Deymo 171b03f9f983a22fabb8d53e036abf1b192e7d5811Alex Deymo#include "update_engine/hardware_android.h" 1840d86b22363fd9461e67ad288e0273bed509937bAlex Deymo 19dd132f39cced9028c01e98895a4f6c5fb9553de1Alex Deymo#include <base/files/file_util.h> 203f39d5cc753905874d8d93bef94f857b8808f19eAlex Vakulenko#include <brillo/make_unique_ptr.h> 211c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo#include <cutils/properties.h> 2240d86b22363fd9461e67ad288e0273bed509937bAlex Deymo 2339910dcd1d68987ccee7c3031dc269233a8490bbAlex Deymo#include "update_engine/common/hardware.h" 249c12346d5dc18288153fce61e7ffd0bd8e507afcSen Jiang#include "update_engine/common/platform_constants.h" 2540d86b22363fd9461e67ad288e0273bed509937bAlex Deymo 2640d86b22363fd9461e67ad288e0273bed509937bAlex Deymousing std::string; 2740d86b22363fd9461e67ad288e0273bed509937bAlex Deymo 2840d86b22363fd9461e67ad288e0273bed509937bAlex Deymonamespace chromeos_update_engine { 2940d86b22363fd9461e67ad288e0273bed509937bAlex Deymo 3040d86b22363fd9461e67ad288e0273bed509937bAlex Deymonamespace hardware { 3140d86b22363fd9461e67ad288e0273bed509937bAlex Deymo 3240d86b22363fd9461e67ad288e0273bed509937bAlex Deymo// Factory defined in hardware.h. 3340d86b22363fd9461e67ad288e0273bed509937bAlex Deymostd::unique_ptr<HardwareInterface> CreateHardware() { 343f39d5cc753905874d8d93bef94f857b8808f19eAlex Vakulenko return brillo::make_unique_ptr(new HardwareAndroid()); 3540d86b22363fd9461e67ad288e0273bed509937bAlex Deymo} 3640d86b22363fd9461e67ad288e0273bed509937bAlex Deymo 3740d86b22363fd9461e67ad288e0273bed509937bAlex Deymo} // namespace hardware 3840d86b22363fd9461e67ad288e0273bed509937bAlex Deymo 391c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo// In Android there are normally three kinds of builds: eng, userdebug and user. 401c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo// These builds target respectively a developer build, a debuggable version of 411c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo// the final product and the pristine final product the end user will run. 421c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo// Apart from the ro.build.type property name, they differ in the following 431c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo// properties that characterize the builds: 441c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo// * eng builds: ro.secure=0 and ro.debuggable=1 451c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo// * userdebug builds: ro.secure=1 and ro.debuggable=1 461c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo// * user builds: ro.secure=1 and ro.debuggable=0 471c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo// 481c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo// See IsOfficialBuild() and IsNormalMode() for the meaning of these options in 491c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo// Android. 501c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo 5140d86b22363fd9461e67ad288e0273bed509937bAlex Deymobool HardwareAndroid::IsOfficialBuild() const { 521c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo // We run an official build iff ro.secure == 1, because we expect the build to 531c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo // behave like the end user product and check for updates. Note that while 541c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo // developers are able to build "official builds" by just running "make user", 551c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo // that will only result in a more restrictive environment. The important part 561c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo // is that we don't produce and push "non-official" builds to the end user. 571c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo // 581c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo // In case of a non-bool value, we take the most restrictive option and 591c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo // assume we are in an official-build. 601c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo return property_get_bool("ro.secure", 1) != 0; 6140d86b22363fd9461e67ad288e0273bed509937bAlex Deymo} 6240d86b22363fd9461e67ad288e0273bed509937bAlex Deymo 6340d86b22363fd9461e67ad288e0273bed509937bAlex Deymobool HardwareAndroid::IsNormalBootMode() const { 641c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo // We are running in "dev-mode" iff ro.debuggable == 1. In dev-mode the 651c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo // update_engine will allow extra developers options, such as providing a 661c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo // different update URL. In case of error, we assume the build is in 671c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo // normal-mode. 681c4e84af8f365c8ca96b30738e9aea8ed8f83aa8Alex Deymo return property_get_bool("ro.debuggable", 0) != 1; 6940d86b22363fd9461e67ad288e0273bed509937bAlex Deymo} 7040d86b22363fd9461e67ad288e0273bed509937bAlex Deymo 7140d86b22363fd9461e67ad288e0273bed509937bAlex Deymobool HardwareAndroid::IsOOBEComplete(base::Time* out_time_of_oobe) const { 7240d86b22363fd9461e67ad288e0273bed509937bAlex Deymo LOG(WARNING) << "STUB: Assuming OOBE is complete."; 734d2990d04917bd8140772bee63f2cf43837b6a30Alex Deymo if (out_time_of_oobe) 744d2990d04917bd8140772bee63f2cf43837b6a30Alex Deymo *out_time_of_oobe = base::Time(); 7540d86b22363fd9461e67ad288e0273bed509937bAlex Deymo return true; 7640d86b22363fd9461e67ad288e0273bed509937bAlex Deymo} 7740d86b22363fd9461e67ad288e0273bed509937bAlex Deymo 7840d86b22363fd9461e67ad288e0273bed509937bAlex Deymostring HardwareAndroid::GetHardwareClass() const { 7940d86b22363fd9461e67ad288e0273bed509937bAlex Deymo LOG(WARNING) << "STUB: GetHardwareClass()."; 8040d86b22363fd9461e67ad288e0273bed509937bAlex Deymo return "ANDROID"; 8140d86b22363fd9461e67ad288e0273bed509937bAlex Deymo} 8240d86b22363fd9461e67ad288e0273bed509937bAlex Deymo 8340d86b22363fd9461e67ad288e0273bed509937bAlex Deymostring HardwareAndroid::GetFirmwareVersion() const { 8440d86b22363fd9461e67ad288e0273bed509937bAlex Deymo LOG(WARNING) << "STUB: GetFirmwareVersion()."; 8540d86b22363fd9461e67ad288e0273bed509937bAlex Deymo return "0"; 8640d86b22363fd9461e67ad288e0273bed509937bAlex Deymo} 8740d86b22363fd9461e67ad288e0273bed509937bAlex Deymo 8840d86b22363fd9461e67ad288e0273bed509937bAlex Deymostring HardwareAndroid::GetECVersion() const { 8940d86b22363fd9461e67ad288e0273bed509937bAlex Deymo LOG(WARNING) << "STUB: GetECVersion()."; 9040d86b22363fd9461e67ad288e0273bed509937bAlex Deymo return "0"; 9140d86b22363fd9461e67ad288e0273bed509937bAlex Deymo} 9240d86b22363fd9461e67ad288e0273bed509937bAlex Deymo 9340d86b22363fd9461e67ad288e0273bed509937bAlex Deymoint HardwareAndroid::GetPowerwashCount() const { 9440d86b22363fd9461e67ad288e0273bed509937bAlex Deymo LOG(WARNING) << "STUB: Assuming no factory reset was performed."; 9540d86b22363fd9461e67ad288e0273bed509937bAlex Deymo return 0; 9640d86b22363fd9461e67ad288e0273bed509937bAlex Deymo} 9740d86b22363fd9461e67ad288e0273bed509937bAlex Deymo 98dd132f39cced9028c01e98895a4f6c5fb9553de1Alex Deymobool HardwareAndroid::GetNonVolatileDirectory(base::FilePath* path) const { 999c12346d5dc18288153fce61e7ffd0bd8e507afcSen Jiang base::FilePath local_path(constants::kNonVolatileDirectory); 100dd132f39cced9028c01e98895a4f6c5fb9553de1Alex Deymo if (!base::PathExists(local_path)) { 101dd132f39cced9028c01e98895a4f6c5fb9553de1Alex Deymo LOG(ERROR) << "Non-volatile directory not found: " << local_path.value(); 102dd132f39cced9028c01e98895a4f6c5fb9553de1Alex Deymo return false; 103dd132f39cced9028c01e98895a4f6c5fb9553de1Alex Deymo } 104dd132f39cced9028c01e98895a4f6c5fb9553de1Alex Deymo *path = local_path; 105dd132f39cced9028c01e98895a4f6c5fb9553de1Alex Deymo return true; 106dd132f39cced9028c01e98895a4f6c5fb9553de1Alex Deymo} 107dd132f39cced9028c01e98895a4f6c5fb9553de1Alex Deymo 108dd132f39cced9028c01e98895a4f6c5fb9553de1Alex Deymobool HardwareAndroid::GetPowerwashSafeDirectory(base::FilePath* path) const { 109dd132f39cced9028c01e98895a4f6c5fb9553de1Alex Deymo // On Android, we don't have a directory persisted across powerwash. 110dd132f39cced9028c01e98895a4f6c5fb9553de1Alex Deymo return false; 111dd132f39cced9028c01e98895a4f6c5fb9553de1Alex Deymo} 112dd132f39cced9028c01e98895a4f6c5fb9553de1Alex Deymo 11340d86b22363fd9461e67ad288e0273bed509937bAlex Deymo} // namespace chromeos_update_engine 114