Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 690
Martin L. Avatar asked Oct 09 '14 12:10

Martin L.


People also ask

What is the difference between DP and SP in Android?

Both dp and sp follow this concept and can be used almost identically, albeit with a few differences. It stands for density-independent pixel. It is also sometimes denoted as dip. It stands for scale independent pixel. It used for defining the sizes in all widgets, ranging from TextView to LinearLayout

What is the difference between SP<> and WP<> in Android?

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.

Where can I find a C++ implementation of the NDK?

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.

What are density independent pixels (DP) in Android?

Using constant values to define the sizes while designing the UI of an Android Application can sometimes lead to the app looking good on a few devices but looking jarring on some other devices. To avoid such issues, the Android team developed the concept of using Density Independent Pixels (dp, dip, sp) for defining sizes.


Video Answer


1 Answers

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.

like image 177
fadden Avatar answered Sep 22 '22 03:09

fadden