blob: a79b26ae4fb33024aa060b3970191425312a4f7b [file] [log] [blame]
Songchun Fan3c82a302019-11-29 14:23:45 -08001/*
2 * Copyright (C) 2019 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 "ServiceWrappers.h"
18
19#include <android-base/strings.h>
20#include <android-base/unique_fd.h>
21#include <binder/IServiceManager.h>
22#include <utils/String16.h>
23
24#include <string>
25#include <string_view>
26
27using namespace std::literals;
28
29namespace android::os::incremental {
30
31static constexpr auto kVoldServiceName = "vold"sv;
32static constexpr auto kIncrementalManagerName = "incremental"sv;
33
34RealServiceManager::RealServiceManager(const sp<IServiceManager>& serviceManager)
35 : mServiceManager(serviceManager) {}
36
37template <class INTERFACE>
38sp<INTERFACE> RealServiceManager::getRealService(std::string_view serviceName) const {
39 sp<IBinder> binder = mServiceManager->getService(String16(serviceName.data()));
40 if (binder == 0) {
41 return 0;
42 }
43 return interface_cast<INTERFACE>(binder);
44}
45
46std::shared_ptr<VoldServiceWrapper> RealServiceManager::getVoldService() const {
47 sp<os::IVold> vold = RealServiceManager::getRealService<os::IVold>(kVoldServiceName);
48 if (vold != 0) {
49 return std::make_shared<RealVoldService>(vold);
50 }
51 return nullptr;
52}
53
54std::shared_ptr<IncrementalManagerWrapper> RealServiceManager::getIncrementalManager() const {
55 sp<IIncrementalManager> manager =
56 RealServiceManager::getRealService<IIncrementalManager>(kIncrementalManagerName);
57 if (manager != 0) {
58 return std::make_shared<RealIncrementalManager>(manager);
59 }
60 return nullptr;
61}
62
63std::shared_ptr<IncFsWrapper> RealServiceManager::getIncFs() const {
64 return std::make_shared<RealIncFs>();
65}
66
67} // namespace android::os::incremental