Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 1 | /* |
| 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 Mitchell | 2ed8bfa | 2021-01-08 13:34:28 -0800 | [diff] [blame^] | 21 | #include <android/os/BnIdmap2.h> |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 22 | #include <binder/BinderService.h> |
Ryan Mitchell | 2ed8bfa | 2021-01-08 13:34:28 -0800 | [diff] [blame^] | 23 | #include <idmap2/ResourceContainer.h> |
| 24 | #include <idmap2/Result.h> |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 25 | |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 26 | #include <string> |
| 27 | |
Mårten Kongstad | 0eba72a | 2018-11-29 08:23:14 +0100 | [diff] [blame] | 28 | namespace android::os { |
| 29 | |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 30 | class Idmap2Service : public BinderService<Idmap2Service>, public BnIdmap2 { |
| 31 | public: |
| 32 | static char const* getServiceName() { |
| 33 | return "idmap"; |
| 34 | } |
| 35 | |
Ryan Mitchell | 2ed8bfa | 2021-01-08 13:34:28 -0800 | [diff] [blame^] | 36 | binder::Status getIdmapPath(const std::string& overlay_path, int32_t user_id, |
Mårten Kongstad | cb85d9c | 2018-12-21 08:28:40 +0100 | [diff] [blame] | 37 | std::string* _aidl_return) override; |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 38 | |
Ryan Mitchell | 2ed8bfa | 2021-01-08 13:34:28 -0800 | [diff] [blame^] | 39 | binder::Status removeIdmap(const std::string& overlay_path, int32_t user_id, |
Mårten Kongstad | cb85d9c | 2018-12-21 08:28:40 +0100 | [diff] [blame] | 40 | bool* _aidl_return) override; |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 41 | |
Ryan Mitchell | 2ed8bfa | 2021-01-08 13:34:28 -0800 | [diff] [blame^] | 42 | binder::Status verifyIdmap(const std::string& target_path, const std::string& overlay_path, |
| 43 | int32_t fulfilled_policies, bool enforce_overlayable, int32_t user_id, |
Mårten Kongstad | cb85d9c | 2018-12-21 08:28:40 +0100 | [diff] [blame] | 44 | bool* _aidl_return) override; |
Mårten Kongstad | ef0695d | 2018-12-04 14:36:48 +0100 | [diff] [blame] | 45 | |
Ryan Mitchell | 2ed8bfa | 2021-01-08 13:34:28 -0800 | [diff] [blame^] | 46 | binder::Status createIdmap(const std::string& target_path, const std::string& overlay_path, |
| 47 | int32_t fulfilled_policies, bool enforce_overlayable, int32_t user_id, |
Jooyung Han | 16bac85 | 2020-08-10 12:53:14 +0900 | [diff] [blame] | 48 | std::optional<std::string>* _aidl_return) override; |
Ryan Mitchell | 7d53f19 | 2020-04-24 17:45:25 -0700 | [diff] [blame] | 49 | |
| 50 | private: |
Ryan Mitchell | 2ed8bfa | 2021-01-08 13:34:28 -0800 | [diff] [blame^] | 51 | // idmap2d is killed after a period of inactivity, so any information stored on this class should |
| 52 | // be able to be recalculated if idmap2 dies and restarts. |
| 53 | std::unique_ptr<idmap2::TargetResourceContainer> framework_apk_cache_; |
| 54 | |
| 55 | template <typename T> |
| 56 | using MaybeUniquePtr = std::variant<std::unique_ptr<T>, T*>; |
| 57 | |
| 58 | using TargetResourceContainerPtr = MaybeUniquePtr<idmap2::TargetResourceContainer>; |
| 59 | idmap2::Result<TargetResourceContainerPtr> GetTargetContainer(const std::string& target_path); |
| 60 | |
| 61 | template <typename T> |
| 62 | WARN_UNUSED static const T* GetPointer(const MaybeUniquePtr<T>& ptr); |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 63 | }; |
Mårten Kongstad | 0eba72a | 2018-11-29 08:23:14 +0100 | [diff] [blame] | 64 | |
Ryan Mitchell | 2ed8bfa | 2021-01-08 13:34:28 -0800 | [diff] [blame^] | 65 | template <typename T> |
| 66 | const T* Idmap2Service::GetPointer(const MaybeUniquePtr<T>& ptr) { |
| 67 | auto u = std::get_if<T*>(&ptr); |
| 68 | if (u != nullptr) { |
| 69 | return *u; |
| 70 | } |
| 71 | return std::get<std::unique_ptr<T>>(ptr).get(); |
| 72 | } |
| 73 | |
Mårten Kongstad | 0eba72a | 2018-11-29 08:23:14 +0100 | [diff] [blame] | 74 | } // namespace android::os |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 75 | |
| 76 | #endif // IDMAP2_IDMAP2D_IDMAP2SERVICE_H_ |