blob: 2e31ef1dcc2fe67c5951fd16301e34f0ab1a0e80 [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
Songchun Fan3c82a302019-11-29 14:23:45 -080019#include <utils/String16.h>
20
Songchun Fan3c82a302019-11-29 14:23:45 -080021using namespace std::literals;
22
23namespace android::os::incremental {
24
25static constexpr auto kVoldServiceName = "vold"sv;
Songchun Fan68645c42020-02-27 15:57:35 -080026static constexpr auto kDataLoaderManagerName = "dataloader_manager"sv;
Songchun Fan3c82a302019-11-29 14:23:45 -080027
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -080028RealServiceManager::RealServiceManager(sp<IServiceManager> serviceManager)
29 : mServiceManager(std::move(serviceManager)) {}
Songchun Fan3c82a302019-11-29 14:23:45 -080030
31template <class INTERFACE>
32sp<INTERFACE> RealServiceManager::getRealService(std::string_view serviceName) const {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -080033 sp<IBinder> binder =
34 mServiceManager->getService(String16(serviceName.data(), serviceName.size()));
35 if (!binder) {
36 return nullptr;
Songchun Fan3c82a302019-11-29 14:23:45 -080037 }
38 return interface_cast<INTERFACE>(binder);
39}
40
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -080041std::unique_ptr<VoldServiceWrapper> RealServiceManager::getVoldService() {
Songchun Fan3c82a302019-11-29 14:23:45 -080042 sp<os::IVold> vold = RealServiceManager::getRealService<os::IVold>(kVoldServiceName);
43 if (vold != 0) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -080044 return std::make_unique<RealVoldService>(vold);
Songchun Fan3c82a302019-11-29 14:23:45 -080045 }
46 return nullptr;
47}
48
Songchun Fan68645c42020-02-27 15:57:35 -080049std::unique_ptr<DataLoaderManagerWrapper> RealServiceManager::getDataLoaderManager() {
50 sp<IDataLoaderManager> manager =
51 RealServiceManager::getRealService<IDataLoaderManager>(kDataLoaderManagerName);
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -080052 if (manager) {
Songchun Fan68645c42020-02-27 15:57:35 -080053 return std::make_unique<RealDataLoaderManager>(manager);
Songchun Fan3c82a302019-11-29 14:23:45 -080054 }
55 return nullptr;
56}
57
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -080058std::unique_ptr<IncFsWrapper> RealServiceManager::getIncFs() {
59 return std::make_unique<RealIncFs>();
Songchun Fan3c82a302019-11-29 14:23:45 -080060}
61
62} // namespace android::os::incremental