Loading libs/binder/IPCThreadState.cpp +13 −8 Original line number Original line Diff line number Diff line Loading @@ -387,23 +387,28 @@ int32_t IPCThreadState::getStrictModePolicy() const return mStrictModePolicy; 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; mWorkSource = uid; return returnValue; return token; } } uid_t IPCThreadState::getWorkSource() const uid_t IPCThreadState::getCallingWorkSourceUid() const { { return mWorkSource; return mWorkSource; } } uid_t IPCThreadState::clearWorkSource() int64_t IPCThreadState::clearCallingWorkSource() { return setCallingWorkSourceUid(kUnsetWorkSource); } void IPCThreadState::restoreCallingWorkSource(int64_t token) { { uid_t returnValue = mWorkSource; uid_t uid = (int)token; mWorkSource = kUnsetWorkSource; setCallingWorkSourceUid(uid); return returnValue; } } void IPCThreadState::setLastTransactionBinderFlags(int32_t flags) void IPCThreadState::setLastTransactionBinderFlags(int32_t flags) Loading libs/binder/Parcel.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -601,7 +601,7 @@ status_t Parcel::writeInterfaceToken(const String16& interface) { { writeInt32(IPCThreadState::self()->getStrictModePolicy() | writeInt32(IPCThreadState::self()->getStrictModePolicy() | STRICT_MODE_PENALTY_GATHER); STRICT_MODE_PENALTY_GATHER); writeInt32(IPCThreadState::self()->getWorkSource()); writeInt32(IPCThreadState::self()->getCallingWorkSourceUid()); // currently the interface identification token is just its name as a string // currently the interface identification token is just its name as a string return writeString16(interface); return writeString16(interface); } } Loading Loading @@ -631,7 +631,7 @@ bool Parcel::enforceInterface(const String16& interface, } } // WorkSource. // WorkSource. int32_t workSource = readInt32(); int32_t workSource = readInt32(); threadState->setWorkSource(workSource); threadState->setCallingWorkSourceUid(workSource); // Interface descriptor. // Interface descriptor. const String16 str(readString16()); const String16 str(readString16()); if (str == interface) { if (str == interface) { Loading libs/binder/include/binder/IPCThreadState.h +8 −6 Original line number Original line Diff line number Diff line Loading @@ -47,12 +47,14 @@ public: void setStrictModePolicy(int32_t policy); void setStrictModePolicy(int32_t policy); int32_t getStrictModePolicy() const; int32_t getStrictModePolicy() const; // See Binder#setThreadWorkSource in Binder.java. // See Binder#setCallingWorkSourceUid in Binder.java. uid_t setWorkSource(uid_t uid); int64_t setCallingWorkSourceUid(uid_t uid); // See Binder#getThreadWorkSource in Binder.java. // See Binder#getCallingWorkSourceUid in Binder.java. uid_t getWorkSource() const; uid_t getCallingWorkSourceUid() const; // See Binder#clearThreadWorkSource in Binder.java. // See Binder#clearCallingWorkSource in Binder.java. uid_t clearWorkSource(); int64_t clearCallingWorkSource(); // See Binder#restoreCallingWorkSource in Binder.java. void restoreCallingWorkSource(int64_t token); void setLastTransactionBinderFlags(int32_t flags); void setLastTransactionBinderFlags(int32_t flags); int32_t getLastTransactionBinderFlags() const; int32_t getLastTransactionBinderFlags() const; Loading libs/binder/tests/binderLibTest.cpp +20 −4 Original line number Original line Diff line number Diff line Loading @@ -953,7 +953,7 @@ TEST_F(BinderLibTest, WorkSourceSet) { { status_t ret; status_t ret; Parcel data, reply; Parcel data, reply; uid_t previousWorkSource = IPCThreadState::self()->setWorkSource(100); int64_t previousWorkSource = IPCThreadState::self()->setCallingWorkSourceUid(100); data.writeInterfaceToken(binderLibTestServiceName); data.writeInterfaceToken(binderLibTestServiceName); ret = m_server->transact(BINDER_LIB_TEST_GET_WORK_SOURCE_TRANSACTION, data, &reply); ret = m_server->transact(BINDER_LIB_TEST_GET_WORK_SOURCE_TRANSACTION, data, &reply); EXPECT_EQ(100, reply.readInt32()); EXPECT_EQ(100, reply.readInt32()); Loading @@ -966,8 +966,8 @@ TEST_F(BinderLibTest, WorkSourceCleared) status_t ret; status_t ret; Parcel data, reply; Parcel data, reply; IPCThreadState::self()->setWorkSource(100); IPCThreadState::self()->setCallingWorkSourceUid(100); uid_t previousWorkSource = IPCThreadState::self()->clearWorkSource(); int64_t previousWorkSource = IPCThreadState::self()->clearCallingWorkSource(); data.writeInterfaceToken(binderLibTestServiceName); data.writeInterfaceToken(binderLibTestServiceName); ret = m_server->transact(BINDER_LIB_TEST_GET_WORK_SOURCE_TRANSACTION, data, &reply); ret = m_server->transact(BINDER_LIB_TEST_GET_WORK_SOURCE_TRANSACTION, data, &reply); Loading @@ -976,6 +976,22 @@ TEST_F(BinderLibTest, WorkSourceCleared) EXPECT_EQ(NO_ERROR, ret); 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 class BinderLibTestService : public BBinder { { public: public: Loading Loading @@ -1276,7 +1292,7 @@ class BinderLibTestService : public BBinder } } case BINDER_LIB_TEST_GET_WORK_SOURCE_TRANSACTION: { case BINDER_LIB_TEST_GET_WORK_SOURCE_TRANSACTION: { data.enforceInterface(binderLibTestServiceName); data.enforceInterface(binderLibTestServiceName); reply->writeInt32(IPCThreadState::self()->getWorkSource()); reply->writeInt32(IPCThreadState::self()->getCallingWorkSourceUid()); return NO_ERROR; return NO_ERROR; } } default: default: Loading Loading
libs/binder/IPCThreadState.cpp +13 −8 Original line number Original line Diff line number Diff line Loading @@ -387,23 +387,28 @@ int32_t IPCThreadState::getStrictModePolicy() const return mStrictModePolicy; 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; mWorkSource = uid; return returnValue; return token; } } uid_t IPCThreadState::getWorkSource() const uid_t IPCThreadState::getCallingWorkSourceUid() const { { return mWorkSource; return mWorkSource; } } uid_t IPCThreadState::clearWorkSource() int64_t IPCThreadState::clearCallingWorkSource() { return setCallingWorkSourceUid(kUnsetWorkSource); } void IPCThreadState::restoreCallingWorkSource(int64_t token) { { uid_t returnValue = mWorkSource; uid_t uid = (int)token; mWorkSource = kUnsetWorkSource; setCallingWorkSourceUid(uid); return returnValue; } } void IPCThreadState::setLastTransactionBinderFlags(int32_t flags) void IPCThreadState::setLastTransactionBinderFlags(int32_t flags) Loading
libs/binder/Parcel.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -601,7 +601,7 @@ status_t Parcel::writeInterfaceToken(const String16& interface) { { writeInt32(IPCThreadState::self()->getStrictModePolicy() | writeInt32(IPCThreadState::self()->getStrictModePolicy() | STRICT_MODE_PENALTY_GATHER); STRICT_MODE_PENALTY_GATHER); writeInt32(IPCThreadState::self()->getWorkSource()); writeInt32(IPCThreadState::self()->getCallingWorkSourceUid()); // currently the interface identification token is just its name as a string // currently the interface identification token is just its name as a string return writeString16(interface); return writeString16(interface); } } Loading Loading @@ -631,7 +631,7 @@ bool Parcel::enforceInterface(const String16& interface, } } // WorkSource. // WorkSource. int32_t workSource = readInt32(); int32_t workSource = readInt32(); threadState->setWorkSource(workSource); threadState->setCallingWorkSourceUid(workSource); // Interface descriptor. // Interface descriptor. const String16 str(readString16()); const String16 str(readString16()); if (str == interface) { if (str == interface) { Loading
libs/binder/include/binder/IPCThreadState.h +8 −6 Original line number Original line Diff line number Diff line Loading @@ -47,12 +47,14 @@ public: void setStrictModePolicy(int32_t policy); void setStrictModePolicy(int32_t policy); int32_t getStrictModePolicy() const; int32_t getStrictModePolicy() const; // See Binder#setThreadWorkSource in Binder.java. // See Binder#setCallingWorkSourceUid in Binder.java. uid_t setWorkSource(uid_t uid); int64_t setCallingWorkSourceUid(uid_t uid); // See Binder#getThreadWorkSource in Binder.java. // See Binder#getCallingWorkSourceUid in Binder.java. uid_t getWorkSource() const; uid_t getCallingWorkSourceUid() const; // See Binder#clearThreadWorkSource in Binder.java. // See Binder#clearCallingWorkSource in Binder.java. uid_t clearWorkSource(); int64_t clearCallingWorkSource(); // See Binder#restoreCallingWorkSource in Binder.java. void restoreCallingWorkSource(int64_t token); void setLastTransactionBinderFlags(int32_t flags); void setLastTransactionBinderFlags(int32_t flags); int32_t getLastTransactionBinderFlags() const; int32_t getLastTransactionBinderFlags() const; Loading
libs/binder/tests/binderLibTest.cpp +20 −4 Original line number Original line Diff line number Diff line Loading @@ -953,7 +953,7 @@ TEST_F(BinderLibTest, WorkSourceSet) { { status_t ret; status_t ret; Parcel data, reply; Parcel data, reply; uid_t previousWorkSource = IPCThreadState::self()->setWorkSource(100); int64_t previousWorkSource = IPCThreadState::self()->setCallingWorkSourceUid(100); data.writeInterfaceToken(binderLibTestServiceName); data.writeInterfaceToken(binderLibTestServiceName); ret = m_server->transact(BINDER_LIB_TEST_GET_WORK_SOURCE_TRANSACTION, data, &reply); ret = m_server->transact(BINDER_LIB_TEST_GET_WORK_SOURCE_TRANSACTION, data, &reply); EXPECT_EQ(100, reply.readInt32()); EXPECT_EQ(100, reply.readInt32()); Loading @@ -966,8 +966,8 @@ TEST_F(BinderLibTest, WorkSourceCleared) status_t ret; status_t ret; Parcel data, reply; Parcel data, reply; IPCThreadState::self()->setWorkSource(100); IPCThreadState::self()->setCallingWorkSourceUid(100); uid_t previousWorkSource = IPCThreadState::self()->clearWorkSource(); int64_t previousWorkSource = IPCThreadState::self()->clearCallingWorkSource(); data.writeInterfaceToken(binderLibTestServiceName); data.writeInterfaceToken(binderLibTestServiceName); ret = m_server->transact(BINDER_LIB_TEST_GET_WORK_SOURCE_TRANSACTION, data, &reply); ret = m_server->transact(BINDER_LIB_TEST_GET_WORK_SOURCE_TRANSACTION, data, &reply); Loading @@ -976,6 +976,22 @@ TEST_F(BinderLibTest, WorkSourceCleared) EXPECT_EQ(NO_ERROR, ret); 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 class BinderLibTestService : public BBinder { { public: public: Loading Loading @@ -1276,7 +1292,7 @@ class BinderLibTestService : public BBinder } } case BINDER_LIB_TEST_GET_WORK_SOURCE_TRANSACTION: { case BINDER_LIB_TEST_GET_WORK_SOURCE_TRANSACTION: { data.enforceInterface(binderLibTestServiceName); data.enforceInterface(binderLibTestServiceName); reply->writeInt32(IPCThreadState::self()->getWorkSource()); reply->writeInt32(IPCThreadState::self()->getCallingWorkSourceUid()); return NO_ERROR; return NO_ERROR; } } default: default: Loading