Merge "Fix AIBinder_linkToDeath cookies" into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-04-08 18:52:00 +00:00
committed by Android (Google) Code Review
3 changed files with 33 additions and 23 deletions

View File

@@ -43,20 +43,23 @@ using android::base::StringPrintf;
using std::unique_ptr; using std::unique_ptr;
struct ConfigReceiverDeathCookie { struct ConfigReceiverDeathCookie {
ConfigReceiverDeathCookie(sp<ConfigManager> configManager, const ConfigKey& configKey, ConfigReceiverDeathCookie(const wp<ConfigManager>& configManager, const ConfigKey& configKey,
const shared_ptr<IPendingIntentRef>& pir): const shared_ptr<IPendingIntentRef>& pir) :
mConfigManager(configManager), mConfigManager(configManager), mConfigKey(configKey), mPir(pir) {
mConfigKey(configKey), }
mPir(pir) {}
sp<ConfigManager> mConfigManager; wp<ConfigManager> mConfigManager;
ConfigKey mConfigKey; ConfigKey mConfigKey;
shared_ptr<IPendingIntentRef> mPir; shared_ptr<IPendingIntentRef> mPir;
}; };
void ConfigManager::configReceiverDied(void* cookie) { void ConfigManager::configReceiverDied(void* cookie) {
auto cookie_ = static_cast<ConfigReceiverDeathCookie*>(cookie); auto cookie_ = static_cast<ConfigReceiverDeathCookie*>(cookie);
sp<ConfigManager>& thiz = cookie_->mConfigManager; sp<ConfigManager> thiz = cookie_->mConfigManager.promote();
if (!thiz) {
return;
}
ConfigKey& configKey = cookie_->mConfigKey; ConfigKey& configKey = cookie_->mConfigKey;
shared_ptr<IPendingIntentRef>& pir = cookie_->mPir; shared_ptr<IPendingIntentRef>& pir = cookie_->mPir;
@@ -74,20 +77,23 @@ void ConfigManager::configReceiverDied(void* cookie) {
} }
struct ActiveConfigChangedReceiverDeathCookie { struct ActiveConfigChangedReceiverDeathCookie {
ActiveConfigChangedReceiverDeathCookie(sp<ConfigManager> configManager, const int uid, ActiveConfigChangedReceiverDeathCookie(const wp<ConfigManager>& configManager, const int uid,
const shared_ptr<IPendingIntentRef>& pir): const shared_ptr<IPendingIntentRef>& pir) :
mConfigManager(configManager), mConfigManager(configManager), mUid(uid), mPir(pir) {
mUid(uid), }
mPir(pir) {}
sp<ConfigManager> mConfigManager; wp<ConfigManager> mConfigManager;
int mUid; int mUid;
shared_ptr<IPendingIntentRef> mPir; shared_ptr<IPendingIntentRef> mPir;
}; };
void ConfigManager::activeConfigChangedReceiverDied(void* cookie) { void ConfigManager::activeConfigChangedReceiverDied(void* cookie) {
auto cookie_ = static_cast<ActiveConfigChangedReceiverDeathCookie*>(cookie); auto cookie_ = static_cast<ActiveConfigChangedReceiverDeathCookie*>(cookie);
sp<ConfigManager>& thiz = cookie_->mConfigManager; sp<ConfigManager> thiz = cookie_->mConfigManager.promote();
if (!thiz) {
return;
}
int uid = cookie_->mUid; int uid = cookie_->mUid;
shared_ptr<IPendingIntentRef>& pir = cookie_->mPir; shared_ptr<IPendingIntentRef>& pir = cookie_->mPir;

View File

@@ -44,19 +44,23 @@ namespace statsd {
// Stores the puller as a wp to avoid holding a reference in case it is unregistered and // Stores the puller as a wp to avoid holding a reference in case it is unregistered and
// pullAtomCallbackDied is never called. // pullAtomCallbackDied is never called.
struct PullAtomCallbackDeathCookie { struct PullAtomCallbackDeathCookie {
PullAtomCallbackDeathCookie(sp<StatsPullerManager> pullerManager, const PullerKey& pullerKey, PullAtomCallbackDeathCookie(const wp<StatsPullerManager>& pullerManager,
const wp<StatsPuller>& puller) const PullerKey& pullerKey, const wp<StatsPuller>& puller) :
: mPullerManager(pullerManager), mPullerKey(pullerKey), mPuller(puller) { mPullerManager(pullerManager), mPullerKey(pullerKey), mPuller(puller) {
} }
sp<StatsPullerManager> mPullerManager; wp<StatsPullerManager> mPullerManager;
PullerKey mPullerKey; PullerKey mPullerKey;
wp<StatsPuller> mPuller; wp<StatsPuller> mPuller;
}; };
void StatsPullerManager::pullAtomCallbackDied(void* cookie) { void StatsPullerManager::pullAtomCallbackDied(void* cookie) {
PullAtomCallbackDeathCookie* cookie_ = static_cast<PullAtomCallbackDeathCookie*>(cookie); PullAtomCallbackDeathCookie* cookie_ = static_cast<PullAtomCallbackDeathCookie*>(cookie);
sp<StatsPullerManager>& thiz = cookie_->mPullerManager; sp<StatsPullerManager> thiz = cookie_->mPullerManager.promote();
if (!thiz) {
return;
}
const PullerKey& pullerKey = cookie_->mPullerKey; const PullerKey& pullerKey = cookie_->mPullerKey;
wp<StatsPuller> puller = cookie_->mPuller; wp<StatsPuller> puller = cookie_->mPuller;

View File

@@ -190,13 +190,13 @@ TEST_F(StatsCallbackPullerTest, RegisterAndTimeout) {
int32_t uid = 123; int32_t uid = 123;
values.push_back(value); values.push_back(value);
StatsPullerManager pullerManager; sp<StatsPullerManager> pullerManager = new StatsPullerManager();
pullerManager.RegisterPullAtomCallback(uid, pullTagId, pullCoolDownNs, pullTimeoutNs, pullerManager->RegisterPullAtomCallback(uid, pullTagId, pullCoolDownNs, pullTimeoutNs,
vector<int32_t>(), cb); vector<int32_t>(), cb);
vector<shared_ptr<LogEvent>> dataHolder; vector<shared_ptr<LogEvent>> dataHolder;
int64_t startTimeNs = getElapsedRealtimeNs(); int64_t startTimeNs = getElapsedRealtimeNs();
// Returns false, since StatsPuller code will evaluate the timeout. // Returns false, since StatsPuller code will evaluate the timeout.
EXPECT_FALSE(pullerManager.Pull(pullTagId, {uid}, &dataHolder)); EXPECT_FALSE(pullerManager->Pull(pullTagId, {uid}, &dataHolder));
int64_t endTimeNs = getElapsedRealtimeNs(); int64_t endTimeNs = getElapsedRealtimeNs();
int64_t actualPullDurationNs = endTimeNs - startTimeNs; int64_t actualPullDurationNs = endTimeNs - startTimeNs;