48 Commits

Author SHA1 Message Date
Yao Chen
318296726d Increase the size limit of incident reports.
Bug: 133425862
Test: incidentd_test
Change-Id: I323878958a93e0280b782de1745ed59e44f79b0b
2019-05-23 21:31:25 +00:00
Yao Chen
a51f3fa6fe Remove encryption from incidentd
Test: build
Bug: 131371777

Change-Id: I412c73658025246004412f3bcdcf30f74d766326
2019-04-30 11:51:24 -07:00
Joe Onorato
e547205eec Get incidentd cts working again.
- The buffer size increased, and the CTS test that checked that
  was triggering.
- Privacy filtering wasn't working for the stack trace sections
- The incident command was not handling the default arguments correctly
- The throttler was throttling streaming reports, which made the
  test flaky.

Bug: 126253679
Test: atest CtsIncidentHostTestCases
Change-Id: I342cd7d0421ea8c22b7796fc99e779f21855af73
2019-04-26 17:44:10 -07:00
Yao Chen
43706b4470 Add encryption in incidentd.
+ Sections which require encryption will be encryted on disk.

+ When the sections are requested by clients (e.g., permission controller, report assignee),
  incidentd will decrypte the data.

+ For efficiency, encryption is done ONLY for sections that require encryption.

+ Use Keystore API for key management.

Bug: 131084614
Test: incidentd_test
Change-Id: I84d6b86807ba5bbde1051e847b2df6e79e6b5be5
2019-04-23 15:20:38 -07:00
Yao Chen
9f433c8509 Fix a bug in ProtoFileReader.
Classic and consuming

Bug: 131037240
Test: unit test added in incidentd_test
Change-Id: I9200122ed35e874ef453eb12adc7fbf28c22003e
2019-04-21 20:10:27 -07:00
Joe Onorato
99598ee6ee incidentd can now handle multiple callers asking it for incident reports
Test: bit incident_test:* GtsIncidentManagerTestCases:*
Bug: 123543706
Change-Id: I9f671dd5d8b2ad139f952a23e575c2be16120459
2019-03-26 11:20:48 -07:00
Yao Chen
ec216489fc Remove the IncidentHeaderProto dependency from statsd.
+ IncidentReportArgs takes the bytes instead of IncidentHeaderProto object

This cl is the ag/6287053 + build fix.

Test: incidentd_test && statsd_test
Change-Id: I86bcb48f4ab212b36ca4611a1fa05faace9c3702
2019-02-07 09:45:13 -08:00
Mark Salyzyn
adc63f02b3 Merge changes I664fb325,I5e289469 am: 701001688f am: 833a491fab
am: beea2153ab

Change-Id: Ifd30d79d06e4e80103ff2f09b0ae960ceb8bc7f9
2018-11-19 13:46:31 -08:00
Mark Salyzyn
d100107806 switch to using android-base/file.h instead of android-base/test_utils.h
Test: compile
Bug: 119313545
Change-Id: I664fb32522d01909c603d7b903475c4e9aea9223
2018-11-14 15:54:32 -08:00
Mark Salyzyn
7751045a3a Remove unused reference to android-base/test_utils.h
Test: compile
Bug: 119313545
Change-Id: I5e289469b40ccf5bf17982197a3cdefad1254f78
2018-11-14 15:53:27 -08:00
Kweku Adams
e04ef777c1 Treating all FileSection files as device specific.
Arc++ devices don't have the /d/wakeup_sources file. There's a chance
other device won't have it either, and there may be other files that we
thought were standard but are actually not, so it's safer to just assume
that not every file will be available on every device and not treat a
missing file as an error.

Bug: 110109543
Test: atest incidentd_test
Change-Id: Ief09427f08d18aee611d057ddafdb9a3466744db
2018-06-13 12:46:12 -07:00
Yi Jin
e09cde0cd9 Merge "Add a section flag to bypass failure if a specific path can't be found." into pi-dev 2018-05-02 21:36:23 +00:00
Yi Jin
7fe3dee3ae Add a section flag to bypass failure if a specific path can't be found.
This is a temporary solution to bypass failure of reading cpu info or 
battery type in P if the path doesn't exist on some devices. See bug for
details. However in Q, incidentd should implement reading from the
common Linux kernel interfaces.

Bug: 78028767
Bug: 78239764
Test: atest incidentd_test
Change-Id: I08ffcb21709efe5478d2ac46121deb5795af1024
Merged-In: I08ffcb21709efe5478d2ac46121deb5795af1024
2018-05-02 01:31:08 +00:00
Yi Jin
3f3603587c Add a section flag to bypass failure if a specific path can't be found.
This is a temporary solution to bypass failure of reading cpu info or
battery type in P if the path doesn't exist on some devices. See bug for
details. However in Q, incidentd should implement reading from the
common Linux kernel interfaces.

Bug: 78028767
Bug: 78239764
Test: atest incidentd_test
Change-Id: I08ffcb21709efe5478d2ac46121deb5795af1024
2018-05-01 16:25:52 -07:00
Yi Jin
8cb370f2a2 Use the right printf symbols rather than converting to ints.
Bug: 77333635
Test: make -j incidentd
Change-Id: I3338279c385051b5df334af481e7f47f16d16480
2018-04-23 13:03:14 -07:00
TreeHugger Robot
0f0c9243be Merge "Fix incidentd skip collecting timedout of a section." into pi-dev 2018-04-17 16:22:20 +00:00
Yi Jin
98ce81050b Fix incidentd skip collecting timedout of a section.
By moving the section stats collection before any return statements,
it won't missing stats collection.

Bug: 77962855
Test: atest incidentd_test
Change-Id: I0900556428c51636e24df48a407eb916ccff795c
2018-04-16 13:42:48 -07:00
Yi Jin
ba7ee6ff11 Add tests to cover handling negative varint.
The gtest will fail if the fix of b/77291057 isn't there. Should make
this change in with the fix, but later than none.

Bug: 77291057
Test: atest incidentd_test
Change-Id: I48ece311f78ee18d97486839a3b8b434c9419cf3
2018-04-12 22:59:41 +00:00
Yi Jin
6cacbcbf43 Use modern c++ code style for incidentd.
This cl does not contain code logic changes.

Bug: 77333635
Test: manual and incidentd_test
Change-Id: Iea0a402b1051defd45159ca267e6dd705f9ffa49
2018-03-30 17:36:49 -07:00
Yi Jin
1ebfc94aa1 Merge "Use unique_fd with the clear ownership." into pi-dev 2018-03-30 20:53:30 +00:00
Yi Jin
c858e2781c Enable Last Kmsg, also fix the GZipSection test.
Bug: 73354384, 76208934
Test: atest incidentd_test and manual as well
Change-Id: I074027f4d972686ae3e9415b50e4d3967f6a2355
2018-03-29 18:44:54 -07:00
Yi Jin
e3dab2d906 Use unique_fd with the clear ownership.
FdBuffer won't take ownership of the `main` fd.
It only enforces transfer ownership in readProcessedDataInStream.

Bug: 74021345
Test: atest incidentd_test
Change-Id: I6182730241c81c34b3be865b827a2d3e8c10c21c
2018-03-28 12:44:36 -07:00
Yi Jin
c36e91dd12 Found out it is not possible to exec procrank as non-root/shell.
But it is ok to disable procrank since the information can be obtain via
dumpsys meminfo

Optimize the code style a bit.

Bug: 72510307
Test: atest incidentd_test
Change-Id: If06201aa708461b569d9fb007f20d1e51342d5c2
2018-03-27 15:01:20 -07:00
Yi Jin
6355d2f3ab Wrap fd with unique_fd so it won't leak.
Bug: 74021345
Test: manual and atest incidentd_test
Change-Id: Ib1000bfe6917c3d5cae7b9edce5b67d50897e10d
2018-03-14 16:26:28 -07:00
Yi Jin
86dce413f8 Optimize incidentd memory usage
1. Remove dependency of libprotobuf-cpp-lite, saves .so mmap ~200KB
2. Don't use auto except iterator for readability.

Bug: 74254200
Test: adb shell dumpsys meminfo `pid incidentd`
Change-Id: If6198521c3b80929d6ea3f7ed466b5195991ccfd
2018-03-07 18:25:44 -08:00
Yi Jin
1a11fa1097 Implement a new section to attach LAST_KMSG to incident report
This section simply gzip a large file and stores result in GZippedFileProto

This greatly improves the size, before gzip, the last kmsg size ~500KB,
after gzip the proto size is ~60KB.

Bug: 73354384
Test: atest incidentd_test and manual on device test
Change-Id: I9bfc2cf07384487671edbffb5f0bd8495608fea6
2018-02-27 11:36:29 -08:00
Yi Jin
4e843106a6 Throttler for incidentd based on size putting into dropbox.
The incidentd will accumulate the total size put into dropbox and once
it exceeds a threshold (currently 20MB) daily, it will stop further
requests. It allows collection again 24 hours later.

Bug: 64219725
Test: atest incidentd_test and manually flashed incidentd and test.
Change-Id: Iea21fbae40d5d01108797b190231d73e74eff213
2018-02-20 13:11:22 -08:00
Yi Jin
b592e3bc31 This cl formats incidentd and makes it easier for debugging.
Bug: 72755317
Test: clang-format -type=file -i <files>
Change-Id: Ide91227f26c6b1db6d2e5fe8117ca5cc4cf77fd3
2018-02-15 16:53:22 -08:00
Yi Jin
329130b7e4 Put metadata or stats into each dropbox incident report.
Bug: 65451198
Test: atest incidentd_test
Change-Id: Ib406b177ad7f1b4bda7fef2e606fc66a9836e060
2018-02-14 16:12:57 -08:00
Yi Jin
3ec5cc792e Modify SystemApi so it can be used by CTS to trigger incident report
Bug: 72502621
Test: Cts/Gts tests covered, see the cls from the same topic
Change-Id: Id0c1cc0fc0054e620de1349dab66513e554b1caa
2018-01-29 21:01:09 -08:00
Yi Jin
437aa6e8ad Add more information to incident header. Especially add config keys
to check if the report is uploadable.

Move incidentheader.proto to libincident so statds is able to include a lite
proto class for incident header.

Change IncidentReportArgs to add the proto object instead of serialized
bytes to prevent caller gives meaningless data.

Bug: 70241842
Test: push config to statsd and verify incidentd generate the report
with correct header.

Change-Id: If95b655be71047b019b229e5903a08f3c21a1f29
2018-01-21 22:36:01 -08:00
Yi Jin
3c034c987e Implement a new type of section which reads from logd and dumps proto.
And implement a file section which reads from event-log-tags for
decoding binary logs.

Bug: 70936599
Test: atest incidentd_test && atest incident_helper_test and flush on
device and test log sections and event_log_tag_map
Change-Id: Ib3d35e317f355de69f01ded012482486e9a43da6
2018-01-06 20:33:14 -08:00
Yi Jin
bdf58942c8 1. Implement Privacy Policy Tag Inheritance
2. Expose Dest values in IIncidentReportArgs.h

Please see bug for detail descriptions.

Bug: 67869340
Test: unit tested and on-device test. Ran command:
$ out/host/linux-x86/bin/incident-section-gen incidentd
to test various of privacy taggings.
Change-Id: I12af3d7da4c7c72bd63598893fe2c1f70b09baa4
2017-12-01 13:37:13 -08:00
Wei Wang
254102d858 Remove unnecessary parameter WriteStringToFile
By default, WriteStringToFile will not follow link, the 'false'
parameter is unnecessary.

Test: build
Change-Id: Ied6dcbf2a85533108dc2f6d71a4571b44684e800
2017-11-10 17:32:25 +00:00
Yi Jin
be6de3017b Enable Window Dumpsys Section
Protobuf defines classes, which can have self recursive message
definitions and cause a bug in generating privacy flags.
Solve the problem here. The details is in incident_section_gen/main.cpp.
The logic is a bit complicated to address more than one level of self
recursion proto message definition.

Also solve a bug when PrivacyBuffer strips fields.
Modify PRIVACY_POLICY_LIST to be type Privacy** in order to allow
initialization by a method.

Bug: 68162512
Test: unit tested and on device tests
Change-Id: I1d0b79f6813e5fd66c4cf5823d0fa17efc57bb1d
2017-11-01 18:24:57 -07:00
Yi Jin
e08333067a Fix several nits
1. Change the APIs of ProtoOutputStream to be able to write bytes
2. Fix the tests in incidentd, stdout is closed so can't capture the
value, use temporaryFile instead.

Test: N/A
Change-Id: Ibc31f2efd068afc6c06188d92f57ca5a754c3683
2017-10-23 16:36:06 -07:00
Yi Jin
c23fad2f90 Implement c++ native lib for streaming proto, part 1
Extract protobuf class out and creates EncodedBuffer class
which holds protobuf data.
Next step is to create a ProtoOutputStream and let incident helper
adapt the change as well.
please see frameworks/base/core/java/android/util/proto

Bug: 65641021
Test: unit tested
Change-Id: I0dd343b2e62d60f091c8f857fae3452ec8da6b96
2017-09-27 12:23:51 -07:00
George Burgess IV
bbe04e87e9 incidentd: fix memory leaks in a test
The static analyzer found many memory leaks in this file. Converting
everything to use unique_ptr became really ugly, and involved lots of
copying from lists of unique_ptr<Privacy> to lists of Privacy*. Since
these tests really don't seem to allocate much, freeing everything en
masse at the end should be good enough.

Bug: 27101951
Test: mma; memory leak warnings are gone. Running
/data/nativetest64/incidentd_test/incidentd_test shows no failures.
Change-Id: I151b7ef4e02ee736e4e833924c0500e8dbedcc49
2017-09-19 16:42:01 -07:00
Yi Jin
7e0b4e5880 Fixes regarding to comments in ag/2839267
1. use struct {} to instantiate privacy fields for efficiency reason
2. use vector<uint8_t>* instead of vector<uint8_t>& to indicate the
caller knows the value gets changed.
3. binary search privay policy for sections

Bug: 65595927
Test: unit test covers
Change-Id: Ic58c2f607465d1a7f10352b9a38c3d8b1a5cf352
2017-09-13 14:32:42 -07:00
Yi Jin
edfd5bb788 Extract IncidentHeaderProto to a separated file for statsd to consume
Create a HeaderSection to deal with header protos which is more testable

Bug: 65422268
Test: unit tested
Change-Id: Icdcbeded8bc963940a8f9e503cb65a9a247ca5b2
2017-09-07 17:33:07 -07:00
Yi Jin
0f0471623e Implement Pii Stripper Part 3
The incident request args sets privacy spec. Strip action is optimized
to run once for each type of spec and ready for flush multiple times.
Incident command is updated to take -p option to specify privacy spec.

Bug: 64687253
Test: unit tests written, manually run incident command to test as well
Change-Id: I6753df117f76dc1a5f4d2152baa3fbbf56b490e4
2017-09-07 10:53:51 -07:00
Yi Jin
99c248feb2 Implement PII Stripper, part 2
Implement EncodedBuffer that strip pii based on given privacy request.
The reason to implement another buffer is the length-delimited field's
size could change when its submessage gets stripped. It also intends to
keep the orignal data around for other requests to consume it.

In addition, the section implementation has adapted EncodedBuffer so
write out to each request's fd could be request-specific. The next step
is allow requests to set its privacy spec.

Notice the current design set the privacy spec of dropbox to AUTOMATIC,
this behavior might change in the future.

Bug: 64687253
Test: unit tests are writtern, see README.md for how to run unit tests.
Change-Id: I7ac236b8265ba9289dc6e17a8a5bf7f67ffb6bf5
2017-09-07 10:53:51 -07:00
Yi Jin
0ed9b68a3f Implement PII stripper in incidentd, part 1
1. automatically parse privacy options and generate lookup table
2. create FdBuffer iterator API in order to remove dependency on Reporter.h

Bug: 64687253
Test: Unit test for iterator API, and manually tested lookup table
Change-Id: I1ea376a4481fc4afc7bdf447936f767b63690fd3
2017-08-23 18:13:01 -07:00
Yi Jin
f860184599 Automatically generate section_list.cpp file from incident.proto
with the SectionFlags field annotations

Bug: 64728679
Test: tested manually on device
Change-Id: I5b067b09cd6ccc3528f0845d7290cc9e2bc63a07
2017-08-17 15:04:21 -07:00
Yi Jin
add11e9176 Add tests for reporter class
Test: Add test for Reporter class
Change-Id: Ic1d87a26dd4b8271bab7b03374c7a1d4d7b87f92
2017-08-03 19:40:21 -07:00
Yi Jin
b44f7d46b6 This cl implements CommandSection and use it to add procrank.proto Section
Bug: 63863444
Test: manual - create gtests for CommandSection and Procrank Parser following
instructions in the README.md of incidentd and incident_helper on how to
run them.

Change-Id: I099808fd13bf9ed9a564b122f1126b1691a83291
2017-08-02 16:33:17 -07:00
George Burgess IV
4e4a34bc4f Remove useless open modes
Open modes are ignored if the user doesn't want the file to be created:
http://man7.org/linux/man-pages/man2/open.2.html

Since it's somewhat misleading/potentially indicative of a missing
O_CREAT/O_TMPFILE, we plan to issue a warning on open calls with useless
mode bits in the near future. Because -Werror is used in this project
(thank you!), we need to either make these modes useful, or remove them.

Bug: 64132680
Test: mma. New warnings no longer appear.
Change-Id: I5d9b98152e48135ea716592b28c5c771cc74018b
2017-07-31 11:12:23 -07:00
Yi Jin
0a3406fc4f This cl does the following things:
0) Implements a skeleton of incident_helper
1) Implements FileSection class which calls incident_helper to parse
   file content to protobuf
2) Adds Kernel Wake Sources to incident.proto and makes it parsed by
   FileSection
3) Adds basic gtests to test FdBuffer, io_utils, FileSection
implementation

Bug: 62923266
Bug: 62926061
Test: manual - push incidentd, incident_helper and incident to my device
      and verify kernel wakeup sources file is able to be parsed.
Change-Id: I2aa6b6158d962ce70e6fa6c8a9c42213a45ff41c
2017-07-24 11:50:33 -07:00