trunks: wait for service readiness in dbus proxy init

The callers of TrunksDBusProxy::Init() assume that they can start
sending messages to trunksd as soon as this function returns true.
In reality, it was returning true wthout checking if trunksd has
already registered on dbus. That led to race conditions with
daemons attempting to send messages to trunksd before it was
initialized.

1) Fix that by returning true from TrunksDBusProxy::Init() only if
trunks service has an owner (wait for the owner, if needed, with
a timeout).

2) Check if the service is ready when sending messages to trunksd,
and return an appropriate error if the service is not ready. A new
code SAPI_RC_NO_CONNECTION was created for that purpose.

3) Modify tpm_managerd to check timestamps instead of counting
the number of attempts when waiting for TrunksDBusProxy
initialization to succeed.

4) Add unit tests for TrunksDBusProxy.

BUG=chromium:697295
TEST=1) Unit tests (new added).
     2) Inject an artificial delay in trunksd start sequence,
        verify that tpm_managerd doesn't crash and waits for
        trunksd to start before sending messages to it.

Change-Id: Ic1b2eae7dc7f343b5debe694ba3742dce6a2ce1a
Reviewed-on: https://chromium-review.googlesource.com/456048
Commit-Ready: Andrey Pronin <apronin@chromium.org>
Tested-by: Andrey Pronin <apronin@chromium.org>
Reviewed-by: Ben Chan <benchan@chromium.org>
8 files changed