Arun Kumar K.R | f6f49a1 | 2012-11-27 11:46:50 -0800 | [diff] [blame] | 1 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2010 The Android Open Source Project |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 4 | * Copyright (C) 2012, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 5 | * |
| 6 | * Not a Contribution, Apache license notifications and license are |
| 7 | * retained for attribution purposes only. |
| 8 | |
| 9 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | * you may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | * |
| 15 | * Unless required by applicable law or agreed to in writing, software |
| 16 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | * See the License for the specific language governing permissions and |
| 19 | * limitations under the License. |
| 20 | */ |
Saurabh Shah | 649cda6 | 2012-09-16 16:05:58 -0700 | [diff] [blame] | 21 | #define UEVENT_DEBUG 0 |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 22 | #include <hardware_legacy/uevent.h> |
| 23 | #include <utils/Log.h> |
| 24 | #include <sys/resource.h> |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 25 | #include <sys/prctl.h> |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 26 | #include <string.h> |
| 27 | #include <stdlib.h> |
| 28 | #include "hwc_utils.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 29 | #include "external.h" |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 30 | |
| 31 | namespace qhwc { |
| 32 | |
Iliyan Malchev | 0f9c397 | 2012-10-11 15:16:15 -0700 | [diff] [blame] | 33 | #define HWC_UEVENT_THREAD_NAME "hwcUeventThread" |
| 34 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 35 | static void handle_uevent(hwc_context_t* ctx, const char* udata, int len) |
| 36 | { |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 37 | int vsync = 0; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 38 | int64_t timestamp = 0; |
| 39 | const char *str = udata; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 40 | |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame^] | 41 | if(!strcasestr(str, "change@/devices/virtual/switch/hdmi") && |
| 42 | !strcasestr(str, "change@/devices/virtual/switch/wfd")) { |
Saurabh Shah | 649cda6 | 2012-09-16 16:05:58 -0700 | [diff] [blame] | 43 | ALOGD_IF(UEVENT_DEBUG, "%s: Not Ext Disp Event ", __FUNCTION__); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 44 | return; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 45 | } |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame^] | 46 | |
Arun Kumar K.R | f6f49a1 | 2012-11-27 11:46:50 -0800 | [diff] [blame] | 47 | int connected = -1; // initial value - will be set to 1/0 based on hotplug |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame^] | 48 | // parse HDMI/WFD switch state for connect/disconnect |
| 49 | // for HDMI: |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 50 | // The event will be of the form: |
Arun Kumar K.R | f6f49a1 | 2012-11-27 11:46:50 -0800 | [diff] [blame] | 51 | // change@/devices/virtual/switch/hdmi ACTION=change |
| 52 | // SWITCH_STATE=1 or SWITCH_STATE=0 |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame^] | 53 | |
Arun Kumar K.R | f6f49a1 | 2012-11-27 11:46:50 -0800 | [diff] [blame] | 54 | while(*str) { |
| 55 | if (!strncmp(str, "SWITCH_STATE=", strlen("SWITCH_STATE="))) { |
| 56 | connected = atoi(str + strlen("SWITCH_STATE=")); |
Saurabh Shah | 1a8cda0 | 2012-10-12 17:00:39 -0700 | [diff] [blame] | 57 | //Disabled until SF calls unblank |
| 58 | ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false; |
Arun Kumar K.R | f6f49a1 | 2012-11-27 11:46:50 -0800 | [diff] [blame] | 59 | break; |
Saurabh Shah | 1a8cda0 | 2012-10-12 17:00:39 -0700 | [diff] [blame] | 60 | } |
Arun Kumar K.R | f6f49a1 | 2012-11-27 11:46:50 -0800 | [diff] [blame] | 61 | str += strlen(str) + 1; |
| 62 | if (str - udata >= len) |
| 63 | break; |
| 64 | } |
| 65 | |
| 66 | if(connected != -1) { //either we got switch_state connected or disconnect |
| 67 | ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected = connected; |
Amara Venkata Mastan Manoj Kumar | 5182a78 | 2012-12-03 12:08:48 -0800 | [diff] [blame^] | 68 | if(connected) { |
| 69 | ctx->mExtDisplay->processUEventOnline(udata); |
| 70 | }else { |
| 71 | ctx->mExtDisplay->processUEventOffline(udata); |
| 72 | } |
| 73 | ALOGD("%s sending hotplug: connected = %d", __FUNCTION__, connected); |
Arun Kumar K.R | f6f49a1 | 2012-11-27 11:46:50 -0800 | [diff] [blame] | 74 | Locker::Autolock _l(ctx->mExtSetLock); //hwc comp could be on |
| 75 | ctx->proc->hotplug(ctx->proc, HWC_DISPLAY_EXTERNAL, connected); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 76 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static void *uevent_loop(void *param) |
| 80 | { |
| 81 | int len = 0; |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 82 | static char udata[PAGE_SIZE]; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 83 | hwc_context_t * ctx = reinterpret_cast<hwc_context_t *>(param); |
Iliyan Malchev | 0f9c397 | 2012-10-11 15:16:15 -0700 | [diff] [blame] | 84 | char thread_name[64] = HWC_UEVENT_THREAD_NAME; |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 85 | prctl(PR_SET_NAME, (unsigned long) &thread_name, 0, 0, 0); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 86 | setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY); |
| 87 | uevent_init(); |
| 88 | |
| 89 | while(1) { |
| 90 | len = uevent_next_event(udata, sizeof(udata) - 2); |
| 91 | handle_uevent(ctx, udata, len); |
| 92 | } |
| 93 | |
| 94 | return NULL; |
| 95 | } |
| 96 | |
| 97 | void init_uevent_thread(hwc_context_t* ctx) |
| 98 | { |
| 99 | pthread_t uevent_thread; |
Iliyan Malchev | 0f9c397 | 2012-10-11 15:16:15 -0700 | [diff] [blame] | 100 | int ret; |
| 101 | |
| 102 | ALOGI("Initializing UEVENT Thread"); |
| 103 | ret = pthread_create(&uevent_thread, NULL, uevent_loop, (void*) ctx); |
| 104 | if (ret) { |
| 105 | ALOGE("%s: failed to create %s: %s", __FUNCTION__, |
| 106 | HWC_UEVENT_THREAD_NAME, strerror(ret)); |
| 107 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | }; //namespace |