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

Commit 0db05d34 authored by Peng Xu's avatar Peng Xu Committed by Android (Google) Code Review
Browse files

Merge "Synchronous resource recover mechanism for ISensorEventConnection" into oc-dr1-dev

parents 5ebcaf1b 8cbefd7a
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -36,7 +36,8 @@ enum {
    ENABLE_DISABLE,
    SET_EVENT_RATE,
    FLUSH_SENSOR,
    CONFIGURE_CHANNEL
    CONFIGURE_CHANNEL,
    DESTROY,
};

class BpSensorEventConnection : public BpInterface<ISensorEventConnection>
@@ -96,6 +97,17 @@ public:
        remote()->transact(CONFIGURE_CHANNEL, data, &reply);
        return reply.readInt32();
    }

    virtual void onLastStrongRef(const void* id) {
        destroy();
        BpInterface<ISensorEventConnection>::onLastStrongRef(id);
    }

protected:
    virtual void destroy() {
        Parcel data, reply;
        remote()->transact(DESTROY, data, &reply);
    }
};

// Out-of-line virtual method definition to trigger vtable emission in this
@@ -150,6 +162,10 @@ status_t BnSensorEventConnection::onTransact(
            reply->writeInt32(result);
            return NO_ERROR;
        }
        case DESTROY: {
            destroy();
            return NO_ERROR;
        }

    }
    return BBinder::onTransact(code, data, reply, flags);
+2 −0
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ public:
    virtual status_t setEventRate(int handle, nsecs_t ns) = 0;
    virtual status_t flush() = 0;
    virtual int32_t configureChannel(int32_t handle, int32_t rateLevel) = 0;
protected:
    virtual void destroy() = 0; // synchronously release resource hold by remote object
};

// ----------------------------------------------------------------------------
+11 −1
Original line number Diff line number Diff line
@@ -27,12 +27,21 @@ SensorService::SensorDirectConnection::SensorDirectConnection(const sp<SensorSer
        const String16& opPackageName)
        : mService(service), mUid(uid), mMem(*mem),
        mHalChannelHandle(halChannelHandle),
        mOpPackageName(opPackageName) {
        mOpPackageName(opPackageName), mDestroyed(false) {
    ALOGD_IF(DEBUG_CONNECTIONS, "Created SensorDirectConnection");
}

SensorService::SensorDirectConnection::~SensorDirectConnection() {
    ALOGD_IF(DEBUG_CONNECTIONS, "~SensorDirectConnection %p", this);
    destroy();
}

void SensorService::SensorDirectConnection::destroy() {
    Mutex::Autolock _l(mDestroyLock);
    // destroy once only
    if (mDestroyed) {
        return;
    }

    stopAll();
    mService->cleanupConnection(this);
@@ -40,6 +49,7 @@ SensorService::SensorDirectConnection::~SensorDirectConnection() {
        native_handle_close(mMem.handle);
        native_handle_delete(const_cast<struct native_handle*>(mMem.handle));
    }
    mDestroyed = true;
}

void SensorService::SensorDirectConnection::onFirstRef() {
+5 −2
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ public:
    // stop all active sensor report. if backupRecord is set to false,
    // those report can be recovered by recoverAll
    // called by SensorService when enter restricted mode
    void stopAll(bool clearRecord = false);
    void stopAll(bool backupRecord = false);

    // recover sensor reports previously stopped by stopAll(true)
    // called by SensorService when return to NORMAL mode.
@@ -63,7 +63,7 @@ protected:
    virtual status_t setEventRate(int handle, nsecs_t samplingPeriodNs);
    virtual status_t flush();
    virtual int32_t configureChannel(int handle, int rateLevel);

    virtual void destroy();
private:
    const sp<SensorService> mService;
    const uid_t mUid;
@@ -74,6 +74,9 @@ private:
    mutable Mutex mConnectionLock;
    std::unordered_map<int, int> mActivated;
    std::unordered_map<int, int> mActivatedBackup;

    mutable Mutex mDestroyLock;
    bool mDestroyed;
};

} // namepsace android
+14 −1
Original line number Diff line number Diff line
@@ -32,7 +32,8 @@ SensorService::SensorEventConnection::SensorEventConnection(
        const String16& opPackageName)
    : mService(service), mUid(uid), mWakeLockRefCount(0), mHasLooperCallbacks(false),
      mDead(false), mDataInjectionMode(isDataInjectionMode), mEventCache(NULL),
      mCacheSize(0), mMaxCacheSize(0), mPackageName(packageName), mOpPackageName(opPackageName) {
      mCacheSize(0), mMaxCacheSize(0), mPackageName(packageName), mOpPackageName(opPackageName),
      mDestroyed(false) {
    mChannel = new BitTube(mService->mSocketBufferSize);
#if DEBUG_CONNECTIONS
    mEventsReceived = mEventsSentFromCache = mEventsSent = 0;
@@ -42,10 +43,22 @@ SensorService::SensorEventConnection::SensorEventConnection(

SensorService::SensorEventConnection::~SensorEventConnection() {
    ALOGD_IF(DEBUG_CONNECTIONS, "~SensorEventConnection(%p)", this);
    destroy();
}

void SensorService::SensorEventConnection::destroy() {
    Mutex::Autolock _l(mDestroyLock);

    // destroy once only
    if (mDestroyed) {
        return;
    }

    mService->cleanupConnection(this);
    if (mEventCache != NULL) {
        delete mEventCache;
    }
    mDestroyed = true;
}

void SensorService::SensorEventConnection::onFirstRef() {
Loading