Start of work on passing around StrictMode policy over Binder calls.

This is (intendend to be) a no-op change.

At this stage, Binder RPCs just have an additional uint32 passed around
in the header, right before the interface name.  But nothing is actually
done with them yet.  That value should right now always be 0.

This now boots and seems to work.

Change-Id: I135b7c84f07575e6b9717fef2424d301a450df7b
This commit is contained in:
Brad Fitzpatrick 2010-06-18 13:07:53 -07:00
parent 5adc399c76
commit 702ea9d42f
5 changed files with 30 additions and 9 deletions

View File

@ -40,6 +40,9 @@ public:
int getCallingPid();
int getCallingUid();
void setStrictModePolicy(int32_t policy);
int32_t getStrictModePolicy() const;
int64_t clearCallingIdentity();
void restoreCallingIdentity(int64_t token);
@ -109,8 +112,9 @@ private:
status_t mLastError;
pid_t mCallingPid;
uid_t mCallingUid;
int32_t mStrictModePolicy;
};
}; // namespace android
// ---------------------------------------------------------------------------

View File

@ -56,9 +56,12 @@ public:
bool hasFileDescriptors() const;
// Writes the RPC header.
status_t writeInterfaceToken(const String16& interface);
// Parses the RPC header, returning true if the interface name
// in the header matches the expected interface from the caller.
bool enforceInterface(const String16& interface) const;
bool checkInterface(IBinder*) const;
bool checkInterface(IBinder*) const;
void freeData();

View File

@ -367,6 +367,16 @@ int64_t IPCThreadState::clearCallingIdentity()
return token;
}
void IPCThreadState::setStrictModePolicy(int32_t policy)
{
mStrictModePolicy = policy;
}
int32_t IPCThreadState::getStrictModePolicy() const {
return mStrictModePolicy;
}
void IPCThreadState::restoreCallingIdentity(int64_t token)
{
mCallingUid = (int)(token>>32);
@ -588,7 +598,8 @@ status_t IPCThreadState::clearDeathNotification(int32_t handle, BpBinder* proxy)
}
IPCThreadState::IPCThreadState()
: mProcess(ProcessState::self()), mMyThreadId(androidGetTid())
: mProcess(ProcessState::self()), mMyThreadId(androidGetTid()),
mStrictModePolicy(0)
{
pthread_setspecific(gTLS, this);
clearCaller();

View File

@ -129,19 +129,19 @@ public:
: BpInterface<IServiceManager>(impl)
{
}
virtual sp<IBinder> getService(const String16& name) const
{
unsigned n;
for (n = 0; n < 5; n++){
sp<IBinder> svc = checkService(name);
if (svc != NULL) return svc;
LOGI("Waiting for sevice %s...\n", String8(name).string());
LOGI("Waiting for service %s...\n", String8(name).string());
sleep(1);
}
return NULL;
}
virtual sp<IBinder> checkService( const String16& name) const
{
Parcel data, reply;
@ -226,4 +226,3 @@ status_t BnServiceManager::onTransact(
}
}; // namespace android

View File

@ -19,6 +19,7 @@
#include <binder/Parcel.h>
#include <binder/IPCThreadState.h>
#include <binder/Binder.h>
#include <binder/BpBinder.h>
#include <utils/Debug.h>
@ -436,19 +437,22 @@ bool Parcel::hasFileDescriptors() const
return mHasFds;
}
// Write RPC headers. (previously just the interface token)
status_t Parcel::writeInterfaceToken(const String16& interface)
{
writeInt32(IPCThreadState::self()->getStrictModePolicy());
// currently the interface identification token is just its name as a string
return writeString16(interface);
}
bool Parcel::checkInterface(IBinder* binder) const
{
return enforceInterface(binder->getInterfaceDescriptor());
return enforceInterface(binder->getInterfaceDescriptor());
}
bool Parcel::enforceInterface(const String16& interface) const
{
int32_t strict_policy = readInt32();
const String16 str(readString16());
if (str == interface) {
return true;
@ -457,7 +461,7 @@ bool Parcel::enforceInterface(const String16& interface) const
String8(interface).string(), String8(str).string());
return false;
}
}
}
const size_t* Parcel::objects() const
{