From da56ab30720515d524008f01810050f97258ab79 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 23 Mar 2018 11:04:25 -0700 Subject: Remove non-tombstoned ANR path. Bug: http://b/73140330 Test: `adb bugreport` includes /data/anr/anr_* files Change-Id: I3bd7fd932fd24cb798ef1819845d2812e5c577f1 --- cmds/dumpstate/dumpstate.cpp | 99 ++++++-------------------------------------- 1 file changed, 12 insertions(+), 87 deletions(-) (limited to 'cmds/dumpstate/dumpstate.cpp') diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index 9648edefe9..6e0578c5dc 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -918,53 +918,6 @@ static void DumpIpTablesAsRoot() { RunCommand("IP6TABLES RAW", {"ip6tables", "-t", "raw", "-L", "-nvx"}); } -static void AddGlobalAnrTraceFile(const bool add_to_zip, const std::string& anr_traces_file, - const std::string& anr_traces_dir) { - std::string dump_traces_dir; - - if (dump_traces_path != nullptr) { - if (add_to_zip) { - dump_traces_dir = dirname(dump_traces_path); - MYLOGD("Adding ANR traces (directory %s) to the zip file\n", dump_traces_dir.c_str()); - ds.AddDir(dump_traces_dir, true); - } else { - MYLOGD("Dumping current ANR traces (%s) to the main bugreport entry\n", - dump_traces_path); - ds.DumpFile("VM TRACES JUST NOW", dump_traces_path); - } - } - - - // Make sure directory is not added twice. - // TODO: this is an overzealous check because it's relying on dump_traces_path - which is - // generated by dump_traces() - and anr_traces_path - which is retrieved from a system - // property - but in reality they're the same path (although the former could be nullptr). - // Anyways, once dump_traces() is refactored as a private Dumpstate function, this logic should - // be revisited. - bool already_dumped = anr_traces_dir == dump_traces_dir; - - MYLOGD("AddGlobalAnrTraceFile(): dump_traces_dir=%s, anr_traces_dir=%s, already_dumped=%d\n", - dump_traces_dir.c_str(), anr_traces_dir.c_str(), already_dumped); - - android::base::unique_fd fd(TEMP_FAILURE_RETRY( - open(anr_traces_file.c_str(), O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK))); - if (fd.get() < 0) { - printf("*** NO ANR VM TRACES FILE (%s): %s\n\n", anr_traces_file.c_str(), strerror(errno)); - } else { - if (add_to_zip) { - if (!already_dumped) { - MYLOGD("Adding dalvik ANR traces (directory %s) to the zip file\n", - anr_traces_dir.c_str()); - ds.AddDir(anr_traces_dir, true); - } - } else { - MYLOGD("Dumping last ANR traces (%s) to the main bugreport entry\n", - anr_traces_file.c_str()); - dump_file_from_fd("VM TRACES AT LAST ANR", anr_traces_file.c_str(), fd.get()); - } - } -} - static void AddAnrTraceDir(const bool add_to_zip, const std::string& anr_traces_dir) { MYLOGD("AddAnrTraceDir(): dump_traces_file=%s, anr_traces_dir=%s\n", dump_traces_path, anr_traces_dir.c_str()); @@ -1007,50 +960,22 @@ static void AddAnrTraceDir(const bool add_to_zip, const std::string& anr_traces_ static void AddAnrTraceFiles() { const bool add_to_zip = ds.IsZipping() && ds.version_ == VERSION_SPLIT_ANR; - std::string anr_traces_file; - std::string anr_traces_dir; - bool is_global_trace_file = true; - - // First check whether the stack-trace-dir property is set. When it's set, - // each ANR trace will be written to a separate file and not to a global - // stack trace file. - anr_traces_dir = android::base::GetProperty("dalvik.vm.stack-trace-dir", ""); - if (anr_traces_dir.empty()) { - anr_traces_file = android::base::GetProperty("dalvik.vm.stack-trace-file", ""); - if (!anr_traces_file.empty()) { - anr_traces_dir = dirname(anr_traces_file.c_str()); - } - } else { - is_global_trace_file = false; - } - - // We have neither configured a global trace file nor a trace directory, - // there will be nothing to dump. - if (anr_traces_file.empty() && anr_traces_dir.empty()) { - printf("*** NO VM TRACES FILE DEFINED (dalvik.vm.stack-trace-file)\n\n"); - return; - } + std::string anr_traces_dir = "/data/anr"; - if (is_global_trace_file) { - AddGlobalAnrTraceFile(add_to_zip, anr_traces_file, anr_traces_dir); - } else { - AddAnrTraceDir(add_to_zip, anr_traces_dir); - } + AddAnrTraceDir(add_to_zip, anr_traces_dir); - /* slow traces for slow operations */ + // Slow traces for slow operations. struct stat st; - if (!anr_traces_dir.empty()) { - int i = 0; - while (true) { - const std::string slow_trace_path = - anr_traces_dir + android::base::StringPrintf("slow%02d.txt", i); - if (stat(slow_trace_path.c_str(), &st)) { - // No traces file at this index, done with the files. - break; - } - ds.DumpFile("VM TRACES WHEN SLOW", slow_trace_path.c_str()); - i++; + int i = 0; + while (true) { + const std::string slow_trace_path = + anr_traces_dir + android::base::StringPrintf("slow%02d.txt", i); + if (stat(slow_trace_path.c_str(), &st)) { + // No traces file at this index, done with the files. + break; } + ds.DumpFile("VM TRACES WHEN SLOW", slow_trace_path.c_str()); + i++; } } -- cgit v1.2.3-59-g8ed1b From e3694e314e14a696c056ab627c8a3b9066a4e87d Mon Sep 17 00:00:00 2001 From: Vishnu Nair Date: Mon, 2 Jul 2018 14:20:06 -0700 Subject: Bugreport: Fix SystemUI service from being dumped twice 2/2 Bug: 110490179 Fix: 110490179 Test: Manual test dumpsys activity adb shell dumpsys activity service all-platform-non-critical adb shell dumpsys activity service all-platform adb shell dumpsys activity service Take bugreport and check contents Test: mmm -j56 frameworks/native/cmds/dumpstate && \ mmm -j56 frameworks/native/cmds/dumpsys && adb sync data && \ adb shell /data/nativetest64/dumpstate_test/dumpstate_test && \ adb shell /data/nativetest64/dumpsys_test/dumpsys_test && \ adb shell /data/nativetest64/dumpstate_smoke_test/dumpstate_smoke_test && \ printf "\n\n#### ALL TESTS PASSED ####\n" Change-Id: I3736823f72ccb42e0b2603575e827a1647d02ef1 --- cmds/dumpstate/dumpstate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmds/dumpstate/dumpstate.cpp') diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index 7dbc9a4baa..91a56f027f 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -1368,7 +1368,7 @@ static void dumpstate() { printf("== Running Application Services (platform)\n"); printf("========================================================\n"); - RunDumpsys("APP SERVICES PLATFORM", {"activity", "service", "all-platform"}, + RunDumpsys("APP SERVICES PLATFORM", {"activity", "service", "all-platform-non-critical"}, DUMPSYS_COMPONENTS_OPTIONS); printf("========================================================\n"); -- cgit v1.2.3-59-g8ed1b From c67f9a4cf0d7894f7b49f70806ac323630ba178e Mon Sep 17 00:00:00 2001 From: Yi Kong Date: Fri, 20 Jul 2018 13:39:55 -0700 Subject: [cmds] Modernize codebase by replacing NULL with nullptr Fixes -Wzero-as-null-pointer-constant warning. Test: m Bug: 68236239 Change-Id: I73a0a82e3e32001f8ffb0880250c7023dd8290d3 --- cmds/atrace/atrace.cpp | 52 +++++++++++++++++----------------- cmds/cmd/cmd.cpp | 12 ++++---- cmds/dumpstate/DumpstateUtil.cpp | 6 ++-- cmds/dumpstate/dumpstate.cpp | 12 ++++---- cmds/dumpstate/utils.cpp | 12 ++++---- cmds/flatland/GLHelper.cpp | 30 ++++++++++---------- cmds/flatland/Main.cpp | 20 ++++++------- cmds/lshal/ListCommand.cpp | 4 +-- cmds/lshal/PipeRelay.cpp | 2 +- cmds/lshal/Timeout.h | 6 ++-- cmds/rawbu/backup.cpp | 40 +++++++++++++------------- cmds/service/service.cpp | 32 ++++++++++----------- cmds/surfacereplayer/replayer/Main.cpp | 2 +- 13 files changed, 115 insertions(+), 115 deletions(-) (limited to 'cmds/dumpstate/dumpstate.cpp') diff --git a/cmds/atrace/atrace.cpp b/cmds/atrace/atrace.cpp index 668a701eb5..b583442791 100644 --- a/cmds/atrace/atrace.cpp +++ b/cmds/atrace/atrace.cpp @@ -229,8 +229,8 @@ static int g_traceBufferSizeKB = 2048; static bool g_compress = false; static bool g_nohup = false; static int g_initialSleepSecs = 0; -static const char* g_categoriesFile = NULL; -static const char* g_kernelTraceFuncs = NULL; +static const char* g_categoriesFile = nullptr; +static const char* g_kernelTraceFuncs = nullptr; static const char* g_debugAppCmdLine = ""; static const char* g_outputFile = nullptr; @@ -406,7 +406,7 @@ static bool isCategorySupported(const TracingCategory& category) for (int i = 0; i < MAX_SYS_FILES; i++) { const char* path = category.sysfiles[i].path; bool req = category.sysfiles[i].required == REQ; - if (path != NULL) { + if (path != nullptr) { if (req) { if (!fileIsWritable(path)) { return false; @@ -431,7 +431,7 @@ static bool isCategorySupportedForRoot(const TracingCategory& category) for (int i = 0; i < MAX_SYS_FILES; i++) { const char* path = category.sysfiles[i].path; bool req = category.sysfiles[i].required == REQ; - if (path != NULL) { + if (path != nullptr) { if (req) { if (!fileExists(path)) { return false; @@ -547,10 +547,10 @@ static bool pokeBinderServices() Vector services = sm->listServices(); for (size_t i = 0; i < services.size(); i++) { sp obj = sm->checkService(services[i]); - if (obj != NULL) { + if (obj != nullptr) { Parcel data; if (obj->transact(IBinder::SYSPROPS_TRANSACTION, data, - NULL, 0) != OK) { + nullptr, 0) != OK) { if (false) { // XXX: For some reason this fails on tablets trying to // poke the "phone" service. It's not clear whether some @@ -640,9 +640,9 @@ static bool setAppCmdlineProperty(char* cmdline) { int i = 0; char* start = cmdline; - while (start != NULL) { + while (start != nullptr) { char* end = strchr(start, ','); - if (end != NULL) { + if (end != nullptr) { *end = '\0'; end++; } @@ -672,7 +672,7 @@ static bool disableKernelTraceEvents() { const TracingCategory &c = k_categories[i]; for (int j = 0; j < MAX_SYS_FILES; j++) { const char* path = c.sysfiles[j].path; - if (path != NULL && fileIsWritable(path)) { + if (path != nullptr && fileIsWritable(path)) { ok &= setKernelOptionEnable(path, false); } } @@ -708,7 +708,7 @@ static bool verifyKernelTraceFuncs(const char* funcs) ok = false; } } - func = strtok(NULL, ","); + func = strtok(nullptr, ","); } free(myFuncs); return ok; @@ -719,7 +719,7 @@ static bool setKernelTraceFuncs(const char* funcs) { bool ok = true; - if (funcs == NULL || funcs[0] == '\0') { + if (funcs == nullptr || funcs[0] == '\0') { // Disable kernel function tracing. if (fileIsWritable(k_currentTracerPath)) { ok &= writeStr(k_currentTracerPath, "nop"); @@ -741,7 +741,7 @@ static bool setKernelTraceFuncs(const char* funcs) char* func = strtok(myFuncs, ","); while (func) { ok &= appendStr(k_ftraceFilterPath, func); - func = strtok(NULL, ","); + func = strtok(nullptr, ","); } free(myFuncs); @@ -783,7 +783,7 @@ static bool setCategoriesEnableFromFile(const char* categories_file) if (!categories_file) { return true; } - Tokenizer* tokenizer = NULL; + Tokenizer* tokenizer = nullptr; if (Tokenizer::open(String8(categories_file), &tokenizer) != NO_ERROR) { return false; } @@ -885,7 +885,7 @@ static bool setUpKernelTracing() for (int j = 0; j < MAX_SYS_FILES; j++) { const char* path = c.sysfiles[j].path; bool required = c.sysfiles[j].required == REQ; - if (path != NULL) { + if (path != nullptr) { if (fileIsWritable(path)) { ok &= setKernelOptionEnable(path, true); } else if (required) { @@ -910,7 +910,7 @@ static void cleanUpKernelTracing() setTraceOverwriteEnable(true); setTraceBufferSizeKB(1); setPrintTgidEnableIfPresent(false); - setKernelTraceFuncs(NULL); + setKernelTraceFuncs(nullptr); setUserInitiatedTraceProperty(false); } @@ -1068,10 +1068,10 @@ static void registerSigHandler() sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = handleSignal; - sigaction(SIGHUP, &sa, NULL); - sigaction(SIGINT, &sa, NULL); - sigaction(SIGQUIT, &sa, NULL); - sigaction(SIGTERM, &sa, NULL); + sigaction(SIGHUP, &sa, nullptr); + sigaction(SIGINT, &sa, nullptr); + sigaction(SIGQUIT, &sa, nullptr); + sigaction(SIGTERM, &sa, nullptr); } static void listSupportedCategories() @@ -1161,13 +1161,13 @@ int main(int argc, char **argv) int ret; int option_index = 0; static struct option long_options[] = { - {"async_start", no_argument, 0, 0 }, - {"async_stop", no_argument, 0, 0 }, - {"async_dump", no_argument, 0, 0 }, - {"only_userspace", no_argument, 0, 0 }, - {"list_categories", no_argument, 0, 0 }, - {"stream", no_argument, 0, 0 }, - { 0, 0, 0, 0 } + {"async_start", no_argument, nullptr, 0 }, + {"async_stop", no_argument, nullptr, 0 }, + {"async_dump", no_argument, nullptr, 0 }, + {"only_userspace", no_argument, nullptr, 0 }, + {"list_categories", no_argument, nullptr, 0 }, + {"stream", no_argument, nullptr, 0 }, + {nullptr, 0, nullptr, 0 } }; ret = getopt_long(argc, argv, "a:b:cf:k:ns:t:zo:", diff --git a/cmds/cmd/cmd.cpp b/cmds/cmd/cmd.cpp index 423853175b..0616adda61 100644 --- a/cmds/cmd/cmd.cpp +++ b/cmds/cmd/cmd.cpp @@ -103,12 +103,12 @@ public: } if (is_selinux_enabled() && seLinuxContext.size() > 0) { String8 seLinuxContext8(seLinuxContext); - security_context_t tmp = NULL; + security_context_t tmp = nullptr; getfilecon(fullPath.string(), &tmp); Unique_SecurityContext context(tmp); if (checkWrite) { int accessGranted = selinux_check_access(seLinuxContext8.string(), context.get(), - "file", "write", NULL); + "file", "write", nullptr); if (accessGranted != 0) { #if DEBUG ALOGD("openFile: failed selinux write check!"); @@ -122,7 +122,7 @@ public: } if (checkRead) { int accessGranted = selinux_check_access(seLinuxContext8.string(), context.get(), - "file", "read", NULL); + "file", "read", nullptr); if (accessGranted != 0) { #if DEBUG ALOGD("openFile: failed selinux read check!"); @@ -174,7 +174,7 @@ int main(int argc, char* const argv[]) #endif sp sm = defaultServiceManager(); fflush(stdout); - if (sm == NULL) { + if (sm == nullptr) { ALOGW("Unable to get default service manager!"); aerr << "cmd: Unable to get default service manager!" << endl; return 20; @@ -192,7 +192,7 @@ int main(int argc, char* const argv[]) for (size_t i=0; i service = sm->checkService(services[i]); - if (service != NULL) { + if (service != nullptr) { aout << " " << services[i] << endl; } } @@ -205,7 +205,7 @@ int main(int argc, char* const argv[]) } String16 cmd = String16(argv[1]); sp service = sm->checkService(cmd); - if (service == NULL) { + if (service == nullptr) { ALOGW("Can't find service %s", argv[1]); aerr << "cmd: Can't find service: " << argv[1] << endl; return 20; diff --git a/cmds/dumpstate/DumpstateUtil.cpp b/cmds/dumpstate/DumpstateUtil.cpp index 85eb464104..600a500e86 100644 --- a/cmds/dumpstate/DumpstateUtil.cpp +++ b/cmds/dumpstate/DumpstateUtil.cpp @@ -56,11 +56,11 @@ static bool waitpid_with_timeout(pid_t pid, int timeout_ms, int* status) { timespec ts; ts.tv_sec = MSEC_TO_SEC(timeout_ms); ts.tv_nsec = (timeout_ms % 1000) * 1000000; - int ret = TEMP_FAILURE_RETRY(sigtimedwait(&child_mask, NULL, &ts)); + int ret = TEMP_FAILURE_RETRY(sigtimedwait(&child_mask, nullptr, &ts)); int saved_errno = errno; // Set the signals back the way they were. - if (sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1) { + if (sigprocmask(SIG_SETMASK, &old_mask, nullptr) == -1) { printf("*** sigprocmask failed: %s\n", strerror(errno)); if (ret == 0) { return false; @@ -310,7 +310,7 @@ int RunCommandToFd(int fd, const std::string& title, const std::vectord_name[0] == '.') && (((d->d_name[1] == '.') && (d->d_name[2] == '\0')) || (d->d_name[1] == '\0'))) { @@ -648,7 +648,7 @@ int dump_files(const std::string& title, const char* dir, bool (*skip)(const cha printf("*** %s: %s\n", newpath, strerror(errno)); continue; } - (*dump_from_fd)(NULL, newpath, fd.get()); + (*dump_from_fd)(nullptr, newpath, fd.get()); } closedir(dirp); if (!title.empty()) { diff --git a/cmds/flatland/GLHelper.cpp b/cmds/flatland/GLHelper.cpp index d5b3372f96..62d2fa1548 100644 --- a/cmds/flatland/GLHelper.cpp +++ b/cmds/flatland/GLHelper.cpp @@ -29,7 +29,7 @@ GLHelper::GLHelper() : mContext(EGL_NO_CONTEXT), mDummySurface(EGL_NO_SURFACE), mConfig(0), - mShaderPrograms(NULL), + mShaderPrograms(nullptr), mDitherTexture(0) { } @@ -101,12 +101,12 @@ bool GLHelper::setUp(const ShaderDesc* shaderDescs, size_t numShaders) { } void GLHelper::tearDown() { - if (mShaderPrograms != NULL) { + if (mShaderPrograms != nullptr) { delete[] mShaderPrograms; - mShaderPrograms = NULL; + mShaderPrograms = nullptr; } - if (mSurfaceComposerClient != NULL) { + if (mSurfaceComposerClient != nullptr) { mSurfaceComposerClient->dispose(); mSurfaceComposerClient.clear(); } @@ -210,7 +210,7 @@ bool GLHelper::createNamedSurfaceTexture(GLuint name, uint32_t w, uint32_t h, glc->setConsumerUsageBits(GRALLOC_USAGE_HW_COMPOSER); sp anw = new Surface(producer); - EGLSurface s = eglCreateWindowSurface(mDisplay, mConfig, anw.get(), NULL); + EGLSurface s = eglCreateWindowSurface(mDisplay, mConfig, anw.get(), nullptr); if (s == EGL_NO_SURFACE) { fprintf(stderr, "eglCreateWindowSurface error: %#x\n", eglGetError()); return false; @@ -223,7 +223,7 @@ bool GLHelper::createNamedSurfaceTexture(GLuint name, uint32_t w, uint32_t h, bool GLHelper::computeWindowScale(uint32_t w, uint32_t h, float* scale) { sp dpy = mSurfaceComposerClient->getBuiltInDisplay(0); - if (dpy == NULL) { + if (dpy == nullptr) { fprintf(stderr, "SurfaceComposer::getBuiltInDisplay failed.\n"); return false; } @@ -247,7 +247,7 @@ bool GLHelper::createWindowSurface(uint32_t w, uint32_t h, bool result; status_t err; - if (mSurfaceComposerClient == NULL) { + if (mSurfaceComposerClient == nullptr) { mSurfaceComposerClient = new SurfaceComposerClient; } err = mSurfaceComposerClient->initCheck(); @@ -258,7 +258,7 @@ bool GLHelper::createWindowSurface(uint32_t w, uint32_t h, sp sc = mSurfaceComposerClient->createSurface( String8("Benchmark"), w, h, PIXEL_FORMAT_RGBA_8888, 0); - if (sc == NULL || !sc->isValid()) { + if (sc == nullptr || !sc->isValid()) { fprintf(stderr, "Failed to create SurfaceControl.\n"); return false; } @@ -275,7 +275,7 @@ bool GLHelper::createWindowSurface(uint32_t w, uint32_t h, .apply(); sp anw = sc->getSurface(); - EGLSurface s = eglCreateWindowSurface(mDisplay, mConfig, anw.get(), NULL); + EGLSurface s = eglCreateWindowSurface(mDisplay, mConfig, anw.get(), nullptr); if (s == EGL_NO_SURFACE) { fprintf(stderr, "eglCreateWindowSurface error: %#x\n", eglGetError()); return false; @@ -294,7 +294,7 @@ static bool compileShader(GLenum shaderType, const char* src, return false; } - glShaderSource(shader, 1, &src, NULL); + glShaderSource(shader, 1, &src, nullptr); glCompileShader(shader); GLint compiled = 0; @@ -305,7 +305,7 @@ static bool compileShader(GLenum shaderType, const char* src, if (infoLen) { char* buf = new char[infoLen]; if (buf) { - glGetShaderInfoLog(shader, infoLen, NULL, buf); + glGetShaderInfoLog(shader, infoLen, nullptr, buf); fprintf(stderr, "Shader compile log:\n%s\n", buf); delete[] buf; } @@ -318,21 +318,21 @@ static bool compileShader(GLenum shaderType, const char* src, } static void printShaderSource(const char* const* src) { - for (size_t i = 0; i < MAX_SHADER_LINES && src[i] != NULL; i++) { + for (size_t i = 0; i < MAX_SHADER_LINES && src[i] != nullptr; i++) { fprintf(stderr, "%3zu: %s\n", i+1, src[i]); } } static const char* makeShaderString(const char* const* src) { size_t len = 0; - for (size_t i = 0; i < MAX_SHADER_LINES && src[i] != NULL; i++) { + for (size_t i = 0; i < MAX_SHADER_LINES && src[i] != nullptr; i++) { // The +1 is for the '\n' that will be added. len += strlen(src[i]) + 1; } char* result = new char[len+1]; char* end = result; - for (size_t i = 0; i < MAX_SHADER_LINES && src[i] != NULL; i++) { + for (size_t i = 0; i < MAX_SHADER_LINES && src[i] != nullptr; i++) { strcpy(end, src[i]); end += strlen(src[i]); *end = '\n'; @@ -376,7 +376,7 @@ static bool linkShaderProgram(GLuint vs, GLuint fs, GLuint* outPgm) { if (bufLength) { char* buf = new char[bufLength]; if (buf) { - glGetProgramInfoLog(program, bufLength, NULL, buf); + glGetProgramInfoLog(program, bufLength, nullptr, buf); fprintf(stderr, "Program link log:\n%s\n", buf); delete[] buf; } diff --git a/cmds/flatland/Main.cpp b/cmds/flatland/Main.cpp index 3d7cac0bb3..7ceb397032 100644 --- a/cmds/flatland/Main.cpp +++ b/cmds/flatland/Main.cpp @@ -284,7 +284,7 @@ class Layer { public: Layer() : - mGLHelper(NULL), + mGLHelper(nullptr), mSurface(EGL_NO_SURFACE) { } @@ -316,23 +316,23 @@ public: } void tearDown() { - if (mComposer != NULL) { + if (mComposer != nullptr) { mComposer->tearDown(); delete mComposer; - mComposer = NULL; + mComposer = nullptr; } - if (mRenderer != NULL) { + if (mRenderer != nullptr) { mRenderer->tearDown(); delete mRenderer; - mRenderer = NULL; + mRenderer = nullptr; } if (mSurface != EGL_NO_SURFACE) { mGLHelper->destroySurface(&mSurface); mGLConsumer->abandon(); } - mGLHelper = NULL; + mGLHelper = nullptr; mGLConsumer.clear(); } @@ -377,7 +377,7 @@ public: mDesc(desc), mInstance(instance), mNumLayers(countLayers(desc)), - mGLHelper(NULL), + mGLHelper(nullptr), mSurface(EGL_NO_SURFACE), mWindowSurface(EGL_NO_SURFACE) { } @@ -443,7 +443,7 @@ public: mLayers[i].tearDown(); } - if (mGLHelper != NULL) { + if (mGLHelper != nullptr) { if (mWindowSurface != EGL_NO_SURFACE) { mGLHelper->destroySurface(&mWindowSurface); } @@ -453,7 +453,7 @@ public: mSurfaceControl.clear(); mGLHelper->tearDown(); delete mGLHelper; - mGLHelper = NULL; + mGLHelper = nullptr; } } @@ -553,7 +553,7 @@ private: static size_t countLayers(const BenchmarkDesc& desc) { size_t i; for (i = 0; i < MAX_NUM_LAYERS; i++) { - if (desc.layers[i].rendererFactory == NULL) { + if (desc.layers[i].rendererFactory == nullptr) { break; } } diff --git a/cmds/lshal/ListCommand.cpp b/cmds/lshal/ListCommand.cpp index 09eeaa8851..8d5f0d2e7c 100644 --- a/cmds/lshal/ListCommand.cpp +++ b/cmds/lshal/ListCommand.cpp @@ -1073,9 +1073,9 @@ static std::unique_ptr getLongOptions( i++; } // getopt_long last option has all zeros - ret[i].name = NULL; + ret[i].name = nullptr; ret[i].has_arg = 0; - ret[i].flag = NULL; + ret[i].flag = nullptr; ret[i].val = 0; return ret; diff --git a/cmds/lshal/PipeRelay.cpp b/cmds/lshal/PipeRelay.cpp index 3828bbf27f..87d75ac2d4 100644 --- a/cmds/lshal/PipeRelay.cpp +++ b/cmds/lshal/PipeRelay.cpp @@ -78,7 +78,7 @@ void PipeRelay::CloseFd(int *fd) { PipeRelay::~PipeRelay() { CloseFd(&mFds[1]); - if (mThread != NULL) { + if (mThread != nullptr) { mThread->join(); mThread.clear(); } diff --git a/cmds/lshal/Timeout.h b/cmds/lshal/Timeout.h index c940404200..58119a6fcf 100644 --- a/cmds/lshal/Timeout.h +++ b/cmds/lshal/Timeout.h @@ -57,7 +57,7 @@ void *callAndNotify(void *data) { BackgroundTaskState &state = *static_cast(data); state(); state.notify(); - return NULL; + return nullptr; } template @@ -65,7 +65,7 @@ bool timeout(std::chrono::duration delay, std::function &&func auto now = std::chrono::system_clock::now(); BackgroundTaskState state{std::forward(func)}; pthread_t thread; - if (pthread_create(&thread, NULL, callAndNotify, &state)) { + if (pthread_create(&thread, nullptr, callAndNotify, &state)) { std::cerr << "FATAL: could not create background thread." << std::endl; return false; } @@ -73,7 +73,7 @@ bool timeout(std::chrono::duration delay, std::function &&func if (!success) { pthread_kill(thread, SIGINT); } - pthread_join(thread, NULL); + pthread_join(thread, nullptr); return success; } diff --git a/cmds/rawbu/backup.cpp b/cmds/rawbu/backup.cpp index 0072281d4d..8b20e3e5ff 100644 --- a/cmds/rawbu/backup.cpp +++ b/cmds/rawbu/backup.cpp @@ -38,7 +38,7 @@ static char nameBuffer[PATH_MAX]; static struct stat statBuffer; static char copyBuffer[8192]; -static char *backupFilePath = NULL; +static char *backupFilePath = nullptr; static uint32_t inputFileVersion; @@ -58,7 +58,7 @@ static const struct special_dir SKIP_PATHS[] = { { "/data/system/batterystats.bin", SPECIAL_NO_TOUCH }, { "/data/system/location", SPECIAL_NO_TOUCH }, { "/data/dalvik-cache", SPECIAL_NO_BACKUP }, - { NULL, 0 }, + { nullptr, 0 }, }; /* This is just copied from the shell's built-in wipe command. */ @@ -71,7 +71,7 @@ static int wipe (const char *path) dir = opendir(path); - if (dir == NULL) { + if (dir == nullptr) { fprintf (stderr, "Error opendir'ing %s: %s\n", path, strerror(errno)); return 0; @@ -87,7 +87,7 @@ static int wipe (const char *path) for (;;) { de = readdir(dir); - if (de == NULL) { + if (de == nullptr) { break; } @@ -115,7 +115,7 @@ static int wipe (const char *path) } } - if (!noBackup && SKIP_PATHS[i].path != NULL) { + if (!noBackup && SKIP_PATHS[i].path != nullptr) { // This is a SPECIAL_NO_TOUCH directory. continue; } @@ -203,7 +203,7 @@ static int copy_file(FILE* dest, FILE* src, off_t size, const char* destName, int amt = size > (off_t)sizeof(copyBuffer) ? sizeof(copyBuffer) : (int)size; int readLen = fread(copyBuffer, 1, amt, src); if (readLen <= 0) { - if (srcName != NULL) { + if (srcName != nullptr) { fprintf(stderr, "unable to read source (%d of %ld bytes) file '%s': %s\n", amt, origSize, srcName, errno != 0 ? strerror(errno) : "unexpected EOF"); } else { @@ -214,7 +214,7 @@ static int copy_file(FILE* dest, FILE* src, off_t size, const char* destName, } int writeLen = fwrite(copyBuffer, 1, readLen, dest); if (writeLen != readLen) { - if (destName != NULL) { + if (destName != nullptr) { fprintf(stderr, "unable to write file (%d of %d bytes) '%s': '%s'\n", writeLen, readLen, destName, strerror(errno)); } else { @@ -256,14 +256,14 @@ static int backup_dir(FILE* fh, const char* srcPath) { DIR *dir; struct dirent *de; - char* fullPath = NULL; + char* fullPath = nullptr; int srcLen = strlen(srcPath); int result = 1; int i; dir = opendir(srcPath); - if (dir == NULL) { + if (dir == nullptr) { fprintf (stderr, "error opendir'ing '%s': %s\n", srcPath, strerror(errno)); return 0; @@ -272,7 +272,7 @@ static int backup_dir(FILE* fh, const char* srcPath) for (;;) { de = readdir(dir); - if (de == NULL) { + if (de == nullptr) { break; } @@ -283,7 +283,7 @@ static int backup_dir(FILE* fh, const char* srcPath) continue; } - if (fullPath != NULL) { + if (fullPath != nullptr) { free(fullPath); } fullPath = (char*)malloc(srcLen + strlen(de->d_name) + 2); @@ -298,7 +298,7 @@ static int backup_dir(FILE* fh, const char* srcPath) break; } } - if (SKIP_PATHS[i].path != NULL) { + if (SKIP_PATHS[i].path != nullptr) { continue; } } @@ -343,14 +343,14 @@ static int backup_dir(FILE* fh, const char* srcPath) } FILE* src = fopen(fullPath, "r"); - if (src == NULL) { + if (src == nullptr) { fprintf(stderr, "unable to open source file '%s': %s\n", fullPath, strerror(errno)); result = 0; goto done; } - int copyres = copy_file(fh, src, size, NULL, fullPath); + int copyres = copy_file(fh, src, size, nullptr, fullPath); fclose(src); if (!copyres) { result = 0; @@ -360,7 +360,7 @@ static int backup_dir(FILE* fh, const char* srcPath) } done: - if (fullPath != NULL) { + if (fullPath != nullptr) { free(fullPath); } @@ -374,7 +374,7 @@ static int backup_data(const char* destPath) int res = -1; FILE* fh = fopen(destPath, "w"); - if (fh == NULL) { + if (fh == nullptr) { fprintf(stderr, "unable to open destination '%s': %s\n", destPath, strerror(errno)); return -1; @@ -504,7 +504,7 @@ static int restore_data(const char* srcPath) int res = -1; FILE* fh = fopen(srcPath, "r"); - if (fh == NULL) { + if (fh == nullptr) { fprintf(stderr, "Unable to open source '%s': %s\n", srcPath, strerror(errno)); return -1; @@ -534,7 +534,7 @@ static int restore_data(const char* srcPath) while (1) { int type; - char* path = NULL; + char* path = nullptr; if (read_header(fh, &type, &path, &statBuffer) == 0) { goto done; } @@ -570,14 +570,14 @@ static int restore_data(const char* srcPath) printf("Restoring file %s...\n", path); FILE* dest = fopen(path, "w"); - if (dest == NULL) { + if (dest == nullptr) { fprintf(stderr, "unable to open destination file '%s': %s\n", path, strerror(errno)); free(path); goto done; } - int copyres = copy_file(dest, fh, size, path, NULL); + int copyres = copy_file(dest, fh, size, path, nullptr); fclose(dest); if (!copyres) { free(path); diff --git a/cmds/service/service.cpp b/cmds/service/service.cpp index bc11256a73..34a3fdc420 100644 --- a/cmds/service/service.cpp +++ b/cmds/service/service.cpp @@ -30,7 +30,7 @@ using namespace android; void writeString16(Parcel& parcel, const char* string) { - if (string != NULL) + if (string != nullptr) { parcel.writeString16(String16(string)); } @@ -43,7 +43,7 @@ void writeString16(Parcel& parcel, const char* string) // get the name of the generic interface we hold a reference to static String16 get_interface_name(sp service) { - if (service != NULL) { + if (service != nullptr) { Parcel data, reply; status_t err = service->transact(IBinder::INTERFACE_TRANSACTION, data, &reply); if (err == NO_ERROR) { @@ -93,7 +93,7 @@ int main(int argc, char* const argv[]) #endif sp sm = defaultServiceManager(); fflush(stdout); - if (sm == NULL) { + if (sm == nullptr) { aerr << "service: Unable to get default service manager!" << endl; return 20; } @@ -106,7 +106,7 @@ int main(int argc, char* const argv[]) if (optind < argc) { sp service = sm->checkService(String16(argv[optind])); aout << "Service " << argv[optind] << - (service == NULL ? ": not found" : ": found") << endl; + (service == nullptr ? ": not found" : ": found") << endl; } else { aerr << "service: No service specified for check" << endl; wantsUsage = true; @@ -131,7 +131,7 @@ int main(int argc, char* const argv[]) sp service = sm->checkService(String16(argv[optind++])); String16 ifName = get_interface_name(service); int32_t code = atoi(argv[optind++]); - if (service != NULL && ifName.size() > 0) { + if (service != nullptr && ifName.size() > 0) { Parcel data, reply; // the interface name is first @@ -186,28 +186,28 @@ int main(int argc, char* const argv[]) data.writeDouble(atof(argv[optind++])); } else if (strcmp(argv[optind], "null") == 0) { optind++; - data.writeStrongBinder(NULL); + data.writeStrongBinder(nullptr); } else if (strcmp(argv[optind], "intent") == 0) { - char* action = NULL; - char* dataArg = NULL; - char* type = NULL; + char* action = nullptr; + char* dataArg = nullptr; + char* type = nullptr; int launchFlags = 0; - char* component = NULL; + char* component = nullptr; int categoryCount = 0; char* categories[16]; - char* context1 = NULL; + char* context1 = nullptr; optind++; while (optind < argc) { char* key = strtok_r(argv[optind], "=", &context1); - char* value = strtok_r(NULL, "=", &context1); + char* value = strtok_r(nullptr, "=", &context1); // we have reached the end of the XXX=XXX args. - if (key == NULL) break; + if (key == nullptr) break; if (strcmp(key, "action") == 0) { @@ -231,14 +231,14 @@ int main(int argc, char* const argv[]) } else if (strcmp(key, "categories") == 0) { - char* context2 = NULL; + char* context2 = nullptr; int categoryCount = 0; categories[categoryCount] = strtok_r(value, ",", &context2); - while (categories[categoryCount] != NULL) + while (categories[categoryCount] != nullptr) { categoryCount++; - categories[categoryCount] = strtok_r(NULL, ",", &context2); + categories[categoryCount] = strtok_r(nullptr, ",", &context2); } } diff --git a/cmds/surfacereplayer/replayer/Main.cpp b/cmds/surfacereplayer/replayer/Main.cpp index 7090bdb503..fbfcacf1aa 100644 --- a/cmds/surfacereplayer/replayer/Main.cpp +++ b/cmds/surfacereplayer/replayer/Main.cpp @@ -94,7 +94,7 @@ int main(int argc, char** argv) { } char** input = argv + optind; - if (input[0] == NULL) { + if (input[0] == nullptr) { std::cerr << "No trace file provided...exiting" << std::endl; abort(); } -- cgit v1.2.3-59-g8ed1b From bbd6fdb674a9aa04fe2e3f1dd01a8be437d8e92b Mon Sep 17 00:00:00 2001 From: Kelly Rossmoyer Date: Tue, 21 Aug 2018 18:06:38 -0700 Subject: Add batterystats -c data to telephony bugreports Telephony bugreports currently capture 'dumpsys batterystats' output, but only in its human-friendly format. While humans may enjoy that format, Historian does not, and fails to properly load telephony bugreports (including those triggered by LowPowerMonitor) as a result. This makes it essentially impossible to use Historian when triaging/ analyzing telephony-style bugreports. To enable Historian processing of telephony bugreports, this change adds the 'checkin' format ("dumpsys batterystats -c") data along with the existing entries. ABT (Android Bug Tool) still doesn't properly list dumpsys sections in its UI even with this change, but I think nothing short of a full, comprehensive dumpsys run will make ABT happy. And that's okay, because all of the text content can still be navigated manually. Bug: 111763716 Test: Triggered telephony bugreports within and without the change on a blueline device, manually verified that the checkin format data was present with the code change in place, and loaded the bugreport into Historian successfully. Change-Id: Iba434bfd219c627cd3c058e549a627947d9ce501 --- cmds/dumpstate/dumpstate.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'cmds/dumpstate/dumpstate.cpp') diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index 2c248c664a..9216e7565e 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -1463,6 +1463,12 @@ static void DumpstateTelephonyOnly() { RunDumpsys("APP SERVICES NON-PLATFORM", {"activity", "service", "all-non-platform"}, DUMPSYS_COMPONENTS_OPTIONS); + printf("========================================================\n"); + printf("== Checkins\n"); + printf("========================================================\n"); + + RunDumpsys("CHECKIN BATTERYSTATS", {"batterystats", "-c"}); + printf("========================================================\n"); printf("== dumpstate: done (id %d)\n", ds.id_); printf("========================================================\n"); -- cgit v1.2.3-59-g8ed1b From e9a0703322ec261adb50592a05bf0ea9a953cf05 Mon Sep 17 00:00:00 2001 From: Nandana Dutt Date: Fri, 14 Sep 2018 16:57:00 +0100 Subject: Remove dumping raft logs Raft has been replaced by logpersistd per b/28633932. Remove code to handle raft logs. BUG: 28633932 Test: adb shell /data/nativetest64/dumpstate_test/dumpstate_test Test: adb bugreport ~/br.zip Change-Id: I5380ed1367c4dc39a1531a9b3c61a3965fe56981 --- cmds/dumpstate/dumpstate.cpp | 38 -------------------------------------- 1 file changed, 38 deletions(-) (limited to 'cmds/dumpstate/dumpstate.cpp') diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index 43620192da..ff15794c05 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -101,7 +101,6 @@ void add_mountinfo(); #define ALT_PSTORE_LAST_KMSG "/sys/fs/pstore/console-ramoops-0" #define BLK_DEV_SYS_DIR "/sys/block" -#define RAFT_DIR "/data/misc/raft" #define RECOVERY_DIR "/cache/recovery" #define RECOVERY_DATA_DIR "/data/misc/recovery" #define UPDATE_ENGINE_LOG_DIR "/data/misc/update_engine_log" @@ -455,40 +454,6 @@ static void dump_systrace() { } } -static void dump_raft() { - if (PropertiesHelper::IsUserBuild()) { - return; - } - - std::string raft_path = ds.GetPath("-raft_log.txt"); - if (raft_path.empty()) { - MYLOGD("raft_path is empty\n"); - return; - } - - struct stat s; - if (stat(RAFT_DIR, &s) != 0 || !S_ISDIR(s.st_mode)) { - MYLOGD("%s does not exist or is not a directory\n", RAFT_DIR); - return; - } - - CommandOptions options = CommandOptions::WithTimeout(600).Build(); - if (!ds.IsZipping()) { - // Write compressed and encoded raft logs to stdout if it's not a zipped bugreport. - RunCommand("RAFT LOGS", {"logcompressor", "-r", RAFT_DIR}, options); - return; - } - - RunCommand("RAFT LOGS", {"logcompressor", "-n", "-r", RAFT_DIR, "-o", raft_path}, options); - if (!ds.AddZipEntry("raft_log.txt", raft_path)) { - MYLOGE("Unable to add raft log %s to zip file\n", raft_path.c_str()); - } else { - if (remove(raft_path.c_str())) { - MYLOGE("Error removing raft file %s: %s\n", raft_path.c_str(), strerror(errno)); - } - } -} - static bool skip_not_stat(const char *path) { static const char stat[] = "/stat"; size_t len = strlen(path); @@ -2085,9 +2050,6 @@ int run_main(int argc, char* argv[]) { // keep the system stats as close to its initial state as possible. RunDumpsysCritical(); - // TODO: Drop root user and move into dumpstate() once b/28633932 is fixed. - dump_raft(); - /* collect stack traces from Dalvik and native processes (needs root) */ dump_traces_path = dump_traces(); -- cgit v1.2.3-59-g8ed1b From 3847214b5b0187e640133b0ac860f3ed5ddc6fb1 Mon Sep 17 00:00:00 2001 From: Bookatz Date: Fri, 28 Sep 2018 10:20:24 -0700 Subject: Statsd dump data and metadata to bugreport Statsd now has two dump outputs: metadata (statsdstats) and report data (in proto form). Both are now dumped to bug reports. The former is for debugging statsd; the latter can be used for debugging a great variety of issues since it contains data from across Android. Test: manual verification Test: cts-tradefed run cts-dev -m CtsStatsdHostTestCases -t android.cts.statsd.atom.HostAtomTests#testDumpsysStats Change-Id: Ifa5537ef22c7545a979677bc371695b37f9a75c8 --- cmds/dumpstate/dumpstate.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'cmds/dumpstate/dumpstate.cpp') diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index 0b9bca013c..904c0e924e 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -1374,6 +1374,12 @@ static void dumpstate() { printf("========================================================\n"); printf("== dumpstate: done (id %d)\n", ds.id_); printf("========================================================\n"); + + printf("========================================================\n"); + printf("== Obtaining statsd metadata\n"); + printf("========================================================\n"); + // This differs from the usual dumpsys stats, which is the stats report data. + RunDumpsys("STATSDSTATS", {"stats", "--metadata"}); } /* Dumps state for the default case. Returns true if everything went fine. */ -- cgit v1.2.3-59-g8ed1b From 5c39003abe28360e6e3a7728ae3e071b9e01a7e4 Mon Sep 17 00:00:00 2001 From: Nandana Dutt Date: Tue, 12 Mar 2019 10:52:56 +0000 Subject: Handle user consent denial sooner Currently dumpstate prompts the user for consent rightaway when called via the API, but does not check for the result until the entire bugreport is generated. This can make for a poor user experience - for e.g. the client will continue to show a progress bar for a long time after user denied consent. Fix by checking for user consent intermittently. BUG: 128270426 Test: Tested canceling during each long running operation Test: bugreport from power menu (ie non-api flow) still works as expected Test: adb shell /data/nativetest64/dumpstate_smoke_test/dumpstate_smoke_test && adb shell /data/nativetest64/dumpstate_test/dumpstate_test Change-Id: Icbed7c510ff9c9a882a7b49eac1a92fa17727635 (cherry picked from commit e49b94c97201214705ec72b50167e544a96e226c) --- cmds/dumpstate/dumpstate.cpp | 143 ++++++++++++++++++++++++++++++------------- cmds/dumpstate/dumpstate.h | 7 +++ cmds/dumpstate/utils.cpp | 12 ++++ 3 files changed, 121 insertions(+), 41 deletions(-) (limited to 'cmds/dumpstate/dumpstate.cpp') diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index 0cf2df069c..704c5f2e47 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -131,6 +131,19 @@ static const std::string ANR_FILE_PREFIX = "anr_"; // TODO: temporary variables and functions used during C++ refactoring static Dumpstate& ds = Dumpstate::GetInstance(); +#define RETURN_IF_USER_DENIED_CONSENT() \ + if (ds.IsUserConsentDenied()) { \ + MYLOGE("Returning early as user denied consent to share bugreport with calling app."); \ + return Dumpstate::RunStatus::USER_CONSENT_DENIED; \ + } + +// Runs func_ptr, but checks user consent before and after running it. Returns USER_CONSENT_DENIED +// if consent is found to be denied. +#define RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK(func_ptr, ...) \ + RETURN_IF_USER_DENIED_CONSENT(); \ + func_ptr(__VA_ARGS__); \ + RETURN_IF_USER_DENIED_CONSENT(); + namespace android { namespace os { namespace { @@ -1054,9 +1067,9 @@ static void DumpIpAddrAndRules() { RunCommand("IP RULES v6", {"ip", "-6", "rule", "show"}); } -static void RunDumpsysTextByPriority(const std::string& title, int priority, - std::chrono::milliseconds timeout, - std::chrono::milliseconds service_timeout) { +static Dumpstate::RunStatus RunDumpsysTextByPriority(const std::string& title, int priority, + std::chrono::milliseconds timeout, + std::chrono::milliseconds service_timeout) { auto start = std::chrono::steady_clock::now(); sp sm = defaultServiceManager(); Dumpsys dumpsys(sm.get()); @@ -1064,6 +1077,7 @@ static void RunDumpsysTextByPriority(const std::string& title, int priority, Dumpsys::setServiceArgs(args, /* asProto = */ false, priority); Vector services = dumpsys.listServices(priority, /* supports_proto = */ false); for (const String16& service : services) { + RETURN_IF_USER_DENIED_CONSENT(); std::string path(title); path.append(" - ").append(String8(service).c_str()); DumpstateSectionReporter section_reporter(path, ds.listener_, ds.report_section_); @@ -1089,6 +1103,7 @@ static void RunDumpsysTextByPriority(const std::string& title, int priority, break; } } + return Dumpstate::RunStatus::OK; } static void RunDumpsysText(const std::string& title, int priority, @@ -1101,24 +1116,27 @@ static void RunDumpsysText(const std::string& title, int priority, } /* Dump all services registered with Normal or Default priority. */ -static void RunDumpsysTextNormalPriority(const std::string& title, - std::chrono::milliseconds timeout, - std::chrono::milliseconds service_timeout) { +static Dumpstate::RunStatus RunDumpsysTextNormalPriority(const std::string& title, + std::chrono::milliseconds timeout, + std::chrono::milliseconds service_timeout) { DurationReporter duration_reporter(title); dprintf(STDOUT_FILENO, "------ %s (/system/bin/dumpsys) ------\n", title.c_str()); fsync(STDOUT_FILENO); RunDumpsysTextByPriority(title, IServiceManager::DUMP_FLAG_PRIORITY_NORMAL, timeout, service_timeout); - RunDumpsysTextByPriority(title, IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT, timeout, - service_timeout); + + RETURN_IF_USER_DENIED_CONSENT(); + + return RunDumpsysTextByPriority(title, IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT, timeout, + service_timeout); } -static void RunDumpsysProto(const std::string& title, int priority, - std::chrono::milliseconds timeout, - std::chrono::milliseconds service_timeout) { +static Dumpstate::RunStatus RunDumpsysProto(const std::string& title, int priority, + std::chrono::milliseconds timeout, + std::chrono::milliseconds service_timeout) { if (!ds.IsZipping()) { MYLOGD("Not dumping %s because it's not a zipped bugreport\n", title.c_str()); - return; + return Dumpstate::RunStatus::OK; } sp sm = defaultServiceManager(); Dumpsys dumpsys(sm.get()); @@ -1129,6 +1147,7 @@ static void RunDumpsysProto(const std::string& title, int priority, auto start = std::chrono::steady_clock::now(); Vector services = dumpsys.listServices(priority, /* supports_proto = */ true); for (const String16& service : services) { + RETURN_IF_USER_DENIED_CONSENT(); std::string path(kProtoPath); path.append(String8(service).c_str()); if (priority == IServiceManager::DUMP_FLAG_PRIORITY_CRITICAL) { @@ -1157,32 +1176,42 @@ static void RunDumpsysProto(const std::string& title, int priority, break; } } + return Dumpstate::RunStatus::OK; } // Runs dumpsys on services that must dump first and will take less than 100ms to dump. -static void RunDumpsysCritical() { +static Dumpstate::RunStatus RunDumpsysCritical() { RunDumpsysText("DUMPSYS CRITICAL", IServiceManager::DUMP_FLAG_PRIORITY_CRITICAL, /* timeout= */ 5s, /* service_timeout= */ 500ms); - RunDumpsysProto("DUMPSYS CRITICAL PROTO", IServiceManager::DUMP_FLAG_PRIORITY_CRITICAL, - /* timeout= */ 5s, /* service_timeout= */ 500ms); + + RETURN_IF_USER_DENIED_CONSENT(); + + return RunDumpsysProto("DUMPSYS CRITICAL PROTO", IServiceManager::DUMP_FLAG_PRIORITY_CRITICAL, + /* timeout= */ 5s, /* service_timeout= */ 500ms); } // Runs dumpsys on services that must dump first but can take up to 250ms to dump. -static void RunDumpsysHigh() { +static Dumpstate::RunStatus RunDumpsysHigh() { // TODO meminfo takes ~10s, connectivity takes ~5sec to dump. They are both // high priority. Reduce timeout once they are able to dump in a shorter time or // moved to a parallel task. RunDumpsysText("DUMPSYS HIGH", IServiceManager::DUMP_FLAG_PRIORITY_HIGH, /* timeout= */ 90s, /* service_timeout= */ 30s); - RunDumpsysProto("DUMPSYS HIGH PROTO", IServiceManager::DUMP_FLAG_PRIORITY_HIGH, - /* timeout= */ 5s, /* service_timeout= */ 1s); + + RETURN_IF_USER_DENIED_CONSENT(); + + return RunDumpsysProto("DUMPSYS HIGH PROTO", IServiceManager::DUMP_FLAG_PRIORITY_HIGH, + /* timeout= */ 5s, /* service_timeout= */ 1s); } // Runs dumpsys on services that must dump but can take up to 10s to dump. -static void RunDumpsysNormal() { +static Dumpstate::RunStatus RunDumpsysNormal() { RunDumpsysTextNormalPriority("DUMPSYS", /* timeout= */ 90s, /* service_timeout= */ 10s); - RunDumpsysProto("DUMPSYS PROTO", IServiceManager::DUMP_FLAG_PRIORITY_NORMAL, - /* timeout= */ 90s, /* service_timeout= */ 10s); + + RETURN_IF_USER_DENIED_CONSENT(); + + return RunDumpsysProto("DUMPSYS PROTO", IServiceManager::DUMP_FLAG_PRIORITY_NORMAL, + /* timeout= */ 90s, /* service_timeout= */ 10s); } static void DumpHals() { @@ -1244,9 +1273,16 @@ static void DumpHals() { } } -static void dumpstate() { +// Dumps various things. Returns early with status USER_CONSENT_DENIED if user denies consent +// via the consent they are shown. Ignores other errors that occur while running various +// commands. The consent checking is currently done around long running tasks, which happen to +// be distributed fairly evenly throughout the function. +static Dumpstate::RunStatus dumpstate() { DurationReporter duration_reporter("DUMPSTATE"); + // Dump various things. Note that anything that takes "long" (i.e. several seconds) should + // check intermittently (if it's intrerruptable like a foreach on pids) and/or should be wrapped + // in a consent check (via RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK). dump_dev_files("TRUSTY VERSION", "/sys/bus/platform/drivers/trusty", "trusty_version"); RunCommand("UPTIME", {"uptime"}); DumpBlockStatFiles(); @@ -1254,7 +1290,9 @@ static void dumpstate() { DumpFile("MEMORY INFO", "/proc/meminfo"); RunCommand("CPU INFO", {"top", "-b", "-n", "1", "-H", "-s", "6", "-o", "pid,tid,user,pr,ni,%cpu,s,virt,res,pcy,cmd,name"}); - RunCommand("PROCRANK", {"procrank"}, AS_ROOT_20); + + RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK(RunCommand, "PROCRANK", {"procrank"}, AS_ROOT_20); + DumpFile("VIRTUAL MEMORY STATS", "/proc/vmstat"); DumpFile("VMALLOC INFO", "/proc/vmallocinfo"); DumpFile("SLAB INFO", "/proc/slabinfo"); @@ -1269,7 +1307,9 @@ static void dumpstate() { RunCommand("PROCESSES AND THREADS", {"ps", "-A", "-T", "-Z", "-O", "pri,nice,rtprio,sched,pcy,time"}); - RunCommand("LIBRANK", {"librank"}, CommandOptions::AS_ROOT); + + RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK(RunCommand, "LIBRANK", {"librank"}, + CommandOptions::AS_ROOT); DumpHals(); @@ -1290,7 +1330,9 @@ static void dumpstate() { } RunCommand("LIST OF OPEN FILES", {"lsof"}, CommandOptions::AS_ROOT); - for_each_pid(do_showmap, "SMAPS OF ALL PROCESSES"); + + RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK(for_each_pid, do_showmap, "SMAPS OF ALL PROCESSES"); + for_each_tid(show_wchan, "BLOCKED PROCESS WAIT-CHANNELS"); for_each_pid(show_showtime, "PROCESS TIMES (pid cmd user system iowait+percentage)"); @@ -1328,7 +1370,7 @@ static void dumpstate() { RunCommand("IPv6 ND CACHE", {"ip", "-6", "neigh", "show"}); RunCommand("MULTICAST ADDRESSES", {"ip", "maddr"}); - RunDumpsysHigh(); + RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK(RunDumpsysHigh); RunCommand("SYSTEM PROPERTIES", {"getprop"}); @@ -1351,7 +1393,7 @@ static void dumpstate() { ds.AddDir(WMTRACE_DATA_DIR, false); } - ds.DumpstateBoard(); + RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK(ds.DumpstateBoard); /* Migrate the ril_dumpstate to a device specific dumpstate? */ int rilDumpstateTimeout = android::base::GetIntProperty("ril.dumpstate.timeout", 0); @@ -1371,14 +1413,16 @@ static void dumpstate() { printf("== Android Framework Services\n"); printf("========================================================\n"); - RunDumpsysNormal(); + RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK(RunDumpsysNormal); printf("========================================================\n"); printf("== Checkins\n"); printf("========================================================\n"); RunDumpsys("CHECKIN BATTERYSTATS", {"batterystats", "-c"}); - RunDumpsys("CHECKIN MEMINFO", {"meminfo", "--checkin"}); + + RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK(RunDumpsys, "CHECKIN MEMINFO", {"meminfo", "--checkin"}); + RunDumpsys("CHECKIN NETSTATS", {"netstats", "--checkin"}); RunDumpsys("CHECKIN PROCSTATS", {"procstats", "-c"}); RunDumpsys("CHECKIN USAGESTATS", {"usagestats", "-c"}); @@ -1442,18 +1486,28 @@ static void dumpstate() { printf("========================================================\n"); // This differs from the usual dumpsys stats, which is the stats report data. RunDumpsys("STATSDSTATS", {"stats", "--metadata"}); + return Dumpstate::RunStatus::OK; } -/* Dumps state for the default case. Returns true if everything went fine. */ -static bool DumpstateDefault() { +/* + * Dumps state for the default case; drops root after it's no longer necessary. + * + * Returns RunStatus::OK if everything went fine. + * Returns RunStatus::ERROR if there was an error. + * Returns RunStatus::USER_DENIED_CONSENT if user explicitly denied consent to sharing the bugreport + * with the caller. + */ +static Dumpstate::RunStatus DumpstateDefault() { // Try to dump anrd trace if the daemon is running. dump_anrd_trace(); // Invoking the following dumpsys calls before dump_traces() to try and // keep the system stats as close to its initial state as possible. - RunDumpsysCritical(); + RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK(RunDumpsysCritical); /* collect stack traces from Dalvik and native processes (needs root) */ + // TODO(128270426): Refactor to take output argument and wrap in + // RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK. dump_traces_path = ds.DumpTraces(); /* Run some operations that require root. */ @@ -1490,11 +1544,11 @@ static bool DumpstateDefault() { } if (!DropRootUser()) { - return false; + return Dumpstate::RunStatus::ERROR; } - dumpstate(); - return true; + RETURN_IF_USER_DENIED_CONSENT(); + return dumpstate(); } // This method collects common dumpsys for telephony and wifi @@ -1730,6 +1784,7 @@ void Dumpstate::DumpstateBoard() { return; } + // TODO(128270426): Check for consent in between? for (size_t i = 0; i < paths.size(); i++) { MYLOGI("Calling IDumpstateDevice implementation using path %s\n", paths[i].c_str()); @@ -2587,9 +2642,12 @@ Dumpstate::RunStatus Dumpstate::RunInternal(int32_t calling_uid, DumpstateWifiOnly(); } else { // Dump state for the default case. This also drops root. - if (!DumpstateDefault()) { - // Something went wrong. - return RunStatus::ERROR; + RunStatus s = DumpstateDefault(); + if (s != RunStatus::OK) { + if (s == RunStatus::USER_CONSENT_TIMED_OUT) { + HandleUserConsentDenied(); + } + return s; } } @@ -2626,9 +2684,7 @@ Dumpstate::RunStatus Dumpstate::RunInternal(int32_t calling_uid, MYLOGI( "Did not receive user consent yet." " Will not copy the bugreport artifacts to caller.\n"); - // TODO(b/111441001): - // 1. cancel outstanding requests - // 2. check for result more frequently + // TODO(b/111441001): cancel outstanding requests } } @@ -2683,6 +2739,11 @@ void Dumpstate::CheckUserConsent(int32_t calling_uid, const android::String16& c } } +bool Dumpstate::IsUserConsentDenied() const { + return ds.consent_callback_ != nullptr && + ds.consent_callback_->getResult() == UserConsentResult::DENIED; +} + void Dumpstate::CleanupFiles() { android::os::UnlinkAndLogOnError(tmp_path_); android::os::UnlinkAndLogOnError(screenshot_path_); diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h index 603af710ff..1463b8b9ba 100644 --- a/cmds/dumpstate/dumpstate.h +++ b/cmds/dumpstate/dumpstate.h @@ -330,6 +330,13 @@ class Dumpstate { /* Sets runtime options. */ void SetOptions(std::unique_ptr options); + /* + * Returns true if user consent is necessary and has been denied. + * Consent is only necessary if the caller has asked to copy over the bugreport to a file they + * provided. + */ + bool IsUserConsentDenied() const; + /* * Structure to hold options that determine the behavior of dumpstate. */ diff --git a/cmds/dumpstate/utils.cpp b/cmds/dumpstate/utils.cpp index 8b9298820d..fe1e4b4b14 100644 --- a/cmds/dumpstate/utils.cpp +++ b/cmds/dumpstate/utils.cpp @@ -278,6 +278,12 @@ static void __for_each_pid(void (*helper)(int, const char *, void *), const char if (header) printf("\n------ %s ------\n", header); while ((de = readdir(d))) { + if (ds.IsUserConsentDenied()) { + MYLOGE( + "Returning early because user denied consent to share bugreport with calling app."); + closedir(d); + return; + } int pid; int fd; char cmdpath[255]; @@ -350,6 +356,12 @@ static void for_each_tid_helper(int pid, const char *cmdline, void *arg) { func(pid, pid, cmdline); while ((de = readdir(d))) { + if (ds.IsUserConsentDenied()) { + MYLOGE( + "Returning early because user denied consent to share bugreport with calling app."); + closedir(d); + return; + } int tid; int fd; char commpath[255]; -- cgit v1.2.3-59-g8ed1b From 1c36d7566d26b0234053e116a89305fed7190770 Mon Sep 17 00:00:00 2001 From: Joe Onorato Date: Sun, 17 Mar 2019 18:26:43 -0700 Subject: Add IncidentReport data structure to aidl for IncidentCompanionService and some extra parameters for incidentd. Test: bit incident_test:* GtsIncidentManagerTestCases:* Bug: 123543706 Change-Id: I5a697770b07c809311ddee47259e921338c3088c --- cmds/dumpstate/dumpstate.cpp | 4 +- libs/incidentcompanion/Android.bp | 6 +- .../binder/android/os/IIncidentCompanion.aidl | 33 +++++ .../binder/android/os/IncidentManager.aidl | 20 +++ .../include/android/os/IncidentManager.h | 71 +++++++++++ libs/incidentcompanion/src/IncidentManager.cpp | 135 +++++++++++++++++++++ 6 files changed, 266 insertions(+), 3 deletions(-) create mode 100644 libs/incidentcompanion/binder/android/os/IncidentManager.aidl create mode 100644 libs/incidentcompanion/include/android/os/IncidentManager.h create mode 100644 libs/incidentcompanion/src/IncidentManager.cpp (limited to 'cmds/dumpstate/dumpstate.cpp') diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index 1fbd2b3820..12de2d2c3c 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -2735,8 +2735,8 @@ void Dumpstate::CheckUserConsent(int32_t calling_uid, const android::String16& c if (ics != nullptr) { MYLOGD("Checking user consent via incidentcompanion service\n"); android::interface_cast(ics)->authorizeReport( - calling_uid, calling_package, 0x1 /* FLAG_CONFIRMATION_DIALOG */, - consent_callback_.get()); + calling_uid, calling_package, String16(), String16(), + 0x1 /* FLAG_CONFIRMATION_DIALOG */, consent_callback_.get()); } else { MYLOGD("Unable to check user consent; incidentcompanion service unavailable\n"); } diff --git a/libs/incidentcompanion/Android.bp b/libs/incidentcompanion/Android.bp index 45eab00fb6..63411b9698 100644 --- a/libs/incidentcompanion/Android.bp +++ b/libs/incidentcompanion/Android.bp @@ -35,8 +35,12 @@ cc_library_static { }, srcs: [ ":incidentcompanion_aidl", + "src/IncidentManager.cpp", + ], + export_include_dirs: [ + "binder", + "include", ], - export_include_dirs: ["binder"], cflags: [ "-Wall", "-Werror", diff --git a/libs/incidentcompanion/binder/android/os/IIncidentCompanion.aidl b/libs/incidentcompanion/binder/android/os/IIncidentCompanion.aidl index 6bf98d2e27..98c28146ad 100644 --- a/libs/incidentcompanion/binder/android/os/IIncidentCompanion.aidl +++ b/libs/incidentcompanion/binder/android/os/IIncidentCompanion.aidl @@ -17,6 +17,7 @@ package android.os; import android.os.IIncidentAuthListener; +import android.os.IncidentManager; /** * Helper service for incidentd and dumpstated to provide user feedback @@ -35,6 +36,10 @@ interface IIncidentCompanion { * returns via the callback whether the application should be trusted. It is up * to the caller to actually implement the restriction to take or not take * the incident or bug report. + * @param receiverClass The class that will be the eventual broacast receiver for the + * INCIDENT_REPORT_READY message. Used as part of the id in incidentd. + * @param reportId The incident report ID. Incidentd should call with this parameter, but + * everyone else should pass null or empty string. * @param flags FLAG_CONFIRMATION_DIALOG (0x1) - to show this as a dialog. Otherwise * a dialog will be shown as a notification. * @param callback Interface to receive results. The results may not come back for @@ -44,6 +49,7 @@ interface IIncidentCompanion { * to send their report. */ oneway void authorizeReport(int callingUid, String callingPackage, + String receiverClass, String reportId, int flags, IIncidentAuthListener callback); /** @@ -51,6 +57,11 @@ interface IIncidentCompanion { */ oneway void cancelAuthorization(IIncidentAuthListener callback); + /** + * Send the report ready broadcast on behalf of incidentd. + */ + oneway void sendReportReadyBroadcast(String pkg, String cls); + /** * Return the list of pending approvals. */ @@ -69,4 +80,26 @@ interface IIncidentCompanion { * @param uri the report. */ void denyReport(String uri); + + /** + * List the incident reports for the given ComponentName. The receiver + * must be for a package inside the caller. + */ + List getIncidentReportList(String pkg, String cls); + + /** + * Get the IncidentReport object. + */ + IncidentManager.IncidentReport getIncidentReport(String pkg, String cls, String id); + + /** + * Signal that the client is done with this incident report and it can be deleted. + */ + void deleteIncidentReports(String pkg, String cls, String id); + + /** + * Signal that the client is done with all incident reports from this package. + * Especially useful for testing. + */ + void deleteAllIncidentReports(String pkg); } diff --git a/libs/incidentcompanion/binder/android/os/IncidentManager.aidl b/libs/incidentcompanion/binder/android/os/IncidentManager.aidl new file mode 100644 index 0000000000..d17823ef05 --- /dev/null +++ b/libs/incidentcompanion/binder/android/os/IncidentManager.aidl @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2014 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. + */ + +package android.os; + +parcelable IncidentManager.IncidentReport cpp_header "android/os/IncidentManager.h"; + diff --git a/libs/incidentcompanion/include/android/os/IncidentManager.h b/libs/incidentcompanion/include/android/os/IncidentManager.h new file mode 100644 index 0000000000..07b6d82441 --- /dev/null +++ b/libs/incidentcompanion/include/android/os/IncidentManager.h @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2019, 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. + */ + +#pragma once + +#include +#include +#include + +#include +#include + +namespace android { +namespace os { + +class IncidentManager : public virtual RefBase { +public: + class IncidentReport : public Parcelable { + public: + IncidentReport(); + virtual ~IncidentReport(); + + virtual status_t writeToParcel(Parcel* out) const; + virtual status_t readFromParcel(const Parcel* in); + + void setTimestampNs(int64_t val) { mTimestampNs = val; } + int64_t getTimestampNs() const { return mTimestampNs; } + int64_t getTimestampMs() const { return mTimestampNs / 1000000; } + + void setPrivacyPolicy(int32_t val) { mPrivacyPolicy = val; } + // This was accidentally published as a long in the java api. + int64_t getPrivacyPolicy() const { return mPrivacyPolicy; } + // Dups the fd, so you retain ownership of the original one. If there is a + // previously set fd, closes that, since this object owns its own fd. + status_t setFileDescriptor(int fd); + + // Does not dup the fd, so ownership is passed to this object. If there is a + // previously set fd, closes that, since this object owns its own fd. + void takeFileDescriptor(int fd); + + // Returns the fd, which you don't own. Call dup if you need a copy. + int getFileDescriptor() const { return mFileDescriptor; } + + private: + int64_t mTimestampNs; + int32_t mPrivacyPolicy; + int mFileDescriptor; + }; + + +private: + // Not implemented for now. + IncidentManager(); + virtual ~IncidentManager(); +}; +} +} + diff --git a/libs/incidentcompanion/src/IncidentManager.cpp b/libs/incidentcompanion/src/IncidentManager.cpp new file mode 100644 index 0000000000..f7c8a5eecc --- /dev/null +++ b/libs/incidentcompanion/src/IncidentManager.cpp @@ -0,0 +1,135 @@ +/** + * Copyright (c) 2016, 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 + +namespace android { +namespace os { + +// ============================================================ +IncidentManager::IncidentReport::IncidentReport() + :mTimestampNs(0), + mPrivacyPolicy(0), + mFileDescriptor(-1) { +} + +IncidentManager::IncidentReport::~IncidentReport() { + if (mFileDescriptor >= 0) { + close(mFileDescriptor); + } +} + +status_t IncidentManager::IncidentReport::writeToParcel(Parcel* out) const { + status_t err; + + err = out->writeInt64(mTimestampNs); + if (err != NO_ERROR) { + return err; + } + + + err = out->writeInt32(mPrivacyPolicy); + if (err != NO_ERROR) { + return err; + } + + if (mFileDescriptor >= 0) { + err = out->writeInt32(1); + if (err != NO_ERROR) { + return err; + } + + err = out->writeDupParcelFileDescriptor(mFileDescriptor); + if (err != NO_ERROR) { + return err; + } + + } else { + err = out->writeInt32(0); + if (err != NO_ERROR) { + return err; + } + } + + return NO_ERROR; +} + +status_t IncidentManager::IncidentReport::readFromParcel(const Parcel* in) { + status_t err; + int32_t hasField; + + err = in->readInt64(&mTimestampNs); + if (err != NO_ERROR) { + return err; + } + + err = in->readInt32(&mPrivacyPolicy); + if (err != NO_ERROR) { + return err; + } + + err = in->readInt32(&hasField); + if (err != NO_ERROR) { + return err; + } + + if (hasField) { + int fd = in->readParcelFileDescriptor(); + if (fd >= 0) { + mFileDescriptor = dup(fd); + if (mFileDescriptor < 0) { + return -errno; + } + } + } + + return NO_ERROR; +} + +status_t IncidentManager::IncidentReport::setFileDescriptor(int fd) { + if (mFileDescriptor >= 0) { + close(mFileDescriptor); + } + if (fd < 0) { + mFileDescriptor = -1; + } else { + mFileDescriptor = dup(fd); + if (mFileDescriptor < 0) { + return -errno; + } + } + return NO_ERROR; +} + +void IncidentManager::IncidentReport::takeFileDescriptor(int fd) { + if (mFileDescriptor >= 0) { + close(mFileDescriptor); + } + if (fd < 0) { + mFileDescriptor = -1; + } else { + mFileDescriptor = fd; + } +} + +// ============================================================ +IncidentManager::~IncidentManager() { +} + +} +} + + -- cgit v1.2.3-59-g8ed1b From c5eff42caa1195edf0403d07f63b81a9d64eac8b Mon Sep 17 00:00:00 2001 From: Abhijeet Kaur Date: Wed, 17 Apr 2019 16:00:09 +0100 Subject: Cancel outstanding user consent request When the end of bugreport generation is reached (i.e. bugreport has been created) but the user has not responded to the user consent dialogue, in that case we cancel the user consent request without copying the file over to the caller. Test: Tested by not replying to the user consent and checking the logs. Bug: 128982019 Merged-In: Idd8cd2a62977ad592db9caf3febe89dd9917203f Change-Id: Idd8cd2a62977ad592db9caf3febe89dd9917203f (cherry picked from commit 5762741b9fae99c2fd90fad0fbb708ee64a9c209) --- cmds/dumpstate/dumpstate.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'cmds/dumpstate/dumpstate.cpp') diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index 2cc1b3292a..671c788b1f 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -2697,7 +2697,15 @@ Dumpstate::RunStatus Dumpstate::RunInternal(int32_t calling_uid, MYLOGI( "Did not receive user consent yet." " Will not copy the bugreport artifacts to caller.\n"); - // TODO(b/111441001): cancel outstanding requests + const String16 incidentcompanion("incidentcompanion"); + sp ics(defaultServiceManager()->getService(incidentcompanion)); + if (ics != nullptr) { + MYLOGD("Canceling user consent request via incidentcompanion service\n"); + android::interface_cast(ics)->cancelAuthorization( + consent_callback_.get()); + } else { + MYLOGD("Unable to cancel user consent; incidentcompanion service unavailable\n"); + } } } -- cgit v1.2.3-59-g8ed1b From a325a5702b93efc68b34934498abb787d758f848 Mon Sep 17 00:00:00 2001 From: Nikita Ioffe Date: Thu, 16 May 2019 19:49:47 +0100 Subject: Add information about Module Metadata Version into bugreport header * In case device supports mainline, the following line will be added to the header of a bugreport: Module Metadata version: * Otherwise this line will be omitted. Test: adb bugreport /tmp/bugreports Bug: 131774400 Change-Id: I03f8c10039381cf788ff353893c82a9beaaaaca8 --- cmds/dumpstate/dumpstate.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'cmds/dumpstate/dumpstate.cpp') diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index 671c788b1f..31a1de03d9 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -50,9 +51,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -204,6 +207,30 @@ static bool IsFileEmpty(const std::string& file_path) { return file.tellg() <= 0; } +int64_t GetModuleMetadataVersion() { + auto binder = defaultServiceManager()->getService(android::String16("package_native")); + if (binder == nullptr) { + MYLOGE("Failed to retrieve package_native service"); + return 0L; + } + auto package_service = android::interface_cast(binder); + std::string package_name; + auto status = package_service->getModuleMetadataPackageName(&package_name); + if (!status.isOk()) { + MYLOGE("Failed to retrieve module metadata package name: %s", status.toString8().c_str()); + return 0L; + } + MYLOGD("Module metadata package name: %s", package_name.c_str()); + int64_t version_code; + status = package_service->getVersionCodeForPackage(android::String16(package_name.c_str()), + &version_code); + if (!status.isOk()) { + MYLOGE("Failed to retrieve module metadata version: %s", status.toString8().c_str()); + return 0L; + } + return version_code; +} + } // namespace } // namespace os } // namespace android @@ -741,6 +768,10 @@ void Dumpstate::PrintHeader() const { printf("Bootloader: %s\n", bootloader.c_str()); printf("Radio: %s\n", radio.c_str()); printf("Network: %s\n", network.c_str()); + int64_t module_metadata_version = android::os::GetModuleMetadataVersion(); + if (module_metadata_version != 0) { + printf("Module Metadata version: %" PRId64 "\n", module_metadata_version); + } printf("Kernel: "); DumpFileToFd(STDOUT_FILENO, "", "/proc/version"); -- cgit v1.2.3-59-g8ed1b From 313202c22495de938aeca949bbfed6eafd46838f Mon Sep 17 00:00:00 2001 From: Greg Kaiser Date: Thu, 16 May 2019 10:32:51 -0700 Subject: dumpstate: Increase timeout for lshal On some Android Go devices, this command takes more than 2 seconds to complete. We change the timeout to 10 to match the timeout for this !isZipping() case. Bug: 132891629 Test: Confirmed this command doesn't get killed during a bugreport on a Go device Merged-In: Ia707a80638fba25adb86618aac69e47aae6b75c0 Change-Id: Ia707a80638fba25adb86618aac69e47aae6b75c0 --- cmds/dumpstate/dumpstate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmds/dumpstate/dumpstate.cpp') diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index 671c788b1f..0c8b1aa55e 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -1232,7 +1232,7 @@ static void DumpHals() { } DurationReporter duration_reporter("DUMP HALS"); RunCommand("HARDWARE HALS", {"lshal", "-lVSietrpc", "--types=b,c,l,z"}, - CommandOptions::WithTimeout(2).AsRootIfAvailable().Build()); + CommandOptions::WithTimeout(10).AsRootIfAvailable().Build()); using android::hidl::manager::V1_0::IServiceManager; using android::hardware::defaultServiceManager; -- cgit v1.2.3-59-g8ed1b