audio: property_get is not workable on Yocto 4.0 [1/2]

PD#TV-149881

Problem:
property_get is not workable on Yocto 4.0.

Solution:
change property_get to aml_audio_property_get_str

Verify:
yocto-t5w

Change-Id: Ie0c16efd3ab0f217f89e06d2056d7d6b44f2e031
Signed-off-by: yayun.shi <yayun.shi@amlogic.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c1943f4..16b0533 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -207,7 +207,6 @@
 	utils/aml_hw_mixer.c
 	utils/alsa_device_parser.c
 	utils/aml_alsa_mixer.c
-	utils/aml_android_utils.c
 	utils/aml_buffer_provider.c
 	utils/aml_data_utils.c
 	utils/aml_dump_debug.c
diff --git a/audio_hal/aml_audio_nonms12_render.c b/audio_hal/aml_audio_nonms12_render.c
index 1beae5d..bd5e449 100644
--- a/audio_hal/aml_audio_nonms12_render.c
+++ b/audio_hal/aml_audio_nonms12_render.c
@@ -33,7 +33,6 @@
 #include "alsa_config_parameters.h"
 #include "dolby_lib_api.h"
 #include "audio_mediasync.h"
-#include "aml_android_utils.h"
 #include "amlAudioMixer.h"
 #include "hal_clipmeta.h"
 #include "dtv_private_object.h"
diff --git a/audio_hal/aml_audio_scaletempo.c b/audio_hal/aml_audio_scaletempo.c
index a5d4654..edd8972 100644
--- a/audio_hal/aml_audio_scaletempo.c
+++ b/audio_hal/aml_audio_scaletempo.c
@@ -35,7 +35,6 @@
 
 #include "aml_audio_scaletempo.h"
 #include "audio_hw_utils.h"
-#include "aml_android_utils.h"
 #include "aml_dump_debug.h"
 
 #ifndef min
diff --git a/audio_hal/aml_audio_stream.c b/audio_hal/aml_audio_stream.c
index d6311e0..7c4036c 100644
--- a/audio_hal/aml_audio_stream.c
+++ b/audio_hal/aml_audio_stream.c
@@ -32,7 +32,6 @@
 #include "alsa_manager.h"
 #include "alsa_device_parser.h"
 #include "tv_patch_avsync.h"
-#include "aml_android_utils.h"
 #include "tv_patch_format_parser.h"
 #include "alsa_config_parameters.h"
 #include "channels.h"
diff --git a/audio_hal/aml_mmap_audio.c b/audio_hal/aml_mmap_audio.c
index 0203e6d..bd8fccd 100644
--- a/audio_hal/aml_mmap_audio.c
+++ b/audio_hal/aml_mmap_audio.c
@@ -28,7 +28,6 @@
 #include "audio_hw_utils.h"
 #include "audio_virtual_buf.h"
 
-#include "aml_android_utils.h"
 #include "aml_audio_timer.h"
 #include "aml_mmap_audio.h"
 #include "aml_volume_utils.h"
diff --git a/audio_hal/audio_hw.c b/audio_hal/audio_hw.c
index bf36c4b..bce1c60 100644
--- a/audio_hal/audio_hw.c
+++ b/audio_hal/audio_hw.c
@@ -55,7 +55,6 @@
 #include <tinyalsa/asoundlib.h>
 #include <audio_route/audio_route.h>
 #include <spdifenc_wrap.h>
-#include <aml_android_utils.h>
 #include <aml_alsa_mixer.h>
 #ifndef NO_AUDIO_CAP
 #include <IpcBuffer/IpcBuffer_c.h>
diff --git a/audio_hal/audio_hw_ms12_common.c b/audio_hal/audio_hw_ms12_common.c
index 4864ee5..448af0a 100644
--- a/audio_hal/audio_hw_ms12_common.c
+++ b/audio_hal/audio_hw_ms12_common.c
@@ -22,7 +22,6 @@
 #include <dolby_ms12.h>
 #include <dolby_ms12_config_params.h>
 #include <dolby_ms12_status.h>
-#include <aml_android_utils.h>
 #include <sys/prctl.h>
 #include <cutils/properties.h>
 #include <inttypes.h>
diff --git a/audio_hal/audio_hw_ms12_v2.c b/audio_hal/audio_hw_ms12_v2.c
index da63732..87d8061 100644
--- a/audio_hal/audio_hw_ms12_v2.c
+++ b/audio_hal/audio_hw_ms12_v2.c
@@ -22,7 +22,6 @@
 #include <dolby_ms12.h>
 #include <dolby_ms12_config_params.h>
 #include <dolby_ms12_status.h>
-#include <aml_android_utils.h>
 #include <sys/prctl.h>
 #include <cutils/properties.h>
 #include <inttypes.h>
diff --git a/audio_hal/audio_hw_utils.c b/audio_hal/audio_hw_utils.c
index 07bf7f5..500db3c 100644
--- a/audio_hal/audio_hw_utils.c
+++ b/audio_hal/audio_hw_utils.c
@@ -431,6 +431,24 @@
     return 0;
 }
 
+unsigned long get_sysfs_ulong(const char *path)
+{
+    int fd;
+    ssize_t ret;
+    char bcmd[24] = "";
+    unsigned long num = 0;
+    if ((fd = open(path, O_RDONLY)) >= 0) {
+        ret = read(fd, bcmd, sizeof(bcmd));
+        if (ret < 0) {
+            ALOGE("%s:read file error.", __func__);
+        }
+        num = strtoul(bcmd, NULL, 0);
+        close(fd);
+    } else {
+        ALOGE("unable to open file %s,err: %s\n", path, strerror(errno));
+    }
+    return num;
+}
 
 int get_sysfs_int(const char *path)
 {
diff --git a/audio_hal/audio_hw_utils.h b/audio_hal/audio_hw_utils.h
index a4d43fb..44551b8 100644
--- a/audio_hal/audio_hw_utils.h
+++ b/audio_hal/audio_hw_utils.h
@@ -90,6 +90,7 @@
 int64_t aml_gettime(void);
 int get_sysfs_uint(const char *path, uint32_t *value);
 int sysfs_set_sysfs_str(const char *path, const char *val);
+unsigned long get_sysfs_ulong(const char *path);
 int set_sysfs_int(const char *path, int value);
 int get_sysfs_int(const char *path);
 int mystrstr(char *mystr, char *substr) ;
diff --git a/audio_hal/audio_hwsync.c b/audio_hal/audio_hwsync.c
index aa0c7d6..e528709 100644
--- a/audio_hal/audio_hwsync.c
+++ b/audio_hal/audio_hwsync.c
@@ -40,7 +40,6 @@
 #include "aml_audio_timer.h"
 #include "audio_hw_ms12_v2.h"
 #include "aml_dump_debug.h"
-#include "aml_android_utils.h"
 
 #define MSYNC_CALLBACK_WAIT_TIMEOUT_US (4000*1000)
 
diff --git a/audio_hal/audio_port.c b/audio_hal/audio_port.c
index 3277929..c5549e7 100644
--- a/audio_hal/audio_port.c
+++ b/audio_hal/audio_port.c
@@ -25,7 +25,6 @@
 #include <tinyalsa/asoundlib.h>
 #include <string.h>
 #include <alsa_device_parser.h>
-#include <aml_android_utils.h>
 #include <IpcBuffer/IpcBuffer_c.h>
 
 #include "audio_port.h"
diff --git a/audio_hal/hal_clipmeta.c b/audio_hal/hal_clipmeta.c
index a997e91..ae26831 100644
--- a/audio_hal/hal_clipmeta.c
+++ b/audio_hal/hal_clipmeta.c
@@ -23,7 +23,6 @@
 
 #include "hal_clipmeta.h"
 #include "audio_hw_utils.h"
-#include "aml_android_utils.h"
 #include "audio_hw_ms12_v2.h"
 
 
diff --git a/decoder/libms12_v24/src/DolbyMS12ConfigParams.cpp b/decoder/libms12_v24/src/DolbyMS12ConfigParams.cpp
index c603542..68eb357 100644
--- a/decoder/libms12_v24/src/DolbyMS12ConfigParams.cpp
+++ b/decoder/libms12_v24/src/DolbyMS12ConfigParams.cpp
@@ -35,7 +35,6 @@
 
 #include "DolbyMS12ConfigParams.h"
 #include "aml_malloc_debug.h"
-#include "aml_android_utils.h"
 
 namespace android
 {
diff --git a/dtv_audio_utils/audio_data_read/uio_audio_read.c b/dtv_audio_utils/audio_data_read/uio_audio_read.c
index 1e1a096..25a3627 100644
--- a/dtv_audio_utils/audio_data_read/uio_audio_read.c
+++ b/dtv_audio_utils/audio_data_read/uio_audio_read.c
@@ -24,8 +24,8 @@
 #include <pthread.h>
 #include <cutils/log.h>
 #include <sys/mman.h>
-#include <aml_android_utils.h>
 #include <aml_audio_log.h>
+#include "audio_hw_utils.h"
 //#include <amthreadpool.h>
 
 #define ASTREAM_DEV "/dev/uio0"
@@ -66,7 +66,7 @@
 
 static unsigned long  get_num_infile(char *file)
 {
-    return amsysfs_get_sysfs_ulong(file);
+    return get_sysfs_ulong(file);
 }
 
 int uio_init_new(int  *fd_uio, int debug)
diff --git a/input/dtv_patch_hal_avsync.c b/input/dtv_patch_hal_avsync.c
index 86d5b8d..297ee24 100644
--- a/input/dtv_patch_hal_avsync.c
+++ b/input/dtv_patch_hal_avsync.c
@@ -45,7 +45,6 @@
 #include <system/audio-base.h>
 #endif
 #include <hardware/audio.h>
-#include <aml_android_utils.h>
 #include <aml_data_utils.h>
 #include "aml_audio_stream.h"
 #include "aml_audio_timer.h"
diff --git a/input/dtv_patch_utils.c b/input/dtv_patch_utils.c
index 3e3546b..d02adc0 100644
--- a/input/dtv_patch_utils.c
+++ b/input/dtv_patch_utils.c
@@ -286,7 +286,7 @@
 void dtv_check_audio_reset()
 {
     AM_LOGI("reset dtv audio port");
-    aml_sysfs_set_str(AMSTREAM_AUDIO_PORT_RESET, "1");
+    sysfs_set_sysfs_str(AMSTREAM_AUDIO_PORT_RESET, "1");
 }
 void dtv_es_data_free(struct mAudioEsDataInfo *mEsData)
 {
diff --git a/input/include/dtv_patch_utils.h b/input/include/dtv_patch_utils.h
index 7a6cebf..b29ae5d 100644
--- a/input/include/dtv_patch_utils.h
+++ b/input/include/dtv_patch_utils.h
@@ -21,7 +21,6 @@
 #include "aml_dec_api.h"
 #include "dolby_lib_api.h"
 #include "audio_hw.h"
-#include <aml_android_utils.h>
 
 #define AMSTREAM_AUDIO_PORT_RESET   "/sys/class/amstream/reset_audio_port"
 
diff --git a/input/tv_patch_avsync.c b/input/tv_patch_avsync.c
index d33741c..7a93049 100644
--- a/input/tv_patch_avsync.c
+++ b/input/tv_patch_avsync.c
@@ -21,7 +21,6 @@
 #include <linux/ioctl.h>
 #include <sound/asound.h>
 #include <tinyalsa/asoundlib.h>
-#include <aml_android_utils.h>
 
 #include "audio_hw.h"
 #include "audio_hw_utils.h"
diff --git a/utils/SPDIFEncoderAD.cpp b/utils/SPDIFEncoderAD.cpp
index 91f6f23..d24113e 100644
--- a/utils/SPDIFEncoderAD.cpp
+++ b/utils/SPDIFEncoderAD.cpp
@@ -25,7 +25,6 @@
 #include <cutils/properties.h>
 #include "SPDIFEncoder.h"
 #include "SPDIFEncoderAD.h"
-#include "aml_android_utils.h"
 #include "aml_dump_debug.h"
 
 extern "C"
diff --git a/utils/aml_android_utils.c b/utils/aml_android_utils.c
deleted file mode 100644
index aff2bcc..0000000
--- a/utils/aml_android_utils.c
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * Copyright (C) 2017 Amlogic Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- ** aml_android_utils.c
- **
- ** This program is APIs for get/set android property, get/set sys fs point.
- ** author: shen pengru
- **
- */
-#include <stdlib.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <cutils/log.h>
-#include <fcntl.h>
-#include <cutils/log.h>
-#include <cutils/str_parms.h>
-#include <cutils/properties.h>
-#include <aml_android_utils.h>
-
-#undef  LOG_TAG
-#define LOG_TAG "audio_android_utils"
-
-/*
- * Android Property
- */
-int aml_getprop_bool(const char * path)
-{
-	char buf[PROPERTY_VALUE_MAX];
-	int ret = -1;
-
-	ret = property_get(path, buf, NULL);
-	if (ret > 0) {
-		if (strcasecmp(buf, "true") == 0 || strcmp(buf, "1") == 0)
-			return eAML_BOOL_TRUE;
-	}
-
-	return eAML_BOOL_FALSE;
-}
-
-int aml_getprop_int(const char *path)
-{
-	char buf[PROPERTY_VALUE_MAX];
-	int ret = -1;
-	int value = 0;
-
-	ret = property_get(path, buf, NULL);
-	if (ret > 0) {
-		sscanf(buf, "%d", &value);
-	}
-
-	return value;
-}
-
-int aml_property_set(char *string, char *val, int overwrite)
-{
-	return setenv(string, val, overwrite);
-}
-
-void aml_property_decrease(char *string, char *str2)
-{
-	int printcount = aml_getprop_int(string);
-	if (printcount > 0)
-	{
-		char putstr[50] = {0};
-		memset(putstr, 0, 50);
-		printcount--;
-		sprintf(putstr,"%d", printcount);
-		aml_property_set(str2, putstr, 1);
-		//ALOGI("aml_property_decrease6, %d,!!!\n", printcount);
-	}
-}
-
-/*
-* Linux Sys Fs Set/Get Interface
-*/
-int aml_sysfs_get_int (const char *path)
-{
-	int val = 0;
-	int ret = 0;
-	int fd = open(path, O_RDONLY);
-	if (fd >= 0) {
-		char bcmd[16];
-		ret = read(fd, bcmd, sizeof (bcmd) - 1);
-		if (ret < 0) {
-			ALOGE("%s(), fail to read", __func__);
-		}
-		bcmd[sizeof (bcmd) - 1] = '\0';
-		val = strtol(bcmd, NULL, 10);
-		close(fd);
-	} else {
-		ALOGE("%s: open %s node failed! return 0, err: %s\n", __func__, path, strerror(errno));
-	}
-
-	return val;
-}
-
-int aml_sysfs_get_int16(const char *path,unsigned *value)
-{
-	int fd;
-	char valstr[64];
-	unsigned  val = 0;
-	int ret = 0;
-
-	fd = open(path, O_RDONLY);
-	if (fd >= 0) {
-		memset(valstr, 0, 64);
-		ret = read(fd, valstr, 64 - 1);
-		if (ret < 0) {
-			ALOGE("%s(), fail to read", __func__);
-		}
-		valstr[strlen(valstr)] = '\0';
-		close(fd);
-	} else {
-		ALOGE("%s: unable to open file %s, err: %s\n", __func__, path, strerror(errno));
-		return -1;
-	}
-	if (sscanf(valstr, "0x%x", &val) < 1) {
-		ALOGE("%s: unable to get pts from: %s, err: %s\n", __func__, valstr, strerror(errno));
-		return -1;
-	}
-	*value = val;
-
-	return 0;
-}
-
-unsigned long amsysfs_get_sysfs_ulong(const char *path)
-{
-	int fd;
-	ssize_t ret;
-	char bcmd[24] = "";
-	unsigned long num = 0;
-	if ((fd = open(path, O_RDONLY)) >= 0) {
-		ret = read(fd, bcmd, sizeof(bcmd));
-		if (ret < 0) {
-			ALOGE("%s:read file error.", __func__);
-		}
-		num = strtoul(bcmd, NULL, 0);
-		close(fd);
-	} else {
-		ALOGE("unable to open file %s,err: %s\n", path, strerror(errno));
-	}
-	return num;
-}
-
-int aml_sysfs_get_str(const char *path, char *buf, int count)
-{
-	int fd, len;
-	int i , j;
-
-	if ( NULL == buf ) {
-		ALOGE("buf is NULL");
-		return -1;
-	}
-
-	if ((fd = open(path, O_RDONLY)) < 0) {
-		ALOGE("readSys, open %s error(%s)", path, strerror (errno));
-		return -1;
-	}
-
-	len = read(fd, buf, count);
-	if (len < 0) {
-		ALOGE("read %s error, %s\n", path, strerror(errno));
-		goto exit;
-	}
-
-	for (i = 0, j = 0; i <= len -1; i++) {
-		//change '\0' to 0x20(spacing), otherwise the string buffer will be cut off ,if the last char is '\0' should not replace it
-		if (0x0 == buf[i] && i < len - 1) {
-			buf[i] = 0x20;
-		}
-		/* delete all the character of '\n' */
-		if (0x0a != buf[i]) {
-			buf[j++] = buf[i];
-		}
-	}
-
-	buf[j] = 0x0;
-
-exit:
-	close(fd);
-
-	return len;
-}
-
-int aml_sysfs_set_str(const char *path, const char *val)
-{
-	int fd;
-	int bytes;
-
-	fd = open(path, O_CREAT | O_RDWR | O_TRUNC, 0644);
-	if (fd >= 0) {
-		bytes = write(fd, val, strlen(val));
-		close(fd);
-		return 0;
-	} else {
-		ALOGE("%s: unable to open file %s,err: %s\n", __func__, path, strerror(errno));
-	}
-
-	return -1;
-}
-
-/*
-* Aml private strstr
-*/
-int aml_strstr(char *mystr,char *substr) {
-	int i=0;
-	int j=0;
-	int score = 0;
-	int substrlen = 0;
-	int ok = 0;
-
-	substrlen = strlen(substr);
-	for (i =0;i < 1024 - substrlen;i++) {
-		for (j = 0;j < substrlen;j++) {
-			score += (substr[j] == mystr[i+j])?1:0;
-		}
-		if (score == substrlen) {
-			ok = 1;
-			break;
-		}
-		score = 0;
-	}
-
-	return ok;
-}
diff --git a/utils/aml_configs/aml_conf_parser.c b/utils/aml_configs/aml_conf_parser.c
index 27d28c5..e23b336 100644
--- a/utils/aml_configs/aml_conf_parser.c
+++ b/utils/aml_configs/aml_conf_parser.c
@@ -37,6 +37,7 @@
 #include <cutils/properties.h>
 #include "aml_malloc_debug.h"
 #include "iniparser.h"
+#include "audio_hw_utils.h"
 
 /*************************************************
     Utils
@@ -383,12 +384,8 @@
     int ret = -1;
     char node[PROPERTY_VALUE_MAX];
 
-    ret = property_get("vendor.tv.model_name", node, "");
-    if (ret <= 0) {
-        snprintf(model_name, size, "FHD");
-        ALOGD("%s: Can't get model name! use default model_name (%s)",
-            __FUNCTION__, model_name);
-    } else {
+    char *pro_ret = aml_audio_property_get_str("tv.model_name", node, "FHD");
+    if (pro_ret != NULL) {
         snprintf(model_name, size, "%s", node);
         ALOGD("%s: Model Name (%s)", __FUNCTION__, model_name);
     }
diff --git a/utils/aml_dump_debug.c b/utils/aml_dump_debug.c
index f2a29d4..b5f1516 100644
--- a/utils/aml_dump_debug.c
+++ b/utils/aml_dump_debug.c
@@ -27,7 +27,6 @@
 #include <cutils/properties.h>
 
 #include <aml_dump_debug.h>
-#include <aml_android_utils.h>
 #include "aml_malloc_debug.h"
 #include "audio_hw_utils.h"
 
diff --git a/utils/include/aml_android_utils.h b/utils/include/aml_android_utils.h
deleted file mode 100644
index 16979cf..0000000
--- a/utils/include/aml_android_utils.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2017 Amlogic Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _AML_ANDROID_UTILS_H_
-#define _AML_ANDROID_UTILS_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum AML_BOOLEAN_DEFINE {
-	eAML_BOOL_FALSE = 0,
-	eAML_BOOL_TRUE  = 1,
-} eAmlBoolean;
-
-/*
- * Android Property Interface
- */
-int aml_getprop_bool(const char *path);
-int aml_getprop_int(const char *path);
-int aml_property_set(char *string, char *val, int overwrite);
-void aml_property_decrease(char *string, char *str2);
-
-/*
- * Sys Fs Interface
- */
-int aml_sysfs_get_int(const char *path);
-int aml_sysfs_get_int16(const char *path, unsigned *value);
-int aml_sysfs_get_str(const char *path, char *buf, int count);
-unsigned long amsysfs_get_sysfs_ulong(const char *path);
-int aml_sysfs_set_int(const char *path, int value);
-int aml_sysfs_set_str(const char *path, const char *value);
-
-/*
- * Others
- */
-int aml_strstr(char *mystr,char *substr);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif