Rename WorkSource methods on IPCThreadState.
Test: unit tests
Change-Id: I0ed38b0e3cfdeea1dbaf2562271f9390d1e992c1
diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp
index 7a47724..f0c21f5 100644
--- a/libs/binder/IPCThreadState.cpp
+++ b/libs/binder/IPCThreadState.cpp
@@ -387,23 +387,28 @@
return mStrictModePolicy;
}
-uid_t IPCThreadState::setWorkSource(uid_t uid)
+int64_t IPCThreadState::setCallingWorkSourceUid(uid_t uid)
{
- uid_t returnValue = mWorkSource;
+ // Note: we currently only use half of the int64. We return an int64 for extensibility.
+ int64_t token = mWorkSource;
mWorkSource = uid;
- return returnValue;
+ return token;
}
-uid_t IPCThreadState::getWorkSource() const
+uid_t IPCThreadState::getCallingWorkSourceUid() const
{
return mWorkSource;
}
-uid_t IPCThreadState::clearWorkSource()
+int64_t IPCThreadState::clearCallingWorkSource()
{
- uid_t returnValue = mWorkSource;
- mWorkSource = kUnsetWorkSource;
- return returnValue;
+ return setCallingWorkSourceUid(kUnsetWorkSource);
+}
+
+void IPCThreadState::restoreCallingWorkSource(int64_t token)
+{
+ uid_t uid = (int)token;
+ setCallingWorkSourceUid(uid);
}
void IPCThreadState::setLastTransactionBinderFlags(int32_t flags)
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index bc1a71c..5c7a43a 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -601,7 +601,7 @@
{
writeInt32(IPCThreadState::self()->getStrictModePolicy() |
STRICT_MODE_PENALTY_GATHER);
- writeInt32(IPCThreadState::self()->getWorkSource());
+ writeInt32(IPCThreadState::self()->getCallingWorkSourceUid());
// currently the interface identification token is just its name as a string
return writeString16(interface);
}
@@ -631,7 +631,7 @@
}
// WorkSource.
int32_t workSource = readInt32();
- threadState->setWorkSource(workSource);
+ threadState->setCallingWorkSourceUid(workSource);
// Interface descriptor.
const String16 str(readString16());
if (str == interface) {
diff --git a/libs/binder/include/binder/IPCThreadState.h b/libs/binder/include/binder/IPCThreadState.h
index 5888e14..de126d5 100644
--- a/libs/binder/include/binder/IPCThreadState.h
+++ b/libs/binder/include/binder/IPCThreadState.h
@@ -47,12 +47,14 @@
void setStrictModePolicy(int32_t policy);
int32_t getStrictModePolicy() const;
- // See Binder#setThreadWorkSource in Binder.java.
- uid_t setWorkSource(uid_t uid);
- // See Binder#getThreadWorkSource in Binder.java.
- uid_t getWorkSource() const;
- // See Binder#clearThreadWorkSource in Binder.java.
- uid_t clearWorkSource();
+ // See Binder#setCallingWorkSourceUid in Binder.java.
+ int64_t setCallingWorkSourceUid(uid_t uid);
+ // See Binder#getCallingWorkSourceUid in Binder.java.
+ uid_t getCallingWorkSourceUid() const;
+ // See Binder#clearCallingWorkSource in Binder.java.
+ int64_t clearCallingWorkSource();
+ // See Binder#restoreCallingWorkSource in Binder.java.
+ void restoreCallingWorkSource(int64_t token);
void setLastTransactionBinderFlags(int32_t flags);
int32_t getLastTransactionBinderFlags() const;
diff --git a/libs/binder/tests/binderLibTest.cpp b/libs/binder/tests/binderLibTest.cpp
index 7bcfffd..22c1bad 100644
--- a/libs/binder/tests/binderLibTest.cpp
+++ b/libs/binder/tests/binderLibTest.cpp
@@ -953,7 +953,7 @@
{
status_t ret;
Parcel data, reply;
- uid_t previousWorkSource = IPCThreadState::self()->setWorkSource(100);
+ int64_t previousWorkSource = IPCThreadState::self()->setCallingWorkSourceUid(100);
data.writeInterfaceToken(binderLibTestServiceName);
ret = m_server->transact(BINDER_LIB_TEST_GET_WORK_SOURCE_TRANSACTION, data, &reply);
EXPECT_EQ(100, reply.readInt32());
@@ -966,8 +966,8 @@
status_t ret;
Parcel data, reply;
- IPCThreadState::self()->setWorkSource(100);
- uid_t previousWorkSource = IPCThreadState::self()->clearWorkSource();
+ IPCThreadState::self()->setCallingWorkSourceUid(100);
+ int64_t previousWorkSource = IPCThreadState::self()->clearCallingWorkSource();
data.writeInterfaceToken(binderLibTestServiceName);
ret = m_server->transact(BINDER_LIB_TEST_GET_WORK_SOURCE_TRANSACTION, data, &reply);
@@ -976,6 +976,22 @@
EXPECT_EQ(NO_ERROR, ret);
}
+TEST_F(BinderLibTest, WorkSourceRestored)
+{
+ status_t ret;
+ Parcel data, reply;
+
+ IPCThreadState::self()->setCallingWorkSourceUid(100);
+ int64_t token = IPCThreadState::self()->clearCallingWorkSource();
+ IPCThreadState::self()->restoreCallingWorkSource(token);
+
+ data.writeInterfaceToken(binderLibTestServiceName);
+ ret = m_server->transact(BINDER_LIB_TEST_GET_WORK_SOURCE_TRANSACTION, data, &reply);
+
+ EXPECT_EQ(100, reply.readInt32());
+ EXPECT_EQ(NO_ERROR, ret);
+}
+
class BinderLibTestService : public BBinder
{
public:
@@ -1276,7 +1292,7 @@
}
case BINDER_LIB_TEST_GET_WORK_SOURCE_TRANSACTION: {
data.enforceInterface(binderLibTestServiceName);
- reply->writeInt32(IPCThreadState::self()->getWorkSource());
+ reply->writeInt32(IPCThreadState::self()->getCallingWorkSourceUid());
return NO_ERROR;
}
default: