From 70081a1511955f53bd0ed7f2aec9a1bf09f0f379 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 27 Jul 2010 09:49:11 -0700 Subject: [PATCH] Replace several IPCThreadState::get() lookups with one. Also, make StrictMode's ThreadLocal final. Change-Id: I08d400ed254fa67bb7a3dae1227f205a54c00df0 --- include/binder/Parcel.h | 12 ++++++++---- libs/binder/Parcel.cpp | 10 +++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h index fd0fc1f30..32c9a1d5a 100644 --- a/include/binder/Parcel.h +++ b/include/binder/Parcel.h @@ -26,11 +26,12 @@ // --------------------------------------------------------------------------- namespace android { +class Flattenable; class IBinder; +class IPCThreadState; class ProcessState; class String8; class TextOutput; -class Flattenable; struct flat_binder_object; // defined in support_p/binder_module.h @@ -61,10 +62,13 @@ public: // Parses the RPC header, returning true if the interface name // in the header matches the expected interface from the caller. - // If strict_policy_out is non-NULL, the RPC header's StrictMode policy - // mask is returned. + // + // Additionally, enforceInterface does part of the work of + // propagating the StrictMode policy mask, populating the current + // IPCThreadState, which as an optimization may optionally be + // passed in. bool enforceInterface(const String16& interface, - int32_t* strict_policy_out = NULL) const; + IPCThreadState* threadState = NULL) const; bool checkInterface(IBinder*) const; void freeData(); diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index 60babad37..18f75df2e 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -458,13 +458,13 @@ bool Parcel::checkInterface(IBinder* binder) const } bool Parcel::enforceInterface(const String16& interface, - int32_t* strict_policy_out) const + IPCThreadState* threadState) const { - int32_t strict_policy = readInt32(); - IPCThreadState::self()->setStrictModePolicy(strict_policy); - if (strict_policy_out != NULL) { - *strict_policy_out = strict_policy; + int32_t strictPolicy = readInt32(); + if (threadState == NULL) { + threadState = IPCThreadState::self(); } + threadState->setStrictModePolicy(strictPolicy); const String16 str(readString16()); if (str == interface) { return true;