OSDN Git Service

No more ashmem equivalent checker false alarm
authorPeng Xu <pengxu@google.com>
Tue, 16 May 2017 22:12:22 +0000 (15:12 -0700)
committerPeng Xu <pengxu@google.com>
Tue, 16 May 2017 22:34:34 +0000 (15:34 -0700)
The checker for ashmem file descriptor equivalency is
too strict and false alarms. This CL fix the issue.

Bug: 38352409
Test: successfully register multiple ashmem sensor direct channels
      without "Duplicate create channel request for the
      same share memory"

Change-Id: Ib80b47944940ce708953632855174d2f90c41b49

services/sensorservice/SensorDirectConnection.cpp

index 91923b3..870635b 100644 (file)
@@ -18,8 +18,6 @@
 #include "SensorDirectConnection.h"
 #include <hardware/sensors.h>
 
-#include <sys/stat.h>
-
 #define UNUSED(x) (void)(x)
 
 namespace android {
@@ -182,13 +180,12 @@ bool SensorService::SensorDirectConnection::isEquivalent(const sensors_direct_me
     if (mMem.type == mem->type) {
         switch (mMem.type) {
             case SENSOR_DIRECT_MEM_TYPE_ASHMEM: {
-                struct stat s1, s2;
-                int fd1, fd2;
-                fd1 = mMem.handle->data[0];
-                fd2 = mem->handle->data[0];
-                if (fstat(fd1, &s1) < 0 || fstat(fd2, &s2) < 0 || s1.st_ino == s2.st_ino) {
-                    ret = true;
-                }
+                // there is no known method to test if two ashmem fds are equivalent besides
+                // trivially comparing the fd values (ino number from fstat() are always the
+                // same, pointing to "/dev/ashmem").
+                int fd1 = mMem.handle->data[0];
+                int fd2 = mem->handle->data[0];
+                ret = (fd1 == fd2);
                 break;
             }
             case SENSOR_DIRECT_MEM_TYPE_GRALLOC: