Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 310839e7 authored by Olivier Gaillard's avatar Olivier Gaillard Committed by Android (Google) Code Review
Browse files

Merge "Rename WorkSource methods on IPCThreadState."

parents 30ac3560 a8e7bf22
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
@@ -387,23 +387,28 @@ int32_t IPCThreadState::getStrictModePolicy() const
    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()
{
    return setCallingWorkSourceUid(kUnsetWorkSource);
}

void IPCThreadState::restoreCallingWorkSource(int64_t token)
{
    uid_t returnValue = mWorkSource;
    mWorkSource = kUnsetWorkSource;
    return returnValue;
    uid_t uid = (int)token;
    setCallingWorkSourceUid(uid);
}

void IPCThreadState::setLastTransactionBinderFlags(int32_t flags)
+2 −2
Original line number Diff line number Diff line
@@ -601,7 +601,7 @@ status_t Parcel::writeInterfaceToken(const String16& interface)
{
    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 @@ bool Parcel::enforceInterface(const String16& interface,
    }
    // WorkSource.
    int32_t workSource = readInt32();
    threadState->setWorkSource(workSource);
    threadState->setCallingWorkSourceUid(workSource);
    // Interface descriptor.
    const String16 str(readString16());
    if (str == interface) {
+8 −6
Original line number Diff line number Diff line
@@ -47,12 +47,14 @@ public:
            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;
+20 −4
Original line number Diff line number Diff line
@@ -953,7 +953,7 @@ TEST_F(BinderLibTest, WorkSourceSet)
{
    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 @@ TEST_F(BinderLibTest, WorkSourceCleared)
    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 @@ TEST_F(BinderLibTest, WorkSourceCleared)
    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 @@ class BinderLibTestService : public BBinder
            }
            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: