lazy hals: fix onClient(true) double-send.

Before, if guaranteeClient was called, and mHasClients was true
(meaning that we should have a client and there is a record of having
a client), then an onClient(true) notification would be called.
However, since mHasClients is true, we must have already sent a
notification out. A CHECK for this situation was also added.

Test: hwservicemanager_test
    HidlServiceLazyTest AcquisitionAfterGuarantee (now passes)
Test: internal 'lazy_hidl_test' fuzzing health storage HAL, health
    storage HAL no longer reports double-acquisition of clients.

Change-Id: I18489c1b1d085028ce39163035a06ca04fd9f10d
diff --git a/test_lazy.cpp b/test_lazy.cpp
index 0aeac47..542bf53 100644
--- a/test_lazy.cpp
+++ b/test_lazy.cpp
@@ -147,3 +147,26 @@
     service->handleClientCallbacks(true /*onInterval*/);
     ASSERT_THAT(cb->stream, ElementsAre(true, false)); // reported only after two intervals
 }
+
+TEST_F(HidlServiceLazyTest, AcquisitionAfterGuarantee) {
+    sp<RecordingClientCallback> cb = new RecordingClientCallback;
+
+    std::unique_ptr<HidlService> service = makeService();
+    service->addClientCallback(cb);
+
+    setReportedClientCount(2);
+    service->handleClientCallbacks(false /*onInterval*/);
+    ASSERT_THAT(cb->stream, ElementsAre(true));
+
+    setReportedClientCount(1);
+    service->guaranteeClient();
+
+    service->handleClientCallbacks(false /*onInterval*/);
+    ASSERT_THAT(cb->stream, ElementsAre(true));
+
+    service->handleClientCallbacks(true /*onInterval*/);
+    ASSERT_THAT(cb->stream, ElementsAre(true));
+
+    service->handleClientCallbacks(true /*onInterval*/);
+    ASSERT_THAT(cb->stream, ElementsAre(true, false)); // reported only after two intervals
+}