From: Mark Salyzyn Date: Tue, 24 May 2016 19:38:40 +0000 (-0700) Subject: resolve merge conflicts of 1750081 to nyc-dev-plus-aosp X-Git-Tag: android-x86-8.1-r1~377^2~223^2~167 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=261a733906981fc2390f0803effdc55c51842a5c;p=android-x86%2Fframeworks-native.git resolve merge conflicts of 1750081 to nyc-dev-plus-aosp Change-Id: If25f336cfc2fa02cba863987da6f55647636417e --- 261a733906981fc2390f0803effdc55c51842a5c diff --cc cmds/dumpstate/Android.mk index c798dde86f,45604159b2..2dc8787591 --- a/cmds/dumpstate/Android.mk +++ b/cmds/dumpstate/Android.mk @@@ -14,9 -14,7 +14,9 @@@ LOCAL_SRC_FILES := dumpstate.cpp utils. LOCAL_MODULE := dumpstate - LOCAL_SHARED_LIBRARIES := libcutils liblog libselinux + LOCAL_SHARED_LIBRARIES := libcutils liblog libselinux libbase +# ZipArchive support, the order matters here to get all symbols. - LOCAL_STATIC_LIBRARIES := libziparchive libz libbase libcrypto_static ++LOCAL_STATIC_LIBRARIES := libziparchive libz libcrypto_static LOCAL_HAL_STATIC_LIBRARIES := libdumpstate LOCAL_CFLAGS += -Wall -Werror -Wno-unused-parameter LOCAL_INIT_RC := dumpstate.rc diff --cc cmds/dumpstate/utils.cpp index 2b4091a8e1,f5183d1b20..b33d7ab55b --- a/cmds/dumpstate/utils.cpp +++ b/cmds/dumpstate/utils.cpp @@@ -33,12 -31,10 +33,14 @@@ #include #include #include +#include #include +#define LOG_TAG "dumpstate" ++ + #include #include +#include #include #include #include @@@ -1172,105 -923,18 +1174,91 @@@ void dump_route_tables() fclose(fp); } +/* overall progress */ +int progress = 0; +int do_update_progress = 0; // Set by dumpstate.cpp +int weight_total = WEIGHT_TOTAL; + +// TODO: make this function thread safe if sections are generated in parallel. +void update_progress(int delta) { + if (!do_update_progress) return; + + progress += delta; + + char key[PROPERTY_KEY_MAX]; + char value[PROPERTY_VALUE_MAX]; + + // adjusts max on the fly + if (progress > weight_total) { + int new_total = weight_total * 1.2; + MYLOGD("Adjusting total weight from %d to %d\n", weight_total, new_total); + weight_total = new_total; + snprintf(key, sizeof(key), "dumpstate.%d.max", getpid()); + snprintf(value, sizeof(value), "%d", weight_total); + int status = property_set(key, value); + if (status) { + MYLOGE("Could not update max weight by setting system property %s to %s: %d\n", + key, value, status); + } + } + + snprintf(key, sizeof(key), "dumpstate.%d.progress", getpid()); + snprintf(value, sizeof(value), "%d", progress); + + if (progress % 100 == 0) { + // We don't want to spam logcat, so only log multiples of 100. + MYLOGD("Setting progress (%s): %s/%d\n", key, value, weight_total); + } else { + // stderr is ignored on normal invocations, but useful when calling /system/bin/dumpstate + // directly for debuggging. + fprintf(stderr, "Setting progress (%s): %s/%d\n", key, value, weight_total); + } + + int status = property_set(key, value); + if (status) { + MYLOGE("Could not update progress by setting system property %s to %s: %d\n", + key, value, status); + } +} + +void take_screenshot(const std::string& path) { + const char *args[] = { "/system/bin/screencap", "-p", path.c_str(), NULL }; + run_command_always(NULL, DONT_DROP_ROOT, REDIRECT_TO_STDERR, 10, args); +} + +void vibrate(FILE* vibrator, int ms) { + fprintf(vibrator, "%d\n", ms); + fflush(vibrator); +} + +bool is_dir(const char* pathname) { + struct stat info; + if (stat(pathname, &info) == -1) { + return false; + } + return S_ISDIR(info.st_mode); +} + +time_t get_mtime(int fd, time_t default_mtime) { + struct stat info; + if (fstat(fd, &info) == -1) { + return default_mtime; + } + return info.st_mtime; +} + void dump_emmc_ecsd(const char *ext_csd_path) { - static const size_t EXT_CSD_REV = 192; - static const size_t EXT_PRE_EOL_INFO = 267; - static const size_t EXT_DEVICE_LIFE_TIME_EST_TYP_A = 268; - static const size_t EXT_DEVICE_LIFE_TIME_EST_TYP_B = 269; + // List of interesting offsets struct hex { char str[2]; - } buffer[512]; - int fd, ext_csd_rev, ext_pre_eol_info; - ssize_t bytes_read; - static const char *ver_str[] = { - "4.0", "4.1", "4.2", "4.3", "Obsolete", "4.41", "4.5", "5.0" - }; - static const char *eol_str[] = { - "Undefined", - "Normal", - "Warning (consumed 80% of reserve)", - "Urgent (consumed 90% of reserve)" }; + static const size_t EXT_CSD_REV = 192 * sizeof(hex); + static const size_t EXT_PRE_EOL_INFO = 267 * sizeof(hex); + static const size_t EXT_DEVICE_LIFE_TIME_EST_TYP_A = 268 * sizeof(hex); + static const size_t EXT_DEVICE_LIFE_TIME_EST_TYP_B = 269 * sizeof(hex); - printf("------ %s Extended CSD ------\n", ext_csd_path); - - fd = TEMP_FAILURE_RETRY(open(ext_csd_path, - O_RDONLY | O_NONBLOCK | O_CLOEXEC)); - if (fd < 0) { - printf("*** %s: %s\n\n", ext_csd_path, strerror(errno)); + std::string buffer; + if (!android::base::ReadFileToString(ext_csd_path, &buffer)) { return; }