Merge "Prevent object of AudioEffect be deleted until construction finished" am: 637ee654cf am: 1b201ee707
am: e21535e728
Change-Id: I3a4e538c2e0b89be867f9d145acc0988fb697339
diff --git a/media/libaudioclient/AudioEffect.cpp b/media/libaudioclient/AudioEffect.cpp
index 0641b6e..da7d85e 100644
--- a/media/libaudioclient/AudioEffect.cpp
+++ b/media/libaudioclient/AudioEffect.cpp
@@ -52,6 +52,7 @@
)
: mStatus(NO_INIT), mOpPackageName(opPackageName)
{
+ AutoMutex lock(mConstructLock);
mStatus = set(type, uuid, priority, cbf, user, sessionId, io);
}
@@ -85,6 +86,7 @@
}
}
+ AutoMutex lock(mConstructLock);
mStatus = set(pType, pUuid, priority, cbf, user, sessionId, io);
}
diff --git a/media/libaudioclient/include/media/AudioEffect.h b/media/libaudioclient/include/media/AudioEffect.h
index c97f783..58a9baa 100644
--- a/media/libaudioclient/include/media/AudioEffect.h
+++ b/media/libaudioclient/include/media/AudioEffect.h
@@ -494,6 +494,7 @@
effect_descriptor_t mDescriptor; // effect descriptor
int32_t mId; // system wide unique effect engine instance ID
Mutex mLock; // Mutex for mEnabled access
+ Mutex mConstructLock; // Mutex for integrality construction
String16 mOpPackageName; // The package name used for app op checks.
@@ -520,12 +521,22 @@
virtual void controlStatusChanged(bool controlGranted) {
sp<AudioEffect> effect = mEffect.promote();
if (effect != 0) {
+ {
+ // Got the mConstructLock means the construction of AudioEffect
+ // has finished, we should release the mConstructLock immediately.
+ AutoMutex lock(effect->mConstructLock);
+ }
effect->controlStatusChanged(controlGranted);
}
}
virtual void enableStatusChanged(bool enabled) {
sp<AudioEffect> effect = mEffect.promote();
if (effect != 0) {
+ {
+ // Got the mConstructLock means the construction of AudioEffect
+ // has finished, we should release the mConstructLock immediately.
+ AutoMutex lock(effect->mConstructLock);
+ }
effect->enableStatusChanged(enabled);
}
}
@@ -536,6 +547,11 @@
void *pReplyData) {
sp<AudioEffect> effect = mEffect.promote();
if (effect != 0) {
+ {
+ // Got the mConstructLock means the construction of AudioEffect
+ // has finished, we should release the mConstructLock immediately.
+ AutoMutex lock(effect->mConstructLock);
+ }
effect->commandExecuted(
cmdCode, cmdSize, pCmdData, replySize, pReplyData);
}
@@ -545,6 +561,11 @@
virtual void binderDied(const wp<IBinder>& /*who*/) {
sp<AudioEffect> effect = mEffect.promote();
if (effect != 0) {
+ {
+ // Got the mConstructLock means the construction of AudioEffect
+ // has finished, we should release the mConstructLock immediately.
+ AutoMutex lock(effect->mConstructLock);
+ }
effect->binderDied();
}
}