Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0beacddf authored by Alexey Polyudov's avatar Alexey Polyudov Committed by Android (Google) Code Review
Browse files

Merge "sensors: pass sensor handle along with injected event"

parents ba67722e 88711e87
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -119,10 +119,12 @@ public:
        return interface_cast<ISensorEventConnection>(reply.readStrongBinder());
    }

    virtual int setOperationParameter(
            int32_t type, const Vector<float> &floats, const Vector<int32_t> &ints) {
    virtual int setOperationParameter(int32_t handle, int32_t type,
                                      const Vector<float> &floats,
                                      const Vector<int32_t> &ints) {
        Parcel data, reply;
        data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor());
        data.writeInt32(handle);
        data.writeInt32(type);
        data.writeUint32(static_cast<uint32_t>(floats.size()));
        for (auto i : floats) {
@@ -203,10 +205,12 @@ status_t BnSensorServer::onTransact(
        }
        case SET_OPERATION_PARAMETER: {
            CHECK_INTERFACE(ISensorServer, data, reply);
            int32_t handle;
            int32_t type;
            Vector<float> floats;
            Vector<int32_t> ints;

            handle = data.readInt32();
            type = data.readInt32();
            floats.resize(data.readUint32());
            for (auto &i : floats) {
@@ -217,7 +221,7 @@ status_t BnSensorServer::onTransact(
                i = data.readInt32();
            }

            int32_t ret = setOperationParameter(type, floats, ints);
            int32_t ret = setOperationParameter(handle, type, floats, ints);
            reply->writeInt32(ret);
            return NO_ERROR;
        }
+3 −2
Original line number Diff line number Diff line
@@ -305,12 +305,13 @@ int SensorManager::configureDirectChannel(int channelNativeHandle, int sensorHan
}

int SensorManager::setOperationParameter(
        int type, const Vector<float> &floats, const Vector<int32_t> &ints) {
        int handle, int type,
        const Vector<float> &floats, const Vector<int32_t> &ints) {
    Mutex::Autolock _l(mLock);
    if (assertStateLocked() != NO_ERROR) {
        return NO_INIT;
    }
    return mSensorServer->setOperationParameter(type, floats, ints);
    return mSensorServer->setOperationParameter(handle, type, floats, ints);
}

// ----------------------------------------------------------------------------
+1 −1
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ public:
            uint32_t size, int32_t type, int32_t format, const native_handle_t *resource) = 0;

    virtual int setOperationParameter(
            int32_t type, const Vector<float> &floats, const Vector<int32_t> &ints) = 0;
            int32_t handle, int32_t type, const Vector<float> &floats, const Vector<int32_t> &ints) = 0;
};

// ----------------------------------------------------------------------------
+1 −1
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ public:
    int createDirectChannel(size_t size, int channelType, const native_handle_t *channelData);
    void destroyDirectChannel(int channelNativeHandle);
    int configureDirectChannel(int channelNativeHandle, int sensorHandle, int rateLevel);
    int setOperationParameter(int type, const Vector<float> &floats, const Vector<int32_t> &ints);
    int setOperationParameter(int handle, int type, const Vector<float> &floats, const Vector<int32_t> &ints);

private:
    // DeathRecipient interface
+20 −7
Original line number Diff line number Diff line
@@ -1033,17 +1033,16 @@ sp<ISensorEventConnection> SensorService::createSensorDirectConnection(
}

int SensorService::setOperationParameter(
            int32_t type, const Vector<float> &floats, const Vector<int32_t> &ints) {
            int32_t handle, int32_t type,
            const Vector<float> &floats, const Vector<int32_t> &ints) {
    Mutex::Autolock _l(mLock);

    // check permission
    int32_t uid;
    bool hasPermission = checkCallingPermission(sLocationHardwarePermission, nullptr, &uid);
    if (!hasPermission || (uid != 1000 && uid != 0)) {
    if (!checkCallingPermission(sLocationHardwarePermission, nullptr, nullptr)) {
        return PERMISSION_DENIED;
    }

    bool isFloat = true;
    bool isCustom = false;
    size_t expectSize = INT32_MAX;
    switch (type) {
        case AINFO_LOCAL_GEOMAGNETIC_FIELD:
@@ -1061,6 +1060,20 @@ int SensorService::setOperationParameter(
            expectSize = 1;
            break;
        default:
            // CUSTOM events must only contain float data; it may have variable size
            if (type < AINFO_CUSTOM_START || type >= AINFO_DEBUGGING_START ||
                    ints.size() ||
                    sizeof(additional_info_event_t::data_float)/sizeof(float) < floats.size() ||
                    handle < 0) {
                return BAD_VALUE;
            }
            isFloat = true;
            isCustom = true;
            expectSize = floats.size();
            break;
    }

    if (!isCustom && handle != -1) {
        return BAD_VALUE;
    }

@@ -1071,7 +1084,7 @@ int SensorService::setOperationParameter(
    for (sensors_event_t* i = event; i < event + 3; i++) {
        *i = (sensors_event_t) {
            .version = sizeof(sensors_event_t),
            .sensor = SENSORS_HANDLE_BASE - 1, // sensor that never exists
            .sensor = handle,
            .type = SENSOR_TYPE_ADDITIONAL_INFO,
            .timestamp = timestamp++,
            .additional_info = (additional_info_event_t) {
Loading