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
17 #include "update_engine/hardware_android.h"
18
19 #include <base/files/file_util.h>
20 #include <brillo/make_unique_ptr.h>
21 #include <cutils/properties.h>
22
23 #include "update_engine/common/hardware.h"
24 #include "update_engine/common/platform_constants.h"
25
26 using std::string;
27
28 namespace chromeos_update_engine {
29
30 namespace hardware {
31
32 // Factory defined in hardware.h.
CreateHardware()33 std::unique_ptr<HardwareInterface> CreateHardware() {
34 return brillo::make_unique_ptr(new HardwareAndroid());
35 }
36
37 } // namespace hardware
38
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
IsOfficialBuild() const51 bool HardwareAndroid::IsOfficialBuild() const {
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;
61 }
62
IsNormalBootMode() const63 bool HardwareAndroid::IsNormalBootMode() const {
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;
69 }
70
IsOOBEComplete(base::Time * out_time_of_oobe) const71 bool HardwareAndroid::IsOOBEComplete(base::Time* out_time_of_oobe) const {
72 LOG(WARNING) << "STUB: Assuming OOBE is complete.";
73 if (out_time_of_oobe)
74 *out_time_of_oobe = base::Time();
75 return true;
76 }
77
GetHardwareClass() const78 string HardwareAndroid::GetHardwareClass() const {
79 LOG(WARNING) << "STUB: GetHardwareClass().";
80 return "ANDROID";
81 }
82
GetFirmwareVersion() const83 string HardwareAndroid::GetFirmwareVersion() const {
84 LOG(WARNING) << "STUB: GetFirmwareVersion().";
85 return "0";
86 }
87
GetECVersion() const88 string HardwareAndroid::GetECVersion() const {
89 LOG(WARNING) << "STUB: GetECVersion().";
90 return "0";
91 }
92
GetPowerwashCount() const93 int HardwareAndroid::GetPowerwashCount() const {
94 LOG(WARNING) << "STUB: Assuming no factory reset was performed.";
95 return 0;
96 }
97
GetNonVolatileDirectory(base::FilePath * path) const98 bool HardwareAndroid::GetNonVolatileDirectory(base::FilePath* path) const {
99 base::FilePath local_path(constants::kNonVolatileDirectory);
100 if (!base::PathExists(local_path)) {
101 LOG(ERROR) << "Non-volatile directory not found: " << local_path.value();
102 return false;
103 }
104 *path = local_path;
105 return true;
106 }
107
GetPowerwashSafeDirectory(base::FilePath * path) const108 bool HardwareAndroid::GetPowerwashSafeDirectory(base::FilePath* path) const {
109 // On Android, we don't have a directory persisted across powerwash.
110 return false;
111 }
112
113 } // namespace chromeos_update_engine
114