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

Commit 81ed8642 authored by Yi Kong's avatar Yi Kong Committed by Xin Li
Browse files

[binder] Replace NULL/0 with nullptr

Fixes -Wzero-as-null-pointer-constant warning.

clang-tidy -checks=modernize-use-nullptr -p compile_commands.json -fix
...

Test: m
Bug: 68236239
Change-Id: I3181bc5683796423a98b0f9b94daf30880c07bdc
Merged-In: I3181bc5683796423a98b0f9b94daf30880c07bdc
parent 246946a3
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -34,16 +34,16 @@ sp<IActivityManager> ActivityManager::getService()
    std::lock_guard<Mutex> scoped_lock(mLock);
    int64_t startTime = 0;
    sp<IActivityManager> service = mService;
    while (service == NULL || !IInterface::asBinder(service)->isBinderAlive()) {
    while (service == nullptr || !IInterface::asBinder(service)->isBinderAlive()) {
        sp<IBinder> binder = defaultServiceManager()->checkService(String16("activity"));
        if (binder == NULL) {
        if (binder == nullptr) {
            // Wait for the activity service to come back...
            if (startTime == 0) {
                startTime = uptimeMillis();
                ALOGI("Waiting for activity service");
            } else if ((uptimeMillis() - startTime) > 1000000) {
                ALOGW("Waiting too long for activity service, giving up");
                service = NULL;
                service = nullptr;
                break;
            }
            usleep(25000);
@@ -58,7 +58,7 @@ sp<IActivityManager> ActivityManager::getService()
int ActivityManager::openContentUri(const String16& stringUri)
{
    sp<IActivityManager> service = getService();
    return service != NULL ? service->openContentUri(stringUri) : -1;
    return service != nullptr ? service->openContentUri(stringUri) : -1;
}

void ActivityManager::registerUidObserver(const sp<IUidObserver>& observer,
@@ -67,7 +67,7 @@ void ActivityManager::registerUidObserver(const sp<IUidObserver>& observer,
                                          const String16& callingPackage)
{
    sp<IActivityManager> service = getService();
    if (service != NULL) {
    if (service != nullptr) {
        service->registerUidObserver(observer, event, cutpoint, callingPackage);
    }
}
@@ -75,7 +75,7 @@ void ActivityManager::registerUidObserver(const sp<IUidObserver>& observer,
void ActivityManager::unregisterUidObserver(const sp<IUidObserver>& observer)
{
    sp<IActivityManager> service = getService();
    if (service != NULL) {
    if (service != nullptr) {
        service->unregisterUidObserver(observer);
    }
}
@@ -83,7 +83,7 @@ void ActivityManager::unregisterUidObserver(const sp<IUidObserver>& observer)
bool ActivityManager::isUidActive(const uid_t uid, const String16& callingPackage)
{
    sp<IActivityManager> service = getService();
    if (service != NULL) {
    if (service != nullptr) {
        return service->isUidActive(uid, callingPackage);
    }
    return false;
@@ -91,7 +91,7 @@ bool ActivityManager::isUidActive(const uid_t uid, const String16& callingPackag

status_t ActivityManager::linkToDeath(const sp<IBinder::DeathRecipient>& recipient) {
    sp<IActivityManager> service = getService();
    if (service != NULL) {
    if (service != nullptr) {
        return IInterface::asBinder(service)->linkToDeath(recipient);
    }
    return INVALID_OPERATION;
@@ -99,7 +99,7 @@ status_t ActivityManager::linkToDeath(const sp<IBinder::DeathRecipient>& recipie

status_t ActivityManager::unlinkToDeath(const sp<IBinder::DeathRecipient>& recipient) {
    sp<IActivityManager> service = getService();
    if (service != NULL) {
    if (service != nullptr) {
        return IInterface::asBinder(service)->unlinkToDeath(recipient);
    }
    return INVALID_OPERATION;
+10 −10
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ static sp<IBinder> gToken;

static const sp<IBinder>& getToken(const sp<IAppOpsService>& service) {
    pthread_mutex_lock(&gTokenMutex);
    if (gToken == NULL || gToken->pingBinder() != NO_ERROR) {
    if (gToken == nullptr || gToken->pingBinder() != NO_ERROR) {
        gToken = service->getToken(new BBinder());
    }
    pthread_mutex_unlock(&gTokenMutex);
@@ -63,16 +63,16 @@ sp<IAppOpsService> AppOpsManager::getService()
    std::lock_guard<Mutex> scoped_lock(mLock);
    int64_t startTime = 0;
    sp<IAppOpsService> service = mService;
    while (service == NULL || !IInterface::asBinder(service)->isBinderAlive()) {
    while (service == nullptr || !IInterface::asBinder(service)->isBinderAlive()) {
        sp<IBinder> binder = defaultServiceManager()->checkService(_appops);
        if (binder == NULL) {
        if (binder == nullptr) {
            // Wait for the app ops service to come back...
            if (startTime == 0) {
                startTime = uptimeMillis();
                ALOGI("Waiting for app ops service");
            } else if ((uptimeMillis()-startTime) > 10000) {
                ALOGW("Waiting too long for app ops service, giving up");
                service = NULL;
                service = nullptr;
                break;
            }
            sleep(1);
@@ -88,14 +88,14 @@ sp<IAppOpsService> AppOpsManager::getService()
int32_t AppOpsManager::checkOp(int32_t op, int32_t uid, const String16& callingPackage)
{
    sp<IAppOpsService> service = getService();
    return service != NULL
    return service != nullptr
            ? service->checkOperation(op, uid, callingPackage)
            : APP_OPS_MANAGER_UNAVAILABLE_MODE;
}

int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPackage) {
    sp<IAppOpsService> service = getService();
    return service != NULL
    return service != nullptr
            ? service->noteOperation(op, uid, callingPackage)
            : APP_OPS_MANAGER_UNAVAILABLE_MODE;
}
@@ -110,7 +110,7 @@ int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& c

void AppOpsManager::finishOp(int32_t op, int32_t uid, const String16& callingPackage) {
    sp<IAppOpsService> service = getService();
    if (service != NULL) {
    if (service != nullptr) {
        service->finishOperation(getToken(service), op, uid, callingPackage);
    }
}
@@ -118,21 +118,21 @@ void AppOpsManager::finishOp(int32_t op, int32_t uid, const String16& callingPac
void AppOpsManager::startWatchingMode(int32_t op, const String16& packageName,
        const sp<IAppOpsCallback>& callback) {
    sp<IAppOpsService> service = getService();
    if (service != NULL) {
    if (service != nullptr) {
        service->startWatchingMode(op, packageName, callback);
    }
}

void AppOpsManager::stopWatchingMode(const sp<IAppOpsCallback>& callback) {
    sp<IAppOpsService> service = getService();
    if (service != NULL) {
    if (service != nullptr) {
        service->stopWatchingMode(callback);
    }
}

int32_t AppOpsManager::permissionToOpCode(const String16& permission) {
    sp<IAppOpsService> service = getService();
    if (service != NULL) {
    if (service != nullptr) {
        return service->permissionToOpCode(permission);
    }
    return -1;
+10 −10
Original line number Diff line number Diff line
@@ -43,17 +43,17 @@ IBinder::~IBinder()

sp<IInterface>  IBinder::queryLocalInterface(const String16& /*descriptor*/)
{
    return NULL;
    return nullptr;
}

BBinder* IBinder::localBinder()
{
    return NULL;
    return nullptr;
}

BpBinder* IBinder::remoteBinder()
{
    return NULL;
    return nullptr;
}

bool IBinder::checkSubclass(const void* /*subclassID*/) const
@@ -76,8 +76,8 @@ status_t IBinder::shellCommand(const sp<IBinder>& target, int in, int out, int e
    for (size_t i = 0; i < numArgs; i++) {
        send.writeString16(args[i]);
    }
    send.writeStrongBinder(callback != NULL ? IInterface::asBinder(callback) : NULL);
    send.writeStrongBinder(resultReceiver != NULL ? IInterface::asBinder(resultReceiver) : NULL);
    send.writeStrongBinder(callback != nullptr ? IInterface::asBinder(callback) : nullptr);
    send.writeStrongBinder(resultReceiver != nullptr ? IInterface::asBinder(resultReceiver) : nullptr);
    return target->transact(SHELL_COMMAND_TRANSACTION, send, &reply);
}

@@ -130,7 +130,7 @@ status_t BBinder::transact(
            break;
    }

    if (reply != NULL) {
    if (reply != nullptr) {
        reply->setDataPosition(0);
    }

@@ -171,7 +171,7 @@ void BBinder::attachObject(
            delete e;
            e = expected;  // Filled in by CAS
        }
        if (e == 0) return; // out of memory
        if (e == nullptr) return; // out of memory
    }

    AutoMutex _l(e->mLock);
@@ -181,7 +181,7 @@ void BBinder::attachObject(
void* BBinder::findObject(const void* objectID) const
{
    Extras* e = mExtras.load(std::memory_order_acquire);
    if (!e) return NULL;
    if (!e) return nullptr;

    AutoMutex _l(e->mLock);
    return e->mObjects.find(objectID);
@@ -246,7 +246,7 @@ status_t BBinder::onTransact(
            (void)out;
            (void)err;

            if (resultReceiver != NULL) {
            if (resultReceiver != nullptr) {
                resultReceiver->send(INVALID_OPERATION);
            }

@@ -273,7 +273,7 @@ enum {
};

BpRefBase::BpRefBase(const sp<IBinder>& o)
    : mRemote(o.get()), mRefs(NULL), mState(0)
    : mRemote(o.get()), mRefs(nullptr), mState(0)
{
    extendObjectLifetime(OBJECT_LIFETIME_WEAK);

+13 −13
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ void BpBinder::ObjectManager::attach(
void* BpBinder::ObjectManager::find(const void* objectID) const
{
    const ssize_t i = mObjects.indexOfKey(objectID);
    if (i < 0) return NULL;
    if (i < 0) return nullptr;
    return mObjects.valueAt(i).object;
}

@@ -95,7 +95,7 @@ void BpBinder::ObjectManager::kill()
    ALOGV("Killing %zu objects in manager %p", N, this);
    for (size_t i=0; i<N; i++) {
        const entry_t& e = mObjects.valueAt(i);
        if (e.func != NULL) {
        if (e.func != nullptr) {
            e.func(mObjects.keyAt(i), e.object, e.cleanupCookie);
        }
    }
@@ -228,7 +228,7 @@ status_t BpBinder::linkToDeath(
    ob.cookie = cookie;
    ob.flags = flags;

    LOG_ALWAYS_FATAL_IF(recipient == NULL,
    LOG_ALWAYS_FATAL_IF(recipient == nullptr,
                        "linkToDeath(): recipient must be non-NULL");

    {
@@ -268,9 +268,9 @@ status_t BpBinder::unlinkToDeath(
    for (size_t i=0; i<N; i++) {
        const Obituary& obit = mObituaries->itemAt(i);
        if ((obit.recipient == recipient
                    || (recipient == NULL && obit.cookie == cookie))
                    || (recipient == nullptr && obit.cookie == cookie))
                && obit.flags == flags) {
            if (outRecipient != NULL) {
            if (outRecipient != nullptr) {
                *outRecipient = mObituaries->itemAt(i).recipient;
            }
            mObituaries->removeAt(i);
@@ -280,7 +280,7 @@ status_t BpBinder::unlinkToDeath(
                self->clearDeathNotification(mHandle, this);
                self->flushCommands();
                delete mObituaries;
                mObituaries = NULL;
                mObituaries = nullptr;
            }
            return NO_ERROR;
        }
@@ -299,12 +299,12 @@ void BpBinder::sendObituary()

    mLock.lock();
    Vector<Obituary>* obits = mObituaries;
    if(obits != NULL) {
    if(obits != nullptr) {
        ALOGV("Clearing sent death notification: %p handle %d\n", this, mHandle);
        IPCThreadState* self = IPCThreadState::self();
        self->clearDeathNotification(mHandle, this);
        self->flushCommands();
        mObituaries = NULL;
        mObituaries = nullptr;
    }
    mObitsSent = 1;
    mLock.unlock();
@@ -312,7 +312,7 @@ void BpBinder::sendObituary()
    ALOGV("Reporting death of proxy %p for %zu recipients\n",
        this, obits ? obits->size() : 0U);

    if (obits != NULL) {
    if (obits != nullptr) {
        const size_t N = obits->size();
        for (size_t i=0; i<N; i++) {
            reportOneDeath(obits->itemAt(i));
@@ -326,7 +326,7 @@ void BpBinder::reportOneDeath(const Obituary& obit)
{
    sp<DeathRecipient> recipient = obit.recipient.promote();
    ALOGV("Reporting death to recipient: %p\n", recipient.get());
    if (recipient == NULL) return;
    if (recipient == nullptr) return;

    recipient->binderDied(this);
}
@@ -386,13 +386,13 @@ BpBinder::~BpBinder()

    mLock.lock();
    Vector<Obituary>* obits = mObituaries;
    if(obits != NULL) {
    if(obits != nullptr) {
        if (ipc) ipc->clearDeathNotification(mHandle, this);
        mObituaries = NULL;
        mObituaries = nullptr;
    }
    mLock.unlock();

    if (obits != NULL) {
    if (obits != nullptr) {
        // XXX Should we tell any remaining DeathRecipient
        // objects that the last strong ref has gone away, so they
        // are no longer linked?
+4 −4
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ struct BufferedTextOutput::BufferState : public RefBase
{
    explicit BufferState(int32_t _seq)
        : seq(_seq)
        , buffer(NULL)
        , buffer(nullptr)
        , bufferPos(0)
        , bufferSize(0)
        , atFront(true)
@@ -266,13 +266,13 @@ BufferedTextOutput::BufferState* BufferedTextOutput::getBuffer() const
    if ((mFlags&MULTITHREADED) != 0) {
        ThreadState* ts = getThreadState();
        if (ts) {
            while (ts->states.size() <= (size_t)mIndex) ts->states.add(NULL);
            while (ts->states.size() <= (size_t)mIndex) ts->states.add(nullptr);
            BufferState* bs = ts->states[mIndex].get();
            if (bs != NULL && bs->seq == mSeq) return bs;
            if (bs != nullptr && bs->seq == mSeq) return bs;
            
            ts->states.editItemAt(mIndex) = new BufferState(mIndex);
            bs = ts->states[mIndex].get();
            if (bs != NULL) return bs;
            if (bs != nullptr) return bs;
        }
    }
    
Loading