Add more debug messages to the PP API

Bug: b/228883709
Test: atest AdServicesServiceCoreUnitTests

Change-Id: I909abd501c1a85f77e27be6df527d1744e0364b1
diff --git a/adservices/service-core/java/com/android/adservices/service/topics/CacheManager.java b/adservices/service-core/java/com/android/adservices/service/topics/CacheManager.java
index c226ca2..8448b0a 100644
--- a/adservices/service-core/java/com/android/adservices/service/topics/CacheManager.java
+++ b/adservices/service-core/java/com/android/adservices/service/topics/CacheManager.java
@@ -20,6 +20,7 @@
 import android.content.Context;
 import android.util.Pair;
 
+import com.android.adservices.LogUtil;
 import com.android.adservices.data.topics.Topic;
 import com.android.adservices.data.topics.TopicsDao;
 import com.android.adservices.service.Flags;
@@ -79,9 +80,13 @@
                 mTopicsDao.retrieveReturnedTopics(mEpochManager.getCurrentEpochId(),
                         mFlags.getTopicsNumberOfLookBackEpochs() + 1);
 
-        mReadWriteLock.writeLock().lock();
-        mCachedTopics = cacheFromDb;
-        mReadWriteLock.writeLock().unlock();
+        LogUtil.v("CachedTopics mapping size is  " + cacheFromDb.size());
+        try {
+            mReadWriteLock.writeLock().lock();
+            mCachedTopics = cacheFromDb;
+        } finally {
+            mReadWriteLock.writeLock().unlock();
+        }
     }
 
     /**
diff --git a/adservices/service-core/java/com/android/adservices/service/topics/EpochManager.java b/adservices/service-core/java/com/android/adservices/service/topics/EpochManager.java
index 78abcff..3a2512c 100644
--- a/adservices/service-core/java/com/android/adservices/service/topics/EpochManager.java
+++ b/adservices/service-core/java/com/android/adservices/service/topics/EpochManager.java
@@ -116,17 +116,21 @@
         // This cross db and java boundaries multiple times so we need to have a db transaction.
         db.beginTransaction();
         long epochId = getCurrentEpochId();
+        LogUtil.v("Current epochId is %d", epochId);
         try {
             // Step 1: Compute the UsageMap from the UsageHistory table.
             // appSdksUsageMap = Map<App, List<SDK>> has the app and its SDKs that called Topics API
             // in the current Epoch.
             Map<String, List<String>> appSdksUsageMap = mTopicsDao.retrieveAppSdksUsageMap(epochId);
+            LogUtil.v("appSdksUsageMap size is  %d", appSdksUsageMap.size());
 
             // Step 2: Compute the Map from App to its classification topics.
             // Only produce for apps that called the Topics API in the current Epoch.
             // appClassificationTopicsMap = Map<App, List<Topics>>
             Map<String, List<String>> appClassificationTopicsMap =
                     computeAppClassificationTopics(appSdksUsageMap);
+            LogUtil.v("appClassificationTopicsMap size is %d", appClassificationTopicsMap.size());
+
             // Then save app-topics Map into DB
             mTopicsDao.persistAppClassificationTopics(epochId, /* taxonomyVersion = */ 1L,
                     /* modelVersion = */ 1L, appClassificationTopicsMap);
@@ -135,6 +139,9 @@
             // This is similar to the Callers Can Learn table in the explainer.
             Map<String, Set<String>> callersCanLearnThisEpochMap =
                     computeCallersCanLearnMap(appSdksUsageMap, appClassificationTopicsMap);
+            LogUtil.v("callersCanLearnThisEpochMap size is  %d",
+                    callersCanLearnThisEpochMap.size());
+
             // And then save this CallersCanLearnMap to DB.
             mTopicsDao.persistCallerCanLearnTopics(epochId, callersCanLearnThisEpochMap);
 
@@ -144,11 +151,14 @@
             Map<String, Set<String>> callersCanLearnMap =
                     mTopicsDao.retrieveCallerCanLearnTopicsMap(epochId,
                             mFlags.getTopicsNumberOfLookBackEpochs());
+            LogUtil.v("callersCanLearnMap size is %d", callersCanLearnMap.size());
 
             // Step 5: Retrieve the Top Topics. This will return a list of 5 top topics and
             // the 6th topic which is selected randomly. We can refer this 6th topic as the
             // random-topic.
             List<String> topTopics = computeTopTopics(appClassificationTopicsMap);
+            LogUtil.v("topTopics are  %s", topTopics.toString());
+
             // Then save Top Topics into DB
             mTopicsDao.persistTopTopics(epochId, topTopics);
 
@@ -157,6 +167,7 @@
             // Return returnedAppSdkTopics = Map<Pair<App, Sdk>, Topic>
             Map<Pair<String, String>, String> returnedAppSdkTopics =
                     computeReturnedAppSdkTopics(callersCanLearnMap, appSdksUsageMap, topTopics);
+            LogUtil.v("returnedAppSdkTopics size is  %d", returnedAppSdkTopics.size());
 
             // And persist the map to DB so that we can reuse later.
             mTopicsDao.persistReturnedAppTopicsMap(epochId, /* taxonomyVersion = */ 1L,
@@ -201,6 +212,7 @@
      */
     public void recordUsageHistory(String app, String sdk) {
         long epochID = getCurrentEpochId();
+        LogUtil.v("Current epochId is %d", epochID);
         mTopicsDao.recordUsageHistory(epochID, app, sdk);
         mTopicsDao.recordAppUsageHistory(epochID, app);
     }
@@ -321,6 +333,7 @@
     @VisibleForTesting
     public long getCurrentEpochId() {
         // TODO(b/221463765): Don't use a fix epoch origin like this. This is for Alpha 1 only.
+        LogUtil.v("Epoch length is  %d", mFlags.getTopicsEpochJobPeriodMs());
         return (long) Math.floor((System.currentTimeMillis() - ORIGIN_EPOCH_TIMESTAMP)
                 /  mFlags.getTopicsEpochJobPeriodMs());
     }