From 3c0699bc5ff449f79b4cf8bcffbb73be24710e73 Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Sat, 14 Sep 2019 04:06:49 +0200 Subject: [PATCH] libutils: Restore old RefBase-behavior for SDK < Q to avoid loops with legacy blobs 09-14 01: 13:36.048 528 528 D RefBase : RefBase: Explicit destruction, weak count = 0 (in 0xe5afad00) 09-14 01: 13:36.114 528 528 D RefBase : #00 pc 0000b1bd /system/lib/libutils.so (android::RefBase::~RefBase()+104) 09-14 01: 13:36.114 528 528 D RefBase : #01 pc 0009b15b /vendor/lib/hw/camera.msm8994.so (qcamera::CKPIItem::~CKPIItem()+22) 09-14 01: 13:36.114 528 528 D RefBase : #02 pc 0009b195 /vendor/lib/hw/camera.msm8994.so (qcamera::frame_quality::~frame_quality()+24) 09-14 01: 13:36.114 528 528 D RefBase : #03 pc 000abed9 /vendor/lib/hw/camera.msm8994.so (qcamera::Hal8994_EXT::~Hal8994_EXT()+112) 09-14 01: 13:36.114 528 528 D RefBase : #04 pc 000abff1 /vendor/lib/hw/camera.msm8994.so (qcamera::Hal8994_EXT::~Hal8994_EXT()+4) 09-14 01: 13:36.114 528 528 D RefBase : #05 pc 0006751f /vendor/lib/hw/camera.msm8994.so (qcamera::QCamera2HardwareInterface::~QCamera2HardwareInterface()+174) 09-14 01: 13:36.114 528 528 D RefBase : #06 pc 00067585 /vendor/lib/hw/camera.msm8994.so (qcamera::QCamera2HardwareInterface::~QCamera2HardwareInterface()+4) 09-14 01: 13:36.115 528 528 D RefBase : #07 pc 0005be5d /vendor/lib/hw/camera.msm8994.so (qcamera::QCamera2HardwareInterface::close_camera_device(hw_device_t*)+148) 09-14 01: 13:36.115 528 528 D RefBase : #08 pc 00015627 /vendor/lib/camera.device@1.0-impl-hima.so (android::hardware::camera::device::V1_0::implementation::CameraDevice::close()+54) 09-14 01: 13:36.115 528 528 D RefBase : #09 pc 00026819 /system/lib/android.hardware.camera.device@1.0.so (android::hardware::camera::device::V1_0::BsCameraDevice::close()+76) 09-14 01: 13:36.115 528 528 D RefBase : #10 pc 000ed439 /system/lib/libcameraservice.so (android::CameraHardwareInterface::release()+32) 09-14 01: 13:36.115 528 528 D RefBase : #11 pc 000b53f1 /system/lib/libcameraservice.so (android::CameraClient::disconnect()+164) 09-14 01: 13:36.115 528 528 D RefBase : #12 pc 0002eda7 /system/lib/libcamera_client.so (android::hardware::BnCamera::onTransact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+106) 09-14 01: 13:36.115 528 528 D RefBase : #13 pc 00032ee5 /system/lib/libbinder.so (android::BBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+72) 09-14 01: 13:36.115 528 528 D RefBase : #14 pc 0003afe9 /system/lib/libbinder.so (android::IPCThreadState::executeCommand(int)+768) 09-14 01: 13:36.115 528 528 D RefBase : #15 pc 0003ac2b /system/lib/libbinder.so (android::IPCThreadState::getAndExecuteCommand()+98) 09-14 01: 13:36.115 528 528 D RefBase : #16 pc 0003b1bf /system/lib/libbinder.so (android::IPCThreadState::joinThreadPool(bool)+38) 09-14 01: 13:36.115 528 528 D RefBase : #17 pc 000010ab /system/bin/cameraserver (main+102) 09-14 01: 13:36.115 528 528 D RefBase : #18 pc 000598f9 /apex/com.android.runtime/lib/bionic/libc.so (__libc_init+68) 09-14 01: 13:36.115 528 528 D RefBase : #19 pc 0000102f /system/bin/cameraserver (_start_main+38) 09-14 01: 13:36.115 528 528 D RefBase : #20 pc 0000446e Change-Id: I586a51d77968aec93d27c17aa92d0b3a55fb4878 Change-Id: Icd2bf08f14759e833e59c393f0f1771dd61128c3 --- libutils/Android.bp | 1 + libutils/RefBase.cpp | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libutils/Android.bp b/libutils/Android.bp index 13e4c02de0db..2a83fe953067 100644 --- a/libutils/Android.bp +++ b/libutils/Android.bp @@ -164,6 +164,7 @@ cc_library { srcs: [ "Trace.cpp", ], + cflags: ["-DCHECK_SDK"], }, linux: { header_libs: ["libbase_headers"], diff --git a/libutils/RefBase.cpp b/libutils/RefBase.cpp index b57e28741de2..be7ea7990b40 100644 --- a/libutils/RefBase.cpp +++ b/libutils/RefBase.cpp @@ -751,6 +751,12 @@ RefBase::~RefBase() } } else if (mRefs->mStrong.load(std::memory_order_relaxed) == INITIAL_STRONG_VALUE) { // We never acquired a strong reference on this object. +#ifdef CHECK_SDK +#include + // In Android Q this also fails for objects with 0 weak references. + // Restore old behavior if the SDK version precedes Q. + if ((android_get_application_target_sdk_version() >= __ANDROID_API_Q__) || (mRefs->mWeak.load() != 0)) { +#endif #if DEBUG_REFBASE_DESTRUCTION // Treating this as fatal is prone to causing boot loops. For debugging, it's // better to treat as non-fatal. @@ -760,7 +766,11 @@ RefBase::~RefBase() CallStack::logStack(LOG_TAG); #endif #else - LOG_ALWAYS_FATAL("RefBase: Explicit destruction, weak count = %d", mRefs->mWeak.load()); + LOG_ALWAYS_FATAL("RefBase: Explicit destruction, weak count = %d", mRefs->mWeak.load()); +#endif +#ifdef CHECK_SDK + } + delete mRefs; #endif } // For debugging purposes, clear mRefs. Ineffective against outstanding wp's.