Skip to content

Commit 17be590

Browse files
delphijGerrit Code Review
authored andcommitted
Merge "Merge Android 14 QPR2 to AOSP main" into main
2 parents 3ef8cc8 + df7e621 commit 17be590

782 files changed

Lines changed: 45574 additions & 23715 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmds/dumpstate/Android.bp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ cc_defaults {
104104
"libvintf",
105105
"libbinderdebug",
106106
"packagemanager_aidl-cpp",
107+
"server_configurable_flags",
108+
"device_policy_aconfig_flags_c_lib",
107109
],
108110
srcs: [
109111
"DumpstateService.cpp",

cmds/dumpstate/DumpstateService.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ struct DumpstateInfo {
3737
Dumpstate* ds = nullptr;
3838
int32_t calling_uid = -1;
3939
std::string calling_package;
40+
int32_t user_id = -1;
41+
bool keep_bugreport_on_retrieval = false;
4042
};
4143

4244
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,
6062

6163
[[noreturn]] static void* dumpstate_thread_retrieve(void* data) {
6264
std::unique_ptr<DumpstateInfo> ds_info(static_cast<DumpstateInfo*>(data));
63-
ds_info->ds->Retrieve(ds_info->calling_uid, ds_info->calling_package);
65+
ds_info->ds->Retrieve(ds_info->calling_uid, ds_info->calling_package, ds_info->keep_bugreport_on_retrieval);
6466
MYLOGD("Finished retrieving a bugreport. Exiting.\n");
6567
exit(0);
6668
}
@@ -141,6 +143,7 @@ binder::Status DumpstateService::startBugreport(int32_t calling_uid,
141143
bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_WEAR &&
142144
bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_TELEPHONY &&
143145
bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_WIFI &&
146+
bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_ONBOARDING &&
144147
bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_DEFAULT) {
145148
MYLOGE("Invalid input: bad bugreport mode: %d", bugreport_mode);
146149
signalErrorAndExit(listener, IDumpstateListener::BUGREPORT_ERROR_INVALID_INPUT);
@@ -200,16 +203,19 @@ binder::Status DumpstateService::cancelBugreport(int32_t calling_uid,
200203
}
201204

202205
binder::Status DumpstateService::retrieveBugreport(
203-
int32_t calling_uid, const std::string& calling_package,
206+
int32_t calling_uid, const std::string& calling_package, int32_t user_id,
204207
android::base::unique_fd bugreport_fd,
205208
const std::string& bugreport_file,
209+
const bool keep_bugreport_on_retrieval,
206210
const sp<IDumpstateListener>& listener) {
207211

208212
ds_ = &(Dumpstate::GetInstance());
209213
DumpstateInfo* ds_info = new DumpstateInfo();
210214
ds_info->ds = ds_;
211215
ds_info->calling_uid = calling_uid;
212216
ds_info->calling_package = calling_package;
217+
ds_info->user_id = user_id;
218+
ds_info->keep_bugreport_on_retrieval = keep_bugreport_on_retrieval;
213219
ds_->listener_ = listener;
214220
std::unique_ptr<Dumpstate::DumpOptions> options = std::make_unique<Dumpstate::DumpOptions>();
215221
// Use a /dev/null FD when initializing options since none is provided.

cmds/dumpstate/DumpstateService.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ class DumpstateService : public BinderService<DumpstateService>, public BnDumpst
4848

4949
binder::Status retrieveBugreport(int32_t calling_uid,
5050
const std::string& calling_package,
51+
int32_t user_id,
5152
android::base::unique_fd bugreport_fd,
5253
const std::string& bugreport_file,
54+
const bool keep_bugreport_on_retrieval,
5355
const sp<IDumpstateListener>& listener)
5456
override;
5557

cmds/dumpstate/binder/android/os/IDumpstate.aidl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,18 @@ interface IDumpstate {
4949
// Default mode.
5050
const int BUGREPORT_MODE_DEFAULT = 6;
5151

52+
// Bugreport taken for onboarding related flows.
53+
const int BUGREPORT_MODE_ONBOARDING = 7;
54+
5255
// Use pre-dumped data.
5356
const int BUGREPORT_FLAG_USE_PREDUMPED_UI_DATA = 0x1;
5457

5558
// Defer user consent.
5659
const int BUGREPORT_FLAG_DEFER_CONSENT = 0x2;
5760

61+
// Keep bugreport stored after retrieval.
62+
const int BUGREPORT_FLAG_KEEP_BUGREPORT_ON_RETRIEVAL = 0x4;
63+
5864
/**
5965
* Speculatively pre-dumps UI data for a bugreport request that might come later.
6066
*
@@ -113,12 +119,16 @@ interface IDumpstate {
113119
*
114120
* @param callingUid UID of the original application that requested the report.
115121
* @param callingPackage package of the original application that requested the report.
122+
* @param userId user Id of the original package that requested the report.
116123
* @param bugreportFd the file to which the zipped bugreport should be written
117124
* @param bugreportFile the path of the bugreport file
125+
* @param keepBugreportOnRetrieval boolean to indicate if the bugreport should be kept in the
126+
* platform after it has been retrieved by the caller.
118127
* @param listener callback for updates; optional
119128
*/
120-
void retrieveBugreport(int callingUid, @utf8InCpp String callingPackage,
129+
void retrieveBugreport(int callingUid, @utf8InCpp String callingPackage, int userId,
121130
FileDescriptor bugreportFd,
122131
@utf8InCpp String bugreportFile,
132+
boolean keepBugreportOnRetrieval,
123133
IDumpstateListener listener);
124134
}

cmds/dumpstate/dumpstate.cpp

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include <vector>
6060

6161
#include <aidl/android/hardware/dumpstate/IDumpstateDevice.h>
62+
#include <android_app_admin_flags.h>
6263
#include <android-base/file.h>
6364
#include <android-base/properties.h>
6465
#include <android-base/scopeguard.h>
@@ -1088,8 +1089,14 @@ static void MaybeAddSystemTraceToZip() {
10881089
// This function copies into the .zip the system trace that was snapshotted
10891090
// by the early call to MaybeSnapshotSystemTrace(), if any background
10901091
// tracing was happening.
1091-
if (!ds.has_system_trace_) {
1092-
// No background trace was happening at the time dumpstate was invoked.
1092+
bool system_trace_exists = access(SYSTEM_TRACE_SNAPSHOT, F_OK) == 0;
1093+
if (!system_trace_exists) {
1094+
// No background trace was happening at the time MaybeSnapshotSystemTrace() was invoked.
1095+
if (!PropertiesHelper::IsUserBuild()) {
1096+
MYLOGI(
1097+
"No system traces found. Check for previously uploaded traces by looking for "
1098+
"go/trace-uuid in logcat")
1099+
}
10931100
return;
10941101
}
10951102
ds.AddZipEntry(
@@ -1653,8 +1660,6 @@ Dumpstate::RunStatus Dumpstate::dumpstate() {
16531660
dump_board = ds.dump_pool_->enqueueTaskWithFd(
16541661
DUMP_BOARD_TASK, &Dumpstate::DumpstateBoard, &ds, _1);
16551662
dump_checkins = ds.dump_pool_->enqueueTaskWithFd(DUMP_CHECKINS_TASK, &DumpCheckins, _1);
1656-
post_process_ui_traces = ds.dump_pool_->enqueueTask(
1657-
POST_PROCESS_UI_TRACES_TASK, &Dumpstate::MaybePostProcessUiTraces, &ds);
16581663
}
16591664

16601665
// Dump various things. Note that anything that takes "long" (i.e. several seconds) should
@@ -1864,12 +1869,6 @@ Dumpstate::RunStatus Dumpstate::dumpstate() {
18641869
DumpIncidentReport);
18651870
}
18661871

1867-
if (ds.dump_pool_) {
1868-
WaitForTask(std::move(post_process_ui_traces));
1869-
} else {
1870-
RUN_SLOW_FUNCTION_AND_LOG(POST_PROCESS_UI_TRACES_TASK, MaybePostProcessUiTraces);
1871-
}
1872-
18731872
MaybeAddUiTracesToZip();
18741873

18751874
return Dumpstate::RunStatus::OK;
@@ -2178,6 +2177,11 @@ static void DumpstateWifiOnly() {
21782177
printf("========================================================\n");
21792178
}
21802179

2180+
// Collects a lightweight dumpstate to be used for debugging onboarding related flows.
2181+
static void DumpstateOnboardingOnly() {
2182+
ds.AddDir(LOGPERSIST_DATA_DIR, false);
2183+
}
2184+
21812185
Dumpstate::RunStatus Dumpstate::DumpTraces(const char** path) {
21822186
const std::string temp_file_pattern = ds.bugreport_internal_dir_ + "/dumptrace_XXXXXX";
21832187
const size_t buf_size = temp_file_pattern.length() + 1;
@@ -2310,6 +2314,7 @@ static dumpstate_hal_hidl::DumpstateMode GetDumpstateHalModeHidl(
23102314
return dumpstate_hal_hidl::DumpstateMode::CONNECTIVITY;
23112315
case Dumpstate::BugreportMode::BUGREPORT_WIFI:
23122316
return dumpstate_hal_hidl::DumpstateMode::WIFI;
2317+
case Dumpstate::BugreportMode::BUGREPORT_ONBOARDING:
23132318
case Dumpstate::BugreportMode::BUGREPORT_DEFAULT:
23142319
return dumpstate_hal_hidl::DumpstateMode::DEFAULT;
23152320
}
@@ -2331,6 +2336,7 @@ static dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode GetDumpstateHalModeAi
23312336
return dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode::CONNECTIVITY;
23322337
case Dumpstate::BugreportMode::BUGREPORT_WIFI:
23332338
return dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode::WIFI;
2339+
case Dumpstate::BugreportMode::BUGREPORT_ONBOARDING:
23342340
case Dumpstate::BugreportMode::BUGREPORT_DEFAULT:
23352341
return dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode::DEFAULT;
23362342
}
@@ -2814,6 +2820,8 @@ static inline const char* ModeToString(Dumpstate::BugreportMode mode) {
28142820
return "BUGREPORT_TELEPHONY";
28152821
case Dumpstate::BugreportMode::BUGREPORT_WIFI:
28162822
return "BUGREPORT_WIFI";
2823+
case Dumpstate::BugreportMode::BUGREPORT_ONBOARDING:
2824+
return "BUGREPORT_ONBOARDING";
28172825
case Dumpstate::BugreportMode::BUGREPORT_DEFAULT:
28182826
return "BUGREPORT_DEFAULT";
28192827
}
@@ -2859,6 +2867,10 @@ static void SetOptionsFromMode(Dumpstate::BugreportMode mode, Dumpstate::DumpOpt
28592867
options->wifi_only = true;
28602868
options->do_screenshot = false;
28612869
break;
2870+
case Dumpstate::BugreportMode::BUGREPORT_ONBOARDING:
2871+
options->onboarding_only = true;
2872+
options->do_screenshot = false;
2873+
break;
28622874
case Dumpstate::BugreportMode::BUGREPORT_DEFAULT:
28632875
break;
28642876
}
@@ -2971,14 +2983,17 @@ Dumpstate::RunStatus Dumpstate::Run(int32_t calling_uid, const std::string& call
29712983
return status;
29722984
}
29732985

2974-
Dumpstate::RunStatus Dumpstate::Retrieve(int32_t calling_uid, const std::string& calling_package) {
2975-
Dumpstate::RunStatus status = RetrieveInternal(calling_uid, calling_package);
2986+
Dumpstate::RunStatus Dumpstate::Retrieve(int32_t calling_uid, const std::string& calling_package,
2987+
const bool keep_bugreport_on_retrieval) {
2988+
Dumpstate::RunStatus status = RetrieveInternal(calling_uid, calling_package,
2989+
keep_bugreport_on_retrieval);
29762990
HandleRunStatus(status);
29772991
return status;
29782992
}
29792993

29802994
Dumpstate::RunStatus Dumpstate::RetrieveInternal(int32_t calling_uid,
2981-
const std::string& calling_package) {
2995+
const std::string& calling_package,
2996+
const bool keep_bugreport_on_retrieval) {
29822997
consent_callback_ = new ConsentCallback();
29832998
const String16 incidentcompanion("incidentcompanion");
29842999
sp<android::IBinder> ics(
@@ -3013,9 +3028,12 @@ Dumpstate::RunStatus Dumpstate::RetrieveInternal(int32_t calling_uid,
30133028

30143029
bool copy_succeeded =
30153030
android::os::CopyFileToFd(path_, options_->bugreport_fd.get());
3016-
if (copy_succeeded) {
3017-
android::os::UnlinkAndLogOnError(path_);
3031+
3032+
if (copy_succeeded && (!android::app::admin::flags::onboarding_bugreport_v2_enabled()
3033+
|| !keep_bugreport_on_retrieval)) {
3034+
android::os::UnlinkAndLogOnError(path_);
30183035
}
3036+
30193037
return copy_succeeded ? Dumpstate::RunStatus::OK
30203038
: Dumpstate::RunStatus::ERROR;
30213039
}
@@ -3066,6 +3084,7 @@ void Dumpstate::Cancel() {
30663084
}
30673085

30683086
void Dumpstate::PreDumpUiData() {
3087+
MaybeSnapshotSystemTrace();
30693088
MaybeSnapshotUiTraces();
30703089
}
30713090

@@ -3252,25 +3271,23 @@ Dumpstate::RunStatus Dumpstate::RunInternal(int32_t calling_uid,
32523271
// duration is logged into MYLOG instead.
32533272
PrintHeader();
32543273

3255-
bool is_dumpstate_restricted = options_->telephony_only
3256-
|| options_->wifi_only
3257-
|| options_->limited_only;
3258-
if (!is_dumpstate_restricted) {
3259-
// Invoke critical dumpsys first to preserve system state, before doing anything else.
3260-
RunDumpsysCritical();
3261-
}
3262-
MaybeTakeEarlyScreenshot();
3263-
3274+
bool is_dumpstate_restricted =
3275+
options_->telephony_only || options_->wifi_only || options_->limited_only;
32643276
if (!is_dumpstate_restricted) {
32653277
// Snapshot the system trace now (if running) to avoid that dumpstate's
32663278
// own activity pushes out interesting data from the trace ring buffer.
32673279
// The trace file is added to the zip by MaybeAddSystemTraceToZip().
32683280
MaybeSnapshotSystemTrace();
32693281

3282+
// Invoke critical dumpsys to preserve system state, before doing anything else.
3283+
RunDumpsysCritical();
3284+
32703285
// Snapshot the UI traces now (if running).
32713286
// The trace files will be added to bugreport later.
32723287
MaybeSnapshotUiTraces();
32733288
}
3289+
3290+
MaybeTakeEarlyScreenshot();
32743291
onUiIntensiveBugreportDumpsFinished(calling_uid);
32753292
MaybeCheckUserConsent(calling_uid, calling_package);
32763293
if (options_->telephony_only) {
@@ -3279,6 +3296,8 @@ Dumpstate::RunStatus Dumpstate::RunInternal(int32_t calling_uid,
32793296
DumpstateWifiOnly();
32803297
} else if (options_->limited_only) {
32813298
DumpstateLimitedOnly();
3299+
} else if (options_->onboarding_only) {
3300+
DumpstateOnboardingOnly();
32823301
} else {
32833302
// Dump state for the default case. This also drops root.
32843303
RunStatus s = DumpstateDefaultAfterCritical();
@@ -3366,21 +3385,28 @@ void Dumpstate::MaybeTakeEarlyScreenshot() {
33663385
}
33673386

33683387
void Dumpstate::MaybeSnapshotSystemTrace() {
3388+
// When capturing traces via bugreport handler (BH), this function will be invoked twice:
3389+
// 1) When BH invokes IDumpstate::PreDumpUiData()
3390+
// 2) When BH invokes IDumpstate::startBugreport(flags = BUGREPORT_USE_PREDUMPED_UI_DATA)
3391+
// In this case we don't want to re-invoke perfetto in step 2.
3392+
// In all other standard invocation states, this function is invoked once
3393+
// without the flag BUGREPORT_USE_PREDUMPED_UI_DATA.
3394+
if (options_->use_predumped_ui_data) {
3395+
return;
3396+
}
3397+
3398+
// If a stale file exists already, remove it.
3399+
unlink(SYSTEM_TRACE_SNAPSHOT);
3400+
33693401
// If a background system trace is happening and is marked as "suitable for
33703402
// bugreport" (i.e. bugreport_score > 0 in the trace config), this command
33713403
// will stop it and serialize into SYSTEM_TRACE_SNAPSHOT. In the (likely)
33723404
// case that no trace is ongoing, this command is a no-op.
33733405
// Note: this should not be enqueued as we need to freeze the trace before
33743406
// dumpstate starts. Otherwise the trace ring buffers will contain mostly
33753407
// the dumpstate's own activity which is irrelevant.
3376-
int res = RunCommand(
3377-
"SERIALIZE PERFETTO TRACE",
3378-
{"perfetto", "--save-for-bugreport"},
3379-
CommandOptions::WithTimeout(10)
3380-
.DropRoot()
3381-
.CloseAllFileDescriptorsOnExec()
3382-
.Build());
3383-
has_system_trace_ = res == 0;
3408+
RunCommand("SERIALIZE PERFETTO TRACE", {"perfetto", "--save-for-bugreport"},
3409+
CommandOptions::WithTimeout(10).DropRoot().CloseAllFileDescriptorsOnExec().Build());
33843410
// MaybeAddSystemTraceToZip() will take care of copying the trace in the zip
33853411
// file in the later stages.
33863412
}
@@ -3407,33 +3433,6 @@ void Dumpstate::MaybeSnapshotUiTraces() {
34073433
"", command,
34083434
CommandOptions::WithTimeout(10).Always().DropRoot().RedirectStderr().Build());
34093435
}
3410-
3411-
// This command needs to be run as root
3412-
static const auto SURFACEFLINGER_COMMAND_SAVE_ALL_TRACES = std::vector<std::string> {
3413-
"service", "call", "SurfaceFlinger", "1042"
3414-
};
3415-
// Empty name because it's not intended to be classified as a bugreport section.
3416-
// Actual tracing files can be found in "/data/misc/wmtrace/" in the bugreport.
3417-
RunCommand(
3418-
"", SURFACEFLINGER_COMMAND_SAVE_ALL_TRACES,
3419-
CommandOptions::WithTimeout(10).Always().AsRoot().RedirectStderr().Build());
3420-
}
3421-
3422-
void Dumpstate::MaybePostProcessUiTraces() {
3423-
if (PropertiesHelper::IsUserBuild()) {
3424-
return;
3425-
}
3426-
3427-
RunCommand(
3428-
// Empty name because it's not intended to be classified as a bugreport section.
3429-
// Actual tracing files can be found in "/data/misc/wmtrace/" in the bugreport.
3430-
"", {
3431-
"/system/xbin/su", "system",
3432-
"/system/bin/layertracegenerator",
3433-
"/data/misc/wmtrace/transactions_trace.winscope",
3434-
"/data/misc/wmtrace/layers_trace_from_transactions.winscope"
3435-
},
3436-
CommandOptions::WithTimeout(120).Always().RedirectStderr().Build());
34373436
}
34383437

34393438
void Dumpstate::MaybeAddUiTracesToZip() {

0 commit comments

Comments
 (0)