blob: 4d16ff39884b66336619bc28a97573cc77591ecd [file] [log] [blame]
Mårten Kongstad02751232018-04-27 13:16:32 +02001/*
2 * Copyright (C) 2018 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#ifndef IDMAP2_IDMAP2D_IDMAP2SERVICE_H_
18#define IDMAP2_IDMAP2D_IDMAP2SERVICE_H_
19
20#include <android-base/unique_fd.h>
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -080021#include <android/os/BnIdmap2.h>
Ryan Mitchell6a2ca782021-01-19 13:51:15 -080022#include <android/os/FabricatedOverlayInfo.h>
Mårten Kongstad02751232018-04-27 13:16:32 +020023#include <binder/BinderService.h>
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -080024#include <idmap2/ResourceContainer.h>
25#include <idmap2/Result.h>
Mårten Kongstad02751232018-04-27 13:16:32 +020026
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -070027#include <string>
28
Mårten Kongstad0eba72a2018-11-29 08:23:14 +010029namespace android::os {
30
Mårten Kongstad02751232018-04-27 13:16:32 +020031class Idmap2Service : public BinderService<Idmap2Service>, public BnIdmap2 {
32 public:
33 static char const* getServiceName() {
34 return "idmap";
35 }
36
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -080037 binder::Status getIdmapPath(const std::string& overlay_path, int32_t user_id,
Mårten Kongstadcb85d9c2018-12-21 08:28:40 +010038 std::string* _aidl_return) override;
Mårten Kongstad02751232018-04-27 13:16:32 +020039
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -080040 binder::Status removeIdmap(const std::string& overlay_path, int32_t user_id,
Mårten Kongstadcb85d9c2018-12-21 08:28:40 +010041 bool* _aidl_return) override;
Mårten Kongstad02751232018-04-27 13:16:32 +020042
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -080043 binder::Status verifyIdmap(const std::string& target_path, const std::string& overlay_path,
Ryan Mitchell6a2ca782021-01-19 13:51:15 -080044 const std::string& overlay_name, int32_t fulfilled_policies,
45 bool enforce_overlayable, int32_t user_id,
Mårten Kongstadcb85d9c2018-12-21 08:28:40 +010046 bool* _aidl_return) override;
Mårten Kongstadef0695d2018-12-04 14:36:48 +010047
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -080048 binder::Status createIdmap(const std::string& target_path, const std::string& overlay_path,
Ryan Mitchell6a2ca782021-01-19 13:51:15 -080049 const std::string& overlay_name, int32_t fulfilled_policies,
50 bool enforce_overlayable, int32_t user_id,
Jooyung Han16bac852020-08-10 12:53:14 +090051 std::optional<std::string>* _aidl_return) override;
Ryan Mitchell7d53f192020-04-24 17:45:25 -070052
Ryan Mitchell6a2ca782021-01-19 13:51:15 -080053 binder::Status createFabricatedOverlay(
54 const os::FabricatedOverlayInternal& overlay,
55 std::optional<os::FabricatedOverlayInfo>* _aidl_return) override;
56
57 binder::Status deleteFabricatedOverlay(const std::string& overlay_path,
58 bool* _aidl_return) override;
59
60 binder::Status getFabricatedOverlayInfos(
61 std::vector<os::FabricatedOverlayInfo>* _aidl_return) override;
62
Ryan Mitchell7d53f192020-04-24 17:45:25 -070063 private:
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -080064 // idmap2d is killed after a period of inactivity, so any information stored on this class should
65 // be able to be recalculated if idmap2 dies and restarts.
66 std::unique_ptr<idmap2::TargetResourceContainer> framework_apk_cache_;
67
Ryan Mitchell6a2ca782021-01-19 13:51:15 -080068 std::vector<os::FabricatedOverlayInfo> fabricated_overlays_;
69
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -080070 template <typename T>
71 using MaybeUniquePtr = std::variant<std::unique_ptr<T>, T*>;
72
73 using TargetResourceContainerPtr = MaybeUniquePtr<idmap2::TargetResourceContainer>;
74 idmap2::Result<TargetResourceContainerPtr> GetTargetContainer(const std::string& target_path);
75
76 template <typename T>
77 WARN_UNUSED static const T* GetPointer(const MaybeUniquePtr<T>& ptr);
Mårten Kongstad02751232018-04-27 13:16:32 +020078};
Mårten Kongstad0eba72a2018-11-29 08:23:14 +010079
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -080080template <typename T>
81const T* Idmap2Service::GetPointer(const MaybeUniquePtr<T>& ptr) {
82 auto u = std::get_if<T*>(&ptr);
83 if (u != nullptr) {
84 return *u;
85 }
86 return std::get<std::unique_ptr<T>>(ptr).get();
87}
88
Mårten Kongstad0eba72a2018-11-29 08:23:14 +010089} // namespace android::os
Mårten Kongstad02751232018-04-27 13:16:32 +020090
91#endif // IDMAP2_IDMAP2D_IDMAP2SERVICE_H_