diff --git a/Android.mk b/Android.mk new file mode 100644 index 0000000..34f4385 --- /dev/null +++ b/Android.mk @@ -0,0 +1,3 @@ +LOCAL_PATH:= $(call my-dir) + +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/libapp2sys/Android.mk b/libapp2sys/Android.mk new file mode 100644 index 0000000..2de0955 --- /dev/null +++ b/libapp2sys/Android.mk @@ -0,0 +1,79 @@ +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_C_INCLUDE := $(LOCAL_PATH)/src/main/cpp/cjson +LOCAL_SRC_FILES := src/main/cpp/cjson/cJSON.c +LOCAL_CFLAGS := -Wall -Werror -Wno-unused -ffunction-sections -fdata-sections -fvisibility=hidden -DANDROID_STL=c++_shared +LOCAL_CXXFLAGS := -Wall -Werror -Wno-unused -ffunction-sections -fdata-sections -fvisibility=hidden -DANDROID_STL=c++_shared +LOCAL_MODULE := libcjson +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := STATIC_LIBRARIES +LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/src/main/cpp/cjson +include $(BUILD_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := libamc_proto +LOCAL_MODULE_CLASS := STATIC_LIBRARIES +LOCAL_CFLAGS := -Wall -Werror -Wno-unused -ffunction-sections -fdata-sections -fvisibility=hidden -Wno-unused-parameter -DANDROID_STL=c++_shared +LOCAL_CXXFLAGS := -Wall -Werror -Wno-unused -ffunction-sections -fdata-sections -fvisibility=hidden -Wno-unused-parameter -DANDROID_STL=c++_shared +LOCAL_SRC_FILES := $(call all-proto-files-under, src/main/proto) +generated_sources_dir := $(call local-generated-sources-dir) +LOCAL_EXPORT_C_INCLUDE_DIRS := $(generated_sources_dir)/proto/$(LOCAL_PATH)/src/main/proto +#LOCAL_EXPORT_C_INCLUDE_DIRS += $(LOCAL_PATH)/prebuilt/include/google/protobuf +#LOCAL_C_INCLUDE := $(LOCAL_PATH)/prebuilt/include/google/protobuf +LOCAL_SHARED_LIBRARIES := libprotobuf-cpp-lite +include $(BUILD_STATIC_LIBRARY) + +include $(CLEAR_VARS) + +LOCAL_PROTOC_OPTIMIZE_TYPE := lite +LOCAL_CFLAGS := -Wall -Werror -Wno-unused -ffunction-sections -fdata-sections -fvisibility=hidden -Wno-unused-parameter -DANDROID_STL=c++_shared +LOCAL_CXXFLAGS := -Wall -Werror -Wno-unused -ffunction-sections -fdata-sections -fvisibility=hidden -Wno-unused-parameter -DANDROID_STL=c++_shared +LOCAL_SRC_FILES := src/main/cpp/server.cpp +# src/main/proto/amc.proto + +LOCAL_MODULE := server +LOCAL_MODULE_TAGS := optional +LOCAL_C_INCLUDE := $(LOCAL_PATH)/src/main/cpp + +LOCAL_MODULE_CLASS := EXECUTABLES + +LOCAL_SHARED_LIBRARIES := liblog +LOCAL_SHARED_LIBRARIES += libprotobuf-cpp-lite + +LOCAL_STATIC_LIBRARIES := libcjson +LOCAL_STATIC_LIBRARIES += libamc_proto + +include $(BUILD_EXECUTABLE) + +include $(CLEAR_VARS) + +LOCAL_CFLAGS := -Wall -Werror -Wno-unused -ffunction-sections -fdata-sections -fvisibility=hidden -Wno-unused-parameter -DANDROID_STL=c++_shared -Wno-format +LOCAL_CXXFLAGS := -Wall -Werror -Wno-unused -ffunction-sections -fdata-sections -fvisibility=hidden -Wno-unused-parameter -DANDROID_STL=c++_shared -Wno-format +LOCAL_C_INCLUDE :=$(LOCAL_PATH)/src/main/cpp +LOCAL_STATIC_LIBRARIES := libcjson +LOCAL_STATIC_LIBRARIES += libamc_proto +LOCAL_SHARED_LIBRARIES += libprotobuf-cpp-lite +LOCAL_SHARED_LIBRARIES += liblog + +LOCAL_MODULE := libhardcoder +LOCAL_SRC_FILES := src/main/cpp/com_tencent_mm_hardcoder_HardCoderJNI.cpp + +include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := optional +LOCAL_SRC_FILES := $(call all-java-files-under, src/main/java) $(call all-proto-files-under, src/main/proto) +LOCAL_MODULE := libapp2sys +LOCAL_SDK_VERSION := system_current +LOCAL_MIN_SDK_VERSION := 23 + +#LOCAL_JNI_SHARED_LIBRARIES := libhardcoder +LOCAL_PROTOC_OPTIMIZE_TYPE := lite +LOCAL_PROTOC_FLAGS := --proto_path=$(LOCAL_PATH)/src/main/proto +LOCAL_PROGUARD_ENABLED := disabled + +include $(BUILD_STATIC_JAVA_LIBRARY) + + diff --git a/libapp2sys/src/main/cpp/header.h b/libapp2sys/src/main/cpp/header.h index 906f680..cc5c62a 100644 --- a/libapp2sys/src/main/cpp/header.h +++ b/libapp2sys/src/main/cpp/header.h @@ -84,7 +84,7 @@ static int64_t genReqPack(uint32_t funcid, uint8_t *data, int dataLen, uint8_t * *outPack = buf; *outLen = totalLen; - pdbg("genReqPack json header len:%d, requestid:%lld", header->headerlen, header->requestid); + pdbg("genReqPack json header len:%d, requestid:%ld", header->headerlen, header->requestid); return header->requestid; } else {//proto @@ -108,7 +108,7 @@ static int64_t genReqPack(uint32_t funcid, uint8_t *data, int dataLen, uint8_t * *outPack = buf; *outLen = totalLen; - pdbg("genReqPack pb header len:%zu requestid:%lld", sizeof(AMCReqHeader), header->requestid); + pdbg("genReqPack pb header len:%zu requestid:%ld", sizeof(AMCReqHeader), header->requestid); return header->requestid; } @@ -162,7 +162,7 @@ static int64_t genRespPack(uint32_t funcid, uint32_t retCode, uint64_t requestId struct timespec ts = {0, 0}; clock_gettime(CLOCK_BOOTTIME_ALARM, &ts); p->timestamp = (static_cast(ts.tv_sec) * 1000 * 1000 * 1000) + ts.tv_nsec; - pdbg("genRespPack json funcid:%d timestamp:%d ms requestId:%lld", funcid, TOINT(p->timestamp/1000000L), requestId); + pdbg("genRespPack json funcid:%d timestamp:%d ms requestId:%ld", funcid, TOINT(p->timestamp/1000000L), requestId); p->begin = HEADER_BEGIN; p->version = HEADER_VERSION; @@ -186,7 +186,7 @@ static int64_t genRespPack(uint32_t funcid, uint32_t retCode, uint64_t requestId struct timespec ts = {0, 0}; clock_gettime(CLOCK_BOOTTIME_ALARM, &ts); p->timestamp = (static_cast(ts.tv_sec) * 1000 * 1000 * 1000) + ts.tv_nsec; - pdbg("genRespPack proto funcid:%d timestamp:%d ms requestId:%lld", funcid, TOINT(p->timestamp/1000000L), requestId); + pdbg("genRespPack proto funcid:%d timestamp:%d ms requestId:%ld", funcid, TOINT(p->timestamp/1000000L), requestId); p->begin = HEADER_BEGIN; p->version = HEADER_VERSION; diff --git a/libapp2sys/src/main/cpp/protocol.h b/libapp2sys/src/main/cpp/protocol.h index 5cad3a4..bc87b55 100644 --- a/libapp2sys/src/main/cpp/protocol.h +++ b/libapp2sys/src/main/cpp/protocol.h @@ -324,7 +324,7 @@ class ServerDataWorker { int64_t processSend(uint32_t funcid, T *r, uint8_t *data, uint32_t len) {//server send remote = *r; int64_t requestId = genRespPack(funcid, RET_OK, 0, data, len, &resp, &respLen); - pdbg("processSend funcid:%d, len:%d, remote:%d requestId:%lld, respLen:%d", funcid, len, remote, requestId, respLen); + pdbg("processSend funcid:%d, len:%d, remote:%d requestId:%ld, respLen:%d", funcid, len, remote, requestId, respLen); return requestId; } @@ -578,7 +578,7 @@ class ClientProtocal : public IHardCoderDataCallback { if (!manufactures.empty() && manufactures.size() == certs.size()) { cJSON *certTags; cJSON_AddItemToObject(jsonRequest, "certTags", certTags = cJSON_CreateArray()); - for (int index = 0; index < manufactures.size(); index++) { + for (unsigned long index = 0; index < manufactures.size(); index++) { cJSON *certTag; certTag = cJSON_CreateObject(); cJSON_AddStringToObject(certTag, "manufacture", manufactures[index].c_str()); @@ -596,7 +596,7 @@ class ClientProtocal : public IHardCoderDataCallback { } else { amc::CheckPermission request; if (!manufactures.empty() && manufactures.size() == certs.size()) { - for (int index = 0; index < manufactures.size(); index++) { + for (unsigned long index = 0; index < manufactures.size(); index++) { amc::CertTag* certTag = request.add_certtags(); certTag->set_manufacture(manufactures[index]); certTag->set_cert(certs[index]); @@ -607,7 +607,7 @@ class ClientProtocal : public IHardCoderDataCallback { request.SerializeToArray(body, len); requestid = pEngine->sendReq(FUNC_CHECK_PERMISSION, body, len, tid, timestamp); } - pdbg("checkPermission requestid:%lld, pid:%d, uid:%d, local pid:%d, uid:%d, tid:%d, timestamp:%d", requestid, + pdbg("checkPermission requestid:%ld, pid:%d, uid:%d, local pid:%d, uid:%d, tid:%d, timestamp:%d", requestid, pid, uid, getpid(), getuid(), tid, TOINT(timestamp / 1000000L)); return requestid; } @@ -650,7 +650,7 @@ class ClientProtocal : public IHardCoderDataCallback { requestid = pEngine->sendReq(FUNC_CPU_HIGH_FREQ, body, len, tid, timestamp); } - pdbg("requestCpuHighFreq requestid:%lld, scene:%d, action:%d, level:%d, timeoutms:%d, tid:%d, timestamp:%d" , + pdbg("requestCpuHighFreq requestid:%ld, scene:%d, action:%d, level:%d, timeoutms:%d, tid:%d, timestamp:%d" , requestid, scene, TOINT(action), level, timeoutms, tid, TOINT(timestamp/1000000L)); return requestid; } @@ -679,7 +679,7 @@ class ClientProtocal : public IHardCoderDataCallback { } else { requestid = pEngine->sendReq(FUNC_CANCEL_CPU_HIGH_FREQ, NULL, 0, tid, timestamp); } - pdbg("cancelCpuHighFreq requestid:%lld, tid:%d, timestamp:%d", requestid, tid, TOINT(timestamp / 1000000L)); + pdbg("cancelCpuHighFreq requestid:%ld, tid:%d, timestamp:%d", requestid, tid, TOINT(timestamp / 1000000L)); return requestid; } @@ -719,7 +719,7 @@ class ClientProtocal : public IHardCoderDataCallback { requestid = pEngine->sendReq(FUNC_GPU_HIGH_FREQ, body, len, tid, timestamp); } - pdbg("requestGpuHighFreq requestid:%lld, scene:%d, action:%d, level:%d, timeoutms:%d, tid:%d, timestamp:%d" , + pdbg("requestGpuHighFreq requestid:%ld, scene:%d, action:%d, level:%d, timeoutms:%d, tid:%d, timestamp:%d" , requestid, scene, TOINT(action), level, timeoutms, tid, TOINT(timestamp/1000000L)); return requestid; } @@ -749,7 +749,7 @@ class ClientProtocal : public IHardCoderDataCallback { } else { requestid = pEngine->sendReq(FUNC_CANCEL_GPU_HIGH_FREQ, NULL, 0, tid, timestamp); } - pdbg("cancelGpuHighFreq ret:%d, tid:%d, timestamp:%d", requestid, tid, TOINT(timestamp / 1000000L)); + pdbg("cancelGpuHighFreq ret:%ld, tid:%d, timestamp:%d", requestid, tid, TOINT(timestamp / 1000000L)); return requestid; } @@ -801,7 +801,7 @@ class ClientProtocal : public IHardCoderDataCallback { requestid = pEngine->sendReq(FUNC_CPU_CORE_FOR_THREAD, body, len, tid, timestamp); } - pdbg("requestCpuCoreForThread requestid:%lld, scene:%d, action:%d, bindlen:%d, timeoutms:%d", requestid, scene, TOINT(action), bindlen, timeoutms); + pdbg("requestCpuCoreForThread requestid:%ld, scene:%d, action:%d, bindlen:%d, timeoutms:%d", requestid, scene, TOINT(action), bindlen, timeoutms); return requestid; } @@ -850,7 +850,7 @@ class ClientProtocal : public IHardCoderDataCallback { requestid = pEngine->sendReq(FUNC_CANCEL_CPU_CORE_FOR_THREAD, body, len, tid, timestamp); } - pdbg("cancelCpuCoreForThread requestid:%lld, unbindlen:%d", requestid, unbindlen); + pdbg("cancelCpuCoreForThread requestid:%ld, unbindlen:%d", requestid, unbindlen); return requestid; } @@ -891,7 +891,7 @@ class ClientProtocal : public IHardCoderDataCallback { requestid = pEngine->sendReq(FUNC_HIGH_IO_FREQ, body, len, tid, timestamp); } - pdbg("requestCpuCoreForThread requestid:%lld, scene:%d, action:%d, level:%d, timeoutms:%d", requestid, scene, TOINT(action), level, timeoutms); + pdbg("requestCpuCoreForThread requestid:%ld, scene:%d, action:%d, level:%d, timeoutms:%d", requestid, scene, TOINT(action), level, timeoutms); return requestid; } @@ -919,7 +919,7 @@ class ClientProtocal : public IHardCoderDataCallback { } else { requestid = pEngine->sendReq(FUNC_CANCEL_HIGH_IO_FREQ, NULL, 0, tid, timestamp); } - pdbg("cancelHighIOFreq requestid:%lld", requestid); + pdbg("cancelHighIOFreq requestid:%ld", requestid); return requestid; } @@ -954,7 +954,7 @@ class ClientProtocal : public IHardCoderDataCallback { request.SerializeToArray(body, len); requestid = pEngine->sendReq(FUNC_SET_SCREEN_RESOLUTION, body, len, tid, timestamp); } - pdbg("requestScreenResolution requestid:%lld, level:%d, uiName:%s", requestid, level, uiName.c_str()); + pdbg("requestScreenResolution requestid:%ld, level:%d, uiName:%s", requestid, level, uiName.c_str()); return requestid; } @@ -981,7 +981,7 @@ class ClientProtocal : public IHardCoderDataCallback { } else { requestid = pEngine->sendReq(FUNC_RESET_SCREEN_RESOLUTION, NULL, 0, tid, timestamp); } - pdbg("resetScreenResolution requestid:%lld ", requestid); + pdbg("resetScreenResolution requestid:%ld ", requestid); return requestid; } @@ -1018,7 +1018,7 @@ class ClientProtocal : public IHardCoderDataCallback { request.SerializeToArray(body, len); requestid = pEngine->sendReq(FUNC_REG_ANR_CALLBACK, body, len, tid, timestamp); } - pdbg("registerANRCallback requestid:%lld ", requestid); + pdbg("registerANRCallback requestid:%ld ", requestid); return requestid; } @@ -1055,7 +1055,7 @@ class ClientProtocal : public IHardCoderDataCallback { request.SerializeToArray(body, len); requestid = pEngine->sendReq(FUNC_REG_SYSTEM_EVENT_CALLBACK, body, len, tid, timestamp); } - pdbg("registerSystemEventCallback requestid:%lld ", requestid); + pdbg("registerSystemEventCallback requestid:%ld ", requestid); return requestid; } @@ -1075,7 +1075,7 @@ class ClientProtocal : public IHardCoderDataCallback { if (files.size() > 0) { cJSON *filelist; cJSON_AddItemToObject(jsonRequest, "filelist", filelist = cJSON_CreateArray()); - for (int index = 0; index < files.size(); index++) { + for (unsigned long index = 0; index < files.size(); index++) { cJSON_AddItemToArray(filelist, cJSON_CreateString(files[index].c_str())); } } @@ -1097,7 +1097,7 @@ class ClientProtocal : public IHardCoderDataCallback { request.SerializeToArray(body, len); requestid = pEngine->sendReq(FUNC_REG_PRELOAD_BOOT_RESOURCE, body, len, tid, timestamp); } - pdbg("registerBootPreloadResource requestid:%lld, files size:%d", requestid, TOINT(files.size())); + pdbg("registerBootPreloadResource requestid:%ld, files size:%d", requestid, TOINT(files.size())); return requestid; } @@ -1124,7 +1124,7 @@ class ClientProtocal : public IHardCoderDataCallback { } else { requestid = pEngine->sendReq(FUNC_TERMINATE_APP, NULL, 0, tid, timestamp); } - pdbg("terminateApp requestid:%lld", requestid); + pdbg("terminateApp requestid:%ld", requestid); return requestid; } @@ -1187,7 +1187,7 @@ class ClientProtocal : public IHardCoderDataCallback { requestid = pEngine ->sendReq(FUNC_UNIFY_CPU_IO_THREAD_CORE_GPU, body, len, tid, timestamp); } - pdbg("requestUnifyCpuIOThreadCoreGpu requestid:%lld, scene:%d, action:%d, cpulevel:%d, iolevel:%d, bindlen:%d, gpulevel:%d, timeoutms:%d", requestid, scene, TOINT(action), cpulevel, iolevel, bindlen, gpulevel, timeoutms); + pdbg("requestUnifyCpuIOThreadCoreGpu requestid:%ld, scene:%d, action:%d, cpulevel:%d, iolevel:%d, bindlen:%d, gpulevel:%d, timeoutms:%d", requestid, scene, TOINT(action), cpulevel, iolevel, bindlen, gpulevel, timeoutms); return requestid; } @@ -1241,7 +1241,7 @@ class ClientProtocal : public IHardCoderDataCallback { request.SerializeToArray(body, len); requestid = pEngine->sendReq(FUNC_CANCEL_UNIFY_CPU_IO_THREAD_CORE_GPU, body, len, tid, timestamp); } - pdbg("cancelUnifyCpuIOThreadCoreGpu requestid:%lld, cancelcpu:%d, cancelio:%d, cancelthread:%d, unbindlen:%d, cancelgpu:%d ", requestid, cancelcpu, cancelio, cancelthread, unbindlen, cancelgpu); + pdbg("cancelUnifyCpuIOThreadCoreGpu requestid:%ld, cancelcpu:%d, cancelio:%d, cancelthread:%d, unbindlen:%d, cancelgpu:%d ", requestid, cancelcpu, cancelio, cancelthread, unbindlen, cancelgpu); return requestid; } @@ -1272,7 +1272,7 @@ class ClientProtocal : public IHardCoderDataCallback { request.SerializeToArray(body, len); requestid = pEngine->sendReq(FUNC_CONFIGURE, body, len, tid, timestamp); - pdbg("configure requestid:%lld, request size:%d", requestid, request.ByteSize()); + pdbg("configure requestid:%ld, request size:%d", requestid, request.ByteSize()); } return requestid; } @@ -1304,7 +1304,7 @@ class ClientProtocal : public IHardCoderDataCallback { request.SerializeToArray(body, len); requestid = pEngine->sendReq(FUNC_GET_PARAMETERS, body, len, tid, timestamp); - pdbg("getParameters requestid:%lld, request size:%d", requestid, request.ByteSize()); + pdbg("getParameters requestid:%ld, request size:%d", requestid, request.ByteSize()); } return requestid; } @@ -1312,7 +1312,7 @@ class ClientProtocal : public IHardCoderDataCallback { int onCallback(int uid, int funcid, uint64_t requestid, int bodyFormat, uint64_t timestamp, int retCode, uint8_t *data, int len) { UNUSED(uid); - pdbg("onCallback c2JavaCallback:0x%x, funcid:%d, requestid:%lld, bodyFormat:%d, retCode:%d, data:0x%x, len:%d", TOINT(c2JavaCallback()), funcid, requestid, bodyFormat, retCode, TOINT(data), len); + pdbg("onCallback c2JavaCallback:0x%x, funcid:%d, requestid:%ld, bodyFormat:%d, retCode:%d, data:0x%x, len:%d", TOINT(c2JavaCallback()), funcid, requestid, bodyFormat, retCode, TOINT(data), len); if (!c2JavaCallback()) { return 0; } diff --git a/libapp2sys/src/main/cpp/server.h b/libapp2sys/src/main/cpp/server.h index 3dacdd3..dd94656 100644 --- a/libapp2sys/src/main/cpp/server.h +++ b/libapp2sys/src/main/cpp/server.h @@ -152,7 +152,7 @@ private : } int64_t requestId = pp->processSend(funcid, &fd, data, len); - pdbg("callback funcid:%d, len:%d requestId:%d", funcid, len, requestId); + pdbg("callback funcid:%d, len:%d requestId:%ld", funcid, len, requestId); respQueue.push(pp); return requestId; } diff --git a/libapp2sys/src/main/cpp/util.h b/libapp2sys/src/main/cpp/util.h index 3f2f4ac..11ded91 100644 --- a/libapp2sys/src/main/cpp/util.h +++ b/libapp2sys/src/main/cpp/util.h @@ -142,7 +142,8 @@ static std::string sockaddrToString(struct sockaddr_in addr) { } static sockaddr_in toSockaddr(const char *ip, uint16_t port) { - struct sockaddr_in addr = {0}; + struct sockaddr_in addr; + memset(&addr, 0, sizeof(struct sockaddr_in)); addr.sin_family = AF_INET; addr.sin_port = htons(port); inet_pton(AF_INET, ip, &(addr.sin_addr)); diff --git a/testapp/Android.mk b/testapp/Android.mk new file mode 100644 index 0000000..81613a4 --- /dev/null +++ b/testapp/Android.mk @@ -0,0 +1,16 @@ +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := optional +LOCAL_SRC_FILES := $(call all-java-files-under, src/main/java) +LOCAL_PACKAGE_NAME := hctestapp +LOCAL_SDK_VERSION := system_current +LOCAL_MIN_SDK_VERSION := 23 +LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/src/main/res +LOCAL_MANIFEST_FILE := src/main/AndroidManifest.xml +LOCAL_PROGUARD_ENABLED := disabled + +LOCAL_JNI_SHARED_LIBRARIES := libhardcoder +LOCAL_STATIC_JAVA_LIBRARIES:= libapp2sys + +include $(BUILD_PACKAGE)