Baseline update from LYNQ_SDK_ASR_T108_V05.03.01.00(kernel build error.)
Change-Id: I56fc72cd096e82c589920026553170e5cb9692eb
diff --git a/package/utils/adbd/src/adb/services.c b/package/utils/adbd/src/adb/services.c
old mode 100644
new mode 100755
index 0dbe4db..b57e891
--- a/package/utils/adbd/src/adb/services.c
+++ b/package/utils/adbd/src/adb/services.c
@@ -21,6 +21,12 @@
#include <string.h>
#include <errno.h>
+#ifdef MBTK_ADB_SEC_SUPPORT
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#endif
+
#include "sysdeps.h"
#define TRACE_TAG TRACE_SERVICES
@@ -300,15 +306,70 @@
}
#endif /* !ABD_HOST */
-//#define ADB_PASSWD
#if ADB_HOST
#define SHELL_COMMAND "/bin/sh"
#else
-#ifdef ADB_PASSWD
-#define SHELL_COMMAND "/bin/login"
+
+#ifdef MBTK_ADB_SEC_SUPPORT
+#define SHELL_COMMAND "/bin/adb_shell"
#else
#define SHELL_COMMAND "/bin/sh"
-#endif //ADB_PASSWD
+#endif
+
+#endif
+
+#ifdef MBTK_ADB_SEC_SUPPORT
+#define MBTK_LOGIN_STATE_FILE "/tmp/mbtk_login_count"
+
+static int login_conf_read(const char *path, long *value)
+{
+ char buff[64];
+ int fd = adb_open(path, O_RDONLY);
+ if(fd <= 0)
+ return -1;
+ memset(buff, 0, sizeof(buff));
+ if(adb_read(fd, buff, sizeof(buff)) > 0) {
+ *value = atol(buff);
+ }
+ adb_close(fd);
+ return 0;
+}
+
+static int login_conf_write(const char *path, long value)
+{
+ char buff[64];
+ int fd = adb_open(path, O_WRONLY);
+ if(fd <= 0)
+ return -1;
+ memset(buff, 0, sizeof(buff));
+ snprintf(buff, sizeof(buff), "%ld\n", value);
+ if(adb_write(fd, buff, strlen(buff)) > 0) {
+ adb_close(fd);
+ return 0;
+ }
+ adb_close(fd);
+ return -1;
+}
+
+static int login_count_change(int add)
+{
+ long count = 0L;
+ if(login_conf_read(MBTK_LOGIN_STATE_FILE, &count)) {
+ count = 0L;
+ }
+ // printf("old count is %d\n", count);
+ if(add) {
+ count++;
+ } else {
+ count--;
+ }
+
+ if(count < 0) {
+ count = 0L;
+ }
+ return login_conf_write(MBTK_LOGIN_STATE_FILE, count);
+}
+
#endif
#if !ADB_HOST
@@ -334,6 +395,10 @@
}
}
}
+
+#ifdef MBTK_ADB_SEC_SUPPORT
+ login_count_change(0);
+#endif
D("shell exited fd=%d of pid=%d err=%d\n", fd, pid, errno);
if (SHELL_EXIT_NOTIFY_FD >=0) {
int res;
@@ -352,11 +417,7 @@
const char *arg0, *arg1;
if (name == 0 || *name == 0) {
-#ifdef ADB_PASSWD
- arg0 = "-p"; arg1 = 0;
-#else
arg0 = "-"; arg1 = 0;
-#endif //ADB_PASSWD
} else {
arg0 = "-c"; arg1 = name;
}
@@ -436,7 +497,14 @@
} else if(!HOST && !strncmp(name, "exec:", 5)) {
ret = create_subproc_thread(name + 5, SUBPROC_RAW);
} else if(!strncmp(name, "sync:", 5)) {
- ret = create_service_thread(file_sync_service, NULL);
+#ifdef MBTK_ADB_SEC_SUPPORT
+ long login_success = 0L;
+ if(login_conf_read(MBTK_LOGIN_STATE_FILE, &login_success) == 0 && login_success > 0) {
+ ret = create_service_thread(file_sync_service, NULL);
+ }
+#else
+ ret = create_service_thread(file_sync_service, NULL);
+#endif
} else if(!strncmp(name, "remount:", 8)) {
ret = create_service_thread(remount_service, NULL);
} else if(!strncmp(name, "reboot:", 7)) {