• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define LOG_TAG "hwc-uevent-listener"
18 
19 #include "UEventListener.h"
20 
21 #include <cerrno>
22 
23 #include "utils/log.h"
24 
25 /* Originally defined in system/core/libsystem/include/system/graphics.h as
26  * #define HAL_PRIORITY_URGENT_DISPLAY (-8)*/
27 constexpr int kHalPriorityUrgentDisplay = -8;
28 
29 namespace android {
30 
UEventListener()31 UEventListener::UEventListener()
32     : Worker("uevent-listener", kHalPriorityUrgentDisplay){};
33 
Init()34 int UEventListener::Init() {
35   uevent_ = UEvent::CreateInstance();
36   if (!uevent_) {
37     return -ENODEV;
38   }
39 
40   return InitWorker();
41 }
42 
Routine()43 void UEventListener::Routine() {
44   while (true) {
45     auto uevent_str = uevent_->ReadNext();
46 
47     if (!hotplug_handler_ || !uevent_str)
48       continue;
49 
50     bool drm_event = uevent_str->find("DEVTYPE=drm_minor") != std::string::npos;
51     bool hotplug_event = uevent_str->find("HOTPLUG=1") != std::string::npos;
52 
53     if (drm_event && hotplug_event) {
54       constexpr useconds_t kDelayAfterUeventUs = 200000;
55       /* We need some delay to ensure DrmConnector::UpdateModes() will query
56        * correct modes list, otherwise at least RPI4 board may report 0 modes */
57       usleep(kDelayAfterUeventUs);
58       hotplug_handler_();
59     }
60   }
61 }
62 }  // namespace android
63