Fix AudioSource fromExisting assert fail

- AudioSource::set can be called during ctor, during which
there will be no existing refs, causing fromExisting to fail.
- Removing the fromExisting check
- Remove unnecessary promotions before thread creation in
AudioRecord

Bug: 219554785
Test: atest CtsCameraTestCases
atest android.hardware.cts.CameraTest

Change-Id: I8c8615e39a0e7fa931704b5e505a8e703ab75625
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();
     }