am fb371d6a: Merge "libbinderwrapper: Add GetCallingUid() and GetCallingPid()."
* commit 'fb371d6a6bc59be3eebf089b93b5aa07ad13b5b2': libbinderwrapper: Add GetCallingUid() and GetCallingPid().
This commit is contained in:
commit
487153014b
|
@ -17,6 +17,8 @@
|
|||
#ifndef SYSTEM_CORE_INCLUDE_BINDERWRAPPER_BINDER_WRAPPER_H_
|
||||
#define SYSTEM_CORE_INCLUDE_BINDERWRAPPER_BINDER_WRAPPER_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <base/callback.h>
|
||||
|
@ -68,6 +70,10 @@ class BinderWrapper {
|
|||
// Unregisters the callback, if any, for |binder|.
|
||||
virtual bool UnregisterForDeathNotifications(const sp<IBinder>& binder) = 0;
|
||||
|
||||
// When called while in a transaction, returns the caller's UID or PID.
|
||||
virtual uid_t GetCallingUid() = 0;
|
||||
virtual pid_t GetCallingPid() = 0;
|
||||
|
||||
private:
|
||||
static BinderWrapper* instance_;
|
||||
};
|
||||
|
|
|
@ -77,6 +77,9 @@ class StubBinderWrapper : public BinderWrapper {
|
|||
}
|
||||
void clear_local_binders() { local_binders_.clear(); }
|
||||
|
||||
void set_calling_uid(uid_t uid) { calling_uid_ = uid; }
|
||||
void set_calling_pid(pid_t pid) { calling_pid_ = pid; }
|
||||
|
||||
// Sets the binder to return when |service_name| is passed to GetService() or
|
||||
// WaitForService().
|
||||
void SetBinderForService(const std::string& service_name,
|
||||
|
@ -97,6 +100,8 @@ class StubBinderWrapper : public BinderWrapper {
|
|||
bool RegisterForDeathNotifications(const sp<IBinder>& binder,
|
||||
const base::Closure& callback) override;
|
||||
bool UnregisterForDeathNotifications(const sp<IBinder>& binder) override;
|
||||
uid_t GetCallingUid() override;
|
||||
pid_t GetCallingPid() override;
|
||||
|
||||
private:
|
||||
using ServiceMap = std::map<std::string, sp<IBinder>>;
|
||||
|
@ -116,6 +121,10 @@ class StubBinderWrapper : public BinderWrapper {
|
|||
// death.
|
||||
std::map<sp<IBinder>, base::Closure> death_callbacks_;
|
||||
|
||||
// Values to return from GetCallingUid() and GetCallingPid();
|
||||
uid_t calling_uid_;
|
||||
pid_t calling_pid_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(StubBinderWrapper);
|
||||
};
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <base/logging.h>
|
||||
#include <binder/Binder.h>
|
||||
#include <binder/IBinder.h>
|
||||
#include <binder/IPCThreadState.h>
|
||||
#include <binder/IServiceManager.h>
|
||||
|
||||
namespace android {
|
||||
|
@ -111,4 +112,12 @@ bool RealBinderWrapper::UnregisterForDeathNotifications(
|
|||
return true;
|
||||
}
|
||||
|
||||
uid_t RealBinderWrapper::GetCallingUid() {
|
||||
return IPCThreadState::self()->getCallingUid();
|
||||
}
|
||||
|
||||
pid_t RealBinderWrapper::GetCallingPid() {
|
||||
return IPCThreadState::self()->getCallingPid();
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
|
|
@ -38,6 +38,8 @@ class RealBinderWrapper : public BinderWrapper {
|
|||
bool RegisterForDeathNotifications(const sp<IBinder>& binder,
|
||||
const base::Closure& callback) override;
|
||||
bool UnregisterForDeathNotifications(const sp<IBinder>& binder) override;
|
||||
uid_t GetCallingUid() override;
|
||||
pid_t GetCallingPid() override;
|
||||
|
||||
private:
|
||||
class DeathRecipient;
|
||||
|
|
|
@ -22,7 +22,9 @@
|
|||
|
||||
namespace android {
|
||||
|
||||
StubBinderWrapper::StubBinderWrapper() = default;
|
||||
StubBinderWrapper::StubBinderWrapper()
|
||||
: calling_uid_(-1),
|
||||
calling_pid_(-1) {}
|
||||
|
||||
StubBinderWrapper::~StubBinderWrapper() = default;
|
||||
|
||||
|
@ -73,4 +75,12 @@ bool StubBinderWrapper::UnregisterForDeathNotifications(
|
|||
return true;
|
||||
}
|
||||
|
||||
uid_t StubBinderWrapper::GetCallingUid() {
|
||||
return calling_uid_;
|
||||
}
|
||||
|
||||
pid_t StubBinderWrapper::GetCallingPid() {
|
||||
return calling_pid_;
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
|
Loading…
Reference in New Issue