1 /*
2 * Copyright (C) 2012 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 #define LOG_TAG "emulator PowerHAL"
18 #include <utils/Log.h>
19
20 #include <hardware/hardware.h>
21 #include <hardware/power.h>
22 #include <hardware/qemud.h>
23 #include <fcntl.h>
24 #include <errno.h>
25
26 static int qemud_fd;
27
power_qemu_init(struct power_module * module)28 static void power_qemu_init(struct power_module *module)
29 {
30 qemud_fd = qemud_channel_open("hw-control");
31
32 if (qemud_fd < 0)
33 ALOGE("Error connecting to qemud hw-control service\n");
34 }
35
power_qemu_set_interactive(struct power_module * module,int on)36 static void power_qemu_set_interactive(struct power_module *module, int on)
37 {
38 int r;
39
40 r = qemud_channel_send(qemud_fd, on ? "power:screen_state:wake"
41 : "power:screen_state:standby", -1);
42
43 if (r < 0)
44 ALOGE("Error sending power command to qemud hw-control service\n");
45 }
46
47 static struct hw_module_methods_t power_qemu_module_methods = {
48 .open = NULL,
49 };
50
51 struct power_module HAL_MODULE_INFO_SYM = {
52 .common = {
53 .tag = HARDWARE_MODULE_TAG,
54 .version_major = 1,
55 .version_minor = 0,
56 .id = POWER_HARDWARE_MODULE_ID,
57 .name = "Emulator Power HAL",
58 .author = "The Android Open Source Project",
59 .methods = &power_qemu_module_methods,
60 },
61
62 .init = power_qemu_init,
63 .setInteractive = power_qemu_set_interactive,
64 };
65