blob: a20fe6fe26526ddbabada755e3a70ecb89e86f64 [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 Deymo1b03f9f2015-12-09 00:38:36 -080017#include "update_engine/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"
Sen Jiang9c123462015-11-19 13:16:23 -080024#include "update_engine/common/platform_constants.h"
Alex Deymo40d86b22015-09-03 22:27:10 -070025
26using std::string;
27
28namespace chromeos_update_engine {
29
30namespace hardware {
31
32// Factory defined in hardware.h.
33std::unique_ptr<HardwareInterface> CreateHardware() {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070034 return brillo::make_unique_ptr(new HardwareAndroid());
Alex Deymo40d86b22015-09-03 22:27:10 -070035}
36
37} // namespace hardware
38
Alex Deymo1c4e84a2015-09-22 16:58:10 -070039// 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
Alex Deymo40d86b22015-09-03 22:27:10 -070051bool HardwareAndroid::IsOfficialBuild() const {
Alex Deymo1c4e84a2015-09-22 16:58:10 -070052 // 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;
Alex Deymo40d86b22015-09-03 22:27:10 -070061}
62
63bool HardwareAndroid::IsNormalBootMode() const {
Alex Deymo1c4e84a2015-09-22 16:58:10 -070064 // 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;
Alex Deymo40d86b22015-09-03 22:27:10 -070069}
70
71bool HardwareAndroid::IsOOBEComplete(base::Time* out_time_of_oobe) const {
72 LOG(WARNING) << "STUB: Assuming OOBE is complete.";
Alex Deymo4d2990d2015-09-15 12:11:26 -070073 if (out_time_of_oobe)
74 *out_time_of_oobe = base::Time();
Alex Deymo40d86b22015-09-03 22:27:10 -070075 return true;
76}
77
78string HardwareAndroid::GetHardwareClass() const {
79 LOG(WARNING) << "STUB: GetHardwareClass().";
80 return "ANDROID";
81}
82
83string HardwareAndroid::GetFirmwareVersion() const {
84 LOG(WARNING) << "STUB: GetFirmwareVersion().";
85 return "0";
86}
87
88string HardwareAndroid::GetECVersion() const {
89 LOG(WARNING) << "STUB: GetECVersion().";
90 return "0";
91}
92
93int HardwareAndroid::GetPowerwashCount() const {
94 LOG(WARNING) << "STUB: Assuming no factory reset was performed.";
95 return 0;
96}
97
Alex Deymodd132f32015-09-14 19:12:07 -070098bool HardwareAndroid::GetNonVolatileDirectory(base::FilePath* path) const {
Sen Jiang9c123462015-11-19 13:16:23 -080099 base::FilePath local_path(constants::kNonVolatileDirectory);
Alex Deymodd132f32015-09-14 19:12:07 -0700100 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
108bool HardwareAndroid::GetPowerwashSafeDirectory(base::FilePath* path) const {
109 // On Android, we don't have a directory persisted across powerwash.
110 return false;
111}
112
Alex Deymo40d86b22015-09-03 22:27:10 -0700113} // namespace chromeos_update_engine