summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorDaniel Erat <derat@google.com>2015-10-16 09:04:33 -0600
committerDaniel Erat <derat@google.com>2015-10-16 09:04:33 -0600
commit7cba9db9cdcdafe221d0481c52316a8653f577a1 (patch)
treeeb2764ba9c209794b2a3a5876af0b889205744cc /include
parentb8cc70a94bcbf7b920465d92da6889f0db6d6fa5 (diff)
downloadcore-7cba9db9cdcdafe221d0481c52316a8653f577a1.tar.gz
core-7cba9db9cdcdafe221d0481c52316a8653f577a1.tar.bz2
core-7cba9db9cdcdafe221d0481c52316a8653f577a1.zip
libbinderwrapper: Add GetCallingUid() and GetCallingPid().
Add methods to BinderWrapper for getting the caller's UID and PID while in a transaction. Bug: 24988639 Change-Id: Ibd711fc6b3d83623d4bb1060838c65aaef30d76e
Diffstat (limited to 'include')
-rw-r--r--include/binderwrapper/binder_wrapper.h6
-rw-r--r--include/binderwrapper/stub_binder_wrapper.h9
2 files changed, 15 insertions, 0 deletions
diff --git a/include/binderwrapper/binder_wrapper.h b/include/binderwrapper/binder_wrapper.h
index e57cf8318..921c4ed19 100644
--- a/include/binderwrapper/binder_wrapper.h
+++ b/include/binderwrapper/binder_wrapper.h
@@ -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_;
};
diff --git a/include/binderwrapper/stub_binder_wrapper.h b/include/binderwrapper/stub_binder_wrapper.h
index 6e198aea3..01c96483c 100644
--- a/include/binderwrapper/stub_binder_wrapper.h
+++ b/include/binderwrapper/stub_binder_wrapper.h
@@ -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);
};