blob: a7f58ea45f5739137cc78b00c1f6dc523646cb9d [file] [log] [blame]
Naseer Ahmed72cf9762012-07-21 12:17:13 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Saurabh Shah56f610d2012-08-07 15:27:06 -07003 * Copyright (C) 2012, The Linux Foundation. All rights reserved.
Naseer Ahmed72cf9762012-07-21 12:17:13 -07004 *
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 Shah649cda62012-09-16 16:05:58 -070020#define UEVENT_DEBUG 0
Naseer Ahmed72cf9762012-07-21 12:17:13 -070021#include <hardware_legacy/uevent.h>
22#include <utils/Log.h>
23#include <sys/resource.h>
Naseer Ahmedff4f0252012-10-01 13:03:01 -040024#include <sys/prctl.h>
Naseer Ahmed72cf9762012-07-21 12:17:13 -070025#include <string.h>
26#include <stdlib.h>
27#include "hwc_utils.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070028#include "external.h"
Naseer Ahmed72cf9762012-07-21 12:17:13 -070029
30namespace qhwc {
31
Iliyan Malchev0f9c3972012-10-11 15:16:15 -070032#define HWC_UEVENT_THREAD_NAME "hwcUeventThread"
33
Naseer Ahmed72cf9762012-07-21 12:17:13 -070034const char* MSMFB_HDMI_NODE = "fb1";
35
36static void handle_uevent(hwc_context_t* ctx, const char* udata, int len)
37{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070038 int vsync = 0;
Naseer Ahmed72cf9762012-07-21 12:17:13 -070039 char* hdmi;
40 int64_t timestamp = 0;
41 const char *str = udata;
Naseer Ahmed72cf9762012-07-21 12:17:13 -070042
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070043 if(!strcasestr(str, "@/devices/virtual/graphics/fb")) {
Saurabh Shah649cda62012-09-16 16:05:58 -070044 ALOGD_IF(UEVENT_DEBUG, "%s: Not Ext Disp Event ", __FUNCTION__);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070045 return;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070046 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070047 hdmi = strcasestr(str, MSMFB_HDMI_NODE);
Naseer Ahmedff4f0252012-10-01 13:03:01 -040048 // parse HDMI events
49 // The event will be of the form:
50 // change@/devices/virtual/graphics/fb1 ACTION=change
51 // DEVPATH=/devices/virtual/graphics/fb1
52 // SUBSYSTEM=graphics HDCP_STATE=FAIL MAJOR=29
53 // for now just parsing onlin/offline info is enough
54 if (hdmi) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070055 str = udata;
56 int connected = 0;
57 if(!(strncmp(str,"online@",strlen("online@")))) {
58 connected = 1;
Naseer Ahmedff4f0252012-10-01 13:03:01 -040059 ctx->mExtDisplay->setExternalDisplay(connected);;
Naseer Ahmed72cf9762012-07-21 12:17:13 -070060 } else if(!(strncmp(str,"offline@",strlen("offline@")))) {
61 connected = 0;
Naseer Ahmedff4f0252012-10-01 13:03:01 -040062 ctx->mExtDisplay->setExternalDisplay(connected);;
Naseer Ahmed72cf9762012-07-21 12:17:13 -070063 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070064 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070065}
66
67static void *uevent_loop(void *param)
68{
69 int len = 0;
Naseer Ahmedff4f0252012-10-01 13:03:01 -040070 static char udata[PAGE_SIZE];
Naseer Ahmed72cf9762012-07-21 12:17:13 -070071 hwc_context_t * ctx = reinterpret_cast<hwc_context_t *>(param);
Iliyan Malchev0f9c3972012-10-11 15:16:15 -070072 char thread_name[64] = HWC_UEVENT_THREAD_NAME;
Naseer Ahmedff4f0252012-10-01 13:03:01 -040073 prctl(PR_SET_NAME, (unsigned long) &thread_name, 0, 0, 0);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070074 setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
75 uevent_init();
76
77 while(1) {
78 len = uevent_next_event(udata, sizeof(udata) - 2);
79 handle_uevent(ctx, udata, len);
80 }
81
82 return NULL;
83}
84
85void init_uevent_thread(hwc_context_t* ctx)
86{
87 pthread_t uevent_thread;
Iliyan Malchev0f9c3972012-10-11 15:16:15 -070088 int ret;
89
90 ALOGI("Initializing UEVENT Thread");
91 ret = pthread_create(&uevent_thread, NULL, uevent_loop, (void*) ctx);
92 if (ret) {
93 ALOGE("%s: failed to create %s: %s", __FUNCTION__,
94 HWC_UEVENT_THREAD_NAME, strerror(ret));
95 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070096}
97
98}; //namespace