David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 The Chromium OS Authors. All rights reserved. |
| 3 | * Use of this source code is governed by a BSD-style license that can be |
| 4 | * found in the LICENSE file. |
| 5 | */ |
| 6 | |
Dominik Behr | f50c98f | 2016-03-31 14:05:29 -0700 | [diff] [blame] | 7 | #if DBUS |
| 8 | #include <dbus/dbus.h> |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 9 | #include <stdlib.h> |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 10 | |
Stéphane Marchesin | 62561a1 | 2015-12-11 17:32:37 -0800 | [diff] [blame] | 11 | #include "dbus.h" |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 12 | #include "dbus_interface.h" |
| 13 | #include "image.h" |
Dominik Behr | 46c567f | 2016-03-08 15:11:48 -0800 | [diff] [blame] | 14 | #include "main.h" |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 15 | #include "term.h" |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 16 | #include "util.h" |
| 17 | |
Dominik Behr | 5f6742f | 2016-03-10 18:03:54 -0800 | [diff] [blame] | 18 | #define DBUS_WAIT_DELAY_US (50000) |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 19 | #define DBUS_DEFAULT_DELAY 3000 |
Dominik Behr | 5f6742f | 2016-03-10 18:03:54 -0800 | [diff] [blame] | 20 | #define DBUS_INIT_TIMEOUT_MS (60*1000) |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 21 | |
Dominik Behr | 797a383 | 2016-01-11 15:53:11 -0800 | [diff] [blame] | 22 | typedef struct _dbus_t dbus_t; |
| 23 | |
Dominik Behr | 46c567f | 2016-03-08 15:11:48 -0800 | [diff] [blame] | 24 | static void (*login_prompt_visible_callback)(void*) = NULL; |
| 25 | static void* login_prompt_visible_callback_userptr = NULL; |
Dominik Behr | 1883c04 | 2016-04-27 12:31:02 -0700 | [diff] [blame] | 26 | static void (*suspend_done_callback)(void*) = NULL; |
| 27 | static void* suspend_done_callback_userptr = NULL; |
Dominik Behr | 46c567f | 2016-03-08 15:11:48 -0800 | [diff] [blame] | 28 | static bool chrome_is_already_up = false; |
Dominik Behr | 5f6742f | 2016-03-10 18:03:54 -0800 | [diff] [blame] | 29 | static bool dbus_connect_fail = false; |
| 30 | static int64_t dbus_connect_fail_time; |
| 31 | static bool dbus_first_init = true; |
| 32 | static int64_t dbus_first_init_time; |
Dominik Behr | 46c567f | 2016-03-08 15:11:48 -0800 | [diff] [blame] | 33 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 34 | struct _dbus_t { |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 35 | DBusConnection* conn; |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 36 | DBusWatch* watch; |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 37 | int fd; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
Dominik Behr | 797a383 | 2016-01-11 15:53:11 -0800 | [diff] [blame] | 40 | static dbus_t *dbus = NULL; |
| 41 | |
Stéphane Marchesin | 8fc1352 | 2015-12-14 17:02:28 -0800 | [diff] [blame] | 42 | static void frecon_dbus_unregister(DBusConnection* connection, void* user_data) |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 43 | { |
| 44 | } |
| 45 | |
Stéphane Marchesin | 8fc1352 | 2015-12-14 17:02:28 -0800 | [diff] [blame] | 46 | static DBusHandlerResult frecon_dbus_message_handler(DBusConnection* connection, |
| 47 | DBusMessage* message, |
| 48 | void* user_data) |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 49 | { |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 50 | return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | static DBusObjectPathVTable |
| 54 | frecon_vtable = { |
Stéphane Marchesin | af9e9ff | 2015-12-11 17:49:12 -0800 | [diff] [blame] | 55 | frecon_dbus_unregister, |
| 56 | frecon_dbus_message_handler, |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 57 | NULL |
| 58 | }; |
| 59 | |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 60 | static dbus_bool_t add_watch(DBusWatch* w, void* data) |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 61 | { |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 62 | dbus_t* dbus = (dbus_t*)data; |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 63 | dbus->watch = w; |
| 64 | |
| 65 | return TRUE; |
| 66 | } |
| 67 | |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 68 | static void remove_watch(DBusWatch* w, void* data) |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 69 | { |
| 70 | } |
| 71 | |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 72 | static void toggle_watch(DBusWatch* w, void* data) |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 73 | { |
| 74 | } |
| 75 | |
Dominik Behr | 46c567f | 2016-03-08 15:11:48 -0800 | [diff] [blame] | 76 | static DBusHandlerResult handle_login_prompt_visible(DBusMessage* message) |
| 77 | { |
| 78 | if (login_prompt_visible_callback) { |
| 79 | login_prompt_visible_callback(login_prompt_visible_callback_userptr); |
| 80 | login_prompt_visible_callback = NULL; |
| 81 | login_prompt_visible_callback_userptr = NULL; |
| 82 | } |
| 83 | chrome_is_already_up = true; |
| 84 | |
| 85 | return DBUS_HANDLER_RESULT_HANDLED; |
| 86 | } |
| 87 | |
Dominik Behr | 1883c04 | 2016-04-27 12:31:02 -0700 | [diff] [blame] | 88 | static DBusHandlerResult handle_suspend_done(DBusMessage* message) |
| 89 | { |
| 90 | if (suspend_done_callback) |
| 91 | suspend_done_callback(suspend_done_callback_userptr); |
| 92 | |
| 93 | return DBUS_HANDLER_RESULT_HANDLED; |
| 94 | } |
| 95 | |
Dominik Behr | 46c567f | 2016-03-08 15:11:48 -0800 | [diff] [blame] | 96 | static DBusHandlerResult frecon_dbus_message_filter(DBusConnection* connection, |
| 97 | DBusMessage* message, |
| 98 | void* user_data) |
| 99 | { |
| 100 | if (dbus_message_is_signal(message, |
Dominik Behr | 5f6742f | 2016-03-10 18:03:54 -0800 | [diff] [blame] | 101 | kSessionManagerInterface, kLoginPromptVisibleSignal)) |
Dominik Behr | 46c567f | 2016-03-08 15:11:48 -0800 | [diff] [blame] | 102 | return handle_login_prompt_visible(message); |
Dominik Behr | 1883c04 | 2016-04-27 12:31:02 -0700 | [diff] [blame] | 103 | else if (dbus_message_is_signal(message, |
| 104 | kPowerManagerInterface, kSuspendDoneSignal)) |
| 105 | return handle_suspend_done(message); |
Dominik Behr | 46c567f | 2016-03-08 15:11:48 -0800 | [diff] [blame] | 106 | |
| 107 | return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
| 108 | } |
| 109 | |
Dominik Behr | 797a383 | 2016-01-11 15:53:11 -0800 | [diff] [blame] | 110 | bool dbus_is_initialized(void) |
| 111 | { |
| 112 | return !!dbus; |
| 113 | } |
| 114 | |
| 115 | bool dbus_init() |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 116 | { |
| 117 | dbus_t* new_dbus; |
| 118 | DBusError err; |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 119 | int result; |
| 120 | dbus_bool_t stat; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 121 | |
Dominik Behr | 5f6742f | 2016-03-10 18:03:54 -0800 | [diff] [blame] | 122 | if (dbus_first_init) { |
| 123 | dbus_first_init = false; |
| 124 | dbus_first_init_time = get_monotonic_time_ms(); |
| 125 | } |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 126 | dbus_error_init(&err); |
| 127 | |
| 128 | new_dbus = (dbus_t*)calloc(1, sizeof(*new_dbus)); |
Stéphane Marchesin | c236e0b | 2015-12-14 15:29:15 -0800 | [diff] [blame] | 129 | |
| 130 | if (!new_dbus) |
Dominik Behr | 797a383 | 2016-01-11 15:53:11 -0800 | [diff] [blame] | 131 | return false; |
Stéphane Marchesin | c236e0b | 2015-12-14 15:29:15 -0800 | [diff] [blame] | 132 | |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 133 | new_dbus->fd = -1; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 134 | |
| 135 | new_dbus->conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err); |
| 136 | if (dbus_error_is_set(&err)) { |
Dominik Behr | 5f6742f | 2016-03-10 18:03:54 -0800 | [diff] [blame] | 137 | if (!dbus_connect_fail) { |
| 138 | LOG(ERROR, "Cannot get DBUS connection"); |
| 139 | dbus_connect_fail = true; |
| 140 | dbus_connect_fail_time = get_monotonic_time_ms(); |
| 141 | } |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 142 | free(new_dbus); |
Dominik Behr | 797a383 | 2016-01-11 15:53:11 -0800 | [diff] [blame] | 143 | return false; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Dominik Behr | 5f6742f | 2016-03-10 18:03:54 -0800 | [diff] [blame] | 146 | if (dbus_connect_fail) { |
| 147 | int64_t t = get_monotonic_time_ms() - dbus_connect_fail_time; |
| 148 | LOG(INFO, "DBUS connected after %.1f seconds", (float)t / 1000.0f); |
| 149 | } |
| 150 | |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 151 | result = dbus_bus_request_name(new_dbus->conn, kFreconDbusInterface, |
| 152 | DBUS_NAME_FLAG_DO_NOT_QUEUE, &err); |
| 153 | |
| 154 | if (result <= 0) { |
| 155 | LOG(ERROR, "Unable to get name for server"); |
| 156 | } |
| 157 | |
| 158 | stat = dbus_connection_register_object_path(new_dbus->conn, |
| 159 | kFreconDbusPath, |
| 160 | &frecon_vtable, |
| 161 | NULL); |
| 162 | |
| 163 | if (!stat) { |
| 164 | LOG(ERROR, "failed to register object path"); |
| 165 | } |
| 166 | |
Dominik Behr | 46c567f | 2016-03-08 15:11:48 -0800 | [diff] [blame] | 167 | dbus_bus_add_match(new_dbus->conn, kLoginPromptVisibleRule, &err); |
Dominik Behr | 1883c04 | 2016-04-27 12:31:02 -0700 | [diff] [blame] | 168 | dbus_bus_add_match(new_dbus->conn, kSuspendDoneRule, &err); |
Dominik Behr | 46c567f | 2016-03-08 15:11:48 -0800 | [diff] [blame] | 169 | |
| 170 | stat = dbus_connection_add_filter(new_dbus->conn, frecon_dbus_message_filter, NULL, NULL); |
| 171 | if (!stat) { |
| 172 | LOG(ERROR, "failed to add message filter"); |
| 173 | } |
| 174 | |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 175 | stat = dbus_connection_set_watch_functions(new_dbus->conn, |
| 176 | add_watch, remove_watch, toggle_watch, |
| 177 | new_dbus, NULL); |
| 178 | |
| 179 | if (!stat) { |
| 180 | LOG(ERROR, "Failed to set watch functions"); |
| 181 | } |
| 182 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 183 | dbus_connection_set_exit_on_disconnect(new_dbus->conn, FALSE); |
| 184 | |
Dominik Behr | 797a383 | 2016-01-11 15:53:11 -0800 | [diff] [blame] | 185 | dbus = new_dbus; |
| 186 | return true; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Dominik Behr | 5f6742f | 2016-03-10 18:03:54 -0800 | [diff] [blame] | 189 | bool dbus_init_wait() |
| 190 | { |
| 191 | while (!dbus_is_initialized()) { |
| 192 | if (!dbus_init()) { |
| 193 | int64_t t = get_monotonic_time_ms() - dbus_first_init_time; |
| 194 | if (t >= DBUS_INIT_TIMEOUT_MS) { |
| 195 | LOG(ERROR, "DBUS init failed after a timeout of %u sec", DBUS_INIT_TIMEOUT_MS/1000); |
| 196 | return false; |
| 197 | } |
| 198 | } |
| 199 | usleep(DBUS_WAIT_DELAY_US); |
| 200 | } |
| 201 | return true; |
| 202 | } |
| 203 | |
Dominik Behr | 797a383 | 2016-01-11 15:53:11 -0800 | [diff] [blame] | 204 | static bool dbus_method_call0(const char* service_name, |
| 205 | const char* service_path, |
| 206 | const char* service_interface, |
| 207 | const char* method) |
David Sodman | 003faed | 2014-11-03 09:02:10 -0800 | [diff] [blame] | 208 | { |
Dominik Behr | 797a383 | 2016-01-11 15:53:11 -0800 | [diff] [blame] | 209 | DBusMessage* msg = NULL; |
| 210 | if (!dbus) { |
| 211 | LOG(ERROR, "dbus not initialized"); |
| 212 | return false; |
| 213 | } |
David Sodman | 003faed | 2014-11-03 09:02:10 -0800 | [diff] [blame] | 214 | |
| 215 | msg = dbus_message_new_method_call(service_name, |
| 216 | service_path, service_interface, method); |
| 217 | |
| 218 | if (!msg) |
| 219 | return false; |
| 220 | |
| 221 | if (!dbus_connection_send_with_reply_and_block(dbus->conn, |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 222 | msg, DBUS_DEFAULT_DELAY, NULL)) { |
David Sodman | 003faed | 2014-11-03 09:02:10 -0800 | [diff] [blame] | 223 | dbus_message_unref(msg); |
| 224 | return false; |
| 225 | } |
| 226 | |
| 227 | dbus_connection_flush(dbus->conn); |
| 228 | dbus_message_unref(msg); |
| 229 | |
| 230 | return true; |
| 231 | } |
| 232 | |
Dominik Behr | 797a383 | 2016-01-11 15:53:11 -0800 | [diff] [blame] | 233 | static bool dbus_method_call1(const char* service_name, |
| 234 | const char* service_path, |
| 235 | const char* service_interface, |
| 236 | const char* method, int arg_type, void* param) |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 237 | { |
Dominik Behr | 797a383 | 2016-01-11 15:53:11 -0800 | [diff] [blame] | 238 | DBusMessage* msg = NULL; |
| 239 | if (!dbus) { |
| 240 | LOG(ERROR, "dbus not initialized"); |
| 241 | return false; |
| 242 | } |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 243 | |
| 244 | msg = dbus_message_new_method_call(service_name, |
| 245 | service_path, service_interface, method); |
| 246 | |
| 247 | if (!msg) |
| 248 | return false; |
| 249 | |
| 250 | if (!dbus_message_append_args(msg, |
David Sodman | 19e4f9d | 2015-03-10 11:11:09 -0700 | [diff] [blame] | 251 | arg_type, param, DBUS_TYPE_INVALID)) { |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 252 | dbus_message_unref(msg); |
| 253 | return false; |
| 254 | } |
| 255 | |
| 256 | if (!dbus_connection_send_with_reply_and_block(dbus->conn, |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 257 | msg, DBUS_DEFAULT_DELAY, NULL)) { |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 258 | dbus_message_unref(msg); |
| 259 | return false; |
| 260 | } |
| 261 | |
| 262 | dbus_connection_flush(dbus->conn); |
| 263 | dbus_message_unref(msg); |
| 264 | |
| 265 | return true; |
| 266 | } |
| 267 | |
Dominik Behr | 797a383 | 2016-01-11 15:53:11 -0800 | [diff] [blame] | 268 | void dbus_destroy(void) |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 269 | { |
| 270 | /* FIXME - not sure what the right counterpart to |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 271 | * dbus_bus_get() is, unref documentation is rather |
| 272 | * unclear. Not a big issue but it would be nice to |
| 273 | * clean up properly here |
| 274 | */ |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 275 | /* dbus_connection_unref(dbus->conn); */ |
Dominik Behr | 797a383 | 2016-01-11 15:53:11 -0800 | [diff] [blame] | 276 | if (dbus) { |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 277 | free(dbus); |
Dominik Behr | 797a383 | 2016-01-11 15:53:11 -0800 | [diff] [blame] | 278 | dbus = NULL; |
| 279 | } |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 280 | } |
| 281 | |
Dominik Behr | d711267 | 2016-01-20 16:59:34 -0800 | [diff] [blame] | 282 | void dbus_add_fds(fd_set* read_set, fd_set* exception_set, int *maxfd) |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 283 | { |
Dominik Behr | 797a383 | 2016-01-11 15:53:11 -0800 | [diff] [blame] | 284 | if (!dbus) |
Dominik Behr | d711267 | 2016-01-20 16:59:34 -0800 | [diff] [blame] | 285 | return; |
Dominik Behr | 797a383 | 2016-01-11 15:53:11 -0800 | [diff] [blame] | 286 | |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 287 | if (dbus->fd < 0) |
| 288 | dbus->fd = dbus_watch_get_unix_fd(dbus->watch); |
| 289 | |
| 290 | if (dbus->fd >= 0) { |
| 291 | FD_SET(dbus->fd, read_set); |
| 292 | FD_SET(dbus->fd, exception_set); |
| 293 | } |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 294 | |
Dominik Behr | d711267 | 2016-01-20 16:59:34 -0800 | [diff] [blame] | 295 | if (dbus->fd > *maxfd) |
| 296 | *maxfd = dbus->fd; |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 297 | } |
| 298 | |
Dominik Behr | 797a383 | 2016-01-11 15:53:11 -0800 | [diff] [blame] | 299 | void dbus_dispatch_io(void) |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 300 | { |
Dominik Behr | 797a383 | 2016-01-11 15:53:11 -0800 | [diff] [blame] | 301 | if (!dbus) |
| 302 | return; |
| 303 | |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 304 | dbus_watch_handle(dbus->watch, DBUS_WATCH_READABLE); |
| 305 | while (dbus_connection_get_dispatch_status(dbus->conn) |
| 306 | == DBUS_DISPATCH_DATA_REMAINS) { |
| 307 | dbus_connection_dispatch(dbus->conn); |
| 308 | } |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 309 | } |
Dominik Behr | 797a383 | 2016-01-11 15:53:11 -0800 | [diff] [blame] | 310 | |
| 311 | void dbus_report_user_activity(int activity_type) |
| 312 | { |
| 313 | dbus_bool_t allow_off = false; |
| 314 | if (!dbus) |
| 315 | return; |
| 316 | |
| 317 | dbus_method_call1(kPowerManagerServiceName, |
| 318 | kPowerManagerServicePath, |
| 319 | kPowerManagerInterface, |
| 320 | kHandleUserActivityMethod, |
| 321 | DBUS_TYPE_INT32, &activity_type); |
| 322 | |
| 323 | switch (activity_type) { |
| 324 | case USER_ACTIVITY_BRIGHTNESS_UP_KEY_PRESS: |
| 325 | (void)dbus_method_call0(kPowerManagerServiceName, |
| 326 | kPowerManagerServicePath, |
| 327 | kPowerManagerInterface, |
| 328 | kIncreaseScreenBrightnessMethod); |
| 329 | break; |
| 330 | case USER_ACTIVITY_BRIGHTNESS_DOWN_KEY_PRESS: |
| 331 | /* |
| 332 | * Shouldn't allow the screen to go |
| 333 | * completely off while frecon is active |
| 334 | * so passing false to allow_off |
| 335 | */ |
| 336 | (void)dbus_method_call1(kPowerManagerServiceName, |
| 337 | kPowerManagerServicePath, |
| 338 | kPowerManagerInterface, |
| 339 | kDecreaseScreenBrightnessMethod, |
| 340 | DBUS_TYPE_BOOLEAN, &allow_off); |
| 341 | break; |
| 342 | } |
| 343 | } |
| 344 | |
Dominik Behr | 46c567f | 2016-03-08 15:11:48 -0800 | [diff] [blame] | 345 | /* |
| 346 | * tell Chrome to take ownership of the display (DRM master) |
| 347 | */ |
Dominik Behr | 797a383 | 2016-01-11 15:53:11 -0800 | [diff] [blame] | 348 | void dbus_take_display_ownership(void) |
| 349 | { |
| 350 | if (!dbus) |
| 351 | return; |
| 352 | (void)dbus_method_call0(kLibCrosServiceName, |
| 353 | kLibCrosServicePath, |
| 354 | kLibCrosServiceInterface, |
| 355 | kTakeDisplayOwnership); |
| 356 | } |
| 357 | |
Dominik Behr | 46c567f | 2016-03-08 15:11:48 -0800 | [diff] [blame] | 358 | /* |
| 359 | * ask Chrome to give up display ownership (DRM master) |
| 360 | */ |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 361 | bool dbus_release_display_ownership(void) |
Dominik Behr | 797a383 | 2016-01-11 15:53:11 -0800 | [diff] [blame] | 362 | { |
| 363 | if (!dbus) |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 364 | return true; |
| 365 | return dbus_method_call0(kLibCrosServiceName, |
| 366 | kLibCrosServicePath, |
| 367 | kLibCrosServiceInterface, |
| 368 | kReleaseDisplayOwnership); |
Dominik Behr | 797a383 | 2016-01-11 15:53:11 -0800 | [diff] [blame] | 369 | } |
| 370 | |
Dominik Behr | 46c567f | 2016-03-08 15:11:48 -0800 | [diff] [blame] | 371 | void dbus_set_login_prompt_visible_callback(void (*callback)(void*), |
| 372 | void* userptr) |
| 373 | { |
| 374 | if (chrome_is_already_up) { |
| 375 | if (callback) |
| 376 | callback(userptr); |
| 377 | } else { |
| 378 | if (login_prompt_visible_callback && callback) { |
| 379 | LOG(ERROR, "trying to register login prompt visible callback multiple times"); |
| 380 | return; |
| 381 | } |
| 382 | login_prompt_visible_callback = callback; |
| 383 | login_prompt_visible_callback_userptr = userptr; |
| 384 | } |
| 385 | } |
Dominik Behr | f50c98f | 2016-03-31 14:05:29 -0700 | [diff] [blame] | 386 | |
Dominik Behr | 1883c04 | 2016-04-27 12:31:02 -0700 | [diff] [blame] | 387 | void dbus_set_suspend_done_callback(void (*callback)(void*), |
| 388 | void* userptr) |
| 389 | { |
| 390 | if (suspend_done_callback && callback) { |
| 391 | LOG(ERROR, "trying to register login prompt visible callback multiple times"); |
| 392 | return; |
| 393 | } |
| 394 | suspend_done_callback = callback; |
| 395 | suspend_done_callback_userptr = userptr; |
| 396 | } |
| 397 | |
Dominik Behr | f50c98f | 2016-03-31 14:05:29 -0700 | [diff] [blame] | 398 | #else |
| 399 | |
| 400 | #include <stdlib.h> |
| 401 | #include <stdbool.h> |
| 402 | |
| 403 | bool dbus_init() |
| 404 | { |
| 405 | return true; |
| 406 | } |
| 407 | |
| 408 | bool dbus_init_wait() |
| 409 | { |
| 410 | return true; |
| 411 | } |
| 412 | |
| 413 | void dbus_destroy(void) |
| 414 | { |
| 415 | } |
| 416 | |
| 417 | void dbus_add_fds(fd_set* read_set, fd_set* exception_set, int *maxfd) |
| 418 | { |
| 419 | } |
| 420 | |
| 421 | void dbus_dispatch_io(void) |
| 422 | { |
| 423 | } |
| 424 | |
| 425 | void dbus_report_user_activity(int activity_type) |
| 426 | { |
| 427 | } |
| 428 | |
| 429 | void dbus_take_display_ownership(void) |
| 430 | { |
| 431 | } |
| 432 | |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 433 | bool dbus_release_display_ownership(void) |
Dominik Behr | f50c98f | 2016-03-31 14:05:29 -0700 | [diff] [blame] | 434 | { |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 435 | return true; |
Dominik Behr | f50c98f | 2016-03-31 14:05:29 -0700 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | bool dbus_is_initialized(void) |
| 439 | { |
| 440 | return true; |
| 441 | } |
| 442 | |
| 443 | void dbus_set_login_prompt_visible_callback(void (*callback)(void*), |
| 444 | void* userptr) |
| 445 | { |
| 446 | } |
| 447 | |
Dominik Behr | 1883c04 | 2016-04-27 12:31:02 -0700 | [diff] [blame] | 448 | void dbus_set_suspend_done_callback(void (*callback)(void*), |
| 449 | void* userptr) |
| 450 | { |
| 451 | } |
| 452 | |
Dominik Behr | f50c98f | 2016-03-31 14:05:29 -0700 | [diff] [blame] | 453 | #endif |