Merge "Fix AudioSource fromExisting assert fail"
diff --git a/media/libaudioclient/AudioRecord.cpp b/media/libaudioclient/AudioRecord.cpp
index 2f8845f..a5fb394 100644
--- a/media/libaudioclient/AudioRecord.cpp
+++ b/media/libaudioclient/AudioRecord.cpp
@@ -307,7 +307,6 @@
         int32_t maxSharedAudioHistoryMs)
 {
     status_t status = NO_ERROR;
-    const sp<IAudioRecordCallback> callbackHandle = callback.promote();
     // Note mPortId is not valid until the track is created, so omit mPortId in ALOG for set.
     ALOGV("%s(): inputSource %d, sampleRate %u, format %#x, channelMask %#x, frameCount %zu, "
           "notificationFrames %u, sessionId %d, transferType %d, flags %#x, attributionSource %s"
@@ -373,14 +372,14 @@
     mTransfer = transferType;
     switch (mTransfer) {
     case TRANSFER_DEFAULT:
-        if (callbackHandle == nullptr || threadCanCallJava) {
+        if (callback == nullptr || threadCanCallJava) {
             mTransfer = TRANSFER_SYNC;
         } else {
             mTransfer = TRANSFER_CALLBACK;
         }
         break;
     case TRANSFER_CALLBACK:
-        if (callbackHandle == nullptr) {
+        if (callback == nullptr) {
             errorMessage = StringPrintf(
                     "%s: Transfer type TRANSFER_CALLBACK but callback == nullptr", __func__);
             status = BAD_VALUE;
@@ -429,7 +428,7 @@
     mNotificationFramesReq = notificationFrames;
     // mNotificationFramesAct is initialized in createRecord_l
 
-    mCallback = callbackHandle;
+    mCallback = callback;
     if (mCallback != nullptr) {
         mAudioRecordThread = new AudioRecordThread(*this);
         mAudioRecordThread->run("AudioRecord", ANDROID_PRIORITY_AUDIO);
@@ -640,7 +639,7 @@
 {
     AutoMutex lock(mLock);
     // The only purpose of setting marker position is to get a callback
-    if (mCallback.promote() == nullptr) {
+    if (mCallback == nullptr) {
         return INVALID_OPERATION;
     }
 
@@ -670,7 +669,7 @@
 {
     AutoMutex lock(mLock);
     // The only purpose of setting position update period is to get a callback
-    if (mCallback.promote() == nullptr) {
+    if (mCallback == nullptr) {
         return INVALID_OPERATION;
     }
 
@@ -1037,7 +1036,7 @@
                 mNotificationFramesReq, output.notificationFrameCount, output.frameCount);
     }
     mNotificationFramesAct = (uint32_t)output.notificationFrameCount;
-    if (mServerConfig.format != mFormat && mCallback.promote() != nullptr) {
+    if (mServerConfig.format != mFormat && mCallback != nullptr) {
         mFormatConversionBufRaw = std::make_unique<uint8_t[]>(mNotificationFramesAct * mFrameSize);
         mFormatConversionBuffer.raw = mFormatConversionBufRaw.get();
     }
diff --git a/media/libstagefright/AudioSource.cpp b/media/libstagefright/AudioSource.cpp
index faaae3f..bfe8538 100644
--- a/media/libstagefright/AudioSource.cpp
+++ b/media/libstagefright/AudioSource.cpp
@@ -117,7 +117,7 @@
         audio_channel_in_mask_from_count(channelCount),
         attributionSource,
         (size_t) (bufCount * frameCount),
-        wp<AudioRecord::IAudioRecordCallback>::fromExisting(this),
+        wp<AudioRecord::IAudioRecordCallback>{this},
         frameCount /*notificationFrames*/,
         AUDIO_SESSION_ALLOCATE,
         AudioRecord::TRANSFER_DEFAULT,