Merge "switch over to use new storage read api instead of server_configurable_flags, this new read api lib will be needed for new codegened aconfig flag lib." into main
diff --git a/media/libaaudio/include/aaudio/AAudio.h b/media/libaaudio/include/aaudio/AAudio.h
index 9d9b574..21321b9 100644
--- a/media/libaaudio/include/aaudio/AAudio.h
+++ b/media/libaaudio/include/aaudio/AAudio.h
@@ -1115,6 +1115,17 @@
*
* The default, if you do not call this function, is {@link #AAUDIO_USAGE_MEDIA}.
*
+ * If you set Usage then you will need to associate the volume keys with the resulting stream.
+ * Otherwise the volume keys may not work correctly.
+ * This is done in Java with the following code block.
+ *
+ * <pre><code>if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ * AudioAttributes attributes = new AudioAttributes.Builder().setUsage(usage)
+ * .setContentType(contentType).build();
+ * setVolumeControlStream(attributes.getVolumeControlStream());
+ * }
+ * </code></pre>
+ *
* Available since API level 28.
*
* @param builder reference provided by AAudio_createStreamBuilder()
@@ -1132,6 +1143,17 @@
*
* The default, if you do not call this function, is {@link #AAUDIO_CONTENT_TYPE_MUSIC}.
*
+ * If you set ContentType then you will need to associate the volume keys with the resulting stream.
+ * Otherwise the volume keys may not work correctly.
+ * This is done in Java with the following code block.
+ *
+ * <pre><code>if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ * AudioAttributes attributes = new AudioAttributes.Builder().setUsage(usage)
+ * .setContentType(contentType).build();
+ * setVolumeControlStream(attributes.getVolumeControlStream());
+ * }
+ * </code></pre>
+ *
* Available since API level 28.
*
* @param builder reference provided by AAudio_createStreamBuilder()
diff --git a/media/libaudioclient/IAudioFlinger.cpp b/media/libaudioclient/IAudioFlinger.cpp
index cf3b43a..a707909 100644
--- a/media/libaudioclient/IAudioFlinger.cpp
+++ b/media/libaudioclient/IAudioFlinger.cpp
@@ -923,6 +923,11 @@
return statusTFromBinderStatus(mDelegate->setTracksInternalMute(tracksInternalMuted));
}
+status_t AudioFlingerClientAdapter::resetReferencesForTest() {
+ RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mDelegate->resetReferencesForTest()));
+ return OK;
+}
+
////////////////////////////////////////////////////////////////////////////////////////////////////
// AudioFlingerServerAdapter
AudioFlingerServerAdapter::AudioFlingerServerAdapter(
@@ -1487,4 +1492,9 @@
return Status::fromStatusT(mDelegate->setTracksInternalMute(tracksInternalMute));
}
+Status AudioFlingerServerAdapter::resetReferencesForTest() {
+ RETURN_BINDER_IF_ERROR(mDelegate->resetReferencesForTest());
+ return Status::ok();
+}
+
} // namespace android
diff --git a/media/libaudioclient/ToneGenerator.cpp b/media/libaudioclient/ToneGenerator.cpp
index e213f08..79fcea8 100644
--- a/media/libaudioclient/ToneGenerator.cpp
+++ b/media/libaudioclient/ToneGenerator.cpp
@@ -1264,13 +1264,10 @@
nsec += 1000000000;
}
- if ((sec + 1) > ((time_t)(INT_MAX / mSamplingRate))) {
- mMaxSmp = sec * mSamplingRate;
- } else {
- // mSamplingRate is always > 1000
- sec = sec * 1000 + nsec / 1000000; // duration in milliseconds
- mMaxSmp = (unsigned int)(((int64_t)sec * mSamplingRate) / 1000);
- }
+ const uint64_t msec = static_cast<uint64_t>(sec) * 1000 + nsec / 1'000'000;
+ mMaxSmp = std::min(static_cast<uint64_t>(TONEGEN_INF - 1),
+ msec * mSamplingRate / 1000);
+
ALOGV("stopTone() forcing mMaxSmp to %d, total for far %" PRIu64, mMaxSmp,
mTotalSmp);
} else {
@@ -1638,14 +1635,11 @@
mpToneDesc = mpNewToneDesc;
- if (mDurationMs == -1) {
+ if (mDurationMs < 0) { // mDurationMs is signed, treat all neg numbers as INF.
mMaxSmp = TONEGEN_INF;
} else {
- if (mDurationMs > (int)(TONEGEN_INF / mSamplingRate)) {
- mMaxSmp = (mDurationMs / 1000) * mSamplingRate;
- } else {
- mMaxSmp = (mDurationMs * mSamplingRate) / 1000;
- }
+ mMaxSmp = std::min(static_cast<uint64_t>(TONEGEN_INF - 1),
+ static_cast<uint64_t>(mDurationMs) * mSamplingRate / 1000);
ALOGV("prepareWave, duration limited to %d ms", mDurationMs);
}
@@ -1676,7 +1670,8 @@
if (mpToneDesc->segments[0].duration == TONEGEN_INF) {
mNextSegSmp = TONEGEN_INF;
} else{
- mNextSegSmp = (mpToneDesc->segments[0].duration * mSamplingRate) / 1000;
+ mNextSegSmp = std::min(static_cast<uint64_t>(TONEGEN_INF - 1),
+ static_cast<uint64_t>(mpToneDesc->segments[0].duration) * mSamplingRate / 1000);
}
return true;
diff --git a/media/libaudioclient/aidl/android/media/IAudioFlingerService.aidl b/media/libaudioclient/aidl/android/media/IAudioFlingerService.aidl
index e8fcf77..4f00f83 100644
--- a/media/libaudioclient/aidl/android/media/IAudioFlingerService.aidl
+++ b/media/libaudioclient/aidl/android/media/IAudioFlingerService.aidl
@@ -299,6 +299,12 @@
*/
void setTracksInternalMute(in TrackInternalMuteInfo[] tracksInternalMute);
+ /*
+ * Reset Circular references in AudioFlinger service.
+ * Test API
+ */
+ void resetReferencesForTest();
+
// When adding a new method, please review and update
// IAudioFlinger.h AudioFlingerServerAdapter::Delegate::TransactionCode
// AudioFlinger.cpp AudioFlinger::onTransactWrapper()
diff --git a/media/libaudioclient/include/media/IAudioFlinger.h b/media/libaudioclient/include/media/IAudioFlinger.h
index 860a0bc..211fffa 100644
--- a/media/libaudioclient/include/media/IAudioFlinger.h
+++ b/media/libaudioclient/include/media/IAudioFlinger.h
@@ -392,6 +392,8 @@
virtual status_t setTracksInternalMute(
const std::vector<media::TrackInternalMuteInfo>& tracksInternalMute) = 0;
+
+ virtual status_t resetReferencesForTest() = 0;
};
/**
@@ -510,6 +512,7 @@
struct audio_port_v7 *mixPort) const override;
status_t setTracksInternalMute(
const std::vector<media::TrackInternalMuteInfo>& tracksInternalMute) override;
+ status_t resetReferencesForTest() override;
private:
const sp<media::IAudioFlingerService> mDelegate;
@@ -613,6 +616,8 @@
media::BnAudioFlingerService::TRANSACTION_getAudioPolicyConfig,
GET_AUDIO_MIX_PORT = media::BnAudioFlingerService::TRANSACTION_getAudioMixPort,
SET_TRACKS_INTERNAL_MUTE = media::BnAudioFlingerService::TRANSACTION_setTracksInternalMute,
+ RESET_REFERENCES_FOR_TEST =
+ media::BnAudioFlingerService::TRANSACTION_resetReferencesForTest,
};
protected:
@@ -751,6 +756,7 @@
media::AudioPortFw* _aidl_return) override;
Status setTracksInternalMute(
const std::vector<media::TrackInternalMuteInfo>& tracksInternalMute) override;
+ Status resetReferencesForTest() override;
private:
const sp<AudioFlingerServerAdapter::Delegate> mDelegate;
};
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index c1d1a63..09edf68 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -193,6 +193,7 @@
BINDER_METHOD_ENTRY(getSoundDoseInterface) \
BINDER_METHOD_ENTRY(getAudioPolicyConfig) \
BINDER_METHOD_ENTRY(getAudioMixPort) \
+BINDER_METHOD_ENTRY(resetReferencesForTest) \
// singleton for Binder Method Statistics for IAudioFlinger
static auto& getIAudioFlingerStatistics() {
@@ -466,6 +467,8 @@
sMediaLogService->unregisterWriter(iMemory);
}
}
+ mMediaLogNotifier->requestExit();
+ mPatchCommandThread->exit();
}
//static
@@ -4986,6 +4989,13 @@
return NO_ERROR;
}
+status_t AudioFlinger::resetReferencesForTest() {
+ mDeviceEffectManager.clear();
+ mPatchPanel.clear();
+ mMelReporter->resetReferencesForTest();
+ return NO_ERROR;
+}
+
// ----------------------------------------------------------------------------
status_t AudioFlinger::onTransactWrapper(TransactionCode code,
@@ -5021,6 +5031,7 @@
case TransactionCode::GET_AUDIO_POLICY_CONFIG:
case TransactionCode::GET_AUDIO_MIX_PORT:
case TransactionCode::SET_TRACKS_INTERNAL_MUTE:
+ case TransactionCode::RESET_REFERENCES_FOR_TEST:
ALOGW("%s: transaction %d received from PID %d",
__func__, static_cast<int>(code), IPCThreadState::self()->getCallingPid());
// return status only for non void methods
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index 143a766..501aed1 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -62,6 +62,8 @@
public:
static void instantiate() ANDROID_API;
+ status_t resetReferencesForTest();
+
private:
// ---- begin IAudioFlinger interface
diff --git a/services/audioflinger/MelReporter.cpp b/services/audioflinger/MelReporter.cpp
index 1d38306..57f4ff6 100644
--- a/services/audioflinger/MelReporter.cpp
+++ b/services/audioflinger/MelReporter.cpp
@@ -117,6 +117,11 @@
}
}
+void MelReporter::resetReferencesForTest() {
+ mAfMelReporterCallback.clear();
+ mSoundDoseManager->resetReferencesForTest();
+}
+
void MelReporter::onCreateAudioPatch(audio_patch_handle_t handle,
const IAfPatchPanel::Patch& patch) {
if (!mSoundDoseManager->isCsdEnabled()) {
diff --git a/services/audioflinger/MelReporter.h b/services/audioflinger/MelReporter.h
index 0aeb225..8b062f3 100644
--- a/services/audioflinger/MelReporter.h
+++ b/services/audioflinger/MelReporter.h
@@ -103,6 +103,8 @@
const std::vector<playback_track_metadata_v7_t>& metadataVec)
EXCLUDES_AudioFlinger_Mutex;
+ void resetReferencesForTest();
+
private:
struct ActiveMelPatch {
audio_io_handle_t streamHandle{AUDIO_IO_HANDLE_NONE};
@@ -131,7 +133,7 @@
bool useHalSoundDoseInterface_l() REQUIRES(mutex());
- const sp<IAfMelReporterCallback> mAfMelReporterCallback;
+ sp<IAfMelReporterCallback> mAfMelReporterCallback;
const sp<IAfPatchPanel> mAfPatchPanel;
/* const */ sp<SoundDoseManager> mSoundDoseManager; // set onFirstRef
diff --git a/services/audioflinger/sounddose/SoundDoseManager.cpp b/services/audioflinger/sounddose/SoundDoseManager.cpp
index 3b764d1..cdc36dc 100644
--- a/services/audioflinger/sounddose/SoundDoseManager.cpp
+++ b/services/audioflinger/sounddose/SoundDoseManager.cpp
@@ -753,6 +753,10 @@
}
}
+void SoundDoseManager::resetReferencesForTest() {
+ mMelReporterCallback.clear();
+}
+
sp<media::ISoundDose> SoundDoseManager::getSoundDoseInterface(
const sp<media::ISoundDoseCallback>& callback) {
ALOGV("%s: Register ISoundDoseCallback", __func__);
diff --git a/services/audioflinger/sounddose/SoundDoseManager.h b/services/audioflinger/sounddose/SoundDoseManager.h
index 52a3fd6..8363d9b 100644
--- a/services/audioflinger/sounddose/SoundDoseManager.h
+++ b/services/audioflinger/sounddose/SoundDoseManager.h
@@ -157,6 +157,8 @@
void onMomentaryExposure(float currentMel, audio_port_handle_t deviceId) const override;
+ void resetReferencesForTest();
+
private:
class SoundDose : public media::BnSoundDose,
public IBinder::DeathRecipient {
@@ -229,7 +231,7 @@
mutable std::mutex mLock;
- const sp<IMelReporterCallback> mMelReporterCallback;
+ sp<IMelReporterCallback> mMelReporterCallback;
// no need for lock since MelAggregator is thread-safe
const sp<audio_utils::MelAggregator> mMelAggregator;