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

Commit a53e89d2 authored by Yifan Hong's avatar Yifan Hong
Browse files

SensorDeviceUtils: do not create sp(this) in constructor.

This may cause refcount problems as stated in RefBase
document. Do this in HidlServiceRegistrationWaiter::onFirstRef
instead.

Test: boots multiple times
Bug: 68765551
Change-Id: Iae2589f7e003cb8d44fe6ca43f1342b89125f763
parent 532a5524
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -29,6 +29,11 @@ namespace android {
namespace SensorDeviceUtils {

HidlServiceRegistrationWaiter::HidlServiceRegistrationWaiter() {
}

void HidlServiceRegistrationWaiter::onFirstRef() {
    // Creating sp<...>(this) in the constructor should be avoided, hence
    // registerForNotifications is called in onFirstRef callback.
    mRegistered = ISensors::registerForNotifications("default", this);
}

+2 −0
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@ public:
     * @return true if service is restart since last reset(); false otherwise.
     */
    bool wait();
protected:
    void onFirstRef() override;
private:
    bool mRegistered;