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

Commit cc60dc21 authored by Aravind Akella's avatar Aravind Akella Committed by Android (Google) Code Review
Browse files

Merge "Enable data injection mode in SensorService."

parents 0f7723f6 a9e6cc38
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -38,7 +38,9 @@ public:
    DECLARE_META_INTERFACE(SensorServer);
    DECLARE_META_INTERFACE(SensorServer);


    virtual Vector<Sensor> getSensorList() = 0;
    virtual Vector<Sensor> getSensorList() = 0;
    virtual sp<ISensorEventConnection> createSensorEventConnection(const String8& packageName) = 0;
    virtual sp<ISensorEventConnection> createSensorEventConnection(const String8& packageName,
             int mode) = 0;
    virtual status_t enableDataInjection(int enable) = 0;
};
};


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
+2 −0
Original line number Original line Diff line number Diff line
@@ -77,6 +77,8 @@ public:
    status_t flush() const;
    status_t flush() const;
    // Send an ack for every wake_up sensor event that is set to WAKE_UP_SENSOR_EVENT_NEEDS_ACK.
    // Send an ack for every wake_up sensor event that is set to WAKE_UP_SENSOR_EVENT_NEEDS_ACK.
    void sendAck(const ASensorEvent* events, int count);
    void sendAck(const ASensorEvent* events, int count);

    status_t injectSensorEvent(const ASensorEvent& event);
private:
private:
    sp<Looper> getLooper() const;
    sp<Looper> getLooper() const;
    sp<ISensorEventConnection> mSensorEventConnection;
    sp<ISensorEventConnection> mSensorEventConnection;
+2 −1
Original line number Original line Diff line number Diff line
@@ -53,7 +53,8 @@ public:


    ssize_t getSensorList(Sensor const* const** list) const;
    ssize_t getSensorList(Sensor const* const** list) const;
    Sensor const* getDefaultSensor(int type);
    Sensor const* getDefaultSensor(int type);
    sp<SensorEventQueue> createEventQueue(String8 packageName = String8(""));
    sp<SensorEventQueue> createEventQueue(String8 packageName = String8(""), int mode = 0);
    ssize_t enableDataInjection(bool enable);


private:
private:
    // DeathRecipient interface
    // DeathRecipient interface
+21 −2
Original line number Original line Diff line number Diff line
@@ -35,6 +35,7 @@ namespace android {
enum {
enum {
    GET_SENSOR_LIST = IBinder::FIRST_CALL_TRANSACTION,
    GET_SENSOR_LIST = IBinder::FIRST_CALL_TRANSACTION,
    CREATE_SENSOR_EVENT_CONNECTION,
    CREATE_SENSOR_EVENT_CONNECTION,
    ENABLE_DATA_INJECTION
};
};


class BpSensorServer : public BpInterface<ISensorServer>
class BpSensorServer : public BpInterface<ISensorServer>
@@ -63,14 +64,24 @@ public:
        return v;
        return v;
    }
    }


    virtual sp<ISensorEventConnection> createSensorEventConnection(const String8& packageName)
    virtual sp<ISensorEventConnection> createSensorEventConnection(const String8& packageName,
             int mode)
    {
    {
        Parcel data, reply;
        Parcel data, reply;
        data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor());
        data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor());
        data.writeString8(packageName);
        data.writeString8(packageName);
        data.writeInt32(mode);
        remote()->transact(CREATE_SENSOR_EVENT_CONNECTION, data, &reply);
        remote()->transact(CREATE_SENSOR_EVENT_CONNECTION, data, &reply);
        return interface_cast<ISensorEventConnection>(reply.readStrongBinder());
        return interface_cast<ISensorEventConnection>(reply.readStrongBinder());
    }
    }

    virtual status_t enableDataInjection(int enable) {
        Parcel data, reply;
        data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor());
        data.writeInt32(enable);
        remote()->transact(ENABLE_DATA_INJECTION, data, &reply);
        return reply.readInt32();
    }
};
};


// Out-of-line virtual method definition to trigger vtable emission in this
// Out-of-line virtual method definition to trigger vtable emission in this
@@ -98,10 +109,18 @@ status_t BnSensorServer::onTransact(
        case CREATE_SENSOR_EVENT_CONNECTION: {
        case CREATE_SENSOR_EVENT_CONNECTION: {
            CHECK_INTERFACE(ISensorServer, data, reply);
            CHECK_INTERFACE(ISensorServer, data, reply);
            String8 packageName = data.readString8();
            String8 packageName = data.readString8();
            sp<ISensorEventConnection> connection(createSensorEventConnection(packageName));
            int32_t mode = data.readInt32();
            sp<ISensorEventConnection> connection(createSensorEventConnection(packageName, mode));
            reply->writeStrongBinder(IInterface::asBinder(connection));
            reply->writeStrongBinder(IInterface::asBinder(connection));
            return NO_ERROR;
            return NO_ERROR;
        }
        }
        case ENABLE_DATA_INJECTION: {
            CHECK_INTERFACE(ISensorServer, data, reply);
            int32_t enable = data.readInt32();
            status_t ret = enableDataInjection(enable);
            reply->writeInt32(static_cast<int32_t>(ret));
            return NO_ERROR;
        }
    }
    }
    return BBinder::onTransact(code, data, reply, flags);
    return BBinder::onTransact(code, data, reply, flags);
}
}
+10 −0
Original line number Original line Diff line number Diff line
@@ -149,6 +149,16 @@ status_t SensorEventQueue::setEventRate(Sensor const* sensor, nsecs_t ns) const
    return mSensorEventConnection->setEventRate(sensor->getHandle(), ns);
    return mSensorEventConnection->setEventRate(sensor->getHandle(), ns);
}
}


status_t SensorEventQueue::injectSensorEvent(const ASensorEvent& event) {
   // Blocking call.
   ssize_t size = ::send(mSensorChannel->getFd(), &event, sizeof(event), MSG_NOSIGNAL);
   if (size < 0) {
       ALOGE("injectSensorEvent failure %zd %d", size, mSensorChannel->getFd());
       return size;
   }
   return NO_ERROR;
}

void SensorEventQueue::sendAck(const ASensorEvent* events, int count) {
void SensorEventQueue::sendAck(const ASensorEvent* events, int count) {
    for (int i = 0; i < count; ++i) {
    for (int i = 0; i < count; ++i) {
        if (events[i].flags & WAKE_UP_SENSOR_EVENT_NEEDS_ACK) {
        if (events[i].flags & WAKE_UP_SENSOR_EVENT_NEEDS_ACK) {
Loading