[Bugfix][T106BUG-83] add rtc wakealarm and poweralarm api

Only Configure:No
Affected branch:master
Affected module:Rtc
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update:Need

Change-Id: I153112218065ee7e7af928c4805745d2c8896d91
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf b/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf
index e1ad73d..10afd74 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf
+++ b/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf
@@ -191,6 +191,7 @@
         liblynq-qser-network \
         liblynq-qser-gnss \
         liblynq-qser-fota \
+        libpoweralarm \
 	"
 
 zxic_lib += "${@bb.utils.contains('CONFIG_TEL_API_SUPPORT', 'RIL', 'libril', 'libtelsvr', d)}"
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/libpoweralarm/libpoweralarm.bb b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/libpoweralarm/libpoweralarm.bb
new file mode 100755
index 0000000..0867686
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/libpoweralarm/libpoweralarm.bb
@@ -0,0 +1,58 @@
+#inherit externalsrc package
+DESCRIPTION = "libpoweralarm.so "
+SECTION = "base"
+#LICENSE = "Mobiletek""
+LICENSE = "CLOSED"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=d759532d295a4ec07250edf931caef80"
+DEPENDS += "bootchart  liblynq-log libsctel "
+
+#inherit workonsrc
+WORKONSRC = "${TOPDIR}/../src/lynq/lib/libpoweralarm/"
+
+FILESEXTRAPATHS_prepend :="${TOPDIR}/../src/lynq/lib/:"
+SRC_URI = " \
+          file://libpoweralarm \
+          "
+SRC-DIR = "${S}/../libpoweralarm"
+TARGET_CC_ARCH += "${LDFLAGS}"
+BB_INCLUDE_ADD = "--sysroot=${STAGING_DIR_HOST}"
+BB_LDFLAGS_ADD = "--sysroot=${STAGING_DIR_HOST} -Wl,--hash-style=gnu"
+
+#Parameters passed to do_compile()
+
+FILES_${PN} = "${base_libdir}/*.so \
+               ${base_bindir}\
+               ${base_sbindir}"
+
+
+FILES_${PN}-dev = "/test \
+                   ${includedir}"
+
+FILES_${PN}-doc = "/doc"
+
+FILES_${PN}-dbg ="${base_bindir}/.debug \
+                  ${base_libdir}/.debug \
+                  ${base_sbindir}/.debug"
+
+INSANE_SKIP_${PN} += "already-stripped"
+INSANE_SKIP_${PN} += "installed-vs-shipped"
+
+
+#INHIBIT_PACKAGE_STRIP = "1"
+do_compile () {
+		oe_runmake all -C ${SRC-DIR} ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST} -Os -Wl,--hash-style=gnu -DTELEPHONYWARE"
+}
+
+do_install () {
+    oe_runmake install -C ${SRC-DIR} ROOT=${D}
+	
+    if [ -d "${WORKONSRC}" ] ; then
+        install -d ${D}${includedir}/
+        cp -af ${SRC-DIR}/include/ ${D}${includedir}/
+    fi 
+}
+
+addtask bachclean
+do_bachclean () {
+    oe_runmake clean
+}
diff --git a/cap/zx297520v3/src/lynq/lib/libpoweralarm/LICENSE b/cap/zx297520v3/src/lynq/lib/libpoweralarm/LICENSE
new file mode 100644
index 0000000..7ac229e
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/libpoweralarm/LICENSE
@@ -0,0 +1,31 @@
+Copyright Statement:
+
+This software/firmware and related documentation ("MediaTek 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 MediaTek 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 MEDIATEK 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/lib/libpoweralarm/include/libpoweralarm.h b/cap/zx297520v3/src/lynq/lib/libpoweralarm/include/libpoweralarm.h
new file mode 100755
index 0000000..54191a6
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/libpoweralarm/include/libpoweralarm.h
@@ -0,0 +1,30 @@
+/*******************************************************

+* 

+* @brief:   none

+* @details:  add libpoweralarm api

+* @author:   l.yang

+* @date:     2023.8.21

+* @version:  V1.0

+* @copyright:Copyright (c) MobileTek 

+*

+*********************************************/

+

+#ifndef _LYNQ_POWERALARM_

+#define _LYNQ_POWERALARM_

+#ifdef __cplusplus

+    extern "C" {

+#endif

+

+ssize_t poweralarm(char * buffer);

+ssize_t wakealarm(char *buffer);

+ssize_t cancel_wakealarm(void);

+int lynq_set_wakealarm(unsigned long  time_sec);

+int lynq_set_poweralarm(unsigned long time_sec);

+

+

+#ifdef __cplusplus

+}

+#endif

+#endif

+

+

diff --git a/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp b/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp
new file mode 100755
index 0000000..79629a7
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp
@@ -0,0 +1,269 @@
+/*******************************************************

+* 

+* @brief:    none

+* @details:      Add  wakealrm and poweralarm api code 

+* @author:    l.yang

+* @date:    2023.8.17

+* @version:    V1.0

+* @copyright:    Copyright (c) MobileTek 

+*

+*********************************************/

+

+#include<stdio.h>

+#include<stdlib.h>

+#include<unistd.h>

+#include<stdbool.h>

+#include<log/log.h>

+#include "liblog/lynq_deflog.h"

+#include <include/libpoweralarm.h>

+#include <pthread.h>

+

+

+#ifdef __cplusplus

+extern "C" {

+#endif

+

+#define USER_LOG_TAG "LYNQ_POWERALARM"

+

+

+static int wk_rtc_id = 1;

+static int pw_rtc_id = 2;

+static int wk_srcid = 0;

+

+typedef int (*sc_rtc_timer_exp_cb)(unsigned int src_id, int rtc_id);

+extern int sc_rtc_timer_init(void);

+extern int sc_rtc_timer_uninit(void );

+extern int sc_rtc_timer_add(int srcid, int rtc_id, unsigned long ulSec, sc_rtc_timer_exp_cb rtc_notify);

+extern int sc_rtc_timer_del(int srcid, int rtc_id);

+

+

+

+/*****************************************

+* @brief:sc_rtc_timer_add_cb

+* @param count [IN]:src_id, rtc_id,

+* @param sum [OUT]:NA

+* @return :0

+* @todo:

+* @see:NA

+* @warning:

+******************************************/

+int sc_rtc_timer_add_cb(unsigned int src_id, int rtc_id)

+{

+    return 0;

+}

+

+

+/*****************************************

+* @brief:Set wakealarm time

+* @param count [IN]:buffer,

+* @param sum [OUT]:NA

+* @return :success 0, failed -1

+* @todo:

+* @see:NA

+* @warning:

+******************************************/

+ssize_t wakealarm(char *buffer)

+{

+    unsigned long  time_sec = 0;

+    int ret = 0;

+    

+    LYLOGSET(LOG_INFO);

+    LYLOGEINIT(USER_LOG_TAG);

+    

+    if(buffer == NULL)

+    {

+        LYINFLOG("Bad input parameter,exit!!!!");

+        return -1;

+    }

+

+    time_sec = atol(buffer);

+    

+    LYINFLOG("Set  wakealarm   %ld seconds ",time_sec);

+    wk_srcid = sc_rtc_timer_init();

+    if (wk_srcid <= 0)

+    {

+        LYINFLOG("rtc_timer_init fail!");

+        return -1;

+    }

+    ret = sc_rtc_timer_add(wk_srcid, wk_rtc_id, time_sec, sc_rtc_timer_add_cb);

+    if(ret < 0)

+    {

+        LYINFLOG("Add  rtc timer failed!!!!");

+        return -1;

+    }

+    

+    LYINFLOG("Set wakealarm success !!!");

+

+    ret = sc_rtc_timer_uninit();

+    if(ret != 0)

+    {

+        LYINFLOG("Deinit failed");

+    }

+    

+    return 0;

+

+}

+

+

+/*****************************************

+* @brief:set poweralarm time 

+* @param count [IN]:buffer,

+* @param sum [OUT]:NA

+* @return :success 0, failed -1

+* @todo:

+* @see:NA

+* @warning:

+******************************************/

+ssize_t poweralarm(char *buffer)

+{

+    int srcid = 0;

+    unsigned long  time_sec = 0;

+    int ret = 0;

+    

+    LYLOGSET(LOG_INFO);

+    LYLOGEINIT(USER_LOG_TAG);

+    

+    if(buffer == NULL)

+    {

+        LYINFLOG("Bad input parameter,exit!!!!");

+        return -1;

+    }

+

+    time_sec = atol(buffer);

+    

+    LYINFLOG("Set poweralarm %ld seconds",time_sec);

+    srcid = sc_rtc_timer_init();

+    if (srcid <= 0)

+    {

+        LYINFLOG("rtc_timer_init fail!");

+        return -1;

+    }

+    ret = sc_rtc_timer_add(srcid, pw_rtc_id, time_sec, sc_rtc_timer_add_cb);

+    if(ret < 0)

+    {

+        LYINFLOG("Add  rtc timer failed!!!!");

+        return -1;

+    }

+    

+    LYINFLOG("Set poweralarm success !!!");

+

+    ret = sc_rtc_timer_uninit();

+    if(ret != 0)

+    {

+        LYINFLOG("Deinit failed");

+    }

+    

+    return 0;

+

+}

+

+/**********************************************

+* @brief:cancel_wakealarm,

+* @param count [IN]:void

+* @param sum [OUT]:NA

+* @return :success 0, failed -1

+* @todo:

+* @see:NA

+* @warning:

+********************************************/

+ssize_t cancel_wakealarm(void)

+{

+    int ret = 0;

+

+    LYINFLOG("Enter cancel_wakealarm ");

+    ret = sc_rtc_timer_del(wk_srcid, wk_rtc_id);

+    if(ret < 0)

+    {

+        LYINFLOG("Del wakealarm failed!!!");

+        return -1;

+    }

+

+    return 0;

+    

+}

+

+

+/*****************************************

+* @brief:lynq_set_poweralarm

+* @param count [IN]:unsigned long time_sec

+* @param sum [OUT]:NA

+* @return :success 0, failed -1

+* @todo:

+* @see:NA

+* @warning:

+******************************************/

+int  lynq_set_poweralarm(unsigned long time_sec)

+{

+

+    int ret = 0;

+    int srcid = 0;

+    LYINFLOG("lynq_set_poweralarm %ld seconds",time_sec);

+    srcid = sc_rtc_timer_init();

+    if (srcid <= 0)

+    {

+        LYINFLOG("rtc_timer_init fail!");

+        return -1;

+    }

+    ret = sc_rtc_timer_add(srcid, pw_rtc_id, time_sec, sc_rtc_timer_add_cb);

+    if(ret < 0)

+    {

+        LYINFLOG("Add  rtc timer failed!!!!");

+        return -1;

+    }

+    

+    LYINFLOG("Set poweralarm success !!!");

+

+    ret = sc_rtc_timer_uninit();

+    if(ret != 0)

+    {

+        LYINFLOG("Deinit failed");

+    }

+    

+    return 0;

+

+}

+

+

+/*****************************************

+* @brief:lynq_set_wakealarm

+* @param count [IN]:unsigned long  time_sec

+* @param sum [OUT]:NA

+* @return :success 0, failed -1

+* @todo:

+* @see:NA

+* @warning:

+******************************************/

+int lynq_set_wakealarm(unsigned long  time_sec)

+{

+    int ret = 0;

+    LYINFLOG("lynq_set_wakealarm   %ld seconds ",time_sec);

+    wk_srcid = sc_rtc_timer_init();

+    if (wk_srcid <= 0)

+    {

+        LYINFLOG("rtc_timer_init fail!");

+        return -1;

+    }

+    ret = sc_rtc_timer_add(wk_srcid, wk_rtc_id, time_sec, sc_rtc_timer_add_cb);

+    if(ret < 0)

+    {

+        LYINFLOG("Add  rtc timer failed!!!!");

+        return -1;

+    }

+    

+    LYINFLOG("Set wakealarm success !!!");

+

+    ret = sc_rtc_timer_uninit();

+    if(ret != 0)

+    {

+        LYINFLOG("Deinit failed!!!");

+    }

+    

+    return 0;

+

+}

+

+

+#ifdef __cplusplus

+}

+#endif

+

diff --git a/cap/zx297520v3/src/lynq/lib/libpoweralarm/makefile b/cap/zx297520v3/src/lynq/lib/libpoweralarm/makefile
new file mode 100755
index 0000000..fc6916f
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/libpoweralarm/makefile
@@ -0,0 +1,75 @@
+SHELL = /bin/sh

+RM = rm -f

+

+LOCAL_CFLAGS := -Wall \

+                -std=gnu++14 \

+                -g -Os \

+                -flto \

+                -fPIC \

+                -fpermissive \

+    

+                

+ 

+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

+

+

+$(warning ################# rock ROOT: $(ROOT),includedir:$(includedir),)

+

+LOCAL_PATH   = .

+

+LOCAL_C_INCLUDES = \

+  -I. \

+  -I$(LOCAL_PATH)/include \

+  -I$(ROOT)$(includedir)/logger \

+  -I$(ROOT)$(includedir)/liblog \

+  -I$(ROOT)$(includedir)/glib-2.0 \

+  -I$(ROOT)$(libdir)/glib-2.0/include \

+  -I$(ROOT)$(includedir)  \

+

+

+

+LOCAL_LIBS := \

+    -L. \

+    -ldl \

+    -lstdc++ \

+    -llynq-log \

+	-lsctel \

+

+

+SOURCES = $(wildcard *.cpp)

+

+EXECUTABLE = libpoweralarm.so

+

+OBJECTS=$(SOURCES:.cpp=.o)

+

+

+.PHONY: build clean install pack_rootfs 

+

+all: build

+$(EXECUTABLE): $(OBJECTS)

+	$(CXX) -shared -Wl,--no-undefined $(OBJECTS) $(LOCAL_LIBS) $(LOCAL_CFLAGS) $(LOCAL_C_INCLUDES) -o $@

+

+%.o : %.cpp

+	$(CXX) $(LOCAL_C_INCLUDES) $(LOCAL_CFLAGS) $(LOCAL_LIBS) -o $@ -c $< 

+

+build:  $(EXECUTABLE)

+	$(warning ########## build $(EXECUTABLE)  ##########)

+

+install:

+	mkdir -p $(ROOT)$(base_libdir)/

+	install $(EXECUTABLE) $(ROOT)$(base_libdir)/

+	mkdir -p $(ROOT)$(includedir)/$(NAME)/sdk

+

+pack_rootfs:

+	mkdir -p $(PACK_INITRAMFS_TO)$(base_libdir)/

+	cp -af $(EXECUTABLE) $(PACK_INITRAMFS_TO)$(base_libdir)/

+	$(CROSS)strip $(PACK_INITRAMFS_TO)$(base_libdir)/$(EXECUTABLE)

+	mkdir -p $(PACK_TO)$(base_libdir)/

+	cp -af $(EXECUTABLE) $(PACK_TO)$(base_libdir)/

+	$(CROSS)strip $(PACK_TO)$(base_libdir)/$(EXECUTABLE)

+.PHONY: clean

+clean:

+	$(RM) $(OBJECTS) $(EXECUTABLE)

+