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

Commit fe958b8c authored by Steven Moreland's avatar Steven Moreland Committed by Automerger Merge Worker
Browse files

Merge "libbinder: ignore CallRestriction for magic 0 cmd" am: f1d96134

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1430277

Change-Id: I41aac1a01d9151dffd77f44b28b25fc8e98cf231
parents ed13f4b2 f1d96134
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -448,6 +448,14 @@ int32_t IPCThreadState::getLastTransactionBinderFlags() const
    return mLastTransactionBinderFlags;
    return mLastTransactionBinderFlags;
}
}


void IPCThreadState::setCallRestriction(ProcessState::CallRestriction restriction) {
    mCallRestriction = restriction;
}

ProcessState::CallRestriction IPCThreadState::getCallRestriction() const {
    return mCallRestriction;
}

void IPCThreadState::restoreCallingIdentity(int64_t token)
void IPCThreadState::restoreCallingIdentity(int64_t token)
{
{
    mCallingUid = (int)(token>>32);
    mCallingUid = (int)(token>>32);
+9 −1
Original line number Original line Diff line number Diff line
@@ -282,9 +282,17 @@ sp<IBinder> ProcessState::getStrongProxyForHandle(int32_t handle)
                // a driver API to get a handle to the context manager with
                // a driver API to get a handle to the context manager with
                // proper reference counting.
                // proper reference counting.


                IPCThreadState* ipc = IPCThreadState::self();

                CallRestriction originalCallRestriction = ipc->getCallRestriction();
                ipc->setCallRestriction(CallRestriction::NONE);

                Parcel data;
                Parcel data;
                status_t status = IPCThreadState::self()->transact(
                status_t status = ipc->transact(
                        0, IBinder::PING_TRANSACTION, data, nullptr, 0);
                        0, IBinder::PING_TRANSACTION, data, nullptr, 0);

                ipc->setCallRestriction(originalCallRestriction);

                if (status == DEAD_OBJECT)
                if (status == DEAD_OBJECT)
                   return nullptr;
                   return nullptr;
            }
            }
+6 −3
Original line number Original line Diff line number Diff line
@@ -32,6 +32,8 @@ namespace android {
class IPCThreadState
class IPCThreadState
{
{
public:
public:
    using CallRestriction = ProcessState::CallRestriction;

    static  IPCThreadState*     self();
    static  IPCThreadState*     self();
    static  IPCThreadState*     selfOrNull();  // self(), but won't instantiate
    static  IPCThreadState*     selfOrNull();  // self(), but won't instantiate


@@ -99,6 +101,9 @@ public:
            void                setLastTransactionBinderFlags(int32_t flags);
            void                setLastTransactionBinderFlags(int32_t flags);
            int32_t             getLastTransactionBinderFlags() const;
            int32_t             getLastTransactionBinderFlags() const;


            void                setCallRestriction(CallRestriction restriction);
            CallRestriction     getCallRestriction() const;

            int64_t             clearCallingIdentity();
            int64_t             clearCallingIdentity();
            // Restores PID/UID (not SID)
            // Restores PID/UID (not SID)
            void                restoreCallingIdentity(int64_t token);
            void                restoreCallingIdentity(int64_t token);
@@ -157,7 +162,6 @@ public:
            // This constant needs to be kept in sync with Binder.UNSET_WORKSOURCE from the Java
            // This constant needs to be kept in sync with Binder.UNSET_WORKSOURCE from the Java
            // side.
            // side.
            static const int32_t kUnsetWorkSource = -1;
            static const int32_t kUnsetWorkSource = -1;

private:
private:
                                IPCThreadState();
                                IPCThreadState();
                                ~IPCThreadState();
                                ~IPCThreadState();
@@ -204,8 +208,7 @@ private:
            bool                mPropagateWorkSource;
            bool                mPropagateWorkSource;
            int32_t             mStrictModePolicy;
            int32_t             mStrictModePolicy;
            int32_t             mLastTransactionBinderFlags;
            int32_t             mLastTransactionBinderFlags;

            CallRestriction     mCallRestriction;
            ProcessState::CallRestriction mCallRestriction;
};
};


} // namespace android
} // namespace android
+6 −0
Original line number Original line Diff line number Diff line
@@ -608,6 +608,12 @@ TEST_F(BinderLibTest, AddServer)
    ASSERT_TRUE(server != nullptr);
    ASSERT_TRUE(server != nullptr);
}
}


TEST_F(BinderLibTest, AddManagerToManager) {
    sp<IServiceManager> sm = defaultServiceManager();
    sp<IBinder> binder = IInterface::asBinder(sm);
    EXPECT_EQ(NO_ERROR, sm->addService(String16("binderLibTest-manager"), binder));
}

TEST_F(BinderLibTest, DeathNotificationStrongRef)
TEST_F(BinderLibTest, DeathNotificationStrongRef)
{
{
    status_t ret;
    status_t ret;