Merge "[settings-pixel-search] Add ww logging to track slice fetching timeout" into sc-dev
diff --git a/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java b/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java
index 719cb0a..b1c9ed0 100644
--- a/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java
+++ b/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java
@@ -151,6 +151,7 @@
         private Optional<ToState> mToState = Optional.empty();
         private Optional<String> mEditText = Optional.empty();
         private SliceItem mSliceItem;
+        private LauncherAtom.Slice mSlice;
 
         StatsCompatLogger(Context context) {
             mContext = context;
@@ -193,7 +194,7 @@
         @Override
         public StatsLogger withContainerInfo(ContainerInfo containerInfo) {
             checkState(mItemInfo == DEFAULT_ITEM_INFO,
-                        "ItemInfo and ContainerInfo are mutual exclusive; cannot log both.");
+                    "ItemInfo and ContainerInfo are mutual exclusive; cannot log both.");
             this.mContainerInfo = Optional.of(containerInfo);
             return this;
         }
@@ -218,9 +219,21 @@
 
         @Override
         public StatsLogger withSliceItem(@NonNull SliceItem sliceItem) {
+            checkState(mItemInfo == DEFAULT_ITEM_INFO && mSlice == null,
+                    "ItemInfo, Slice and SliceItem are mutual exclusive; cannot set more than one"
+                            + " of them.");
             this.mSliceItem = checkNotNull(sliceItem, "expected valid sliceItem but received null");
-            checkState(mItemInfo == DEFAULT_ITEM_INFO,
-                    "ItemInfo and SliceItem are mutual exclusive; cannot log both.");
+            return this;
+        }
+
+        @Override
+        public StatsLogger withSlice(LauncherAtom.Slice slice) {
+            checkState(mItemInfo == DEFAULT_ITEM_INFO && mSliceItem == null,
+                    "ItemInfo, Slice and SliceItem are mutual exclusive; cannot set more than one"
+                            + " of them.");
+            checkNotNull(slice, "expected valid slice but received null");
+            checkNotNull(slice.getUri(), "expected valid slice uri but received null");
+            this.mSlice = slice;
             return this;
         }
 
@@ -231,13 +244,16 @@
             }
             LauncherAppState appState = LauncherAppState.getInstanceNoCreate();
 
-            if (mSliceItem != null) {
+            if (mSlice == null && mSliceItem != null) {
+                mSlice = LauncherAtom.Slice.newBuilder().setUri(
+                        mSliceItem.getSlice().getUri().toString()).build();
+            }
+
+            if (mSlice != null) {
                 Executors.MODEL_EXECUTOR.execute(
                         () -> {
                             LauncherAtom.ItemInfo.Builder itemInfoBuilder =
-                                    LauncherAtom.ItemInfo.newBuilder().setSlice(
-                                            LauncherAtom.Slice.newBuilder().setUri(
-                                                    mSliceItem.getSlice().getUri().toString()));
+                                    LauncherAtom.ItemInfo.newBuilder().setSlice(mSlice);
                             mContainerInfo.ifPresent(itemInfoBuilder::setContainerInfo);
                             write(event, applyOverwrites(itemInfoBuilder.build()));
                         });
diff --git a/src/com/android/launcher3/logging/StatsLogManager.java b/src/com/android/launcher3/logging/StatsLogManager.java
index ddff338..79e5b5d 100644
--- a/src/com/android/launcher3/logging/StatsLogManager.java
+++ b/src/com/android/launcher3/logging/StatsLogManager.java
@@ -27,6 +27,7 @@
 import androidx.slice.SliceItem;
 
 import com.android.launcher3.R;
+import com.android.launcher3.logger.LauncherAtom;
 import com.android.launcher3.logger.LauncherAtom.ContainerInfo;
 import com.android.launcher3.logger.LauncherAtom.FromState;
 import com.android.launcher3.logger.LauncherAtom.ToState;
@@ -600,6 +601,13 @@
         }
 
         /**
+         * Sets logging fields from provided {@link LauncherAtom.Slice}.
+         */
+        default StatsLogger withSlice(LauncherAtom.Slice slice) {
+            return this;
+        }
+
+        /**
          * Builds the final message and logs it as {@link EventEnum}.
          */
         default void log(EventEnum event) {