From 12e43443ab9f09b0ddc250c40b3da22218ab3cec Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 26 Jul 2018 10:47:40 +0100 Subject: [PATCH] Shut down adb when closing qrenderdoc if it's our adb * This has some possible problems - e.g. if one copy of qrenderdoc is closed and kills the server used by another copy. However it seems impossible to reliably manage adb and we need to ensure we don't leave the process lingering around. * At the moment 95% of users don't use android, so it's most important that they have a smooth experience. * This was the cause of problems around updating versions because adb.exe would hang around and then be 'in use' and not able to be overwritten. --- qrenderdoc/Code/qrenderdoc.cpp | 2 ++ renderdoc/android/android.cpp | 5 +++++ renderdoc/android/android.h | 1 + renderdoc/android/android_tools.cpp | 14 ++++++++++++++ renderdoc/api/replay/renderdoc_replay.h | 3 +++ 5 files changed, 25 insertions(+) diff --git a/qrenderdoc/Code/qrenderdoc.cpp b/qrenderdoc/Code/qrenderdoc.cpp index cc928cff1..0417fb705 100644 --- a/qrenderdoc/Code/qrenderdoc.cpp +++ b/qrenderdoc/Code/qrenderdoc.cpp @@ -431,6 +431,8 @@ int main(int argc, char *argv[]) config.Save(); } + RENDERDOC_AndroidShutdown(); + PythonContext::GlobalShutdown(); Formatter::shutdown(); diff --git a/renderdoc/android/android.cpp b/renderdoc/android/android.cpp index 8b8cb6c71..4e1e13787 100644 --- a/renderdoc/android/android.cpp +++ b/renderdoc/android/android.cpp @@ -577,6 +577,11 @@ extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_EnumerateAndroidDevices(rdc *deviceList = ret; } +extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_AndroidShutdown() +{ + Android::shutdownAdb(); +} + extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_StartAndroidRemoteServer(const char *device) { int index = 0; diff --git a/renderdoc/android/android.h b/renderdoc/android/android.h index 05c98d05c..a196cdf4b 100644 --- a/renderdoc/android/android.h +++ b/renderdoc/android/android.h @@ -37,5 +37,6 @@ void ResetCaptureSettings(const std::string &deviceID); void ExtractDeviceIDAndIndex(const std::string &hostname, int &index, std::string &deviceID); Process::ProcessResult adbExecCommand(const std::string &deviceID, const std::string &args, const string &workDir = ".", bool silent = false); +void shutdownAdb(); bool InjectWithJDWP(const std::string &deviceID, uint16_t jdwpport); }; diff --git a/renderdoc/android/android_tools.cpp b/renderdoc/android/android_tools.cpp index c9d231c50..ee88a8bcc 100644 --- a/renderdoc/android/android_tools.cpp +++ b/renderdoc/android/android_tools.cpp @@ -28,6 +28,7 @@ namespace Android { +static bool adbKillServer = false; bool toolExists(const std::string &path) { if(path.empty()) @@ -254,7 +255,15 @@ std::string getToolPath(ToolDir subdir, const std::string &toolname, bool checkE toolpath = exedir + "/plugins/android/" + toolname; if(toolExists(toolpath)) + { + if(toolname == "adb") + { + // if we're using our own adb, we should kill the server upon shutdown + adbKillServer = true; + } + return toolpath; + } } toolpath = ""; @@ -298,4 +307,9 @@ Process::ProcessResult adbExecCommand(const std::string &device, const std::stri deviceArgs = StringFormat::Fmt("-s %s %s", device.c_str(), args.c_str()); return execCommand(adb, deviceArgs, workDir, silent); } +void shutdownAdb() +{ + if(adbKillServer) + adbExecCommand("", "kill-server", ".", false); +} }; diff --git a/renderdoc/api/replay/renderdoc_replay.h b/renderdoc/api/replay/renderdoc_replay.h index 1fd19cca4..1b726a5b6 100644 --- a/renderdoc/api/replay/renderdoc_replay.h +++ b/renderdoc/api/replay/renderdoc_replay.h @@ -2135,6 +2135,9 @@ extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_GetAndroidFriendlyName(cons DOCUMENT("Internal function for enumerating android devices."); extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_EnumerateAndroidDevices(rdcstr *deviceList); +DOCUMENT("Internal function for shutting down android use."); +extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_AndroidShutdown(); + DOCUMENT("Internal function for starting an android remote server."); extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_StartAndroidRemoteServer(const char *device);