blob: cc44e1ec4e6d5ef65fa69a49e5bfca451920b037 [file] [log] [blame]
Yifan Hong37535882021-11-29 18:07:21 -08001/*
2 * Copyright (C) 2021 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 <vintf/VintfObjectRecovery.h>
18
19#include "VintfObjectUtils.h"
20#include "constants-private.h"
21
22using std::placeholders::_1;
23using std::placeholders::_2;
24
25namespace android::vintf {
26
27using details::Get;
28using details::kSystemManifest;
29using details::kSystemManifestFragmentDir;
30
31std::shared_ptr<VintfObjectRecovery> VintfObjectRecovery::GetInstance() {
32 static details::LockedSharedPtr<VintfObjectRecovery> sInstance{};
33 std::unique_lock<std::mutex> lock(sInstance.mutex);
34 if (sInstance.object == nullptr) {
35 std::unique_ptr<VintfObjectRecovery> uptr =
36 VintfObjectRecovery::Builder().build<VintfObjectRecovery>();
37 sInstance.object = std::shared_ptr<VintfObjectRecovery>(uptr.release());
38 }
39 return sInstance.object;
40}
41
42std::shared_ptr<const HalManifest> VintfObjectRecovery::getRecoveryHalManifest() {
43 return Get(__func__, &mRecoveryManifest,
44 std::bind(&VintfObjectRecovery::fetchRecoveryHalManifest, this, _1, _2));
45}
46
47// All manifests are installed under /system/etc/vintf.
48// There may be mixed framework and device manifests under that directory. Treat them all
49// as device manifest fragments.
50// Priority:
51// 1. /system/etc/vintf/manifest.xml
52// + /system/etc/vintf/manifest/*.xml if they exist
53status_t VintfObjectRecovery::fetchRecoveryHalManifest(HalManifest* out, std::string* error) {
54 HalManifest manifest;
55 status_t systemEtcStatus = fetchOneHalManifest(kSystemManifest, &manifest, error);
56 if (systemEtcStatus != OK && systemEtcStatus != NAME_NOT_FOUND) {
57 return systemEtcStatus;
58 }
59 // Merge |manifest| to |out| only if the main manifest is found.
60 if (systemEtcStatus == OK) {
61 *out = std::move(manifest);
62 }
63 out->setType(SchemaType::DEVICE);
64 status_t fragmentStatus =
65 addDirectoryManifests(kSystemManifestFragmentDir, out, true /* forceSchemaType */, error);
66 if (fragmentStatus != OK) {
67 return fragmentStatus;
68 }
69 return OK;
70}
71
72VintfObjectRecovery::Builder::Builder()
73 : VintfObjectBuilder(std::unique_ptr<VintfObject>(new VintfObjectRecovery())) {}
74
75} // namespace android::vintf