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

Commit 2e9f93e8 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Update native activity & event APIs to follow correct conventions.

Change-Id: Ie64fb3a9c68bc9c117fa5621b75d1f609e304e0e
parent 059f009d
Loading
Loading
Loading
Loading
+17 −12
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ namespace android
{

struct NativeCode {
    NativeCode(void* _dlhandle, android_activity_create_t* _createFunc) {
    NativeCode(void* _dlhandle, ANativeActivity_createFunc* _createFunc) {
        memset(&activity, sizeof(activity), 0);
        memset(&callbacks, sizeof(callbacks), 0);
        dlhandle = _dlhandle;
@@ -73,7 +73,7 @@ struct NativeCode {
            sp<InputChannel> ic =
                    android_view_InputChannel_getInputChannel(activity.env, _channel);
            if (ic != NULL) {
                nativeInputQueue = new input_queue_t(ic);
                nativeInputQueue = new AInputQueue(ic);
                if (nativeInputQueue->getConsumer().initialize() != android::OK) {
                    delete nativeInputQueue;
                    nativeInputQueue = NULL;
@@ -86,15 +86,15 @@ struct NativeCode {
        return OK;
    }
    
    android_activity_t activity;
    android_activity_callbacks_t callbacks;
    ANativeActivity activity;
    ANativeActivityCallbacks callbacks;
    
    void* dlhandle;
    android_activity_create_t* createActivityFunc;
    ANativeActivity_createFunc* createActivityFunc;
    
    jobject surface;
    jobject inputChannel;
    struct input_queue_t* nativeInputQueue;
    struct AInputQueue* nativeInputQueue;
};

static jint
@@ -108,14 +108,19 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path)
    env->ReleaseStringUTFChars(path, pathStr);
    
    if (handle != NULL) {
        code = new NativeCode(handle, (android_activity_create_t*)
                dlsym(handle, "android_onCreateActivity"));
        code = new NativeCode(handle, (ANativeActivity_createFunc*)
                dlsym(handle, "ANativeActivity_onCreate"));
        if (code->createActivityFunc == NULL) {
            LOGW("android_onCreateActivity not found");
            LOGW("ANativeActivity_onCreate not found");
            delete code;
            return 0;
        }
        code->activity.callbacks = &code->callbacks;
        if (env->GetJavaVM(&code->activity.vm) < 0) {
            LOGW("NativeActivity GetJavaVM failed");
            delete code;
            return 0;
        }
        code->activity.env = env;
        code->activity.clazz = clazz;
        code->createActivityFunc(&code->activity, NULL, 0);
@@ -219,7 +224,7 @@ onSurfaceCreated_native(JNIEnv* env, jobject clazz, jint handle, jobject surface
        code->setSurface(surface);
        if (code->callbacks.onSurfaceCreated != NULL) {
            code->callbacks.onSurfaceCreated(&code->activity,
                    (android_surface_t*)code->surface);
                    (ASurfaceHolder*)code->surface);
        }
    }
}
@@ -232,7 +237,7 @@ onSurfaceChanged_native(JNIEnv* env, jobject clazz, jint handle, jobject surface
        NativeCode* code = (NativeCode*)handle;
        if (code->surface != NULL && code->callbacks.onSurfaceChanged != NULL) {
            code->callbacks.onSurfaceChanged(&code->activity,
                    (android_surface_t*)code->surface, format, width, height);
                    (ASurfaceHolder*)code->surface, format, width, height);
        }
    }
}
@@ -244,7 +249,7 @@ onSurfaceDestroyed_native(JNIEnv* env, jobject clazz, jint handle, jobject surfa
        NativeCode* code = (NativeCode*)handle;
        if (code->surface != NULL && code->callbacks.onSurfaceDestroyed != NULL) {
            code->callbacks.onSurfaceDestroyed(&code->activity,
                    (android_surface_t*)code->surface);
                    (ASurfaceHolder*)code->surface);
        }
        code->setSurface(NULL);
    }
+2 −2
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ enum {
/*
 * Declare a concrete type for the NDK's input event forward declaration.
 */
struct input_event_t { };
struct AInputEvent { };

namespace android {

@@ -136,7 +136,7 @@ struct PointerCoords {
/*
 * Input events.
 */
class InputEvent : public input_event_t {
class InputEvent : public AInputEvent {
public:
    virtual ~InputEvent() { }

+3 −3
Original line number Diff line number Diff line
@@ -333,13 +333,13 @@ private:
/*
 * NDK input queue API.
 */
struct input_queue_t {
struct AInputQueue {
public:
    /* Creates a consumer associated with an input channel. */
    explicit input_queue_t(const android::sp<android::InputChannel>& channel);
    explicit AInputQueue(const android::sp<android::InputChannel>& channel);

    /* Destroys the consumer and releases its input channel. */
    ~input_queue_t();
    ~AInputQueue();

    inline android::InputConsumer& getConsumer() { return mConsumer; }
    
+4 −4
Original line number Diff line number Diff line
@@ -691,7 +691,7 @@ void InputConsumer::populateMotionEvent(MotionEvent* motionEvent) const {

} // namespace android

// --- input_queue_t ---
// --- AInputQueue ---

using android::InputEvent;
using android::InputChannel;
@@ -699,13 +699,13 @@ using android::InputConsumer;
using android::sp;
using android::status_t;

input_queue_t::input_queue_t(const sp<InputChannel>& channel) :
AInputQueue::AInputQueue(const sp<InputChannel>& channel) :
        mConsumer(channel) {
}

input_queue_t::~input_queue_t() {
AInputQueue::~AInputQueue() {
}

status_t input_queue_t::consume(InputEvent** event) {
status_t AInputQueue::consume(InputEvent** event) {
    return mConsumer.consume(&mInputEventFactory, event);
}
+40 −40
Original line number Diff line number Diff line
@@ -27,168 +27,168 @@ using android::InputEvent;
using android::KeyEvent;
using android::MotionEvent;

int32_t input_event_get_type(const input_event_t* event) {
int32_t AInputEvent_getType(const AInputEvent* event) {
    return static_cast<const InputEvent*>(event)->getType();
}

int32_t input_event_get_device_id(const input_event_t* event) {
int32_t AInputEvent_getDeviceId(const AInputEvent* event) {
    return static_cast<const InputEvent*>(event)->getDeviceId();
}

int32_t input_event_get_nature(const input_event_t* event) {
int32_t AInputEvent_getNature(const AInputEvent* event) {
    return static_cast<const InputEvent*>(event)->getNature();
}

int32_t key_event_get_action(const input_event_t* key_event) {
int32_t AKeyEvent_getAction(const AInputEvent* key_event) {
    return static_cast<const KeyEvent*>(key_event)->getAction();
}

int32_t key_event_get_flags(const input_event_t* key_event) {
int32_t AKeyEvent_getFlags(const AInputEvent* key_event) {
    return static_cast<const KeyEvent*>(key_event)->getFlags();
}

int32_t key_event_get_key_code(const input_event_t* key_event) {
int32_t AKeyEvent_getKeyCode(const AInputEvent* key_event) {
    return static_cast<const KeyEvent*>(key_event)->getKeyCode();
}

int32_t key_event_get_scan_code(const input_event_t* key_event) {
int32_t AKeyEvent_getScanCode(const AInputEvent* key_event) {
    return static_cast<const KeyEvent*>(key_event)->getScanCode();
}

int32_t key_event_get_meta_state(const input_event_t* key_event) {
int32_t AKeyEvent_getMetaState(const AInputEvent* key_event) {
    return static_cast<const KeyEvent*>(key_event)->getMetaState();
}
int32_t key_event_get_repeat_count(const input_event_t* key_event) {
int32_t AKeyEvent_getRepeatCount(const AInputEvent* key_event) {
    return static_cast<const KeyEvent*>(key_event)->getRepeatCount();
}

int64_t key_event_get_down_time(const input_event_t* key_event) {
int64_t AKeyEvent_getDownTime(const AInputEvent* key_event) {
    return static_cast<const KeyEvent*>(key_event)->getDownTime();
}

int64_t key_event_get_event_time(const input_event_t* key_event) {
int64_t AKeyEvent_getEventTime(const AInputEvent* key_event) {
    return static_cast<const KeyEvent*>(key_event)->getEventTime();
}

int32_t motion_event_get_action(const input_event_t* motion_event) {
int32_t AMotionEvent_getAction(const AInputEvent* motion_event) {
    return static_cast<const MotionEvent*>(motion_event)->getAction();
}

int32_t motion_event_get_meta_state(const input_event_t* motion_event) {
int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event) {
    return static_cast<const MotionEvent*>(motion_event)->getMetaState();
}

int32_t motion_event_get_edge_flags(const input_event_t* motion_event) {
int32_t AMotionEvent_getEdgeFlags(const AInputEvent* motion_event) {
    return reinterpret_cast<const MotionEvent*>(motion_event)->getEdgeFlags();
}

int64_t motion_event_get_down_time(const input_event_t* motion_event) {
int64_t AMotionEvent_getDownTime(const AInputEvent* motion_event) {
    return static_cast<const MotionEvent*>(motion_event)->getDownTime();
}

int64_t motion_event_get_event_time(const input_event_t* motion_event) {
int64_t AMotionEvent_getEventTime(const AInputEvent* motion_event) {
    return static_cast<const MotionEvent*>(motion_event)->getEventTime();
}

float motion_event_get_x_offset(const input_event_t* motion_event) {
float AMotionEvent_getXOffset(const AInputEvent* motion_event) {
    return static_cast<const MotionEvent*>(motion_event)->getXOffset();
}

float motion_event_get_y_offset(const input_event_t* motion_event) {
float AMotionEvent_getYOffset(const AInputEvent* motion_event) {
    return static_cast<const MotionEvent*>(motion_event)->getYOffset();
}

float motion_event_get_x_precision(const input_event_t* motion_event) {
float AMotionEvent_getXPrecision(const AInputEvent* motion_event) {
    return static_cast<const MotionEvent*>(motion_event)->getXPrecision();
}

float motion_event_get_y_precision(const input_event_t* motion_event) {
float AMotionEvent_getYPrecision(const AInputEvent* motion_event) {
    return static_cast<const MotionEvent*>(motion_event)->getYPrecision();
}

size_t motion_event_get_pointer_count(const input_event_t* motion_event) {
size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event) {
    return static_cast<const MotionEvent*>(motion_event)->getPointerCount();
}

int32_t motion_event_get_pointer_id(const input_event_t* motion_event, size_t pointer_index) {
int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index) {
    return static_cast<const MotionEvent*>(motion_event)->getPointerId(pointer_index);
}

float motion_event_get_raw_x(const input_event_t* motion_event, size_t pointer_index) {
float AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index) {
    return static_cast<const MotionEvent*>(motion_event)->getRawX(pointer_index);
}

float motion_event_get_raw_y(const input_event_t* motion_event, size_t pointer_index) {
float AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index) {
    return static_cast<const MotionEvent*>(motion_event)->getRawY(pointer_index);
}

float motion_event_get_x(const input_event_t* motion_event, size_t pointer_index) {
float AMotionEvent_getX(const AInputEvent* motion_event, size_t pointer_index) {
    return static_cast<const MotionEvent*>(motion_event)->getX(pointer_index);
}

float motion_event_get_y(const input_event_t* motion_event, size_t pointer_index) {
float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index) {
    return static_cast<const MotionEvent*>(motion_event)->getY(pointer_index);
}

float motion_event_get_pressure(const input_event_t* motion_event, size_t pointer_index) {
float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index) {
    return static_cast<const MotionEvent*>(motion_event)->getPressure(pointer_index);
}

float motion_event_get_size(const input_event_t* motion_event, size_t pointer_index) {
float AMotionEvent_getSize(const AInputEvent* motion_event, size_t pointer_index) {
    return static_cast<const MotionEvent*>(motion_event)->getSize(pointer_index);
}

size_t motion_event_get_history_size(const input_event_t* motion_event) {
size_t AMotionEvent_getHistorySize(const AInputEvent* motion_event) {
    return static_cast<const MotionEvent*>(motion_event)->getHistorySize();
}

int64_t motion_event_get_historical_event_time(input_event_t* motion_event,
int64_t AMotionEvent_getHistoricalEventTime(AInputEvent* motion_event,
        size_t history_index) {
    return static_cast<const MotionEvent*>(motion_event)->getHistoricalEventTime(
            history_index);
}

float motion_event_get_historical_raw_x(input_event_t* motion_event, size_t pointer_index,
float AMotionEvent_getHistoricalRawX(AInputEvent* motion_event, size_t pointer_index,
        size_t history_index) {
    return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawX(
            pointer_index, history_index);
}

float motion_event_get_historical_raw_y(input_event_t* motion_event, size_t pointer_index,
float AMotionEvent_getHistoricalRawY(AInputEvent* motion_event, size_t pointer_index,
        size_t history_index) {
    return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawY(
            pointer_index, history_index);
}

float motion_event_get_historical_x(input_event_t* motion_event, size_t pointer_index,
float AMotionEvent_getHistoricalX(AInputEvent* motion_event, size_t pointer_index,
        size_t history_index) {
    return static_cast<const MotionEvent*>(motion_event)->getHistoricalX(
            pointer_index, history_index);
}

float motion_event_get_historical_y(input_event_t* motion_event, size_t pointer_index,
float AMotionEvent_getHistoricalY(AInputEvent* motion_event, size_t pointer_index,
        size_t history_index) {
    return static_cast<const MotionEvent*>(motion_event)->getHistoricalY(
            pointer_index, history_index);
}

float motion_event_get_historical_pressure(input_event_t* motion_event, size_t pointer_index,
float AMotionEvent_getHistoricalPressure(AInputEvent* motion_event, size_t pointer_index,
        size_t history_index) {
    return static_cast<const MotionEvent*>(motion_event)->getHistoricalPressure(
            pointer_index, history_index);
}

float motion_event_get_historical_size(input_event_t* motion_event, size_t pointer_index,
float AMotionEvent_getHistoricalSize(AInputEvent* motion_event, size_t pointer_index,
        size_t history_index) {
    return static_cast<const MotionEvent*>(motion_event)->getHistoricalSize(
            pointer_index, history_index);
}

int input_queue_get_fd(input_queue_t* queue) {
int AInputQueue_getFd(AInputQueue* queue) {
    return queue->getConsumer().getChannel()->getReceivePipeFd();
}

int input_queue_has_events(input_queue_t* queue) {
int AInputQueue_hasEvents(AInputQueue* queue) {
    struct pollfd pfd;
    
    pfd.fd = queue->getConsumer().getChannel()->getReceivePipeFd();
@@ -200,7 +200,7 @@ int input_queue_has_events(input_queue_t* queue) {
    return pfd.revents == POLLIN ? 1 : -1;
}

int32_t input_queue_get_event(input_queue_t* queue, input_event_t** outEvent) {
int32_t AInputQueue_getEvent(AInputQueue* queue, AInputEvent** outEvent) {
    *outEvent = NULL;
    
    int32_t res = queue->getConsumer().receiveDispatchSignal();
@@ -223,7 +223,7 @@ int32_t input_queue_get_event(input_queue_t* queue, input_event_t** outEvent) {
    return 0;
}

void input_queue_finish_event(input_queue_t* queue, input_event_t* event,
void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event,
        int handled) {
    int32_t res = queue->getConsumer().sendFinishedSignal();
    if (res != android::OK) {
Loading