blob: 8e3edab032063cc257cae13a53862da9c8c6bf4b [file] [log] [blame]
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -08001
Naseer Ahmed72cf9762012-07-21 12:17:13 -07002/*
3 * Copyright (C) 2010 The Android Open Source Project
Saurabh Shah56f610d2012-08-07 15:27:06 -07004 * Copyright (C) 2012, The Linux Foundation. All rights reserved.
Naseer Ahmed72cf9762012-07-21 12:17:13 -07005 *
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 Shah649cda62012-09-16 16:05:58 -070021#define UEVENT_DEBUG 0
Naseer Ahmed72cf9762012-07-21 12:17:13 -070022#include <hardware_legacy/uevent.h>
23#include <utils/Log.h>
24#include <sys/resource.h>
Naseer Ahmedff4f0252012-10-01 13:03:01 -040025#include <sys/prctl.h>
Naseer Ahmed72cf9762012-07-21 12:17:13 -070026#include <string.h>
27#include <stdlib.h>
28#include "hwc_utils.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070029#include "external.h"
Naseer Ahmed72cf9762012-07-21 12:17:13 -070030
31namespace qhwc {
32
Iliyan Malchev0f9c3972012-10-11 15:16:15 -070033#define HWC_UEVENT_THREAD_NAME "hwcUeventThread"
34
Naseer Ahmed72cf9762012-07-21 12:17:13 -070035static void handle_uevent(hwc_context_t* ctx, const char* udata, int len)
36{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070037 int vsync = 0;
Naseer Ahmed72cf9762012-07-21 12:17:13 -070038 int64_t timestamp = 0;
39 const char *str = udata;
Naseer Ahmed72cf9762012-07-21 12:17:13 -070040
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -080041 if(!strcasestr(str, "change@/devices/virtual/switch/hdmi")) {
Saurabh Shah649cda62012-09-16 16:05:58 -070042 ALOGD_IF(UEVENT_DEBUG, "%s: Not Ext Disp Event ", __FUNCTION__);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070043 return;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070044 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -080045 int connected = -1; // initial value - will be set to 1/0 based on hotplug
46 // parse HDMI switch state for connect/disconnect
Naseer Ahmedff4f0252012-10-01 13:03:01 -040047 // The event will be of the form:
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -080048 // change@/devices/virtual/switch/hdmi ACTION=change
49 // SWITCH_STATE=1 or SWITCH_STATE=0
50 while(*str) {
51 if (!strncmp(str, "SWITCH_STATE=", strlen("SWITCH_STATE="))) {
52 connected = atoi(str + strlen("SWITCH_STATE="));
Saurabh Shah1a8cda02012-10-12 17:00:39 -070053 //Disabled until SF calls unblank
54 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false;
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -080055 break;
Saurabh Shah1a8cda02012-10-12 17:00:39 -070056 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -080057 str += strlen(str) + 1;
58 if (str - udata >= len)
59 break;
60 }
61
62 if(connected != -1) { //either we got switch_state connected or disconnect
63 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected = connected;
64 ctx->mExtDisplay->setExternalDisplay(connected);
65 ALOGD("%s sending hotplug: connected = %d", __FUNCTION__,connected);
66 Locker::Autolock _l(ctx->mExtSetLock); //hwc comp could be on
67 ctx->proc->hotplug(ctx->proc, HWC_DISPLAY_EXTERNAL, connected);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070068 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -070069}
70
71static void *uevent_loop(void *param)
72{
73 int len = 0;
Naseer Ahmedff4f0252012-10-01 13:03:01 -040074 static char udata[PAGE_SIZE];
Naseer Ahmed72cf9762012-07-21 12:17:13 -070075 hwc_context_t * ctx = reinterpret_cast<hwc_context_t *>(param);
Iliyan Malchev0f9c3972012-10-11 15:16:15 -070076 char thread_name[64] = HWC_UEVENT_THREAD_NAME;
Naseer Ahmedff4f0252012-10-01 13:03:01 -040077 prctl(PR_SET_NAME, (unsigned long) &thread_name, 0, 0, 0);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070078 setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
79 uevent_init();
80
81 while(1) {
82 len = uevent_next_event(udata, sizeof(udata) - 2);
83 handle_uevent(ctx, udata, len);
84 }
85
86 return NULL;
87}
88
89void init_uevent_thread(hwc_context_t* ctx)
90{
91 pthread_t uevent_thread;
Iliyan Malchev0f9c3972012-10-11 15:16:15 -070092 int ret;
93
94 ALOGI("Initializing UEVENT Thread");
95 ret = pthread_create(&uevent_thread, NULL, uevent_loop, (void*) ctx);
96 if (ret) {
97 ALOGE("%s: failed to create %s: %s", __FUNCTION__,
98 HWC_UEVENT_THREAD_NAME, strerror(ret));
99 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700100}
101
102}; //namespace