Merge "AudioFlinger: Util clang-tidy fixes"
diff --git a/media/codec2/sfplugin/CCodecBufferChannel.cpp b/media/codec2/sfplugin/CCodecBufferChannel.cpp
index 156cec1..51082d1 100644
--- a/media/codec2/sfplugin/CCodecBufferChannel.cpp
+++ b/media/codec2/sfplugin/CCodecBufferChannel.cpp
@@ -150,11 +150,10 @@
mFirstValidFrameIndex(0u),
mIsSurfaceToDisplay(false),
mHasPresentFenceTimes(false),
- mRenderingDepth(0u),
+ mRenderingDepth(3u),
mMetaMode(MODE_NONE),
mInputMetEos(false),
mSendEncryptedInfoBuffer(false) {
- mOutputSurface.lock()->maxDequeueBuffers = kSmoothnessFactor;
{
Mutexed<Input>::Locked input(mInput);
input->buffers.reset(new DummyInputBuffers(""));
@@ -176,8 +175,9 @@
pools->outputPoolId = C2BlockPool::BASIC_LINEAR;
}
std::string value = server_configurable_flags::GetServerConfigurableFlag(
- "media_native", "ccodec_rendering_depth", "0");
+ "media_native", "ccodec_rendering_depth", "3");
android::base::ParseInt(value, &mRenderingDepth);
+ mOutputSurface.lock()->maxDequeueBuffers = kSmoothnessFactor + mRenderingDepth;
}
CCodecBufferChannel::~CCodecBufferChannel() {
diff --git a/media/libaaudio/tests/test_resampler.cpp b/media/libaaudio/tests/test_resampler.cpp
index ebda431..13e4a20 100644
--- a/media/libaaudio/tests/test_resampler.cpp
+++ b/media/libaaudio/tests/test_resampler.cpp
@@ -101,14 +101,20 @@
}
}
+ // Flush out remaining frames from the flowgraph
+ while (!mcResampler->isWriteNeeded()) {
+ mcResampler->readNextFrame(output);
+ output++;
+ numRead++;
+ }
+
ASSERT_LE(numRead, kNumOutputSamples);
// Some frames are lost priming the FIR filter.
- const int kMaxAlgorithmicFrameLoss = 16;
+ const int kMaxAlgorithmicFrameLoss = 5;
EXPECT_GT(numRead, kNumOutputSamples - kMaxAlgorithmicFrameLoss);
int sinkZeroCrossingCount = countZeroCrossingsWithHysteresis(outputBuffer.get(), numRead);
- // Some cycles may get chopped off at the end.
- const int kMaxZeroCrossingDelta = 3;
+ const int kMaxZeroCrossingDelta = std::max(sinkRate / sourceRate / 2, 1);
EXPECT_LE(abs(sourceZeroCrossingCount - sinkZeroCrossingCount), kMaxZeroCrossingDelta);
// Detect glitches by looking for spikes in the second derivative.
@@ -136,8 +142,7 @@
TEST(test_resampler, resampler_scan_all) {
- // TODO Add 64000, 88200, 96000 when they work. Failing now.
- const int rates[] = {8000, 11025, 22050, 32000, 44100, 48000};
+ const int rates[] = {8000, 11025, 22050, 32000, 44100, 48000, 64000, 88200, 96000};
const MultiChannelResampler::Quality qualities[] =
{
MultiChannelResampler::Quality::Fastest,
diff --git a/media/libeffects/lvm/lib/Bundle/src/LVM_Process.cpp b/media/libeffects/lvm/lib/Bundle/src/LVM_Process.cpp
index 4eea04f..bfc5059 100644
--- a/media/libeffects/lvm/lib/Bundle/src/LVM_Process.cpp
+++ b/media/libeffects/lvm/lib/Bundle/src/LVM_Process.cpp
@@ -166,9 +166,9 @@
* Bypass mode or everything off, so copy the input to the output
*/
if (pToProcess != pProcessed) {
- Copy_Float(pToProcess, /* Source */
- pProcessed, /* Destination */
- (LVM_INT16)(NrChannels * NrFrames)); /* Copy all samples */
+ Copy_Float(pToProcess, /* Source */
+ pProcessed, /* Destination */
+ SampleCount); /* Copy all samples */
}
/*
diff --git a/services/audioflinger/sounddose/Android.bp b/services/audioflinger/sounddose/Android.bp
index 0a8c8be..d659261 100644
--- a/services/audioflinger/sounddose/Android.bp
+++ b/services/audioflinger/sounddose/Android.bp
@@ -7,12 +7,109 @@
default_applicable_licenses: ["frameworks_av_services_audioflinger_license"],
}
+audioflinger_sounddose_tidy_errors = [
+ // https://clang.llvm.org/extra/clang-tidy/checks/list.html
+ // For many categories, the checks are too many to specify individually.
+ // Feel free to disable as needed - as warnings are generally ignored,
+ // we treat warnings as errors.
+ "android-*",
+ "bugprone-*",
+ "cert-*",
+ "clang-analyzer-security*",
+ "google-*",
+ "misc-*",
+ //"modernize-*", // explicitly list the modernize as they can be subjective.
+ "modernize-avoid-bind",
+ "modernize-avoid-c-arrays", // std::array<> can be verbose
+ "modernize-concat-nested-namespaces",
+ "modernize-deprecated-headers", // C headers still ok even if there is C++ equivalent.
+ "modernize-deprecated-ios-base-aliases",
+ "modernize-loop-convert",
+ "modernize-make-shared",
+ "modernize-make-unique",
+ "modernize-pass-by-value",
+ "modernize-raw-string-literal",
+ "modernize-redundant-void-arg",
+ "modernize-replace-auto-ptr",
+ "modernize-replace-random-shuffle",
+ "modernize-return-braced-init-list",
+ "modernize-shrink-to-fit",
+ "modernize-unary-static-assert",
+ "modernize-use-auto", // debatable - auto can obscure type
+ "modernize-use-bool-literals",
+ "modernize-use-default-member-init",
+ "modernize-use-emplace",
+ "modernize-use-equals-default",
+ "modernize-use-equals-delete",
+ "modernize-use-nodiscard",
+ "modernize-use-noexcept",
+ "modernize-use-nullptr",
+ "modernize-use-override",
+ // "modernize-use-trailing-return-type", // not necessarily more readable
+ "modernize-use-transparent-functors",
+ "modernize-use-uncaught-exceptions",
+ "modernize-use-using",
+ "performance-*",
+
+ // Remove some pedantic stylistic requirements.
+ "-google-readability-casting", // C++ casts not always necessary and may be verbose
+ "-google-readability-todo", // do not require TODO(info)
+
+ "-bugprone-unhandled-self-assignment",
+ "-bugprone-suspicious-string-compare",
+ "-cert-oop54-cpp", // found in TransactionLog.h
+ "-bugprone-narrowing-conversions", // b/182410845
+
+ "-misc-non-private-member-variables-in-classes",
+]
+
+// Eventually use common tidy defaults
+cc_defaults {
+ name: "audioflinger_sounddose_flags_defaults",
+ // https://clang.llvm.org/docs/UsersManual.html#command-line-options
+ // https://clang.llvm.org/docs/DiagnosticsReference.html
+ cflags: [
+ "-Wall",
+ "-Wdeprecated",
+ "-Werror",
+ "-Werror=implicit-fallthrough",
+ "-Werror=sometimes-uninitialized",
+ "-Werror=conditional-uninitialized",
+ "-Wextra",
+
+ // suppress some warning chatter.
+ "-Wno-deprecated-copy-with-dtor",
+ "-Wno-deprecated-copy-with-user-provided-dtor",
+
+ "-Wredundant-decls",
+ "-Wshadow",
+ "-Wstrict-aliasing",
+ "-fstrict-aliasing",
+ "-Wthread-safety",
+ //"-Wthread-safety-negative", // experimental - looks broken in R.
+ "-Wunreachable-code",
+ "-Wunreachable-code-break",
+ "-Wunreachable-code-return",
+ "-Wunused",
+ "-Wused-but-marked-unused",
+ "-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS",
+ ],
+ // https://clang.llvm.org/extra/clang-tidy/
+ tidy: true,
+ tidy_checks: audioflinger_sounddose_tidy_errors,
+ tidy_checks_as_errors: audioflinger_sounddose_tidy_errors,
+ tidy_flags: [
+ "-format-style=file",
+ ],
+}
+
cc_library {
name: "libsounddose",
double_loadable: true,
defaults: [
+ "audioflinger_sounddose_flags_defaults",
"latest_android_media_audio_common_types_ndk_shared",
"latest_android_hardware_audio_core_sounddose_ndk_shared",
"latest_android_hardware_audio_sounddose_ndk_shared",
diff --git a/services/audioflinger/sounddose/SoundDoseManager.cpp b/services/audioflinger/sounddose/SoundDoseManager.cpp
index a114a38..21f346e 100644
--- a/services/audioflinger/sounddose/SoundDoseManager.cpp
+++ b/services/audioflinger/sounddose/SoundDoseManager.cpp
@@ -30,7 +30,6 @@
namespace android {
using aidl::android::media::audio::common::AudioDevice;
-using aidl::android::media::audio::common::AudioDeviceAddress;
namespace {
@@ -48,7 +47,7 @@
sp<audio_utils::MelProcessor> SoundDoseManager::getOrCreateProcessorForDevice(
audio_port_handle_t deviceId, audio_io_handle_t streamHandle, uint32_t sampleRate,
size_t channelCount, audio_format_t format) {
- std::lock_guard _l(mLock);
+ const std::lock_guard _l(mLock);
if (mHalSoundDose != nullptr && mEnabledCsd) {
ALOGD("%s: using HAL MEL computation, no MelProcessor needed.", __func__);
@@ -86,8 +85,9 @@
bool SoundDoseManager::setHalSoundDoseInterface(const std::shared_ptr<ISoundDose>& halSoundDose) {
ALOGV("%s", __func__);
+ std::shared_ptr<HalSoundDoseCallback> halSoundDoseCallback;
{
- std::lock_guard _l(mLock);
+ const std::lock_guard _l(mLock);
mHalSoundDose = halSoundDose;
if (halSoundDose == nullptr) {
@@ -106,9 +106,11 @@
mHalSoundDoseCallback =
ndk::SharedRefBase::make<HalSoundDoseCallback>(this);
}
+ halSoundDoseCallback = mHalSoundDoseCallback;
}
- auto status = halSoundDose->registerSoundDoseCallback(mHalSoundDoseCallback);
+ auto status = halSoundDose->registerSoundDoseCallback(halSoundDoseCallback);
+
if (!status.isOk()) {
// Not a warning since this can happen if the callback was registered before
ALOGI("%s: Cannot register HAL sound dose callback with status message: %s",
@@ -121,7 +123,7 @@
void SoundDoseManager::setOutputRs2UpperBound(float rs2Value) {
ALOGV("%s", __func__);
- std::lock_guard _l(mLock);
+ const std::lock_guard _l(mLock);
if (mHalSoundDose != nullptr) {
// using the HAL sound dose interface
@@ -134,9 +136,9 @@
}
for (auto& streamProcessor : mActiveProcessors) {
- sp<audio_utils::MelProcessor> processor = streamProcessor.second.promote();
+ const sp<audio_utils::MelProcessor> processor = streamProcessor.second.promote();
if (processor != nullptr) {
- status_t result = processor->setOutputRs2UpperBound(rs2Value);
+ const status_t result = processor->setOutputRs2UpperBound(rs2Value);
if (result != NO_ERROR) {
ALOGW("%s: could not set RS2 upper bound %f for stream %d", __func__, rs2Value,
streamProcessor.first);
@@ -148,7 +150,7 @@
}
void SoundDoseManager::removeStreamProcessor(audio_io_handle_t streamHandle) {
- std::lock_guard _l(mLock);
+ const std::lock_guard _l(mLock);
auto callbackToRemove = mActiveProcessors.find(streamHandle);
if (callbackToRemove != mActiveProcessors.end()) {
mActiveProcessors.erase(callbackToRemove);
@@ -156,7 +158,7 @@
}
audio_port_handle_t SoundDoseManager::getIdForAudioDevice(const AudioDevice& audioDevice) const {
- std::lock_guard _l(mLock);
+ const std::lock_guard _l(mLock);
audio_devices_t type;
std::string address;
@@ -178,14 +180,14 @@
void SoundDoseManager::mapAddressToDeviceId(const AudioDeviceTypeAddr& adt,
const audio_port_handle_t deviceId) {
- std::lock_guard _l(mLock);
+ const std::lock_guard _l(mLock);
ALOGI("%s: map address: %d to device id: %d", __func__, adt.mType, deviceId);
mActiveDevices[adt] = deviceId;
mActiveDeviceTypes[deviceId] = adt.mType;
}
void SoundDoseManager::clearMapDeviceIdEntries(audio_port_handle_t deviceId) {
- std::lock_guard _l(mLock);
+ const std::lock_guard _l(mLock);
for (auto activeDevice = mActiveDevices.begin(); activeDevice != mActiveDevices.end();) {
if (activeDevice->second == deviceId) {
ALOGI("%s: clear mapping type: %d to deviceId: %d",
@@ -303,7 +305,7 @@
ALOGV("%s", __func__);
auto soundDoseManager = mSoundDoseManager.promote();
if (soundDoseManager != nullptr) {
- std::lock_guard _l(soundDoseManager->mLock);
+ const std::lock_guard _l(soundDoseManager->mLock);
*value = soundDoseManager->mRs2UpperBound;
}
return binder::Status::ok();
@@ -348,7 +350,7 @@
}
void SoundDoseManager::updateAttenuation(float attenuationDB, audio_devices_t deviceType) {
- std::lock_guard _l(mLock);
+ const std::lock_guard _l(mLock);
ALOGV("%s: updating MEL processor attenuation for device type %d to %f",
__func__, deviceType, attenuationDB);
mMelAttenuationDB[deviceType] = attenuationDB;
@@ -368,7 +370,7 @@
void SoundDoseManager::setCsdEnabled(bool enabled) {
ALOGV("%s", __func__);
- std::lock_guard _l(mLock);
+ const std::lock_guard _l(mLock);
mEnabledCsd = enabled;
for (auto& activeEntry : mActiveProcessors) {
@@ -384,7 +386,7 @@
}
bool SoundDoseManager::isCsdEnabled() {
- std::lock_guard _l(mLock);
+ const std::lock_guard _l(mLock);
return mEnabledCsd;
}
@@ -392,52 +394,51 @@
// invalidate any HAL sound dose interface used
setHalSoundDoseInterface(nullptr);
- std::lock_guard _l(mLock);
+ const std::lock_guard _l(mLock);
mUseFrameworkMel = useFrameworkMel;
}
bool SoundDoseManager::forceUseFrameworkMel() const {
- std::lock_guard _l(mLock);
+ const std::lock_guard _l(mLock);
return mUseFrameworkMel;
}
void SoundDoseManager::setComputeCsdOnAllDevices(bool computeCsdOnAllDevices) {
- std::lock_guard _l(mLock);
+ const std::lock_guard _l(mLock);
mComputeCsdOnAllDevices = computeCsdOnAllDevices;
}
bool SoundDoseManager::forceComputeCsdOnAllDevices() const {
- std::lock_guard _l(mLock);
+ const std::lock_guard _l(mLock);
return mComputeCsdOnAllDevices;
}
bool SoundDoseManager::isSoundDoseHalSupported() const {
- if (!mEnabledCsd) {
- return false;
+ {
+ const std::lock_guard _l(mLock);
+ if (!mEnabledCsd) return false;
}
std::shared_ptr<ISoundDose> halSoundDose;
getHalSoundDose(&halSoundDose);
- if (mHalSoundDose == nullptr) {
- return false;
- }
- return true;
+ return halSoundDose != nullptr;
}
void SoundDoseManager::getHalSoundDose(std::shared_ptr<ISoundDose>* halSoundDose) const {
- std::lock_guard _l(mLock);
+ const std::lock_guard _l(mLock);
*halSoundDose = mHalSoundDose;
}
void SoundDoseManager::resetSoundDose() {
- std::lock_guard lock(mLock);
+ const std::lock_guard lock(mLock);
mSoundDose = nullptr;
}
void SoundDoseManager::resetCsd(float currentCsd,
const std::vector<media::SoundDoseRecord>& records) {
- std::lock_guard lock(mLock);
+ const std::lock_guard lock(mLock);
std::vector<audio_utils::CsdRecord> resetRecords;
+ resetRecords.reserve(records.size());
for (const auto& record : records) {
resetRecords.emplace_back(record.timestamp, record.duration, record.value,
record.averageMel);
@@ -455,13 +456,13 @@
std::vector<audio_utils::CsdRecord> records;
float currentCsd;
{
- std::lock_guard _l(mLock);
+ const std::lock_guard _l(mLock);
if (!mEnabledCsd) {
return;
}
- int64_t timestampSec = getMonotonicSecond();
+ const int64_t timestampSec = getMonotonicSecond();
// only for internal callbacks
records = mMelAggregator->aggregateAndAddNewMelRecord(audio_utils::MelRecord(
@@ -475,6 +476,7 @@
if (records.size() > 0 && soundDoseCallback != nullptr) {
std::vector<media::SoundDoseRecord> newRecordsToReport;
+ newRecordsToReport.resize(records.size());
for (const auto& record : records) {
newRecordsToReport.emplace_back(csdRecordToSoundDoseRecord(record));
}
@@ -484,7 +486,7 @@
}
sp<media::ISoundDoseCallback> SoundDoseManager::getSoundDoseCallback() const {
- std::lock_guard _l(mLock);
+ const std::lock_guard _l(mLock);
if (mSoundDose == nullptr) {
return nullptr;
}
@@ -496,7 +498,7 @@
ALOGV("%s: Momentary exposure for device %d triggered: %f MEL", __func__, deviceId, currentMel);
{
- std::lock_guard _l(mLock);
+ const std::lock_guard _l(mLock);
if (!mEnabledCsd) {
return;
}
@@ -512,7 +514,7 @@
const sp<media::ISoundDoseCallback>& callback) {
ALOGV("%s: Register ISoundDoseCallback", __func__);
- std::lock_guard _l(mLock);
+ const std::lock_guard _l(mLock);
if (mSoundDose == nullptr) {
mSoundDose = sp<SoundDose>::make(this, callback);
}
@@ -522,7 +524,7 @@
std::string SoundDoseManager::dump() const {
std::string output;
{
- std::lock_guard _l(mLock);
+ const std::lock_guard _l(mLock);
if (!mEnabledCsd) {
base::StringAppendF(&output, "CSD is disabled");
return output;
diff --git a/services/audioflinger/sounddose/SoundDoseManager.h b/services/audioflinger/sounddose/SoundDoseManager.h
index 6c02afb..9ed0661 100644
--- a/services/audioflinger/sounddose/SoundDoseManager.h
+++ b/services/audioflinger/sounddose/SoundDoseManager.h
@@ -129,7 +129,7 @@
mSoundDoseCallback(callback) {}
/** IBinder::DeathRecipient. Listen to the death of ISoundDoseCallback. */
- virtual void binderDied(const wp<IBinder>& who);
+ void binderDied(const wp<IBinder>& who) override;
/** BnSoundDose override */
binder::Status setOutputRs2UpperBound(float value) override;
diff --git a/services/camera/libcameraservice/Android.bp b/services/camera/libcameraservice/Android.bp
index c7be582..84dcf26 100644
--- a/services/camera/libcameraservice/Android.bp
+++ b/services/camera/libcameraservice/Android.bp
@@ -66,6 +66,8 @@
"libmedia_codeclist",
"libmedia_omx",
"libmemunreachable",
+ "libprocessgroup",
+ "libprocinfo",
"libsensorprivacy",
"libstagefright",
"libstagefright_foundation",
@@ -185,6 +187,7 @@
"utils/CameraThreadState.cpp",
"utils/CameraTraces.cpp",
"utils/AutoConditionLock.cpp",
+ "utils/SchedulingPolicyUtils.cpp",
"utils/SessionConfigurationUtils.cpp",
"utils/SessionConfigurationUtilsHidl.cpp",
"utils/SessionStatsBuilder.cpp",
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index 9d965cd..ca894fe 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -87,6 +87,7 @@
const char* kActivityServiceName = "activity";
const char* kSensorPrivacyServiceName = "sensor_privacy";
const char* kAppopsServiceName = "appops";
+ const char* kProcessInfoServiceName = "processinfo";
}; // namespace anonymous
namespace android {
@@ -1589,33 +1590,6 @@
}
}
- // Get current active client PIDs
- std::vector<int> ownerPids(mActiveClientManager.getAllOwners());
- ownerPids.push_back(clientPid);
-
- std::vector<int> priorityScores(ownerPids.size());
- std::vector<int> states(ownerPids.size());
-
- // Get priority scores of all active PIDs
- status_t err = ProcessInfoService::getProcessStatesScoresFromPids(
- ownerPids.size(), &ownerPids[0], /*out*/&states[0],
- /*out*/&priorityScores[0]);
- if (err != OK) {
- ALOGE("%s: Priority score query failed: %d",
- __FUNCTION__, err);
- return err;
- }
-
- // Update all active clients' priorities
- std::map<int,resource_policy::ClientPriority> pidToPriorityMap;
- for (size_t i = 0; i < ownerPids.size() - 1; i++) {
- pidToPriorityMap.emplace(ownerPids[i],
- resource_policy::ClientPriority(priorityScores[i], states[i],
- /* isVendorClient won't get copied over*/ false,
- /* oomScoreOffset won't get copied over*/ 0));
- }
- mActiveClientManager.updatePriorities(pidToPriorityMap);
-
// Get state for the given cameraId
auto state = getCameraState(cameraId);
if (state == nullptr) {
@@ -1625,16 +1599,57 @@
return BAD_VALUE;
}
- int32_t actualScore = priorityScores[priorityScores.size() - 1];
- int32_t actualState = states[states.size() - 1];
+ sp<IServiceManager> sm = defaultServiceManager();
+ sp<IBinder> binder = sm->checkService(String16(kProcessInfoServiceName));
+ if (!binder && isAutomotivePrivilegedClient(CameraThreadState::getCallingUid())) {
+ // If processinfo service is not available and the client is automotive privileged
+ // client used for safety critical uses cases such as rear-view and surround-view which
+ // needs to be available before android boot completes, then use the hardcoded values
+ // for the process state and priority score. As this scenario is before android system
+ // services are up and client is native client, hence using NATIVE_ADJ as the priority
+ // score and state as PROCESS_STATE_BOUND_TOP as such automotive apps need to be
+ // visible on the top.
+ clientDescriptor = CameraClientManager::makeClientDescriptor(cameraId,
+ sp<BasicClient>{nullptr}, static_cast<int32_t>(state->getCost()),
+ state->getConflicting(), resource_policy::NATIVE_ADJ, clientPid,
+ ActivityManager::PROCESS_STATE_BOUND_TOP, oomScoreOffset, systemNativeClient);
+ } else {
+ // Get current active client PIDs
+ std::vector<int> ownerPids(mActiveClientManager.getAllOwners());
+ ownerPids.push_back(clientPid);
- // Make descriptor for incoming client. We store the oomScoreOffset
- // since we might need it later on new handleEvictionsLocked and
- // ProcessInfoService would not take that into account.
- clientDescriptor = CameraClientManager::makeClientDescriptor(cameraId,
- sp<BasicClient>{nullptr}, static_cast<int32_t>(state->getCost()),
- state->getConflicting(), actualScore, clientPid, actualState,
- oomScoreOffset, systemNativeClient);
+ std::vector<int> priorityScores(ownerPids.size());
+ std::vector<int> states(ownerPids.size());
+
+ // Get priority scores of all active PIDs
+ status_t err = ProcessInfoService::getProcessStatesScoresFromPids(ownerPids.size(),
+ &ownerPids[0], /*out*/&states[0], /*out*/&priorityScores[0]);
+ if (err != OK) {
+ ALOGE("%s: Priority score query failed: %d", __FUNCTION__, err);
+ return err;
+ }
+
+ // Update all active clients' priorities
+ std::map<int,resource_policy::ClientPriority> pidToPriorityMap;
+ for (size_t i = 0; i < ownerPids.size() - 1; i++) {
+ pidToPriorityMap.emplace(ownerPids[i],
+ resource_policy::ClientPriority(priorityScores[i], states[i],
+ /* isVendorClient won't get copied over*/ false,
+ /* oomScoreOffset won't get copied over*/ 0));
+ }
+ mActiveClientManager.updatePriorities(pidToPriorityMap);
+
+ int32_t actualScore = priorityScores[priorityScores.size() - 1];
+ int32_t actualState = states[states.size() - 1];
+
+ // Make descriptor for incoming client. We store the oomScoreOffset
+ // since we might need it later on new handleEvictionsLocked and
+ // ProcessInfoService would not take that into account.
+ clientDescriptor = CameraClientManager::makeClientDescriptor(cameraId,
+ sp<BasicClient>{nullptr}, static_cast<int32_t>(state->getCost()),
+ state->getConflicting(), actualScore, clientPid, actualState,
+ oomScoreOffset, systemNativeClient);
+ }
resource_policy::ClientPriority clientPriority = clientDescriptor->getPriority();
diff --git a/services/camera/libcameraservice/device3/Camera3Device.cpp b/services/camera/libcameraservice/device3/Camera3Device.cpp
index cfe51c7..afcd29d 100644
--- a/services/camera/libcameraservice/device3/Camera3Device.cpp
+++ b/services/camera/libcameraservice/device3/Camera3Device.cpp
@@ -60,9 +60,9 @@
#include "device3/Camera3InputStream.h"
#include "device3/Camera3OutputStream.h"
#include "device3/Camera3SharedOutputStream.h"
-#include "mediautils/SchedulingPolicyService.h"
#include "utils/CameraThreadState.h"
#include "utils/CameraTraces.h"
+#include "utils/SchedulingPolicyUtils.h"
#include "utils/SessionConfigurationUtils.h"
#include "utils/TraceHFR.h"
@@ -2616,8 +2616,8 @@
if (disableFifo != 1) {
// Boost priority of request thread to SCHED_FIFO.
pid_t requestThreadTid = mRequestThread->getTid();
- res = requestPriority(getpid(), requestThreadTid,
- kRequestThreadPriority, /*isForApp*/ false, /*asynchronous*/ false);
+ res = SchedulingPolicyUtils::requestPriorityDirect(getpid(), requestThreadTid,
+ kRequestThreadPriority);
if (res != OK) {
ALOGW("Can't set realtime priority for request processing thread: %s (%d)",
strerror(-res), res);
diff --git a/services/camera/libcameraservice/utils/SchedulingPolicyUtils.cpp b/services/camera/libcameraservice/utils/SchedulingPolicyUtils.cpp
new file mode 100644
index 0000000..92a1030
--- /dev/null
+++ b/services/camera/libcameraservice/utils/SchedulingPolicyUtils.cpp
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "SchedulingPolicyUtils.h"
+
+#include <errno.h>
+#include <pthread.h>
+#include <sched.h>
+
+#include "CameraThreadState.h"
+#include <private/android_filesystem_config.h>
+#include <processgroup/processgroup.h>
+#include <processgroup/sched_policy.h>
+#include <procinfo/process.h>
+#include <utils/Log.h>
+
+namespace android {
+namespace camera3 {
+namespace SchedulingPolicyUtils {
+
+int requestPriorityDirect(int pid, int tid, int prio) {
+ android::procinfo::ProcessInfo processInfo;
+ static const int kMinPrio = 1;
+ static const int kMaxPrio = 3;
+
+ if (!android::procinfo::GetProcessInfo(tid, &processInfo)) {
+ ALOGE("%s: Error getting process info", __FUNCTION__);
+ return -EPERM;
+ }
+
+ if (prio < kMinPrio || prio > kMaxPrio || processInfo.pid != pid) {
+ ALOGE("%s: Invalid parameter prio=%d pid=%d procinfo.pid=%d", __FUNCTION__, prio, pid,
+ processInfo.pid);
+ return -EPERM;
+ }
+
+ // Set the thread group as audio system thread group in consistent with the
+ // implementation in SchedulingPolicyService.java when isApp is false in
+ // requestPriority method.
+ if (!SetTaskProfiles(tid, {get_sched_policy_profile_name(SP_AUDIO_SYS)},
+ /*use_fd_cache*/ true)) {
+ ALOGE("%s:Error in SetTaskProfiles", __FUNCTION__);
+ return -EPERM;
+ }
+
+ struct sched_param param;
+ param.sched_priority = prio;
+ return sched_setscheduler(tid, SCHED_FIFO | SCHED_RESET_ON_FORK, ¶m);
+}
+
+} // namespace SchedulingPolicyUtils
+} // namespace camera3
+} // namespace android
diff --git a/services/camera/libcameraservice/utils/SchedulingPolicyUtils.h b/services/camera/libcameraservice/utils/SchedulingPolicyUtils.h
new file mode 100644
index 0000000..f71fddf
--- /dev/null
+++ b/services/camera/libcameraservice/utils/SchedulingPolicyUtils.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef ANDROID_SERVICE_CAMERA_SCHEDULING_POLICY_UTILS_H
+#define ANDROID_SERVICE_CAMERA_SCHEDULING_POLICY_UTILS_H
+
+namespace android {
+namespace camera3 {
+namespace SchedulingPolicyUtils {
+
+/**
+ * Request elevated priority for thread tid, whose thread group leader must be pid.
+ * Instead of using scheduling policy service, this method uses direct system calls.
+ * The priority parameter is currently restricted from 1 to 3 matching
+ * scheduling policy service implementation.
+ */
+int requestPriorityDirect(int pid, int tid, int prio);
+
+} // SchedulingPolicyUtils
+} // camera3
+} // android
+
+#endif