Update Last ID early in the bugreport generation
The lifecycle of a bugreport triggered by Shell:
1. Triggers a bugreport using bugreport API. At this point shell does not
have any state of the bugreport. mBugreportInfos is the sparse array in
Shell that tracks bugreportInfos keyed with the ID. The ID of the
bugreport is currently incremented in RunInternal() which is called in a
different thread triggered by the DumpstateService (for an API call)
2. dumpstate calls one of the callbacks #onProgress, #onError and
#onFinished(), it is then that the corresponding bugreportinfo is
tracked in mBugreportInfos keyed with the ID.
Problem: Consider a case when 2 bugreports are triggered such that Shell
has not received #onProgress for the first one, and received #onError
for the second one. This results in a race condition as Shell assumes
that the first bugreport has called onError. This race condition occurs
due to the fact that Shell depends on the callback to track the
bugreports.
Solution: Update Id at a definite time (not in some other thread) in
Initialize so that the service calling the API can track it right away.
Bug: 152292912
Test: Tigger consecutive calls to bugreport from ActivityManager is WAI
Test: adb bugreport (open the finished bugreport and check that the
correct ID is shown)
Test: atest dumpstate_test
Change-Id: I63966800725d2aaa1d1d9d6eb997b86d564acf44
diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h
index 9ce662b..498f338 100644
--- a/cmds/dumpstate/dumpstate.h
+++ b/cmds/dumpstate/dumpstate.h
@@ -216,6 +216,9 @@
/* Checkes whether dumpstate is generating a zipped bugreport. */
bool IsZipping() const;
+ /* Initialize dumpstate fields before starting bugreport generation */
+ void Initialize();
+
/*
* Forks a command, waits for it to finish, and returns its status.
*
@@ -329,7 +332,12 @@
struct DumpOptions;
- /* Main entry point for running a complete bugreport. */
+ /*
+ * Main entry point for running a complete bugreport.
+ *
+ * Initialize() dumpstate before calling this method.
+ *
+ */
RunStatus Run(int32_t calling_uid, const std::string& calling_package);
RunStatus ParseCommandlineAndRun(int argc, char* argv[]);