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

Commit 69390d4f authored by Martijn Coenen's avatar Martijn Coenen
Browse files

Don't initialize ProcessState unless we need to.

Initializing ProcessState opens the binder driver; there are cases
where we want to be able to create simple Parcel objects (Parcels
without binder objects or file descriptors) without initializing
the binder driver -- eg the isolated app zygote, which will receive
a serialized ApplicationInfo Parcel over a socket, and can't open
the binder driver.

Delay opening ProcessState until we actually need it.

Bug: 111434506
Test: builds, ProcessState not opened for "data" Parcels.
Change-Id: I25e2b40c253e5cf3eb8701f76715985d37012947
parent 81c202f1
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -467,7 +467,6 @@ status_t Parcel::setData(const uint8_t* buffer, size_t len)

status_t Parcel::appendFrom(const Parcel *parcel, size_t offset, size_t len)
{
    const sp<ProcessState> proc(ProcessState::self());
    status_t err;
    const uint8_t *data = parcel->mData;
    const binder_size_t *objects = parcel->mObjects;
@@ -520,6 +519,7 @@ status_t Parcel::appendFrom(const Parcel *parcel, size_t offset, size_t len)
    err = NO_ERROR;

    if (numObjects > 0) {
        const sp<ProcessState> proc(ProcessState::self());
        // grow objects
        if (mObjectsCapacity < mObjectsSize + numObjects) {
            size_t newSize = ((mObjectsSize + numObjects)*3)/2;
@@ -2521,8 +2521,11 @@ void Parcel::print(TextOutput& to, uint32_t /*flags*/) const

void Parcel::releaseObjects()
{
    const sp<ProcessState> proc(ProcessState::self());
    size_t i = mObjectsSize;
    if (i == 0) {
        return;
    }
    sp<ProcessState> proc(ProcessState::self());
    uint8_t* const data = mData;
    binder_size_t* const objects = mObjects;
    while (i > 0) {
@@ -2535,8 +2538,11 @@ void Parcel::releaseObjects()

void Parcel::acquireObjects()
{
    const sp<ProcessState> proc(ProcessState::self());
    size_t i = mObjectsSize;
    if (i == 0) {
        return;
    }
    const sp<ProcessState> proc(ProcessState::self());
    uint8_t* const data = mData;
    binder_size_t* const objects = mObjects;
    while (i > 0) {