Remove indentation for Person.toString

Instead of using GenericDocument.toString, we provide a customized
String builder to build the string without indentation for fingerprinting.

The builder is added in PersonBuilderHelper, and duplicates some codes
from GenericDocument#appendGenericDocumentString and
GenericDocument#appendPropertyString, with indenting and some formatting
removed.

In GenericDocument.toString, in order to do the indentation, the first
'\n' is searched over, and we will split the string into two part, and
recursively do the same thing on the substring after '\n'. This is causing stack overflow and big memory consumption if we are getting a big string with a lot of '\n'. It seems there is no optimization for tail recursion here, and calling String.substring will create a copy of sub-string and increase the memory usage.

Memory Test(calling Person.toString many times with big notes before and
after the fix aosp/2413038):

Before: memory usage increase a lot after tests start:
before test started: https://screenshot.googleplex.com/9hrUZrwRzMA28ym
after test started: https://screenshot.googleplex.com/9jKWjy7QKtp2Kqp

After: stable memory usage throughout the test.
https://screenshot.googleplex.com/AyxFnr9TPqGbjUX

After a device gets this change, the index won't be affected, except
that one unnecessary update may occur for each indexed contact, because
the fingerprint will be changed even if the content is the same. This
additional update per contact may happen during either delta update(some
fields we don't care get updated in CP2, thus we get notified), or
during a full update. In full update case, all the existing contacts
will be updated.

This approach is preferred compared with completely re-implementing
toString because we don't want to duplicate the methods in
GenericDocument, which will make it harder to maintain.

Bug: b/263885339
Test: ContactsIndexerTests
Change-Id: Ib3f10630344579cb9ffbb2bfe4685beaae8cb709
(cherry picked from commit 2a3a840126e85d197a0f03c5f86ae3fdd0c68522)
Merged-In: Ib3f10630344579cb9ffbb2bfe4685beaae8cb709
3 files changed