Accept a file descriptor to write bugreport file

This will be used via the bugreporting api.

Changed dumpstate to do bugreport generation in its own directory
in the beginning and to copy over to the destination fd or directory
at the very end.

BUG: 111441001
Test: adb bugreport
Test: adb shell /data/nativetest64/dumpstate_test/dumpstate_test
Test: interactive bugreport
Change-Id: I83e24f0989a202e84266b6e0fdf8edc14ea639bf
diff --git a/cmds/dumpstate/utils.cpp b/cmds/dumpstate/utils.cpp
index 6cbb691..d97ffbf 100644
--- a/cmds/dumpstate/utils.cpp
+++ b/cmds/dumpstate/utils.cpp
@@ -229,7 +229,11 @@
 }
 
 std::string Dumpstate::GetPath(const std::string& suffix) const {
-    return android::base::StringPrintf("%s/%s-%s%s", bugreport_dir_.c_str(), base_name_.c_str(),
+    return GetPath(bugreport_internal_dir_, suffix);
+}
+
+std::string Dumpstate::GetPath(const std::string& directory, const std::string& suffix) const {
+    return android::base::StringPrintf("%s/%s-%s%s", directory.c_str(), base_name_.c_str(),
                                        name_.c_str(), suffix.c_str());
 }