Steven Moreland | 5d5ef7f | 2016-10-20 19:19:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 ANDROID_HARDWARE_ISERVICE_MANAGER_H |
| 18 | #define ANDROID_HARDWARE_ISERVICE_MANAGER_H |
| 19 | |
Steven Moreland | cbefd35 | 2017-01-23 20:29:05 -0800 | [diff] [blame] | 20 | #include <string> |
Steven Moreland | 92b247c | 2019-08-21 14:53:11 -0700 | [diff] [blame] | 21 | #include <vector> |
Martijn Coenen | 86c3abb | 2017-10-24 09:33:28 +0200 | [diff] [blame] | 22 | |
| 23 | #include <android/hidl/base/1.0/IBase.h> |
Steven Moreland | 5d5ef7f | 2016-10-20 19:19:55 -0700 | [diff] [blame] | 24 | #include <utils/StrongPointer.h> |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | namespace hidl { |
| 29 | namespace manager { |
| 30 | namespace V1_0 { |
| 31 | struct IServiceManager; |
Bernhard Rosenkränzer | 0c28fd2 | 2018-06-04 16:01:47 +0200 | [diff] [blame] | 32 | } // namespace V1_0 |
Steven Moreland | 2a2678e | 2017-07-21 18:07:38 -0700 | [diff] [blame] | 33 | namespace V1_1 { |
Steven Moreland | 8990969 | 2018-05-30 14:11:19 -0700 | [diff] [blame] | 34 | struct IServiceManager; |
Bernhard Rosenkränzer | 0c28fd2 | 2018-06-04 16:01:47 +0200 | [diff] [blame] | 35 | } // namespace V1_1 |
Steven Moreland | 8990969 | 2018-05-30 14:11:19 -0700 | [diff] [blame] | 36 | namespace V1_2 { |
| 37 | struct IServiceManager; |
Bernhard Rosenkränzer | 0c28fd2 | 2018-06-04 16:01:47 +0200 | [diff] [blame] | 38 | } // namespace V1_2 |
| 39 | } // namespace manager |
| 40 | } // namespace hidl |
Steven Moreland | 5d5ef7f | 2016-10-20 19:19:55 -0700 | [diff] [blame] | 41 | |
| 42 | namespace hardware { |
| 43 | |
Steven Moreland | cbefd35 | 2017-01-23 20:29:05 -0800 | [diff] [blame] | 44 | namespace details { |
Steven Moreland | cd4dbdf | 2017-04-07 20:31:22 -0700 | [diff] [blame] | 45 | |
Steven Moreland | 0771d8a | 2018-05-09 13:29:14 -0700 | [diff] [blame] | 46 | // Will not attempt to start a lazy HAL |
Steven Moreland | cd4dbdf | 2017-04-07 20:31:22 -0700 | [diff] [blame] | 47 | // e.x.: android.hardware.foo@1.0::IFoo, default |
Steven Moreland | cbefd35 | 2017-01-23 20:29:05 -0800 | [diff] [blame] | 48 | void waitForHwService(const std::string &interface, const std::string &instanceName); |
Steven Moreland | 519306f | 2017-06-06 17:14:12 -0700 | [diff] [blame] | 49 | |
Steven Moreland | b939e7e | 2020-07-08 01:04:23 +0000 | [diff] [blame] | 50 | // Only works on userdebug/eng builds. This allows getService to bypass the |
| 51 | // VINTF manifest for testing only. |
| 52 | void setTrebleTestingOverride(bool testingOverride); |
| 53 | |
Steven Moreland | 519306f | 2017-06-06 17:14:12 -0700 | [diff] [blame] | 54 | void preloadPassthroughService(const std::string &descriptor); |
Martijn Coenen | 86c3abb | 2017-10-24 09:33:28 +0200 | [diff] [blame] | 55 | |
| 56 | // Returns a service with the following constraints: |
Steven Moreland | e5f8f7c | 2021-03-29 17:07:27 +0000 | [diff] [blame^] | 57 | // - retry => service is waited for and returned if it is declared in the |
| 58 | // manifest AND it is available in this process (if errors indicate an |
| 59 | // sepolicy denial, then this will return - TODO(b/28321379) more precise |
| 60 | // errors to handle more cases) |
Martijn Coenen | 86c3abb | 2017-10-24 09:33:28 +0200 | [diff] [blame] | 61 | // - getStub => internal only. Forces to get the unwrapped (no BsFoo) if available. |
| 62 | // TODO(b/65843592) |
| 63 | // If the service is a remote service, this function returns BpBase. If the service is |
| 64 | // a passthrough service, this function returns the appropriately wrapped Bs child object. |
| 65 | sp<::android::hidl::base::V1_0::IBase> getRawServiceInternal(const std::string& descriptor, |
| 66 | const std::string& instance, |
| 67 | bool retry, bool getStub); |
Steven Moreland | bb9eb2a | 2018-10-11 12:10:01 -0700 | [diff] [blame] | 68 | |
| 69 | status_t registerAsServiceInternal(const sp<::android::hidl::base::V1_0::IBase>& service, |
| 70 | const std::string& name); |
| 71 | } // namespace details |
Steven Moreland | cbefd35 | 2017-01-23 20:29:05 -0800 | [diff] [blame] | 72 | |
Steven Moreland | 519306f | 2017-06-06 17:14:12 -0700 | [diff] [blame] | 73 | // These functions are for internal use by hidl. If you want to get ahold |
| 74 | // of an interface, the best way to do this is by calling IFoo::getService() |
| 75 | sp<::android::hidl::manager::V1_0::IServiceManager> defaultServiceManager(); |
Steven Moreland | 2a2678e | 2017-07-21 18:07:38 -0700 | [diff] [blame] | 76 | sp<::android::hidl::manager::V1_1::IServiceManager> defaultServiceManager1_1(); |
Steven Moreland | 8990969 | 2018-05-30 14:11:19 -0700 | [diff] [blame] | 77 | sp<::android::hidl::manager::V1_2::IServiceManager> defaultServiceManager1_2(); |
Steven Moreland | 519306f | 2017-06-06 17:14:12 -0700 | [diff] [blame] | 78 | sp<::android::hidl::manager::V1_0::IServiceManager> getPassthroughServiceManager(); |
Steven Moreland | 2a2678e | 2017-07-21 18:07:38 -0700 | [diff] [blame] | 79 | sp<::android::hidl::manager::V1_1::IServiceManager> getPassthroughServiceManager1_1(); |
Steven Moreland | 519306f | 2017-06-06 17:14:12 -0700 | [diff] [blame] | 80 | |
| 81 | /** |
Steven Moreland | 92b247c | 2019-08-21 14:53:11 -0700 | [diff] [blame] | 82 | * Given a descriptor (e.g. from IFoo::descriptor), return a list of all instance names |
| 83 | * on a device (e.g. the VINTF manifest). These HALs may not be currently running, but |
| 84 | * the expectation is that if they aren't running, they should start as lazy HALs. |
| 85 | * So, getService should return for each of these instance names. |
| 86 | */ |
| 87 | std::vector<std::string> getAllHalInstanceNames(const std::string& descriptor); |
| 88 | |
| 89 | /** |
Steven Moreland | 519306f | 2017-06-06 17:14:12 -0700 | [diff] [blame] | 90 | * Given a service that is in passthrough mode, this function will go ahead and load the |
| 91 | * required passthrough module library (but not call HIDL_FETCH_I* functions to instantiate it). |
| 92 | * |
| 93 | * E.x.: preloadPassthroughService<IFoo>(); |
| 94 | */ |
| 95 | template<typename I> |
| 96 | static inline void preloadPassthroughService() { |
| 97 | details::preloadPassthroughService(I::descriptor); |
| 98 | } |
| 99 | |
Bernhard Rosenkränzer | 0c28fd2 | 2018-06-04 16:01:47 +0200 | [diff] [blame] | 100 | } // namespace hardware |
| 101 | } // namespace android |
Steven Moreland | 5d5ef7f | 2016-10-20 19:19:55 -0700 | [diff] [blame] | 102 | |
| 103 | #endif // ANDROID_HARDWARE_ISERVICE_MANAGER_H |
| 104 | |