am b419c35c: Fix adb, fastboot to compile in Windows SDK under Linux.

Merge commit 'b419c35c660d7421e18a9efef38eca11966b44c7' into froyo-plus-aosp

* commit 'b419c35c660d7421e18a9efef38eca11966b44c7':
  Fix adb, fastboot to compile in Windows SDK under Linux.
diff --git a/adb/adb.c b/adb/adb.c
index a34dd71..6930696 100644
--- a/adb/adb.c
+++ b/adb/adb.c
@@ -920,10 +920,13 @@
     }
 
         /* for the device, start the usb transport if the
-        ** android usb device exists and "service.adb.tcp"
-        ** is not set, otherwise start the network transport.
+        ** android usb device exists and the "service.adb.tcp.port" and
+        ** "persist.adb.tcp.port" properties are not set.
+        ** Otherwise start the network transport.
         */
-    property_get("service.adb.tcp.port", value, "0");
+    property_get("service.adb.tcp.port", value, "");
+    if (!value[0])
+        property_get("persist.adb.tcp.port", value, "");
     if (sscanf(value, "%d", &port) == 1 && port > 0) {
         // listen on TCP port specified by service.adb.tcp.port property
         local_init(port);
diff --git a/adb/commandline.c b/adb/commandline.c
index 857cee3..5f42203 100644
--- a/adb/commandline.c
+++ b/adb/commandline.c
@@ -112,6 +112,7 @@
         "  adb push <local> <remote>    - copy file/dir to device\n"
         "  adb pull <remote> [<local>]  - copy file/dir from device\n"
         "  adb sync [ <directory> ]     - copy host->device only if changed\n"
+        "                                 (-l means list but don't copy)\n"
         "                                 (see 'adb help all')\n"
         "  adb shell                    - run remote shell interactively\n"
         "  adb shell <command>          - run remote shell command\n"
@@ -1042,10 +1043,19 @@
 
     if(!strcmp(argv[0], "sync")) {
         char *srcarg, *android_srcpath, *data_srcpath;
+        int listonly = 0;
+
         int ret;
         if(argc < 2) {
             /* No local path was specified. */
             srcarg = NULL;
+        } else if (argc >= 2 && strcmp(argv[1], "-l") == 0) {
+            listonly = 1;
+            if (argc == 3) {
+                srcarg = argv[2];
+            } else {
+                srcarg = NULL;
+            }
         } else if(argc == 2) {
             /* A local path or "android"/"data" arg was specified. */
             srcarg = argv[1];
@@ -1056,9 +1066,9 @@
         if(ret != 0) return usage();
 
         if(android_srcpath != NULL)
-            ret = do_sync_sync(android_srcpath, "/system");
+            ret = do_sync_sync(android_srcpath, "/system", listonly);
         if(ret == 0 && data_srcpath != NULL)
-            ret = do_sync_sync(data_srcpath, "/data");
+            ret = do_sync_sync(data_srcpath, "/data", listonly);
 
         free(android_srcpath);
         free(data_srcpath);
diff --git a/adb/file_sync_client.c b/adb/file_sync_client.c
index 0ebfe73..da25ae8 100644
--- a/adb/file_sync_client.c
+++ b/adb/file_sync_client.c
@@ -670,7 +670,7 @@
 }
 
 
-static int copy_local_dir_remote(int fd, const char *lpath, const char *rpath, int checktimestamps)
+static int copy_local_dir_remote(int fd, const char *lpath, const char *rpath, int checktimestamps, int listonly)
 {
     copyinfo *filelist = 0;
     copyinfo *ci, *next;
@@ -718,8 +718,9 @@
     for(ci = filelist; ci != 0; ci = next) {
         next = ci->next;
         if(ci->flag == 0) {
-            fprintf(stderr,"push: %s -> %s\n", ci->src, ci->dst);
-            if(sync_send(fd, ci->src, ci->dst, ci->time, ci->mode, 0 /* no verify APK */)){
+            fprintf(stderr,"%spush: %s -> %s\n", listonly ? "would " : "", ci->src, ci->dst);
+            if(!listonly &&
+               sync_send(fd, ci->src, ci->dst, ci->time, ci->mode, 0 /* no verify APK */)){
                 return 1;
             }
             pushed++;
@@ -757,7 +758,7 @@
 
     if(S_ISDIR(st.st_mode)) {
         BEGIN();
-        if(copy_local_dir_remote(fd, lpath, rpath, 0)) {
+        if(copy_local_dir_remote(fd, lpath, rpath, 0, 0)) {
             return 1;
         } else {
             END();
@@ -959,7 +960,7 @@
         return 1;
     }
 
-    if(S_ISREG(mode) || S_ISCHR(mode) || S_ISBLK(mode)) {
+    if(S_ISREG(mode) || S_ISLNK(mode) || S_ISCHR(mode) || S_ISBLK(mode)) {
         if(stat(lpath, &st) == 0) {
             if(S_ISDIR(st.st_mode)) {
                     /* if we're copying a remote file to a local directory,
@@ -1001,7 +1002,7 @@
     }
 }
 
-int do_sync_sync(const char *lpath, const char *rpath)
+int do_sync_sync(const char *lpath, const char *rpath, int listonly)
 {
     fprintf(stderr,"syncing %s...\n",rpath);
 
@@ -1012,7 +1013,7 @@
     }
 
     BEGIN();
-    if(copy_local_dir_remote(fd, lpath, rpath, 1)){
+    if(copy_local_dir_remote(fd, lpath, rpath, 1, listonly)){
         return 1;
     } else {
         END();
diff --git a/adb/file_sync_service.h b/adb/file_sync_service.h
index 4ee40ba..11ea06b 100644
--- a/adb/file_sync_service.h
+++ b/adb/file_sync_service.h
@@ -79,7 +79,7 @@
 void file_sync_service(int fd, void *cookie);
 int do_sync_ls(const char *path);
 int do_sync_push(const char *lpath, const char *rpath, int verifyApk);
-int do_sync_sync(const char *lpath, const char *rpath);
+int do_sync_sync(const char *lpath, const char *rpath, int listonly);
 int do_sync_pull(const char *rpath, const char *lpath);
 
 #define SYNC_DATA_MAX (64*1024)
diff --git a/toolbox/Android.mk b/toolbox/Android.mk
index a6114ac..05b2a34 100644
--- a/toolbox/Android.mk
+++ b/toolbox/Android.mk
@@ -50,6 +50,7 @@
 	top \
 	iftop \
 	id \
+	uptime \
 	vmstat \
 	nandread \
         ionice
diff --git a/toolbox/uptime.c b/toolbox/uptime.c
new file mode 100644
index 0000000..8b1983d
--- /dev/null
+++ b/toolbox/uptime.c
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * 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.
+ */
+
+#include <sys/time.h>
+#include <linux/ioctl.h>
+#include <linux/rtc.h>
+#include <linux/android_alarm.h>
+#include <fcntl.h>
+#include <stdio.h>
+
+
+static void format_time(int time, char* buffer) {
+    int seconds, minutes, hours, days;
+
+    seconds = time % 60;
+    time /= 60;
+    minutes = time % 60;
+    time /= 60;
+    hours = time % 24;
+    days = time / 24;
+
+    if (days > 0)
+        sprintf(buffer, "%d days, %02d:%02d:%02d", days, hours, minutes, seconds);
+    else
+        sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
+}
+
+int64_t elapsedRealtime()
+{
+    struct timespec ts;
+    int fd, result;
+
+    fd = open("/dev/alarm", O_RDONLY);
+    if (fd < 0)
+        return fd;
+
+   result = ioctl(fd, ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), &ts);
+   close(fd);
+
+    if (result == 0)
+        return ts.tv_sec;
+    return -1;
+}
+
+int uptime_main(int argc, char *argv[])
+{
+    float up_time, idle_time;
+    char up_string[100], idle_string[100], sleep_string[100];
+    int elapsed;
+
+    FILE* file = fopen("/proc/uptime", "r");
+    if (!file) {
+        fprintf(stderr, "Could not open /proc/uptime\n");
+        return -1;
+    }
+    if (fscanf(file, "%f %f", &up_time, &idle_time) != 2) {
+        fprintf(stderr, "Could not parse /proc/uptime\n");
+        fclose(file);
+        return -1;
+    }
+    fclose(file);
+
+    elapsed = elapsedRealtime();
+    if (elapsed < 0) {
+        fprintf(stderr, "elapsedRealtime failed\n");
+        return -1;
+    }
+
+    format_time(elapsed, up_string);
+    format_time((int)idle_time, idle_string);
+    format_time((int)(elapsed - up_time), sleep_string);
+    printf("up time: %s, idle time: %s, sleep time: %s\n", up_string, idle_string, sleep_string);
+
+    return 0;
+}