OSDN Git Service

sensor: Allow devices to skip the permission request
[android-x86/frameworks-native.git] / libs / gui / Sensor.cpp
index cc865d1..9d0aa24 100644 (file)
@@ -297,6 +297,7 @@ Sensor::Sensor(struct sensor_t const& hwSensor, const uuid_t& uuid, int halVersi
         mFlags |= (hwSensor.flags & DATA_INJECTION_MASK);
     }
 
+#ifndef NO_SENSOR_PERMISSION_CHECK
     if (mRequiredPermission.length() > 0) {
         // If the sensor is protected by a permission we need to know if it is
         // a runtime one to determine whether we can use the permission cache.
@@ -307,6 +308,7 @@ Sensor::Sensor(struct sensor_t const& hwSensor, const uuid_t& uuid, int halVersi
                     String16(mRequiredPermission));
         }
     }
+#endif
 }
 
 Sensor::~Sensor() {
@@ -408,6 +410,15 @@ const Sensor::uuid_t& Sensor::getUuid() const {
     return mUuid;
 }
 
+void Sensor::setId(int32_t id) {
+    mUuid.i64[0] = id;
+    mUuid.i64[1] = 0;
+}
+
+int32_t Sensor::getId() const {
+    return int32_t(mUuid.i64[0]);
+}
+
 size_t Sensor::getFlattenedSize() const {
     size_t fixedSize =
             sizeof(mVersion) + sizeof(mHandle) + sizeof(mType) +
@@ -448,7 +459,18 @@ status_t Sensor::flatten(void* buffer, size_t size) const {
     FlattenableUtils::write(buffer, size, mRequiredAppOp);
     FlattenableUtils::write(buffer, size, mMaxDelay);
     FlattenableUtils::write(buffer, size, mFlags);
-    FlattenableUtils::write(buffer, size, mUuid);
+    if (mUuid.i64[1] != 0) {
+        // We should never hit this case with our current API, but we
+        // could via a careless API change.  If that happens,
+        // this code will keep us from leaking our UUID (while probably
+        // breaking dynamic sensors).  See b/29547335.
+        ALOGW("Sensor with UUID being flattened; sending 0.  Expect "
+              "bad dynamic sensor behavior");
+        uuid_t tmpUuid;  // default constructor makes this 0.
+        FlattenableUtils::write(buffer, size, tmpUuid);
+    } else {
+        FlattenableUtils::write(buffer, size, mUuid);
+    }
     return NO_ERROR;
 }