Merge "[Feature][ZXW-59][AUTOSUSPEND]autosuspend demo"
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-autosuspend-demo/lynq-qser-autosuspend-demo.bb b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-autosuspend-demo/lynq-qser-autosuspend-demo.bb
new file mode 100644
index 0000000..ab8d052
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-autosuspend-demo/lynq-qser-autosuspend-demo.bb
@@ -0,0 +1,40 @@
+inherit externalsrc package
+DESCRIPTION = "autosuspend-client demo"
+
+LICENSE = "MobileTekProprietary"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=4f60c98fa94e02f659ef5939f67fa8ae"
+#DEPENDS = "platform-libs"
+
+
+inherit workonsrc
+WORKONSRC = "${TOPDIR}/../src/lynq/packages/apps/lynq-qser-autosuspend-demo"
+FILESEXTRAPATHS_prepend :="${TOPDIR}/../src/lynq/packages/apps:"
+SRC_URI = " \
+          file://lynq-qser-autosuspend-demo \
+          "
+
+SRC-DIR = "${S}/../lynq-qser-autosuspend-demo"
+TARGET_CC_ARCH += "${LDFLAGS}"
+
+SYSTEMD_PACKAGES = "${PN}"
+#Parameters passed to do_compile()
+EXTRA_OEMAKE = "'TARGET_PLATFORM = ${TARGET_PLATFORM}'\"
+EXTRA_OEMAKE += "'MOBILETEK_RIL_CFG = ${MOBILETEK_RIL_CFG}'"
+
+EXTRA_OEMAKE += "'MOBILETEK_FOTA_CFG = ${MOBILETEK_FOTA_CFG}'"
+
+#INHIBIT_PACKAGE_STRIP = "1"
+do_compile () {
+	if test "${PACKAGE_ARCH}" = "cortexa7hf-vfp-vfpv4-neon" || test "${PACKAGE_ARCH}" = "cortexa7hf-neon-vfpv4"; then
+		oe_runmake all -C ${SRC-DIR} ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST} -mhard-float"
+	else
+		oe_runmake all -C ${SRC-DIR} ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST}"
+	fi
+}
+
+
+do_install() {
+	install -d ${D}${bindir}/
+	install -m 0755 ${SRC-DIR}/lynq-qser-autosuspend-demo ${D}${bindir}/
+	install -d ${D}${includedir}
+}
diff --git a/cap/zx297520v3/src/lynq/packages/apps/lynq-qser-autosuspend-demo/LICENSE b/cap/zx297520v3/src/lynq/packages/apps/lynq-qser-autosuspend-demo/LICENSE
new file mode 100755
index 0000000..cb88533
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/packages/apps/lynq-qser-autosuspend-demo/LICENSE
@@ -0,0 +1,31 @@
+Copyright Statement:
+
+This software/firmware and related documentation ("Mobiletek Software") are
+protected under relevant copyright laws. The information contained herein is
+confidential and proprietary to Mobiletek Inc. and/or its licensors. Without
+the prior written permission of Mobiletek inc. and/or its licensors, any
+reproduction, modification, use or disclosure of Mobiletek Software, and
+information contained herein, in whole or in part, shall be strictly
+prohibited.
+
+Mobiletek Inc. (C) 2015. All rights reserved.
+
+BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("Mobiletek SOFTWARE")
+RECEIVED FROM Mobiletek AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ON AN "AS-IS" BASIS ONLY. Mobiletek EXPRESSLY DISCLAIMS ANY AND ALL
+WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+NONINFRINGEMENT. NEITHER DOES Mobiletek PROVIDE ANY WARRANTY WHATSOEVER WITH
+RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+INCORPORATED IN, OR SUPPLIED WITH THE Mobiletek SOFTWARE, AND RECEIVER AGREES
+TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN Mobiletek
+SOFTWARE. Mobiletek SHALL ALSO NOT BE RESPONSIBLE FOR ANY Mobiletek SOFTWARE
+RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND Mobiletek'S
+ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE Mobiletek SOFTWARE
+RELEASED HEREUNDER WILL BE, AT Mobiletek'S OPTION, TO REVISE OR REPLACE THE
+Mobiletek SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+CHARGE PAID BY RECEIVER TO Mobiletek FOR SUCH Mobiletek SOFTWARE AT ISSUE.
diff --git a/cap/zx297520v3/src/lynq/packages/apps/lynq-qser-autosuspend-demo/lynq-qser-autosuspend-demo.c b/cap/zx297520v3/src/lynq/packages/apps/lynq-qser-autosuspend-demo/lynq-qser-autosuspend-demo.c
new file mode 100755
index 0000000..6c1b489
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/packages/apps/lynq-qser-autosuspend-demo/lynq-qser-autosuspend-demo.c
@@ -0,0 +1,284 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <dlfcn.h>
+#include <errno.h>
+#include <fcntl.h>
+
+
+#define FILE_LOCK_TABLE "/tmp/.lock_table"
+
+void *dlHandle_wakelock;
+
+int (*qser_lpm_deinit)(void);
+int (*qser_autosuspend_enable)(char enable);
+int (*qser_wakelock_create)(const char *value, size_t len);
+int (*qser_wakelock_lock)(int fd);
+int (*qser_wakelock_unlock)(int fd);
+int (*qser_wakelock_destroy)(int fd);
+
+#define MAX_LOCK_NUM 128
+
+typedef struct
+{
+    char lock_name[MAX_LOCK_NUM][64];
+} LOCK_TABLE;
+
+void init_autosuspend_func(void)
+{
+
+    const char *lynqLibPath_WakeLock = "/lib/liblynq-qser-autosuspend.so";
+
+
+    dlHandle_wakelock = dlopen(lynqLibPath_WakeLock, RTLD_NOW);
+    if (dlHandle_wakelock == NULL) 
+    {
+        printf("dlopen lynqLibPath_WakeLock failed: %s", dlerror());
+        exit(EXIT_FAILURE);
+    }
+
+    qser_lpm_deinit = (int(*)(void))dlsym(dlHandle_wakelock, "qser_lpm_deinit");
+    if (qser_lpm_deinit == NULL)
+    {
+        printf("qser_lpm_deinit not defined or exported in %s", lynqLibPath_WakeLock);
+        exit(EXIT_FAILURE);
+    }
+
+    qser_autosuspend_enable = (int(*)(char))dlsym(dlHandle_wakelock, "qser_autosuspend_enable");
+    if (qser_autosuspend_enable == NULL)
+    {
+        printf("qser_autosuspend_enable not defined or exported in %s", lynqLibPath_WakeLock);
+        exit(EXIT_FAILURE);
+    }
+
+    qser_wakelock_create = (int(*)(const char *value, size_t len))dlsym(dlHandle_wakelock, "qser_wakelock_create");
+    if (qser_wakelock_create == NULL)
+    {
+        printf("qser_wakelock_create not defined or exported in %s", lynqLibPath_WakeLock);
+        exit(EXIT_FAILURE);
+    }
+
+    qser_wakelock_lock = (int(*)(int))dlsym(dlHandle_wakelock, "qser_wakelock_lock");
+    if (qser_wakelock_lock == NULL)
+    {
+        printf("qser_wakelock_lock not defined or exported in %s", lynqLibPath_WakeLock);
+        exit(EXIT_FAILURE);
+    }
+
+    qser_wakelock_unlock = (int(*)(int))dlsym(dlHandle_wakelock, "qser_wakelock_unlock");
+    if (qser_wakelock_unlock == NULL)
+    {
+        printf("qser_wakelock_unlock not defined or exported in %s", lynqLibPath_WakeLock);
+        exit(EXIT_FAILURE);
+    }
+
+    qser_wakelock_destroy = (int(*)(int))dlsym(dlHandle_wakelock, "qser_wakelock_destroy");
+    if (qser_wakelock_destroy == NULL)
+    {
+        printf("qser_wakelock_unlock not defined or exported in %s", lynqLibPath_WakeLock);
+        exit(EXIT_FAILURE);
+    }
+    
+    dlerror(); // Clear any previous dlerror
+
+    return;
+}
+
+
+int check_lock(void)
+{
+    int err;
+    int file_fd;
+    int i;
+    int ret;
+    LOCK_TABLE lock_status;
+    file_fd = open(FILE_LOCK_TABLE,O_RDWR);
+    if(file_fd < 0)
+    {
+        err = errno;
+        printf("Error open lock_table file:%s\n", strerror(errno));
+        return -2;
+    }
+
+    memset(&lock_status, 0, sizeof(lock_status));
+    lseek(file_fd,0,SEEK_SET);
+    ret = read(file_fd,(unsigned char *)&lock_status,sizeof(lock_status));
+    for(i=0;i<128;i++)
+    {
+        if(strlen(lock_status.lock_name[i]) != 0)
+        {
+            printf("fd: %d lock_name:%s strlen:%d\n", i, lock_status.lock_name[i], strlen(lock_status.lock_name[i]));
+        }
+    }
+    if(ret <= 0)
+    {
+        return -2;
+    }
+    close(file_fd);
+    return 0;
+
+}
+
+int main(int argc,char** argv)
+{
+
+    int num;
+    int ret;
+    int len;
+    init_autosuspend_func();
+    if(argc < 2)
+    {
+        printf("wrong input format, please -h \n");
+        return -1;
+    }
+    if(strcmp(argv[1],"-h") == 0)
+    {
+        printf("        -h                  --help\n");
+        printf("        -i                  --qseq_lpm_init\n");
+        printf("        -d                  --qser_lpm_deinit\n");
+        printf("        -e                  --qser_autosuspend_enable\n");
+        printf("        -cl [wakelock name] --qser_wakelock_create \n");
+        printf("        -al [wakelock num]  --qser_wakelock_lock \n");
+        printf("        -rl [wakelock num]  --qser_wakelock_unlock \n");
+        printf("        -dl [wakelock num]  --qser_wakelock_destroy\n");
+        printf("        -ccl                --check created locks\n");
+        printf("        -cll                --check lockup locks\n");
+    }
+    else if(strcmp(argv[1],"-d") == 0)
+    {
+        ret = qser_lpm_deinit();
+        if(ret != 0)
+        {
+            printf("lpm deinit fail\n");
+        }
+        else
+        {
+            printf("lpm deinit success\n");
+        }
+    }
+    else if(strcmp(argv[1],"-e") == 0)
+    {
+        char num='1';
+        ret = qser_autosuspend_enable(num);
+        if(ret != 0)
+        {
+            printf("qser_autosuspend_enable fail\n");
+        }
+        else
+        {
+            printf("qser_autosuspend_enable success\n");
+        }
+    }
+    else if(strcmp(argv[1],"-cl") == 0)
+    {
+        if(argv[2] == NULL)
+        {
+            printf("name is null\n");
+            return -1;
+        }
+        len = strlen(argv[2]);
+        printf("len =%d\n", len);
+        ret = qser_wakelock_create(argv[2], len);
+        if(ret < 0)
+        {
+            printf("wakelock create fail\n");
+            printf("ret=%d\n", ret);
+        }
+        else
+        {
+            printf("wakelock create success\n");
+            printf("fd=%d\n", ret);
+        }
+    }
+    else if (strcmp(argv[1],"-al") == 0)
+    {
+        if(argv[2] == NULL)
+        {
+            printf("fd is null\n");
+            return -1;
+        }
+        num = atoi(argv[2]);
+        ret = qser_wakelock_lock(num);
+        if(ret != 0)
+        {
+            printf("wakelock lock fail\n");
+            printf("ret=%d\n", ret);
+        }
+        else
+        {
+            printf("wakelock lock success\n");
+        }
+    }
+
+    else if (strcmp(argv[1],"-rl") == 0)
+    {
+        if(argv[2] == NULL)
+        {
+            printf("fd is null\n");
+            return -1;
+        }
+        num = atoi(argv[2]);
+        ret = qser_wakelock_unlock(num);
+        if(ret != 0)
+        {
+            printf("wakelock unlock fail\n");
+            printf("ret=%d\n", ret);
+        }
+        else
+        {
+            printf("wakelock unlock success\n");
+        }
+    }
+    else if(strcmp(argv[1],"-dl") == 0)
+    {
+        if(argv[2] == NULL)
+        {
+            printf("fd is null\n");
+            return -1;
+        }
+        num = atoi(argv[2]);
+        ret = qser_wakelock_destroy(num);
+        if(ret != 0)
+        {
+            printf("wakelock destroy fail\n");
+            printf("ret=%d\n", ret);
+        }
+        else
+        {
+            printf("wakelock destroy success\n");
+        }
+    }
+    else if(strcmp(argv[1],"-ccl") == 0)
+    {
+        int ret;
+        ret = check_lock();
+        if(ret != 0)
+        {
+            printf("check lock fail\n");
+            printf("ret=%d\n", ret);
+        }
+        else
+        {
+            printf("check lock success\n");
+        }
+    }
+    else if(strcmp(argv[1],"-cll") == 0)
+    {
+        int ret;
+        ret = system("cat /sys/power/wake_lock");
+        if(ret != 0)
+        {
+            printf("check created lock fail\n");
+        }
+    }
+    else
+    {
+        printf("wrong input format, please -h \n");
+        return -1;
+    }
+    return 0;
+
+}
diff --git a/cap/zx297520v3/src/lynq/packages/apps/lynq-qser-autosuspend-demo/makefile b/cap/zx297520v3/src/lynq/packages/apps/lynq-qser-autosuspend-demo/makefile
new file mode 100755
index 0000000..b3638ea
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/packages/apps/lynq-qser-autosuspend-demo/makefile
@@ -0,0 +1,42 @@
+SHELL = /bin/sh
+RM = rm -f
+
+LOCAL_CFLAGS := -Wall \
+                -g -Os \
+                -flto \
+                -fpermissive \
+                -fPIC \
+
+ifeq ($(strip $(TARGET_PLATFORM)), T106)
+LOCAL_CFLAGS += -DBINDER_IPC_32BIT=1 -DHAVE_ENDIAN_H -DHAVE_PTHREADS -DHAVE_SYS_UIO_H -DHAVE_POSIX_FILEMAP -DHAVE_STRLCPY -DHAVE_PRCTL -DHAVE_MEMSET16 -DHAVE_MEMSET32 -DANDROID_SMP=0
+endif
+
+LOCAL_CFLAGS += -DZXW
+
+LOCAL_PATH   = .
+
+LOCAL_C_INCLUDES = \
+  -I. \
+
+
+LOCAL_LIBS := \
+    -L. \
+    -ldl \
+    -lpthread \
+
+SOURCES = $(wildcard *.c)
+
+EXECUTABLE = lynq-qser-autosuspend-demo
+
+OBJECTS=$(SOURCES:.c=.o)
+all: $(EXECUTABLE)
+
+$(EXECUTABLE): $(OBJECTS)
+	$(CXX) $(OBJECTS) $(LOCAL_LIBS) $(LOCAL_CFLAGS) $(LOCAL_C_INCLUDES) -o $@
+
+%.o : %.c
+	$(CC) $(LOCAL_C_INCLUDES) $(LOCAL_CFLAGS) $(LOCAL_LIBS) -o $@ -c $<
+
+.PHONY: clean
+clean:
+	$(RM) $(OBJECTS) $(EXECUTABLE)