diff options
| author | 2023-10-27 09:36:07 +0000 | |
|---|---|---|
| committer | 2023-10-27 09:36:07 +0000 | |
| commit | 74f05b4a1be2e9571a8d8857c10e98b927a7de93 (patch) | |
| tree | 5e0cb3d96545183a300769fe9fb838c2267f0c1e | |
| parent | a514bec30aeafde9d56a338b3aac590c572705d9 (diff) | |
| parent | 7c3fb7c74c1b070dbc3f1865f23c94b540354574 (diff) | |
Merge "Add ability to retrieve bugreport multiple times" into main
| -rw-r--r-- | cmds/dumpstate/Android.bp | 2 | ||||
| -rw-r--r-- | cmds/dumpstate/DumpstateService.cpp | 9 | ||||
| -rw-r--r-- | cmds/dumpstate/DumpstateService.h | 2 | ||||
| -rw-r--r-- | cmds/dumpstate/binder/android/os/IDumpstate.aidl | 9 | ||||
| -rw-r--r-- | cmds/dumpstate/dumpstate.cpp | 17 | ||||
| -rw-r--r-- | cmds/dumpstate/dumpstate.h | 10 |
6 files changed, 38 insertions, 11 deletions
diff --git a/cmds/dumpstate/Android.bp b/cmds/dumpstate/Android.bp index 860a2d82e6..23f185e305 100644 --- a/cmds/dumpstate/Android.bp +++ b/cmds/dumpstate/Android.bp @@ -104,6 +104,8 @@ cc_defaults { "libvintf", "libbinderdebug", "packagemanager_aidl-cpp", + "server_configurable_flags", + "device_policy_aconfig_flags_c_lib", ], srcs: [ "DumpstateService.cpp", diff --git a/cmds/dumpstate/DumpstateService.cpp b/cmds/dumpstate/DumpstateService.cpp index c787113765..ba0a38aad9 100644 --- a/cmds/dumpstate/DumpstateService.cpp +++ b/cmds/dumpstate/DumpstateService.cpp @@ -37,6 +37,8 @@ struct DumpstateInfo { Dumpstate* ds = nullptr; int32_t calling_uid = -1; std::string calling_package; + int32_t user_id = -1; + bool keep_bugreport_on_retrieval = false; }; static binder::Status exception(uint32_t code, const std::string& msg, @@ -60,7 +62,7 @@ static binder::Status exception(uint32_t code, const std::string& msg, [[noreturn]] static void* dumpstate_thread_retrieve(void* data) { std::unique_ptr<DumpstateInfo> ds_info(static_cast<DumpstateInfo*>(data)); - ds_info->ds->Retrieve(ds_info->calling_uid, ds_info->calling_package); + ds_info->ds->Retrieve(ds_info->calling_uid, ds_info->calling_package, ds_info->keep_bugreport_on_retrieval); MYLOGD("Finished retrieving a bugreport. Exiting.\n"); exit(0); } @@ -201,9 +203,10 @@ binder::Status DumpstateService::cancelBugreport(int32_t calling_uid, } binder::Status DumpstateService::retrieveBugreport( - int32_t calling_uid, const std::string& calling_package, + int32_t calling_uid, const std::string& calling_package, int32_t user_id, android::base::unique_fd bugreport_fd, const std::string& bugreport_file, + const bool keep_bugreport_on_retrieval, const sp<IDumpstateListener>& listener) { ds_ = &(Dumpstate::GetInstance()); @@ -211,6 +214,8 @@ binder::Status DumpstateService::retrieveBugreport( ds_info->ds = ds_; ds_info->calling_uid = calling_uid; ds_info->calling_package = calling_package; + ds_info->user_id = user_id; + ds_info->keep_bugreport_on_retrieval = keep_bugreport_on_retrieval; ds_->listener_ = listener; std::unique_ptr<Dumpstate::DumpOptions> options = std::make_unique<Dumpstate::DumpOptions>(); // Use a /dev/null FD when initializing options since none is provided. diff --git a/cmds/dumpstate/DumpstateService.h b/cmds/dumpstate/DumpstateService.h index dd7331932c..7b76c36380 100644 --- a/cmds/dumpstate/DumpstateService.h +++ b/cmds/dumpstate/DumpstateService.h @@ -48,8 +48,10 @@ class DumpstateService : public BinderService<DumpstateService>, public BnDumpst binder::Status retrieveBugreport(int32_t calling_uid, const std::string& calling_package, + int32_t user_id, android::base::unique_fd bugreport_fd, const std::string& bugreport_file, + const bool keep_bugreport_on_retrieval, const sp<IDumpstateListener>& listener) override; diff --git a/cmds/dumpstate/binder/android/os/IDumpstate.aidl b/cmds/dumpstate/binder/android/os/IDumpstate.aidl index fa9bcf351c..97c470e08c 100644 --- a/cmds/dumpstate/binder/android/os/IDumpstate.aidl +++ b/cmds/dumpstate/binder/android/os/IDumpstate.aidl @@ -58,6 +58,9 @@ interface IDumpstate { // Defer user consent. const int BUGREPORT_FLAG_DEFER_CONSENT = 0x2; + // Keep bugreport stored after retrieval. + const int BUGREPORT_FLAG_KEEP_BUGREPORT_ON_RETRIEVAL = 0x4; + /** * Speculatively pre-dumps UI data for a bugreport request that might come later. * @@ -116,12 +119,16 @@ interface IDumpstate { * * @param callingUid UID of the original application that requested the report. * @param callingPackage package of the original application that requested the report. + * @param userId user Id of the original package that requested the report. * @param bugreportFd the file to which the zipped bugreport should be written * @param bugreportFile the path of the bugreport file + * @param keepBugreportOnRetrieval boolean to indicate if the bugreport should be kept in the + * platform after it has been retrieved by the caller. * @param listener callback for updates; optional */ - void retrieveBugreport(int callingUid, @utf8InCpp String callingPackage, + void retrieveBugreport(int callingUid, @utf8InCpp String callingPackage, int userId, FileDescriptor bugreportFd, @utf8InCpp String bugreportFile, + boolean keepBugreportOnRetrieval, IDumpstateListener listener); } diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index 33f6d38cc6..4f80190954 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -59,6 +59,7 @@ #include <vector> #include <aidl/android/hardware/dumpstate/IDumpstateDevice.h> +#include <android_app_admin_flags.h> #include <android-base/file.h> #include <android-base/properties.h> #include <android-base/scopeguard.h> @@ -2977,14 +2978,17 @@ Dumpstate::RunStatus Dumpstate::Run(int32_t calling_uid, const std::string& call return status; } -Dumpstate::RunStatus Dumpstate::Retrieve(int32_t calling_uid, const std::string& calling_package) { - Dumpstate::RunStatus status = RetrieveInternal(calling_uid, calling_package); +Dumpstate::RunStatus Dumpstate::Retrieve(int32_t calling_uid, const std::string& calling_package, + const bool keep_bugreport_on_retrieval) { + Dumpstate::RunStatus status = RetrieveInternal(calling_uid, calling_package, + keep_bugreport_on_retrieval); HandleRunStatus(status); return status; } Dumpstate::RunStatus Dumpstate::RetrieveInternal(int32_t calling_uid, - const std::string& calling_package) { + const std::string& calling_package, + const bool keep_bugreport_on_retrieval) { consent_callback_ = new ConsentCallback(); const String16 incidentcompanion("incidentcompanion"); sp<android::IBinder> ics( @@ -3019,9 +3023,12 @@ Dumpstate::RunStatus Dumpstate::RetrieveInternal(int32_t calling_uid, bool copy_succeeded = android::os::CopyFileToFd(path_, options_->bugreport_fd.get()); - if (copy_succeeded) { - android::os::UnlinkAndLogOnError(path_); + + if (copy_succeeded && (!android::app::admin::flags::onboarding_bugreport_v2_enabled() + || !keep_bugreport_on_retrieval)) { + android::os::UnlinkAndLogOnError(path_); } + return copy_succeeded ? Dumpstate::RunStatus::OK : Dumpstate::RunStatus::ERROR; } diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h index 0a032ecfc3..d01cfcef4d 100644 --- a/cmds/dumpstate/dumpstate.h +++ b/cmds/dumpstate/dumpstate.h @@ -210,7 +210,9 @@ class Dumpstate { BUGREPORT_USE_PREDUMPED_UI_DATA = android::os::IDumpstate::BUGREPORT_FLAG_USE_PREDUMPED_UI_DATA, BUGREPORT_FLAG_DEFER_CONSENT = - android::os::IDumpstate::BUGREPORT_FLAG_DEFER_CONSENT + android::os::IDumpstate::BUGREPORT_FLAG_DEFER_CONSENT, + BUGREPORT_FLAG_KEEP_BUGREPORT_ON_RETRIEVAL = + android::os::IDumpstate::BUGREPORT_FLAG_KEEP_BUGREPORT_ON_RETRIEVAL }; static android::os::dumpstate::CommandOptions DEFAULT_DUMPSYS; @@ -361,7 +363,8 @@ class Dumpstate { * * Initialize() dumpstate before calling this method. */ - RunStatus Retrieve(int32_t calling_uid, const std::string& calling_package); + RunStatus Retrieve(int32_t calling_uid, const std::string& calling_package, + const bool keep_bugreport_on_retrieval); @@ -562,7 +565,8 @@ class Dumpstate { private: RunStatus RunInternal(int32_t calling_uid, const std::string& calling_package); - RunStatus RetrieveInternal(int32_t calling_uid, const std::string& calling_package); + RunStatus RetrieveInternal(int32_t calling_uid, const std::string& calling_package, + const bool keep_bugreport_on_retrieval); RunStatus DumpstateDefaultAfterCritical(); RunStatus dumpstate(); |