Skip to content

Commit

Permalink
Update Android NDK to v25
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius1922 authored and Daniel Adam committed Sep 21, 2022
1 parent c76304e commit 29ccbf3
Show file tree
Hide file tree
Showing 16 changed files with 195 additions and 84 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ name: CI building android
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
make_android:
make_android:
# The type of runner that the job will run on
runs-on: ubuntu-latest

Expand All @@ -26,8 +26,9 @@ jobs:
uses: actions/checkout@v3

- uses: nttld/setup-ndk@v1
id: setup-ndk
with:
ndk-version: r21e
ndk-version: r25

# Runs a set of commands using the runners shell
- name: android make secured
Expand All @@ -37,13 +38,10 @@ jobs:
# build android
cd port/android
# show which compilers there are
# use v21 since v22 gives an link error with duplicate symbols.
# note that this is hard coded in the makefile
ls -l /usr/local/lib/android/sdk/ndk/
make DYNAMIC=1 TCP=1 IPV4=1 SECURE=1 PKI=1 CLOUD=1 JAVA=1 DEBUG=0
#make DYNAMIC=1 TCP=1 IPV4=1 SECURE=1 PKI=1 JAVA=1 DEBUG=0
env:
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
#NDK_HOME: /usr/local/lib/android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/
NDK_HOME: /usr/local/lib/android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/
MYGITHUB_ACTIONS: true
2 changes: 1 addition & 1 deletion api/oc_ri.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ oc_ri_get_query_nth_key_value(const char *query, size_t query_len,
}
}

int next_pos;
int next_pos = 0;
if (current != NULL) {
*key_len = (current - start);
*key = start;
Expand Down
7 changes: 4 additions & 3 deletions include/oc_obt.h
Original file line number Diff line number Diff line change
Expand Up @@ -846,9 +846,10 @@ void oc_obt_free_roleid(oc_role_t *roles);
* @see oc_obt_add_roleid
* @see oc_obt_free_roleid
*/
int oc_obt_provision_trust_anchor(char *certificate, size_t certificate_size,
char *subject, oc_uuid_t *uuid,
oc_obt_status_cb_t cb, void *data);
int oc_obt_provision_trust_anchor(const char *certificate,
size_t certificate_size, char *subject,
oc_uuid_t *uuid, oc_obt_status_cb_t cb,
void *data);

/* Provision access-control entries (ace2) */
/**
Expand Down
20 changes: 6 additions & 14 deletions port/android/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,37 +81,29 @@ endif

export ANDROID_HOST ?= arm-linux-androideabi-

BIN_BASE := ${ANDROID_BASE}/bin/${ANDROID_HOST}
ifeq ($(origin CC),default)
export CC := ${BIN_BASE}gcc
export CC := ${ANDROID_BASE}/bin/${ANDROID_HOST}gcc
endif
ifeq ($(origin AR),default)
AR := ${BIN_BASE}ar
AR := ${ANDROID_BASE}/bin/llvm-ar
endif
RM ?= rm
MKDIR ?= mkdir


ifeq (${MYGITHUB_ACTIONS}, true)
export HOST_TAG := linux-x86_64
#GITHUBBASE := /usr/local/lib/android/sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/${HOST_TAG}/bin
GITHUBBASE := /usr/local/lib/android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/${HOST_TAG}/bin
#21.4.7075529
# /usr/local/lib/android/sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/bin
export CC := ${GITHUBBASE}/aarch64-linux-android23-clang
AR := ${GITHUBBASE}/aarch64-linux-android-ar
GITHUBBASE := ${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/${HOST_TAG}/bin
export CC := ${GITHUBBASE}/aarch64-linux-android23-clang
AR := ${GITHUBBASE}/llvm-ar
endif


DYNAMIC ?= 1
export SECURE ?= 1
export PKI ?= 1
IPV4 ?= 1
export TCP ?= 1

export CLOUD ?= 1


# unlike other IoTivity-lite builds Android assumes we want to build Java by
# default. It also assumes the use of OC_IDD_API is used by default.
JAVA ?= 1
Expand Down Expand Up @@ -168,7 +160,7 @@ HEADERS_PORT = $(filter-out %_internal.h,$(wildcard ../../port/*.h))
HEADERS_TINYCBOR = $(wildcard ../../deps/tinycbor/src/*.h)

CFLAGS_CLOUD=-I../../api/cloud
CFLAGS?=-fPIC -fno-asynchronous-unwind-tables -fno-omit-frame-pointer -ffreestanding -Os -fno-stack-protector -ffunction-sections -fdata-sections -fno-strict-overflow -I./ -I../../include/ -I../../ -std=gnu99 -Wall -DLONG_BIT=64 -D__ANDROID_API__=${ANDROID_API}
CFLAGS?=-fPIC -fno-asynchronous-unwind-tables -fno-omit-frame-pointer -ffreestanding -Os -fno-stack-protector -ffunction-sections -fdata-sections -fno-strict-overflow -I./ -I../../include/ -I../../ -std=gnu99 -Wall -DLONG_BIT=64 -D__ANDROID_MIN_SDK_VERSION__=${ANDROID_API}
OBJ_COMMON=$(addprefix ${OBJDIR}/,$(notdir $(SRC_COMMON:.c=.o)))
OBJ_CLIENT=$(addprefix ${OBJDIR}/client/,$(notdir $(SRC:.c=.o)))
OBJ_SERVER=$(addprefix ${OBJDIR}/server/,$(filter-out oc_obt.o oc_obt_otm_justworks.o oc_obt_otm_randompin.o oc_obt_otm_cert.o oc_obt_certs.o,$(notdir $(SRC:.c=.o))))
Expand Down
4 changes: 2 additions & 2 deletions security/oc_obt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2151,7 +2151,7 @@ trustanchor_device_RFPRO(int status, void *response_data)
oc_rep_set_text_string(creds, subjectuuid, p->trustanchor_subject);

oc_rep_set_object(creds, publicdata);
oc_rep_set_text_string(publicdata, data, (char *)p->trustanchor);
oc_rep_set_text_string(publicdata, data, p->trustanchor);
oc_rep_set_text_string(publicdata, encoding, "oic.sec.encoding.pem");
oc_rep_close_object(creds, publicdata);

Expand Down Expand Up @@ -2211,7 +2211,7 @@ trustanchor_supports_cert_creds(oc_client_response_t *data)
3) switch dos to RFNOP
*/
int
oc_obt_provision_trust_anchor(char *certificate, size_t certificate_size,
oc_obt_provision_trust_anchor(const char *certificate, size_t certificate_size,
char *subject, oc_uuid_t *uuid,
oc_obt_status_cb_t cb, void *data)
{
Expand Down
2 changes: 1 addition & 1 deletion security/oc_obt_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ typedef struct oc_trustanchor_ctx_t
oc_status_cb_t cb;
oc_device_t *device1;
oc_switch_dos_ctx_t *switch_dos;
char *trustanchor;
const char *trustanchor;
size_t trustanchor_size;
char trustanchor_subject[64];
} oc_trustanchor_ctx_t;
Expand Down
4 changes: 2 additions & 2 deletions swig/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ ifeq ($(OS),android)
LDFLAG += -llog
INSTALL_ANDROID_LIBS = install_android_libs
ifeq ($(ANDROID_API),)
EXTRA_FLAG += -D__ANDROID_API__=23
EXTRA_FLAG += -D__ANDROID_MIN_SDK_VERSION__=23
else
EXTRA_FLAG += -D__ANDROID_API__=$(ANDROID_API)
EXTRA_FLAG += -D__ANDROID_MIN_SDK_VERSION__=$(ANDROID_API)
endif
endif

Expand Down
53 changes: 53 additions & 0 deletions swig/java_lang/oc_iotivity_lite_jni.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,59 @@

static JavaVM *jvm;

#if defined(_WIN32)
HANDLE jni_poll_event_thread;
CRITICAL_SECTION jni_sync_lock;
CONDITION_VARIABLE jni_cv;
CRITICAL_SECTION jni_cs;

int jni_quit;
#elif defined(__linux__)
pthread_t jni_poll_event_thread;
pthread_mutex_t jni_sync_lock;
pthread_mutexattr_t jni_sync_lock_attr;
pthread_cond_t jni_cv;
pthread_mutex_t jni_cs;

int jni_quit;
#endif

jclass cls_ArrayList;
jclass cls_OCMainInitHandler;
jclass cls_OCAddDeviceHandler;
jclass cls_OCClientResponse;
jclass cls_OCCloudContext;
jclass cls_OCConWriteHandler;
jclass cls_OCDiscoveryHandler;
jclass cls_OCDiscoveryAllHandler;
jclass cls_OCFactoryPresetsHandler;
jclass cls_OCGetPropertiesHandler;
jclass cls_OCInitPlatformHandler;
jclass cls_OCOwnershipStatusHandler;
jclass cls_OCQueryValue;
jclass cls_OCRandomPinHandler;
jclass cls_OCRepresentation;
jclass cls_OCRequest;
jclass cls_OCRequestHandler;
jclass cls_OCResponseHandler;
jclass cls_OCResource;
jclass cls_OCSetPropertiesHandler;
jclass cls_OCSoftwareUpdateHandler;
jclass cls_OCTriggerHandler;

jclass cls_OCCoreAddDeviceHandler;
jclass cls_OCCoreInitPlatformHandler;
jclass cls_OCCreds;
jclass cls_OCEndpoint;
jclass cls_OCUuid;
jclass cls_OCObtAclHandler;
jclass cls_OCObtCredsHandler;
jclass cls_OCObtDiscoveryHandler;
jclass cls_OCObtDeviceStatusHandler;
jclass cls_OCObtStatusHandler;
jclass cls_OCCloudHandler;
jclass cls_OCSecurityAcl;

JNIEXPORT jint JNICALL
JNI_OnLoad(JavaVM *vm, void *reserved)
{
Expand Down
92 changes: 46 additions & 46 deletions swig/java_lang/oc_iotivity_lite_jni.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@
#include <jni.h>

#if defined(_WIN32)
HANDLE jni_poll_event_thread;
CRITICAL_SECTION jni_sync_lock;
CONDITION_VARIABLE jni_cv;
CRITICAL_SECTION jni_cs;
extern HANDLE jni_poll_event_thread;
extern CRITICAL_SECTION jni_sync_lock;
extern CONDITION_VARIABLE jni_cv;
extern CRITICAL_SECTION jni_cs;

int jni_quit;
extern int jni_quit;

/* OS specific definition for lock/unlock */
#define jni_mutex_lock(m) EnterCriticalSection(&m)
#define jni_mutex_unlock(m) LeaveCriticalSection(&m)

#elif defined(__linux__)
pthread_t jni_poll_event_thread __attribute__((unused));
pthread_mutex_t jni_sync_lock __attribute__((unused));
pthread_mutexattr_t jni_sync_lock_attr __attribute__((unused));
pthread_cond_t jni_cv __attribute__((unused));
pthread_mutex_t jni_cs __attribute__((unused));
extern pthread_t jni_poll_event_thread;
extern pthread_mutex_t jni_sync_lock;
extern pthread_mutexattr_t jni_sync_lock_attr;
extern pthread_cond_t jni_cv;
extern pthread_mutex_t jni_cs;

int jni_quit __attribute__((unused));
extern int jni_quit;

/* OS specific definition for lock/unlock */
#define jni_mutex_lock(m) pthread_mutex_lock(&m)
Expand Down Expand Up @@ -119,41 +119,41 @@ typedef enum {
* For this reason we pre-load most Java classes that are called from the jni
* code.
*/
jclass cls_ArrayList;
jclass cls_OCMainInitHandler;
jclass cls_OCAddDeviceHandler;
jclass cls_OCClientResponse;
jclass cls_OCCloudContext;
jclass cls_OCConWriteHandler;
jclass cls_OCDiscoveryHandler;
jclass cls_OCDiscoveryAllHandler;
jclass cls_OCFactoryPresetsHandler;
jclass cls_OCGetPropertiesHandler;
jclass cls_OCInitPlatformHandler;
jclass cls_OCOwnershipStatusHandler;
jclass cls_OCQueryValue;
jclass cls_OCRandomPinHandler;
jclass cls_OCRepresentation;
jclass cls_OCRequest;
jclass cls_OCRequestHandler;
jclass cls_OCResponseHandler;
jclass cls_OCResource;
jclass cls_OCSetPropertiesHandler;
jclass cls_OCSoftwareUpdateHandler;
jclass cls_OCTriggerHandler;

jclass cls_OCCoreAddDeviceHandler;
jclass cls_OCCoreInitPlatformHandler;
jclass cls_OCCreds;
jclass cls_OCEndpoint;
jclass cls_OCUuid;
jclass cls_OCObtAclHandler;
jclass cls_OCObtCredsHandler;
jclass cls_OCObtDiscoveryHandler;
jclass cls_OCObtDeviceStatusHandler;
jclass cls_OCObtStatusHandler;
jclass cls_OCCloudHandler;
jclass cls_OCSecurityAcl;
extern jclass cls_ArrayList;
extern jclass cls_OCMainInitHandler;
extern jclass cls_OCAddDeviceHandler;
extern jclass cls_OCClientResponse;
extern jclass cls_OCCloudContext;
extern jclass cls_OCConWriteHandler;
extern jclass cls_OCDiscoveryHandler;
extern jclass cls_OCDiscoveryAllHandler;
extern jclass cls_OCFactoryPresetsHandler;
extern jclass cls_OCGetPropertiesHandler;
extern jclass cls_OCInitPlatformHandler;
extern jclass cls_OCOwnershipStatusHandler;
extern jclass cls_OCQueryValue;
extern jclass cls_OCRandomPinHandler;
extern jclass cls_OCRepresentation;
extern jclass cls_OCRequest;
extern jclass cls_OCRequestHandler;
extern jclass cls_OCResponseHandler;
extern jclass cls_OCResource;
extern jclass cls_OCSetPropertiesHandler;
extern jclass cls_OCSoftwareUpdateHandler;
extern jclass cls_OCTriggerHandler;

extern jclass cls_OCCoreAddDeviceHandler;
extern jclass cls_OCCoreInitPlatformHandler;
extern jclass cls_OCCreds;
extern jclass cls_OCEndpoint;
extern jclass cls_OCUuid;
extern jclass cls_OCObtAclHandler;
extern jclass cls_OCObtCredsHandler;
extern jclass cls_OCObtDiscoveryHandler;
extern jclass cls_OCObtDeviceStatusHandler;
extern jclass cls_OCObtStatusHandler;
extern jclass cls_OCCloudHandler;
extern jclass cls_OCSecurityAcl;

/*
* This struct used to hold information needed for java callbacks.
Expand Down
5 changes: 2 additions & 3 deletions swig/swig_interfaces/oc_api.i
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* File oc_api.i */
%module OCMain
%include "carrays.i"
%include "arrays_java.i"
%include "stdint.i"
%include "typemaps.i"
%include "various.i"
Expand Down Expand Up @@ -1205,9 +1204,9 @@ SWIGEXPORT jobject JNICALL Java_org_iotivity_OCMainJNI_getQueryValues(JNIEnv *je

result = JCALL2(NewObject, jenv, cls_ArrayList, mid_arrayListConstructor);

char *current_key = 0;
const char *current_key = NULL;
size_t key_len = 0;
char *current_value;
const char *current_value;
size_t value_len = 0;
char temp_buffer[512];
int pos = 0;
Expand Down
Loading

0 comments on commit 29ccbf3

Please sign in to comment.