blob: 487b95b2983f300368720b50703f5fe155ba681c [file] [log] [blame]
Lais Andradec86c1d22020-03-30 20:17:42 +01001/*
2 * Copyright (C) 2020 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_POWERHALLOADER_H
18#define ANDROID_POWERHALLOADER_H
19
20#include <android-base/thread_annotations.h>
21
22#include <android/hardware/power/1.1/IPower.h>
23#include <android/hardware/power/IPower.h>
24
25using IPowerV1_0 = android::hardware::power::V1_0::IPower;
26using IPowerV1_1 = android::hardware::power::V1_1::IPower;
27using IPowerAidl = android::hardware::power::IPower;
28
29namespace android {
30
31// Loads available Power HAL services.
32class PowerHalLoader {
33public:
34 static void unloadAll();
35 static sp<IPowerAidl> loadAidl();
36 static sp<IPowerV1_0> loadHidlV1_0();
37 static sp<IPowerV1_1> loadHidlV1_1();
38
39private:
40 static std::mutex gHalMutex;
41 static sp<IPowerAidl> gHalAidl GUARDED_BY(gHalMutex);
42 static sp<IPowerV1_0> gHalHidlV1_0 GUARDED_BY(gHalMutex);
43 static sp<IPowerV1_1> gHalHidlV1_1 GUARDED_BY(gHalMutex);
44
45 static sp<IPowerV1_0> loadHidlV1_0Locked() EXCLUSIVE_LOCKS_REQUIRED(gHalMutex);
46
47 PowerHalLoader() = default;
48};
49
50} // namespace android
51
52#endif // ANDROID_POWERHALLOADER_H