Skip to content

Commit

Permalink
Enable remote display for hwcomposer.remote
Browse files Browse the repository at this point in the history
Use abstract socket and set vendor.hwc_vhal.ready to when it is
ready for access.

Tracked-On: OAM-127105
Signed-off-by: Marc Mao <[email protected]>
  • Loading branch information
xmao4-intel authored and sysopenci committed Nov 13, 2024
1 parent 0775a23 commit e768517
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ cc_library_shared {

cflags: [
"-DENABLE_HWC_REMOTE",
"-DUSE_ABSTRACT_SOCKET",
],

vendor: true,
Expand Down
36 changes: 26 additions & 10 deletions common/RemoteDisplayMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Date: 2021.06.09
//#define LOG_NDEBUG 0

#include <cutils/log.h>
#include <cutils/properties.h>

#include <sys/epoll.h>
#include <sys/ioctl.h>
Expand All @@ -52,9 +53,6 @@ RemoteDisplayMgr::~RemoteDisplayMgr() {
}

int RemoteDisplayMgr::init(IRemoteDevice* dev) {

return -1;

mEpollFd = epoll_create(kMaxEvents);
if (mEpollFd == -1) {
ALOGE("epoll_create:%s", strerror(errno));
Expand Down Expand Up @@ -215,26 +213,44 @@ void RemoteDisplayMgr::socketThreadProc() {
addr.sun_family = AF_UNIX;
strncpy(&addr.sun_path[0], kServerSock, strlen(kServerSock));

unlink(kServerSock);
const char* path = kServerSock;
#ifdef USE_ABSTRACT_SOCKET
bool abstract = true;
#else
bool abstract = false;
#endif
if (abstract) {
path = "hwc-sock";
strncpy(&addr.sun_path[1], path, strlen(path));
addr.sun_path[0] = 0;
} else {
strncpy(&addr.sun_path[0], path, strlen(path));
unlink(path);
}

if (bind(mServerFd, (struct sockaddr*)&addr,
sizeof(sa_family_t) + strlen(kServerSock) + 1) < 0) {
sizeof(sa_family_t) + strlen(path) + 1) < 0) {
ALOGE("Failed to bind server socket address");
return;
}

// TODO: use group access only for security
struct stat st;
__mode_t mod = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
if (fstat(mServerFd, &st) == 0) {
mod |= st.st_mode;
if (!abstract) {
struct stat st;
__mode_t mod = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
if (fstat(mServerFd, &st) == 0) {
mod |= st.st_mode;
}
chmod(path, mod);
}
chmod(kServerSock, mod);

if (listen(mServerFd, 1) < 0) {
ALOGE("Failed to listen on server socket");
return;
}

property_set("vendor.hwc_vhal.ready", "1");

while (true) {
struct epoll_event events[kMaxEvents];
int nfds = epoll_wait(mEpollFd, events, kMaxEvents, -1);
Expand Down

0 comments on commit e768517

Please sign in to comment.