Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 3 | * Copyright (C) 2012, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 4 | * |
| 5 | * Not a Contribution, Apache license notifications and license are |
| 6 | * retained for attribution purposes only. |
| 7 | |
| 8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | * you may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
| 19 | */ |
Saurabh Shah | 649cda6 | 2012-09-16 16:05:58 -0700 | [diff] [blame] | 20 | #define UEVENT_DEBUG 0 |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 21 | #include <hardware_legacy/uevent.h> |
| 22 | #include <utils/Log.h> |
| 23 | #include <sys/resource.h> |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame^] | 24 | #include <sys/prctl.h> |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 25 | #include <string.h> |
| 26 | #include <stdlib.h> |
| 27 | #include "hwc_utils.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 28 | #include "external.h" |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 29 | |
| 30 | namespace qhwc { |
| 31 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 32 | const char* MSMFB_HDMI_NODE = "fb1"; |
| 33 | |
| 34 | static void handle_uevent(hwc_context_t* ctx, const char* udata, int len) |
| 35 | { |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 36 | int vsync = 0; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 37 | char* hdmi; |
| 38 | int64_t timestamp = 0; |
| 39 | const char *str = udata; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 40 | |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 41 | if(!strcasestr(str, "@/devices/virtual/graphics/fb")) { |
Saurabh Shah | 649cda6 | 2012-09-16 16:05:58 -0700 | [diff] [blame] | 42 | ALOGD_IF(UEVENT_DEBUG, "%s: Not Ext Disp Event ", __FUNCTION__); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 43 | return; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 44 | } |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 45 | hdmi = strcasestr(str, MSMFB_HDMI_NODE); |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame^] | 46 | // parse HDMI events |
| 47 | // The event will be of the form: |
| 48 | // change@/devices/virtual/graphics/fb1 ACTION=change |
| 49 | // DEVPATH=/devices/virtual/graphics/fb1 |
| 50 | // SUBSYSTEM=graphics HDCP_STATE=FAIL MAJOR=29 |
| 51 | // for now just parsing onlin/offline info is enough |
| 52 | if (hdmi) { |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 53 | str = udata; |
| 54 | int connected = 0; |
| 55 | if(!(strncmp(str,"online@",strlen("online@")))) { |
| 56 | connected = 1; |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame^] | 57 | ctx->mExtDisplay->setExternalDisplay(connected);; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 58 | } else if(!(strncmp(str,"offline@",strlen("offline@")))) { |
| 59 | connected = 0; |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame^] | 60 | ctx->mExtDisplay->setExternalDisplay(connected);; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 61 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 62 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | static void *uevent_loop(void *param) |
| 66 | { |
| 67 | int len = 0; |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame^] | 68 | static char udata[PAGE_SIZE]; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 69 | hwc_context_t * ctx = reinterpret_cast<hwc_context_t *>(param); |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame^] | 70 | char thread_name[64] = "hwcUeventThread"; |
| 71 | prctl(PR_SET_NAME, (unsigned long) &thread_name, 0, 0, 0); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 72 | setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY); |
| 73 | uevent_init(); |
| 74 | |
| 75 | while(1) { |
| 76 | len = uevent_next_event(udata, sizeof(udata) - 2); |
| 77 | handle_uevent(ctx, udata, len); |
| 78 | } |
| 79 | |
| 80 | return NULL; |
| 81 | } |
| 82 | |
| 83 | void init_uevent_thread(hwc_context_t* ctx) |
| 84 | { |
| 85 | pthread_t uevent_thread; |
| 86 | pthread_create(&uevent_thread, NULL, uevent_loop, (void*) ctx); |
| 87 | } |
| 88 | |
| 89 | }; //namespace |