sdm: Identify device node path before opening.

- Check existence of /dev/graphic/fb* and /dev/fb* path
  and open appropriate device node.

CRs-Fixed: 1062882
Change-Id: Icd1f2a3f444a748eb05a7abbe9f98eae25cf254a
This commit is contained in:
Dileep Marchya
2016-09-02 16:25:30 +05:30
parent cfc854effe
commit bca3c7bdd1
3 changed files with 24 additions and 6 deletions

View File

@@ -54,6 +54,7 @@ class Sys {
#else
typedef int (*ioctl)(int, int, ...);
#endif
typedef int (*access)(const char *, int);
typedef int (*open)(const char *, int, ...);
typedef int (*close)(int);
typedef int (*poll)(struct pollfd *, nfds_t, int);
@@ -68,6 +69,7 @@ class Sys {
static bool getline_(fstream &fs, std::string &line); // NOLINT
static ioctl ioctl_;
static access access_;
static open open_;
static close close_;
static poll poll_;

View File

@@ -107,12 +107,28 @@ HWDevice::HWDevice(BufferSyncHandler *buffer_sync_handler)
}
DisplayError HWDevice::Init() {
char device_name[64] = {0};
// Read the fb node index
fb_node_index_ = GetFBNodeIndex(device_type_);
if (fb_node_index_ == -1) {
DLOGE("%s should be present", device_name_);
DLOGE("device type = %d should be present", device_type_);
return kErrorHardware;
}
const char *dev_name = NULL;
vector<string> dev_paths = {"/dev/graphics/fb", "/dev/fb"};
for (size_t i = 0; i < dev_paths.size(); i++) {
dev_paths[i] += to_string(fb_node_index_);
if (Sys::access_(dev_paths[i].c_str(), F_OK) >= 0) {
dev_name = dev_paths[i].c_str();
DLOGI("access(%s) successful", dev_name);
break;
}
DLOGI("access(%s), errno = %d, error = %s", dev_paths[i].c_str(), errno, strerror(errno));
}
if (!dev_name) {
DLOGE("access() failed for all possible paths");
return kErrorHardware;
}
@@ -122,10 +138,9 @@ DisplayError HWDevice::Init() {
hw_resource_ = HWResourceInfo();
hw_info_intf_->GetHWResourceInfo(&hw_resource_);
snprintf(device_name, sizeof(device_name), "%s%d", "/dev/graphics/fb", fb_node_index_);
device_fd_ = Sys::open_(device_name, O_RDWR);
device_fd_ = Sys::open_(dev_name, O_RDWR);
if (device_fd_ < 0) {
DLOGE("open %s failed err = %d errstr = %s", device_name, errno, strerror(errno));
DLOGE("open %s failed errno = %d, error = %s", dev_name, errno, strerror(errno));
return kErrorResources;
}

View File

@@ -45,6 +45,7 @@ int PthreadCancel(pthread_t /* thread */) {
// Pointer to actual driver interfaces.
Sys::ioctl Sys::ioctl_ = ::ioctl;
Sys::access Sys::access_ = ::access;
Sys::open Sys::open_ = ::open;
Sys::close Sys::close_ = ::close;
Sys::poll Sys::poll_ = ::poll;