audio: Fix the lifetime of the StreamWorker's logic part
Fix the mistake of making StreamWorker to inherit
from the part which provides actual thread logic (Impl).
The lifetime of the logic object must be longer
than the lifetime of the StreamWorker's thread.
Otherwise, the thread could still have running while
the logic has already been destroyed (consider
the order of destructors in C++ class inheritance).
With this fix, the StreamWorker class does not have
to be a template anymore, thus reorganize the code
to move big methods into a .cpp file.
Bug: 205884982
Test: atest libaudioaidlcommon_test --iterations
Change-Id: I5bc2c8fd9d78a0fbc9fddab67456cc5214584045
diff --git a/audio/aidl/common/Android.bp b/audio/aidl/common/Android.bp
index 37da9d6..f2d8fc2 100644
--- a/audio/aidl/common/Android.bp
+++ b/audio/aidl/common/Android.bp
@@ -23,7 +23,7 @@
default_applicable_licenses: ["hardware_interfaces_license"],
}
-cc_library_headers {
+cc_library {
name: "libaudioaidlcommon",
host_supported: true,
vendor_available: true,
@@ -36,13 +36,16 @@
"libbase_headers",
"libsystem_headers",
],
+ srcs: [
+ "StreamWorker.cpp",
+ ],
}
cc_test {
name: "libaudioaidlcommon_test",
host_supported: true,
vendor_available: true,
- header_libs: [
+ static_libs: [
"libaudioaidlcommon",
],
shared_libs: [