blob: 4f06ff22f639f2753b31b4e34664a9787b3636bb [file] [log] [blame]
Alex Deymo40d86b22015-09-03 22:27:10 -07001//
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 Deymo39910dc2015-11-09 17:04:30 -080017#include "update_engine/common/hardware_android.h"
Alex Deymo40d86b22015-09-03 22:27:10 -070018
Alex Deymodd132f32015-09-14 19:12:07 -070019#include <base/files/file_util.h>
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070020#include <brillo/make_unique_ptr.h>
Alex Deymo1c4e84a2015-09-22 16:58:10 -070021#include <cutils/properties.h>
Alex Deymo40d86b22015-09-03 22:27:10 -070022
Alex Deymo39910dc2015-11-09 17:04:30 -080023#include "update_engine/common/hardware.h"
Alex Deymo40d86b22015-09-03 22:27:10 -070024
25using std::string;
26
Alex Deymodd132f32015-09-14 19:12:07 -070027namespace {
28
29// The stateful directory used by update_engine.
30const char kNonVolatileDirectory[] = "/data/misc/update_engine";
31
32} // namespace
33
Alex Deymo40d86b22015-09-03 22:27:10 -070034namespace chromeos_update_engine {
35
36namespace hardware {
37
38// Factory defined in hardware.h.
39std::unique_ptr<HardwareInterface> CreateHardware() {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070040 return brillo::make_unique_ptr(new HardwareAndroid());
Alex Deymo40d86b22015-09-03 22:27:10 -070041}
42
43} // namespace hardware
44
Alex Deymo1c4e84a2015-09-22 16:58:10 -070045// 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 Deymo40d86b22015-09-03 22:27:10 -070057bool HardwareAndroid::IsOfficialBuild() const {
Alex Deymo1c4e84a2015-09-22 16:58:10 -070058 // 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 Deymo40d86b22015-09-03 22:27:10 -070067}
68
69bool HardwareAndroid::IsNormalBootMode() const {
Alex Deymo1c4e84a2015-09-22 16:58:10 -070070 // 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 Deymo40d86b22015-09-03 22:27:10 -070075}
76
77bool HardwareAndroid::IsOOBEComplete(base::Time* out_time_of_oobe) const {
78 LOG(WARNING) << "STUB: Assuming OOBE is complete.";
Alex Deymo4d2990d2015-09-15 12:11:26 -070079 if (out_time_of_oobe)
80 *out_time_of_oobe = base::Time();
Alex Deymo40d86b22015-09-03 22:27:10 -070081 return true;
82}
83
84string HardwareAndroid::GetHardwareClass() const {
85 LOG(WARNING) << "STUB: GetHardwareClass().";
86 return "ANDROID";
87}
88
89string HardwareAndroid::GetFirmwareVersion() const {
90 LOG(WARNING) << "STUB: GetFirmwareVersion().";
91 return "0";
92}
93
94string HardwareAndroid::GetECVersion() const {
95 LOG(WARNING) << "STUB: GetECVersion().";
96 return "0";
97}
98
99int HardwareAndroid::GetPowerwashCount() const {
100 LOG(WARNING) << "STUB: Assuming no factory reset was performed.";
101 return 0;
102}
103
Alex Deymodd132f32015-09-14 19:12:07 -0700104bool 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
114bool HardwareAndroid::GetPowerwashSafeDirectory(base::FilePath* path) const {
115 // On Android, we don't have a directory persisted across powerwash.
116 return false;
117}
118
Alex Deymo40d86b22015-09-03 22:27:10 -0700119} // namespace chromeos_update_engine