summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
Diffstat (limited to 'services')
-rw-r--r--services/audioflinger/AudioFlinger.cpp28
-rw-r--r--services/audioflinger/AudioFlinger.h3
-rw-r--r--services/audioflinger/Threads.cpp48
-rw-r--r--services/audioflinger/Threads.h20
-rwxr-xr-xservices/audiopolicy/common/include/policy.h10
-rw-r--r--services/audiopolicy/managerdefault/AudioPolicyManager.cpp4
-rw-r--r--services/mediaresourcemanager/ResourceManagerService.cpp86
-rw-r--r--services/mediaresourcemanager/ResourceManagerService.h8
-rw-r--r--services/mediaresourcemanager/test/ResourceManagerService_test.cpp137
9 files changed, 192 insertions, 152 deletions
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 52fce34..8f1e050 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -1252,11 +1252,9 @@ void AudioFlinger::registerClient(const sp<IAudioFlingerClient>& client)
if (client == 0) {
return;
}
- bool clientAdded = false;
+ pid_t pid = IPCThreadState::self()->getCallingPid();
{
Mutex::Autolock _cl(mClientLock);
-
- pid_t pid = IPCThreadState::self()->getCallingPid();
if (mNotificationClients.indexOfKey(pid) < 0) {
sp<NotificationClient> notificationClient = new NotificationClient(this,
client,
@@ -1267,22 +1265,19 @@ void AudioFlinger::registerClient(const sp<IAudioFlingerClient>& client)
sp<IBinder> binder = IInterface::asBinder(client);
binder->linkToDeath(notificationClient);
- clientAdded = true;
}
}
// mClientLock should not be held here because ThreadBase::sendIoConfigEvent() will lock the
// ThreadBase mutex and the locking order is ThreadBase::mLock then AudioFlinger::mClientLock.
- if (clientAdded) {
- // the config change is always sent from playback or record threads to avoid deadlock
- // with AudioSystem::gLock
- for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
- mPlaybackThreads.valueAt(i)->sendIoConfigEvent(AUDIO_OUTPUT_OPENED);
- }
+ // the config change is always sent from playback or record threads to avoid deadlock
+ // with AudioSystem::gLock
+ for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
+ mPlaybackThreads.valueAt(i)->sendIoConfigEvent(AUDIO_OUTPUT_OPENED, pid);
+ }
- for (size_t i = 0; i < mRecordThreads.size(); i++) {
- mRecordThreads.valueAt(i)->sendIoConfigEvent(AUDIO_INPUT_OPENED);
- }
+ for (size_t i = 0; i < mRecordThreads.size(); i++) {
+ mRecordThreads.valueAt(i)->sendIoConfigEvent(AUDIO_INPUT_OPENED, pid);
}
}
@@ -1316,12 +1311,15 @@ void AudioFlinger::removeNotificationClient(pid_t pid)
}
void AudioFlinger::ioConfigChanged(audio_io_config_event event,
- const sp<AudioIoDescriptor>& ioDesc)
+ const sp<AudioIoDescriptor>& ioDesc,
+ pid_t pid)
{
Mutex::Autolock _l(mClientLock);
size_t size = mNotificationClients.size();
for (size_t i = 0; i < size; i++) {
- mNotificationClients.valueAt(i)->audioFlingerClient()->ioConfigChanged(event, ioDesc);
+ if ((pid == 0) || (mNotificationClients.keyAt(i) == pid)) {
+ mNotificationClients.valueAt(i)->audioFlingerClient()->ioConfigChanged(event, ioDesc);
+ }
}
}
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index d087ced..4f7e27d 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -559,7 +559,8 @@ private:
float streamVolume_l(audio_stream_type_t stream) const
{ return mStreamTypes[stream].volume; }
void ioConfigChanged(audio_io_config_event event,
- const sp<AudioIoDescriptor>& ioDesc);
+ const sp<AudioIoDescriptor>& ioDesc,
+ pid_t pid = 0);
// Allocate an audio_io_handle_t, session ID, effect ID, or audio_module_handle_t.
// They all share the same ID space, but the namespaces are actually independent
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index d3ea9d8..d9f1a83 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -532,7 +532,8 @@ AudioFlinger::ThreadBase::ThreadBase(const sp<AudioFlinger>& audioFlinger, audio
// RecordThread::readInputParameters_l()
//FIXME: mStandby should be true here. Is this some kind of hack?
mStandby(false), mOutDevice(outDevice), mInDevice(inDevice),
- mPrevInDevice(AUDIO_DEVICE_NONE), mAudioSource(AUDIO_SOURCE_DEFAULT), mId(id),
+ mPrevOutDevice(AUDIO_DEVICE_NONE), mPrevInDevice(AUDIO_DEVICE_NONE),
+ mAudioSource(AUDIO_SOURCE_DEFAULT), mId(id),
// mName will be set by concrete (non-virtual) subclass
mDeathRecipient(new PMDeathRecipient(this)),
mSystemReady(systemReady)
@@ -627,16 +628,16 @@ status_t AudioFlinger::ThreadBase::sendConfigEvent_l(sp<ConfigEvent>& event)
return status;
}
-void AudioFlinger::ThreadBase::sendIoConfigEvent(audio_io_config_event event)
+void AudioFlinger::ThreadBase::sendIoConfigEvent(audio_io_config_event event, pid_t pid)
{
Mutex::Autolock _l(mLock);
- sendIoConfigEvent_l(event);
+ sendIoConfigEvent_l(event, pid);
}
// sendIoConfigEvent_l() must be called with ThreadBase::mLock held
-void AudioFlinger::ThreadBase::sendIoConfigEvent_l(audio_io_config_event event)
+void AudioFlinger::ThreadBase::sendIoConfigEvent_l(audio_io_config_event event, pid_t pid)
{
- sp<ConfigEvent> configEvent = (ConfigEvent *)new IoConfigEvent(event);
+ sp<ConfigEvent> configEvent = (ConfigEvent *)new IoConfigEvent(event, pid);
sendConfigEvent_l(configEvent);
}
@@ -706,7 +707,7 @@ void AudioFlinger::ThreadBase::processConfigEvents_l()
} break;
case CFG_EVENT_IO: {
IoConfigEventData *data = (IoConfigEventData *)event->mData.get();
- ioConfigChanged(data->mEvent);
+ ioConfigChanged(data->mEvent, data->mPid);
} break;
case CFG_EVENT_SET_PARAMETER: {
SetParameterConfigEventData *data = (SetParameterConfigEventData *)event->mData.get();
@@ -1999,7 +2000,7 @@ String8 AudioFlinger::PlaybackThread::getParameters(const String8& keys)
return out_s8;
}
-void AudioFlinger::PlaybackThread::ioConfigChanged(audio_io_config_event event) {
+void AudioFlinger::PlaybackThread::ioConfigChanged(audio_io_config_event event, pid_t pid) {
sp<AudioIoDescriptor> desc = new AudioIoDescriptor();
ALOGV("PlaybackThread::ioConfigChanged, thread %p, event %d", this, event);
@@ -2021,7 +2022,7 @@ void AudioFlinger::PlaybackThread::ioConfigChanged(audio_io_config_event event)
default:
break;
}
- mAudioFlinger->ioConfigChanged(event, desc);
+ mAudioFlinger->ioConfigChanged(event, desc, pid);
}
void AudioFlinger::PlaybackThread::writeCallback()
@@ -3133,7 +3134,10 @@ status_t AudioFlinger::PlaybackThread::createAudioPatch_l(const struct audio_pat
for (size_t i = 0; i < mEffectChains.size(); i++) {
mEffectChains[i]->setDevice_l(type);
}
- bool configChanged = mOutDevice != type;
+
+ // mPrevOutDevice is the latest device set by createAudioPatch_l(). It is not set when
+ // the thread is created so that the first patch creation triggers an ioConfigChanged callback
+ bool configChanged = mPrevOutDevice != type;
mOutDevice = type;
mPatch = *patch;
@@ -3163,6 +3167,7 @@ status_t AudioFlinger::PlaybackThread::createAudioPatch_l(const struct audio_pat
*handle = AUDIO_PATCH_HANDLE_NONE;
}
if (configChanged) {
+ mPrevOutDevice = type;
sendIoConfigEvent_l(AUDIO_OUTPUT_CONFIG_CHANGED);
}
return status;
@@ -4482,9 +4487,16 @@ void AudioFlinger::DirectOutputThread::onAddNewTrack_l()
sp<Track> previousTrack = mPreviousTrack.promote();
sp<Track> latestTrack = mLatestActiveTrack.promote();
- if (previousTrack != 0 && latestTrack != 0 &&
- (previousTrack->sessionId() != latestTrack->sessionId())) {
- mFlushPending = true;
+ if (previousTrack != 0 && latestTrack != 0) {
+ if (mType == DIRECT) {
+ if (previousTrack.get() != latestTrack.get()) {
+ mFlushPending = true;
+ }
+ } else /* mType == OFFLOAD */ {
+ if (previousTrack->sessionId() != latestTrack->sessionId()) {
+ mFlushPending = true;
+ }
+ }
}
PlaybackThread::onAddNewTrack_l();
}
@@ -4577,12 +4589,8 @@ AudioFlinger::PlaybackThread::mixer_state AudioFlinger::DirectOutputThread::prep
if (track != previousTrack.get()) {
// Flush any data still being written from last track
mBytesRemaining = 0;
- // flush data already sent if changing audio session as audio
- // comes from a different source. Also invalidate previous track to force a
- // seek when resuming.
- if (previousTrack->sessionId() != track->sessionId()) {
- previousTrack->invalidate();
- }
+ // Invalidate previous track to force a seek when resuming.
+ previousTrack->invalidate();
}
}
mPreviousTrack = track;
@@ -6868,7 +6876,7 @@ String8 AudioFlinger::RecordThread::getParameters(const String8& keys)
return out_s8;
}
-void AudioFlinger::RecordThread::ioConfigChanged(audio_io_config_event event) {
+void AudioFlinger::RecordThread::ioConfigChanged(audio_io_config_event event, pid_t pid) {
sp<AudioIoDescriptor> desc = new AudioIoDescriptor();
desc->mIoHandle = mId;
@@ -6888,7 +6896,7 @@ void AudioFlinger::RecordThread::ioConfigChanged(audio_io_config_event event) {
default:
break;
}
- mAudioFlinger->ioConfigChanged(event, desc);
+ mAudioFlinger->ioConfigChanged(event, desc, pid);
}
void AudioFlinger::RecordThread::readInputParameters_l()
diff --git a/services/audioflinger/Threads.h b/services/audioflinger/Threads.h
index 0783371..46ac300 100644
--- a/services/audioflinger/Threads.h
+++ b/services/audioflinger/Threads.h
@@ -104,21 +104,22 @@ public:
class IoConfigEventData : public ConfigEventData {
public:
- IoConfigEventData(audio_io_config_event event) :
- mEvent(event) {}
+ IoConfigEventData(audio_io_config_event event, pid_t pid) :
+ mEvent(event), mPid(pid) {}
virtual void dump(char *buffer, size_t size) {
snprintf(buffer, size, "IO event: event %d\n", mEvent);
}
const audio_io_config_event mEvent;
+ const pid_t mPid;
};
class IoConfigEvent : public ConfigEvent {
public:
- IoConfigEvent(audio_io_config_event event) :
+ IoConfigEvent(audio_io_config_event event, pid_t pid) :
ConfigEvent(CFG_EVENT_IO) {
- mData = new IoConfigEventData(event);
+ mData = new IoConfigEventData(event, pid);
}
virtual ~IoConfigEvent() {}
};
@@ -255,13 +256,13 @@ public:
status_t& status) = 0;
virtual status_t setParameters(const String8& keyValuePairs);
virtual String8 getParameters(const String8& keys) = 0;
- virtual void ioConfigChanged(audio_io_config_event event) = 0;
+ virtual void ioConfigChanged(audio_io_config_event event, pid_t pid = 0) = 0;
// sendConfigEvent_l() must be called with ThreadBase::mLock held
// Can temporarily release the lock if waiting for a reply from
// processConfigEvents_l().
status_t sendConfigEvent_l(sp<ConfigEvent>& event);
- void sendIoConfigEvent(audio_io_config_event event);
- void sendIoConfigEvent_l(audio_io_config_event event);
+ void sendIoConfigEvent(audio_io_config_event event, pid_t pid = 0);
+ void sendIoConfigEvent_l(audio_io_config_event event, pid_t pid = 0);
void sendPrioConfigEvent(pid_t pid, pid_t tid, int32_t prio);
void sendPrioConfigEvent_l(pid_t pid, pid_t tid, int32_t prio);
status_t sendSetParameterConfigEvent_l(const String8& keyValuePair);
@@ -436,6 +437,7 @@ protected:
bool mStandby; // Whether thread is currently in standby.
audio_devices_t mOutDevice; // output device
audio_devices_t mInDevice; // input device
+ audio_devices_t mPrevOutDevice; // previous output device
audio_devices_t mPrevInDevice; // previous input device
struct audio_patch mPatch;
audio_source_t mAudioSource;
@@ -572,7 +574,7 @@ public:
{ return android_atomic_acquire_load(&mSuspended) > 0; }
virtual String8 getParameters(const String8& keys);
- virtual void ioConfigChanged(audio_io_config_event event);
+ virtual void ioConfigChanged(audio_io_config_event event, pid_t pid = 0);
status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames);
// FIXME rename mixBuffer() to sinkBuffer() and remove int16_t* dependency.
// Consider also removing and passing an explicit mMainBuffer initialization
@@ -1254,7 +1256,7 @@ public:
status_t& status);
virtual void cacheParameters_l() {}
virtual String8 getParameters(const String8& keys);
- virtual void ioConfigChanged(audio_io_config_event event);
+ virtual void ioConfigChanged(audio_io_config_event event, pid_t pid = 0);
virtual status_t createAudioPatch_l(const struct audio_patch *patch,
audio_patch_handle_t *handle);
virtual status_t releaseAudioPatch_l(const audio_patch_handle_t handle);
diff --git a/services/audiopolicy/common/include/policy.h b/services/audiopolicy/common/include/policy.h
index 4eef02f..4b73e3c 100755
--- a/services/audiopolicy/common/include/policy.h
+++ b/services/audiopolicy/common/include/policy.h
@@ -37,8 +37,9 @@
* A device mask for all audio input and output devices where matching inputs/outputs on device
* type alone is not enough: the address must match too
*/
-#define APM_AUDIO_DEVICE_MATCH_ADDRESS_ALL (AUDIO_DEVICE_IN_REMOTE_SUBMIX | \
- AUDIO_DEVICE_OUT_REMOTE_SUBMIX)
+#define APM_AUDIO_DEVICE_OUT_MATCH_ADDRESS_ALL (AUDIO_DEVICE_OUT_REMOTE_SUBMIX)
+
+#define APM_AUDIO_DEVICE_IN_MATCH_ADDRESS_ALL (AUDIO_DEVICE_IN_REMOTE_SUBMIX)
/**
* Check if the state given correspond to an in call state.
@@ -80,5 +81,8 @@ static inline bool is_virtual_input_device(audio_devices_t device)
*/
static inline bool device_distinguishes_on_address(audio_devices_t device)
{
- return ((device & APM_AUDIO_DEVICE_MATCH_ADDRESS_ALL & ~AUDIO_DEVICE_BIT_IN) != 0);
+ return (((device & AUDIO_DEVICE_BIT_IN) != 0) &&
+ ((~AUDIO_DEVICE_BIT_IN & device & APM_AUDIO_DEVICE_IN_MATCH_ADDRESS_ALL) != 0)) ||
+ (((device & AUDIO_DEVICE_BIT_IN) == 0) &&
+ ((device & APM_AUDIO_DEVICE_OUT_MATCH_ADDRESS_ALL) != 0));
}
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index de204e5..6d99640 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -1076,6 +1076,9 @@ status_t AudioPolicyManager::startSource(sp<AudioOutputDescriptor> outputDesc,
beaconMuteLatency = handleEventForBeacon(STARTING_OUTPUT);
}
+ // check active before incrementing usage count
+ bool force = !outputDesc->isActive();
+
// increment usage count for this stream on the requested output:
// NOTE that the usage count is the same for duplicated output and hardware output which is
// necessary for a correct control of hardware output routing by startOutput() and stopOutput()
@@ -1091,7 +1094,6 @@ status_t AudioPolicyManager::startSource(sp<AudioOutputDescriptor> outputDesc,
(strategy == STRATEGY_SONIFICATION_RESPECTFUL) ||
(beaconMuteLatency > 0);
uint32_t waitMs = beaconMuteLatency;
- bool force = false;
for (size_t i = 0; i < mOutputs.size(); i++) {
sp<AudioOutputDescriptor> desc = mOutputs.valueAt(i);
if (desc != outputDesc) {
diff --git a/services/mediaresourcemanager/ResourceManagerService.cpp b/services/mediaresourcemanager/ResourceManagerService.cpp
index e2b6695..61147ff 100644
--- a/services/mediaresourcemanager/ResourceManagerService.cpp
+++ b/services/mediaresourcemanager/ResourceManagerService.cpp
@@ -204,6 +204,17 @@ void ResourceManagerService::removeResource(int64_t clientId) {
}
}
+void ResourceManagerService::getClientForResource_l(
+ int callingPid, const MediaResource *res, Vector<sp<IResourceManagerClient>> *clients) {
+ if (res == NULL) {
+ return;
+ }
+ sp<IResourceManagerClient> client;
+ if (getLowestPriorityBiggestClient_l(callingPid, res->mType, &client)) {
+ clients->push_back(client);
+ }
+}
+
bool ResourceManagerService::reclaimResource(
int callingPid, const Vector<MediaResource> &resources) {
String8 log = String8::format("reclaimResource(callingPid %d, resources %s)",
@@ -213,54 +224,61 @@ bool ResourceManagerService::reclaimResource(
Vector<sp<IResourceManagerClient>> clients;
{
Mutex::Autolock lock(mLock);
- // first pass to handle secure/non-secure codec conflict
+ const MediaResource *secureCodec = NULL;
+ const MediaResource *nonSecureCodec = NULL;
+ const MediaResource *graphicMemory = NULL;
for (size_t i = 0; i < resources.size(); ++i) {
String8 type = resources[i].mType;
- if (type == kResourceSecureCodec) {
- if (!mSupportsMultipleSecureCodecs) {
- if (!getAllClients_l(callingPid, String8(kResourceSecureCodec), &clients)) {
- return false;
- }
+ if (resources[i].mType == kResourceSecureCodec) {
+ secureCodec = &resources[i];
+ } else if (type == kResourceNonSecureCodec) {
+ nonSecureCodec = &resources[i];
+ } else if (type == kResourceGraphicMemory) {
+ graphicMemory = &resources[i];
+ }
+ }
+
+ // first pass to handle secure/non-secure codec conflict
+ if (secureCodec != NULL) {
+ if (!mSupportsMultipleSecureCodecs) {
+ if (!getAllClients_l(callingPid, String8(kResourceSecureCodec), &clients)) {
+ return false;
}
- if (!mSupportsSecureWithNonSecureCodec) {
- if (!getAllClients_l(callingPid, String8(kResourceNonSecureCodec), &clients)) {
- return false;
- }
+ }
+ if (!mSupportsSecureWithNonSecureCodec) {
+ if (!getAllClients_l(callingPid, String8(kResourceNonSecureCodec), &clients)) {
+ return false;
}
- } else if (type == kResourceNonSecureCodec) {
- if (!mSupportsSecureWithNonSecureCodec) {
- if (!getAllClients_l(callingPid, String8(kResourceSecureCodec), &clients)) {
- return false;
- }
+ }
+ }
+ if (nonSecureCodec != NULL) {
+ if (!mSupportsSecureWithNonSecureCodec) {
+ if (!getAllClients_l(callingPid, String8(kResourceSecureCodec), &clients)) {
+ return false;
}
}
}
if (clients.size() == 0) {
// if no secure/non-secure codec conflict, run second pass to handle other resources.
- for (size_t i = 0; i < resources.size(); ++i) {
- String8 type = resources[i].mType;
- if (type == kResourceGraphicMemory) {
- sp<IResourceManagerClient> client;
- if (!getLowestPriorityBiggestClient_l(callingPid, type, &client)) {
- return false;
- }
- clients.push_back(client);
- }
- }
+ getClientForResource_l(callingPid, graphicMemory, &clients);
}
if (clients.size() == 0) {
// if we are here, run the third pass to free one codec with the same type.
- for (size_t i = 0; i < resources.size(); ++i) {
- String8 type = resources[i].mType;
- if (type == kResourceSecureCodec || type == kResourceNonSecureCodec) {
- sp<IResourceManagerClient> client;
- if (!getLowestPriorityBiggestClient_l(callingPid, type, &client)) {
- return false;
- }
- clients.push_back(client);
- }
+ getClientForResource_l(callingPid, secureCodec, &clients);
+ getClientForResource_l(callingPid, nonSecureCodec, &clients);
+ }
+
+ if (clients.size() == 0) {
+ // if we are here, run the fourth pass to free one codec with the different type.
+ if (secureCodec != NULL) {
+ MediaResource temp(String8(kResourceNonSecureCodec), 1);
+ getClientForResource_l(callingPid, &temp, &clients);
+ }
+ if (nonSecureCodec != NULL) {
+ MediaResource temp(String8(kResourceSecureCodec), 1);
+ getClientForResource_l(callingPid, &temp, &clients);
}
}
}
diff --git a/services/mediaresourcemanager/ResourceManagerService.h b/services/mediaresourcemanager/ResourceManagerService.h
index 0d9d878..ca218fc 100644
--- a/services/mediaresourcemanager/ResourceManagerService.h
+++ b/services/mediaresourcemanager/ResourceManagerService.h
@@ -65,6 +65,9 @@ public:
virtual void removeResource(int64_t clientId);
+ // Tries to reclaim resource from processes with lower priority than the calling process
+ // according to the requested resources.
+ // Returns true if any resource has been reclaimed, otherwise returns false.
virtual bool reclaimResource(int callingPid, const Vector<MediaResource> &resources);
protected:
@@ -95,6 +98,11 @@ private:
bool isCallingPriorityHigher_l(int callingPid, int pid);
+ // A helper function basically calls getLowestPriorityBiggestClient_l and add the result client
+ // to the given Vector.
+ void getClientForResource_l(
+ int callingPid, const MediaResource *res, Vector<sp<IResourceManagerClient>> *clients);
+
mutable Mutex mLock;
sp<ProcessInfoInterface> mProcessInfo;
sp<ServiceLog> mServiceLog;
diff --git a/services/mediaresourcemanager/test/ResourceManagerService_test.cpp b/services/mediaresourcemanager/test/ResourceManagerService_test.cpp
index 3d53f1f..8ae6a55 100644
--- a/services/mediaresourcemanager/test/ResourceManagerService_test.cpp
+++ b/services/mediaresourcemanager/test/ResourceManagerService_test.cpp
@@ -79,6 +79,10 @@ private:
static const int kTestPid1 = 30;
static const int kTestPid2 = 20;
+static const int kLowPriorityPid = 40;
+static const int kMidPriorityPid = 25;
+static const int kHighPriorityPid = 10;
+
class ResourceManagerServiceTest : public ::testing::Test {
public:
ResourceManagerServiceTest()
@@ -227,15 +231,12 @@ protected:
String8 type = String8(kResourceSecureCodec);
String8 unknowType = String8("unknowType");
Vector<sp<IResourceManagerClient> > clients;
- int lowPriorityPid = 100;
- EXPECT_FALSE(mService->getAllClients_l(lowPriorityPid, type, &clients));
- int midPriorityPid = 25;
+ EXPECT_FALSE(mService->getAllClients_l(kLowPriorityPid, type, &clients));
// some higher priority process (e.g. kTestPid2) owns the resource, so getAllClients_l
// will fail.
- EXPECT_FALSE(mService->getAllClients_l(midPriorityPid, type, &clients));
- int highPriorityPid = 10;
- EXPECT_TRUE(mService->getAllClients_l(highPriorityPid, unknowType, &clients));
- EXPECT_TRUE(mService->getAllClients_l(highPriorityPid, type, &clients));
+ EXPECT_FALSE(mService->getAllClients_l(kMidPriorityPid, type, &clients));
+ EXPECT_TRUE(mService->getAllClients_l(kHighPriorityPid, unknowType, &clients));
+ EXPECT_TRUE(mService->getAllClients_l(kHighPriorityPid, type, &clients));
EXPECT_EQ(2u, clients.size());
EXPECT_EQ(mTestClient3, clients[0]);
@@ -254,19 +255,19 @@ protected:
mService->mSupportsSecureWithNonSecureCodec = true;
// priority too low
- EXPECT_FALSE(mService->reclaimResource(40, resources));
- EXPECT_FALSE(mService->reclaimResource(25, resources));
+ EXPECT_FALSE(mService->reclaimResource(kLowPriorityPid, resources));
+ EXPECT_FALSE(mService->reclaimResource(kMidPriorityPid, resources));
// reclaim all secure codecs
- EXPECT_TRUE(mService->reclaimResource(10, resources));
- verifyClients(true, false, true);
+ EXPECT_TRUE(mService->reclaimResource(kHighPriorityPid, resources));
+ verifyClients(true /* c1 */, false /* c2 */, true /* c3 */);
// call again should reclaim one largest graphic memory from lowest process
- EXPECT_TRUE(mService->reclaimResource(10, resources));
- verifyClients(false, true, false);
+ EXPECT_TRUE(mService->reclaimResource(kHighPriorityPid, resources));
+ verifyClients(false /* c1 */, true /* c2 */, false /* c3 */);
// nothing left
- EXPECT_FALSE(mService->reclaimResource(10, resources));
+ EXPECT_FALSE(mService->reclaimResource(kHighPriorityPid, resources));
}
// ### secure codecs can't coexist and secure codec can't coexist with non-secure codec ###
@@ -276,15 +277,15 @@ protected:
mService->mSupportsSecureWithNonSecureCodec = false;
// priority too low
- EXPECT_FALSE(mService->reclaimResource(40, resources));
- EXPECT_FALSE(mService->reclaimResource(25, resources));
+ EXPECT_FALSE(mService->reclaimResource(kLowPriorityPid, resources));
+ EXPECT_FALSE(mService->reclaimResource(kMidPriorityPid, resources));
// reclaim all secure and non-secure codecs
- EXPECT_TRUE(mService->reclaimResource(10, resources));
- verifyClients(true, true, true);
+ EXPECT_TRUE(mService->reclaimResource(kHighPriorityPid, resources));
+ verifyClients(true /* c1 */, true /* c2 */, true /* c3 */);
// nothing left
- EXPECT_FALSE(mService->reclaimResource(10, resources));
+ EXPECT_FALSE(mService->reclaimResource(kHighPriorityPid, resources));
}
@@ -295,23 +296,23 @@ protected:
mService->mSupportsSecureWithNonSecureCodec = false;
// priority too low
- EXPECT_FALSE(mService->reclaimResource(40, resources));
- EXPECT_FALSE(mService->reclaimResource(25, resources));
+ EXPECT_FALSE(mService->reclaimResource(kLowPriorityPid, resources));
+ EXPECT_FALSE(mService->reclaimResource(kMidPriorityPid, resources));
// reclaim all non-secure codecs
- EXPECT_TRUE(mService->reclaimResource(10, resources));
- verifyClients(false, true, false);
+ EXPECT_TRUE(mService->reclaimResource(kHighPriorityPid, resources));
+ verifyClients(false /* c1 */, true /* c2 */, false /* c3 */);
// call again should reclaim one largest graphic memory from lowest process
- EXPECT_TRUE(mService->reclaimResource(10, resources));
- verifyClients(true, false, false);
+ EXPECT_TRUE(mService->reclaimResource(kHighPriorityPid, resources));
+ verifyClients(true /* c1 */, false /* c2 */, false /* c3 */);
// call again should reclaim another largest graphic memory from lowest process
- EXPECT_TRUE(mService->reclaimResource(10, resources));
- verifyClients(false, false, true);
+ EXPECT_TRUE(mService->reclaimResource(kHighPriorityPid, resources));
+ verifyClients(false /* c1 */, false /* c2 */, true /* c3 */);
// nothing left
- EXPECT_FALSE(mService->reclaimResource(10, resources));
+ EXPECT_FALSE(mService->reclaimResource(kHighPriorityPid, resources));
}
// ### secure codecs can coexist and secure codec can coexist with non-secure codec ###
@@ -321,22 +322,22 @@ protected:
mService->mSupportsSecureWithNonSecureCodec = true;
// priority too low
- EXPECT_FALSE(mService->reclaimResource(40, resources));
+ EXPECT_FALSE(mService->reclaimResource(kLowPriorityPid, resources));
- EXPECT_TRUE(mService->reclaimResource(10, resources));
+ EXPECT_TRUE(mService->reclaimResource(kHighPriorityPid, resources));
// one largest graphic memory from lowest process got reclaimed
- verifyClients(true, false, false);
+ verifyClients(true /* c1 */, false /* c2 */, false /* c3 */);
// call again should reclaim another graphic memory from lowest process
- EXPECT_TRUE(mService->reclaimResource(10, resources));
- verifyClients(false, true, false);
+ EXPECT_TRUE(mService->reclaimResource(kHighPriorityPid, resources));
+ verifyClients(false /* c1 */, true /* c2 */, false /* c3 */);
// call again should reclaim another graphic memory from lowest process
- EXPECT_TRUE(mService->reclaimResource(10, resources));
- verifyClients(false, false, true);
+ EXPECT_TRUE(mService->reclaimResource(kHighPriorityPid, resources));
+ verifyClients(false /* c1 */, false /* c2 */, true /* c3 */);
// nothing left
- EXPECT_FALSE(mService->reclaimResource(10, resources));
+ EXPECT_FALSE(mService->reclaimResource(kHighPriorityPid, resources));
}
// ### secure codecs can coexist and secure codec can coexist with non-secure codec ###
@@ -348,19 +349,17 @@ protected:
Vector<MediaResource> resources;
resources.push_back(MediaResource(String8(kResourceSecureCodec), 1));
- EXPECT_TRUE(mService->reclaimResource(10, resources));
+ EXPECT_TRUE(mService->reclaimResource(kHighPriorityPid, resources));
// secure codec from lowest process got reclaimed
- verifyClients(true, false, false);
+ verifyClients(true /* c1 */, false /* c2 */, false /* c3 */);
// call again should reclaim another secure codec from lowest process
- EXPECT_TRUE(mService->reclaimResource(10, resources));
- verifyClients(false, false, true);
-
- // nothing left
- EXPECT_FALSE(mService->reclaimResource(10, resources));
+ EXPECT_TRUE(mService->reclaimResource(kHighPriorityPid, resources));
+ verifyClients(false /* c1 */, false /* c2 */, true /* c3 */);
- // clean up client 2 which still has non secure codec left
- mService->removeResource((int64_t) mTestClient2.get());
+ // no more secure codec, non-secure codec will be reclaimed.
+ EXPECT_TRUE(mService->reclaimResource(kHighPriorityPid, resources));
+ verifyClients(false /* c1 */, true /* c2 */, false /* c3 */);
}
}
@@ -375,19 +374,19 @@ protected:
mService->mSupportsSecureWithNonSecureCodec = false;
// priority too low
- EXPECT_FALSE(mService->reclaimResource(40, resources));
- EXPECT_FALSE(mService->reclaimResource(25, resources));
+ EXPECT_FALSE(mService->reclaimResource(kLowPriorityPid, resources));
+ EXPECT_FALSE(mService->reclaimResource(kMidPriorityPid, resources));
// reclaim all secure codecs
- EXPECT_TRUE(mService->reclaimResource(10, resources));
- verifyClients(true, false, true);
+ EXPECT_TRUE(mService->reclaimResource(kHighPriorityPid, resources));
+ verifyClients(true /* c1 */, false /* c2 */, true /* c3 */);
// call again should reclaim one graphic memory from lowest process
- EXPECT_TRUE(mService->reclaimResource(10, resources));
- verifyClients(false, true, false);
+ EXPECT_TRUE(mService->reclaimResource(kHighPriorityPid, resources));
+ verifyClients(false /* c1 */, true /* c2 */, false /* c3 */);
// nothing left
- EXPECT_FALSE(mService->reclaimResource(10, resources));
+ EXPECT_FALSE(mService->reclaimResource(kHighPriorityPid, resources));
}
@@ -397,22 +396,22 @@ protected:
mService->mSupportsSecureWithNonSecureCodec = true;
// priority too low
- EXPECT_FALSE(mService->reclaimResource(40, resources));
+ EXPECT_FALSE(mService->reclaimResource(kLowPriorityPid, resources));
- EXPECT_TRUE(mService->reclaimResource(10, resources));
+ EXPECT_TRUE(mService->reclaimResource(kHighPriorityPid, resources));
// one largest graphic memory from lowest process got reclaimed
- verifyClients(true, false, false);
+ verifyClients(true /* c1 */, false /* c2 */, false /* c3 */);
// call again should reclaim another graphic memory from lowest process
- EXPECT_TRUE(mService->reclaimResource(10, resources));
- verifyClients(false, true, false);
+ EXPECT_TRUE(mService->reclaimResource(kHighPriorityPid, resources));
+ verifyClients(false /* c1 */, true /* c2 */, false /* c3 */);
// call again should reclaim another graphic memory from lowest process
- EXPECT_TRUE(mService->reclaimResource(10, resources));
- verifyClients(false, false, true);
+ EXPECT_TRUE(mService->reclaimResource(kHighPriorityPid, resources));
+ verifyClients(false /* c1 */, false /* c2 */, true /* c3 */);
// nothing left
- EXPECT_FALSE(mService->reclaimResource(10, resources));
+ EXPECT_FALSE(mService->reclaimResource(kHighPriorityPid, resources));
}
// ### secure codec can coexist with non-secure codec ###
@@ -423,15 +422,15 @@ protected:
Vector<MediaResource> resources;
resources.push_back(MediaResource(String8(kResourceNonSecureCodec), 1));
- EXPECT_TRUE(mService->reclaimResource(10, resources));
+ EXPECT_TRUE(mService->reclaimResource(kHighPriorityPid, resources));
// one non secure codec from lowest process got reclaimed
- verifyClients(false, true, false);
+ verifyClients(false /* c1 */, true /* c2 */, false /* c3 */);
- // nothing left
- EXPECT_FALSE(mService->reclaimResource(10, resources));
+ // no more non-secure codec, secure codec from lowest priority process will be reclaimed
+ EXPECT_TRUE(mService->reclaimResource(kHighPriorityPid, resources));
+ verifyClients(true /* c1 */, false /* c2 */, false /* c3 */);
- // clean up client 1 and 3 which still have secure codec left
- mService->removeResource((int64_t) mTestClient1.get());
+ // clean up client 3 which still left
mService->removeResource((int64_t) mTestClient3.get());
}
}
@@ -439,12 +438,12 @@ protected:
void testGetLowestPriorityBiggestClient() {
String8 type = String8(kResourceGraphicMemory);
sp<IResourceManagerClient> client;
- EXPECT_FALSE(mService->getLowestPriorityBiggestClient_l(10, type, &client));
+ EXPECT_FALSE(mService->getLowestPriorityBiggestClient_l(kHighPriorityPid, type, &client));
addResource();
- EXPECT_FALSE(mService->getLowestPriorityBiggestClient_l(100, type, &client));
- EXPECT_TRUE(mService->getLowestPriorityBiggestClient_l(10, type, &client));
+ EXPECT_FALSE(mService->getLowestPriorityBiggestClient_l(kLowPriorityPid, type, &client));
+ EXPECT_TRUE(mService->getLowestPriorityBiggestClient_l(kHighPriorityPid, type, &client));
// kTestPid1 is the lowest priority process with kResourceGraphicMemory.
// mTestClient1 has the largest kResourceGraphicMemory within kTestPid1.