Martin L.
Martin L.

Reputation: 3036

Use "sp" in Android NDK

I'm trying to intercept some native library-calls via LD_PRELOAD.

This is working fine for simple libraries written in C, but now I try to go further and override some more complex class-methods from the AOSP written in C++.

Here's my example:

#include <rs/cpp/util/RefBase.h>

namespace android {
    sp<MediaCodec> MediaCodec::CreateByType(const sp<ALooper> &looper, const char *mime, bool encoder) {
        // TODO this will be implemented by me
        return NULL;
    }    
}

In my Application.mk, I got the following piece of code:

APP_STL := gnustl_static

and inside the Android.mk this one:

LOCAL_STATIC_LIBRARIES += libstlport_static

Sadly, the error I get is the following:

jni/libhook/ld_preload.cpp:88:1: error: 'sp' does not name a type

Anyone an idea how to use sp<..> here? I assume it's not Android-specific but a standard C++-thing - I'm totally new at C++, just started "today" :)

I know this may be bad practice, so I'm welcome for any other idea.

Upvotes: 7

Views: 14953

Answers (1)

fadden
fadden

Reputation: 52323

sp<> is Android-specific. sp<> is Strong Pointer, wp<> is Weak Pointer; they came into being as part of the Binder IPC implementation.

The place to start looking for the implementation is the framework RefBase.h, which is a bit twisty for a C++ newcomer. None of what you're fiddling with is part of the public API defined by the NDK, which means it's subject to change between releases, so be aware that what you're trying to do may not work across devices or software updates.

Upvotes: 16

Related Questions