1*70a7ec85SAndroid Build Coastguard Worker /*
2*70a7ec85SAndroid Build Coastguard Worker * Copyright (C) 2021 The Android Open Source Project
3*70a7ec85SAndroid Build Coastguard Worker *
4*70a7ec85SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*70a7ec85SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*70a7ec85SAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*70a7ec85SAndroid Build Coastguard Worker *
8*70a7ec85SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*70a7ec85SAndroid Build Coastguard Worker *
10*70a7ec85SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*70a7ec85SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*70a7ec85SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*70a7ec85SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*70a7ec85SAndroid Build Coastguard Worker * limitations under the License.
15*70a7ec85SAndroid Build Coastguard Worker */
16*70a7ec85SAndroid Build Coastguard Worker
17*70a7ec85SAndroid Build Coastguard Worker #include <vintf/VintfObjectRecovery.h>
18*70a7ec85SAndroid Build Coastguard Worker
19*70a7ec85SAndroid Build Coastguard Worker #include "VintfObjectUtils.h"
20*70a7ec85SAndroid Build Coastguard Worker #include "constants-private.h"
21*70a7ec85SAndroid Build Coastguard Worker #include "utils.h"
22*70a7ec85SAndroid Build Coastguard Worker
23*70a7ec85SAndroid Build Coastguard Worker using std::placeholders::_1;
24*70a7ec85SAndroid Build Coastguard Worker using std::placeholders::_2;
25*70a7ec85SAndroid Build Coastguard Worker
26*70a7ec85SAndroid Build Coastguard Worker namespace android::vintf {
27*70a7ec85SAndroid Build Coastguard Worker
28*70a7ec85SAndroid Build Coastguard Worker using details::Get;
29*70a7ec85SAndroid Build Coastguard Worker using details::kSystemManifest;
30*70a7ec85SAndroid Build Coastguard Worker using details::kSystemManifestFragmentDir;
31*70a7ec85SAndroid Build Coastguard Worker
GetInstance()32*70a7ec85SAndroid Build Coastguard Worker std::shared_ptr<VintfObjectRecovery> VintfObjectRecovery::GetInstance() {
33*70a7ec85SAndroid Build Coastguard Worker static details::LockedSharedPtr<VintfObjectRecovery> sInstance{};
34*70a7ec85SAndroid Build Coastguard Worker std::unique_lock<std::mutex> lock(sInstance.mutex);
35*70a7ec85SAndroid Build Coastguard Worker if (sInstance.object == nullptr) {
36*70a7ec85SAndroid Build Coastguard Worker std::unique_ptr<VintfObjectRecovery> uptr =
37*70a7ec85SAndroid Build Coastguard Worker VintfObjectRecovery::Builder().build<VintfObjectRecovery>();
38*70a7ec85SAndroid Build Coastguard Worker sInstance.object = std::shared_ptr<VintfObjectRecovery>(uptr.release());
39*70a7ec85SAndroid Build Coastguard Worker }
40*70a7ec85SAndroid Build Coastguard Worker return sInstance.object;
41*70a7ec85SAndroid Build Coastguard Worker }
42*70a7ec85SAndroid Build Coastguard Worker
getRecoveryHalManifest()43*70a7ec85SAndroid Build Coastguard Worker std::shared_ptr<const HalManifest> VintfObjectRecovery::getRecoveryHalManifest() {
44*70a7ec85SAndroid Build Coastguard Worker return Get(__func__, &mRecoveryManifest,
45*70a7ec85SAndroid Build Coastguard Worker std::bind(&VintfObjectRecovery::fetchRecoveryHalManifest, this, _1, _2));
46*70a7ec85SAndroid Build Coastguard Worker }
47*70a7ec85SAndroid Build Coastguard Worker
48*70a7ec85SAndroid Build Coastguard Worker // All manifests are installed under /system/etc/vintf.
49*70a7ec85SAndroid Build Coastguard Worker // There may be mixed framework and device manifests under that directory. Treat them all
50*70a7ec85SAndroid Build Coastguard Worker // as device manifest fragments.
51*70a7ec85SAndroid Build Coastguard Worker // Priority:
52*70a7ec85SAndroid Build Coastguard Worker // 1. /system/etc/vintf/manifest.xml
53*70a7ec85SAndroid Build Coastguard Worker // + /system/etc/vintf/manifest/*.xml if they exist
fetchRecoveryHalManifest(HalManifest * out,std::string * error)54*70a7ec85SAndroid Build Coastguard Worker status_t VintfObjectRecovery::fetchRecoveryHalManifest(HalManifest* out, std::string* error) {
55*70a7ec85SAndroid Build Coastguard Worker HalManifest manifest;
56*70a7ec85SAndroid Build Coastguard Worker status_t systemEtcStatus = fetchOneHalManifest(kSystemManifest, &manifest, error);
57*70a7ec85SAndroid Build Coastguard Worker if (systemEtcStatus != OK && systemEtcStatus != NAME_NOT_FOUND) {
58*70a7ec85SAndroid Build Coastguard Worker return systemEtcStatus;
59*70a7ec85SAndroid Build Coastguard Worker }
60*70a7ec85SAndroid Build Coastguard Worker // Merge |manifest| to |out| only if the main manifest is found.
61*70a7ec85SAndroid Build Coastguard Worker if (systemEtcStatus == OK) {
62*70a7ec85SAndroid Build Coastguard Worker *out = std::move(manifest);
63*70a7ec85SAndroid Build Coastguard Worker }
64*70a7ec85SAndroid Build Coastguard Worker out->setType(SchemaType::DEVICE);
65*70a7ec85SAndroid Build Coastguard Worker status_t fragmentStatus =
66*70a7ec85SAndroid Build Coastguard Worker addDirectoryManifests(kSystemManifestFragmentDir, out, true /* forceSchemaType */, error);
67*70a7ec85SAndroid Build Coastguard Worker if (fragmentStatus != OK) {
68*70a7ec85SAndroid Build Coastguard Worker return fragmentStatus;
69*70a7ec85SAndroid Build Coastguard Worker }
70*70a7ec85SAndroid Build Coastguard Worker return OK;
71*70a7ec85SAndroid Build Coastguard Worker }
72*70a7ec85SAndroid Build Coastguard Worker
Builder()73*70a7ec85SAndroid Build Coastguard Worker VintfObjectRecovery::Builder::Builder()
74*70a7ec85SAndroid Build Coastguard Worker : VintfObjectBuilder(std::unique_ptr<VintfObject>(new VintfObjectRecovery())) {}
75*70a7ec85SAndroid Build Coastguard Worker
76*70a7ec85SAndroid Build Coastguard Worker } // namespace android::vintf
77