Migrate from Plugin SearchTarget to API search Target [2/3]

- Adds support for android.app.search.SearchTarget in plugin while maintaining plugin SearchTarget support
- Introduces SEARCH_TARGET_LEGACY temporary to switch between plugin and sdk variants.
- Maps resultType and layoutType pairs to the appropriate view

Bug: 177223401
Test: Manual
Change-Id: If8d4bb7c21c47a12447dcb0c56eed8781bd21e54
diff --git a/quickstep/src/com/android/launcher3/search/DeviceSearchAdapterProvider.java b/quickstep/src/com/android/launcher3/search/DeviceSearchAdapterProvider.java
index da325c7..9ce196e 100644
--- a/quickstep/src/com/android/launcher3/search/DeviceSearchAdapterProvider.java
+++ b/quickstep/src/com/android/launcher3/search/DeviceSearchAdapterProvider.java
@@ -18,15 +18,18 @@
 
 import static com.android.launcher3.allapps.AllAppsGridAdapter.VIEW_TYPE_ICON;
 
+import android.app.search.SearchTarget;
 import android.util.SparseIntArray;
 import android.view.LayoutInflater;
 import android.view.ViewGroup;
 
 import com.android.launcher3.Launcher;
 import com.android.launcher3.R;
+import com.android.launcher3.allapps.AllAppsContainerView;
 import com.android.launcher3.allapps.AllAppsGridAdapter;
 import com.android.launcher3.allapps.search.SearchAdapterProvider;
-import com.android.systemui.plugins.shared.SearchTarget;
+import com.android.launcher3.config.FeatureFlags;
+import com.android.systemui.plugins.shared.SearchTargetLegacy;
 
 /**
  * Provides views for on-device search results
@@ -45,11 +48,13 @@
     public static final int VIEW_TYPE_SEARCH_WIDGET_LIVE = 1 << 15;
     public static final int VIEW_TYPE_SEARCH_WIDGET_PREVIEW = 1 << 16;
 
+    private final AllAppsContainerView mAppsView;
 
     private final SparseIntArray mViewTypeToLayoutMap = new SparseIntArray();
 
-    public DeviceSearchAdapterProvider(Launcher launcher) {
+    public DeviceSearchAdapterProvider(Launcher launcher, AllAppsContainerView appsView) {
         super(launcher);
+        mAppsView = appsView;
 
         mViewTypeToLayoutMap.put(VIEW_TYPE_SEARCH_ICON, R.layout.search_result_icon);
         mViewTypeToLayoutMap.put(VIEW_TYPE_SEARCH_CORPUS_TITLE, R.layout.search_section_title);
@@ -68,12 +73,16 @@
 
     @Override
     public void onBindView(AllAppsGridAdapter.ViewHolder holder, int position) {
-        SearchAdapterItem item = (SearchAdapterItem) Launcher.getLauncher(mLauncher)
-                .getAppsView().getApps().getAdapterItems().get(position);
+        SearchAdapterItem item = (SearchAdapterItem) mAppsView.getApps().getAdapterItems().get(
+                position);
         SearchTargetHandler
                 payloadResultView =
                 (SearchTargetHandler) holder.itemView;
-        payloadResultView.applySearchTarget(item.getSearchTarget());
+        if (FeatureFlags.SEARCH_TARGET_LEGACY.get()) {
+            payloadResultView.applySearchTarget(item.getSearchTargetLegacy());
+        } else {
+            payloadResultView.applySearchTarget(item.getSearchTarget());
+        }
     }
 
     @Override
@@ -101,10 +110,23 @@
     @Override
     public boolean onAdapterItemSelected(AllAppsGridAdapter.AdapterItem focusedItem) {
         if (focusedItem instanceof SearchTargetHandler) {
-            SearchTarget searchTarget = ((SearchAdapterItem) focusedItem).getSearchTarget();
+            SearchTargetLegacy searchTarget = ((SearchAdapterItem) focusedItem)
+                    .getSearchTargetLegacy();
             SearchEventTracker.INSTANCE.get(mLauncher).quickSelect(searchTarget);
             return true;
         }
         return false;
     }
+
+    /**
+     * Determines what view type should be used to present search target.
+     * Returns -1 if viewType is not found
+     */
+    public int getViewTypeForSearchTarget(SearchTarget t) {
+        //TODO: Replace with values from :SearchUi
+        if (t.getResultType() == 1 && t.getLayoutType().equals("icon")) {
+            return VIEW_TYPE_SEARCH_ICON;
+        }
+        return -1;
+    }
 }
diff --git a/quickstep/src/com/android/launcher3/search/SearchAdapterItem.java b/quickstep/src/com/android/launcher3/search/SearchAdapterItem.java
index b79e073..258d977 100644
--- a/quickstep/src/com/android/launcher3/search/SearchAdapterItem.java
+++ b/quickstep/src/com/android/launcher3/search/SearchAdapterItem.java
@@ -27,13 +27,16 @@
 import static com.android.launcher3.search.DeviceSearchAdapterProvider.VIEW_TYPE_SEARCH_WIDGET_LIVE;
 import static com.android.launcher3.search.DeviceSearchAdapterProvider.VIEW_TYPE_SEARCH_WIDGET_PREVIEW;
 
+import android.app.search.SearchTarget;
+
 import com.android.launcher3.allapps.AllAppsGridAdapter;
-import com.android.systemui.plugins.shared.SearchTarget;
+import com.android.systemui.plugins.shared.SearchTargetLegacy;
 
 /**
  * Extension of AdapterItem that contains an extra payload specific to item
  */
 public class SearchAdapterItem extends AllAppsGridAdapter.AdapterItem {
+    private SearchTargetLegacy mSearchTargetLegacy;
     private SearchTarget mSearchTarget;
 
 
@@ -43,11 +46,21 @@
             | VIEW_TYPE_SEARCH_WIDGET_PREVIEW | VIEW_TYPE_SEARCH_WIDGET_LIVE
             | VIEW_TYPE_SEARCH_SUGGEST;
 
+    public SearchAdapterItem(SearchTargetLegacy searchTargetLegacy, int type) {
+        mSearchTargetLegacy = searchTargetLegacy;
+        viewType = type;
+    }
+
+
     public SearchAdapterItem(SearchTarget searchTarget, int type) {
         mSearchTarget = searchTarget;
         viewType = type;
     }
 
+    public SearchTargetLegacy getSearchTargetLegacy() {
+        return mSearchTargetLegacy;
+    }
+
     public SearchTarget getSearchTarget() {
         return mSearchTarget;
     }
diff --git a/quickstep/src/com/android/launcher3/search/SearchEventTracker.java b/quickstep/src/com/android/launcher3/search/SearchEventTracker.java
index efb7b19..90fe661 100644
--- a/quickstep/src/com/android/launcher3/search/SearchEventTracker.java
+++ b/quickstep/src/com/android/launcher3/search/SearchEventTracker.java
@@ -23,8 +23,8 @@
 
 import com.android.launcher3.util.MainThreadInitializedObject;
 import com.android.systemui.plugins.AllAppsSearchPlugin;
-import com.android.systemui.plugins.shared.SearchTarget;
-import com.android.systemui.plugins.shared.SearchTargetEvent;
+import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
+import com.android.systemui.plugins.shared.SearchTargetLegacy;
 
 import java.util.WeakHashMap;
 
@@ -34,7 +34,7 @@
 public class SearchEventTracker {
     @Nullable
     private AllAppsSearchPlugin mPlugin;
-    private final WeakHashMap<SearchTarget, SearchTargetHandler>
+    private final WeakHashMap<SearchTargetLegacy, SearchTargetHandler>
             mCallbacks = new WeakHashMap<>();
 
     public static final MainThreadInitializedObject<SearchEventTracker> INSTANCE =
@@ -60,26 +60,27 @@
     /**
      * Sends SearchTargetEvent to search provider
      */
-    public void notifySearchTargetEvent(SearchTargetEvent searchTargetEvent) {
+    public void notifySearchTargetEvent(SearchTargetEventLegacy searchTargetEvent) {
         if (mPlugin != null) {
-            UI_HELPER_EXECUTOR.post(() -> mPlugin.notifySearchTargetEvent(searchTargetEvent));
+            UI_HELPER_EXECUTOR.post(() -> mPlugin.notifySearchTargetEventLegacy(searchTargetEvent));
         }
     }
 
     /**
      * Registers a {@link SearchTargetHandler} to handle quick launch for specified SearchTarget.
      */
-    public void registerWeakHandler(SearchTarget searchTarget, SearchTargetHandler targetHandler) {
+    public void registerWeakHandler(SearchTargetLegacy searchTarget,
+            SearchTargetHandler targetHandler) {
         mCallbacks.put(searchTarget, targetHandler);
     }
 
     /**
      * Handles quick select for SearchTarget
      */
-    public void quickSelect(SearchTarget searchTarget) {
+    public void quickSelect(SearchTargetLegacy searchTarget) {
         SearchTargetHandler searchTargetHandler = mCallbacks.get(searchTarget);
         if (searchTargetHandler != null) {
-            searchTargetHandler.handleSelection(SearchTargetEvent.QUICK_SELECT);
+            searchTargetHandler.handleSelection(SearchTargetEventLegacy.QUICK_SELECT);
         }
     }
 
diff --git a/quickstep/src/com/android/launcher3/search/SearchResultIcon.java b/quickstep/src/com/android/launcher3/search/SearchResultIcon.java
index 1aa89ee..e4d737c 100644
--- a/quickstep/src/com/android/launcher3/search/SearchResultIcon.java
+++ b/quickstep/src/com/android/launcher3/search/SearchResultIcon.java
@@ -20,6 +20,7 @@
 import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
 
 import android.app.RemoteAction;
+import android.app.search.SearchTarget;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.pm.ShortcutInfo;
@@ -42,8 +43,8 @@
 import com.android.launcher3.model.data.WorkspaceItemInfo;
 import com.android.launcher3.touch.ItemLongClickListener;
 import com.android.launcher3.util.ComponentKey;
-import com.android.systemui.plugins.shared.SearchTarget;
-import com.android.systemui.plugins.shared.SearchTargetEvent;
+import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
+import com.android.systemui.plugins.shared.SearchTargetLegacy;
 
 import java.util.function.Consumer;
 
@@ -69,7 +70,7 @@
 
     private final Launcher mLauncher;
 
-    private SearchTarget mSearchTarget;
+    private SearchTargetLegacy mSearchTarget;
     private Consumer<ItemInfoWithIcon> mOnItemInfoChanged;
 
     public SearchResultIcon(Context context) {
@@ -100,13 +101,13 @@
      * Applies search target with a ItemInfoWithIcon consumer to be called after itemInfo is
      * constructed
      */
-    public void applySearchTarget(SearchTarget searchTarget, Consumer<ItemInfoWithIcon> cb) {
+    public void applySearchTarget(SearchTargetLegacy searchTarget, Consumer<ItemInfoWithIcon> cb) {
         mOnItemInfoChanged = cb;
         applySearchTarget(searchTarget);
     }
 
     @Override
-    public void applySearchTarget(SearchTarget searchTarget) {
+    public void applySearchTarget(SearchTargetLegacy searchTarget) {
         mSearchTarget = searchTarget;
         SearchEventTracker.getInstance(getContext()).registerWeakHandler(mSearchTarget, this);
         setVisibility(VISIBLE);
@@ -127,9 +128,16 @@
         }
     }
 
+    @Override
+    public void applySearchTarget(SearchTarget searchTarget) {
+        prepareUsingApp(new ComponentName(searchTarget.getPackageName(),
+                searchTarget.getExtras().getString("class")), searchTarget.getUserHandle());
+    }
+
     private void prepareUsingApp(ComponentName componentName, UserHandle userHandle) {
         AllAppsStore appsStore = mLauncher.getAppsView().getAppsStore();
         AppInfo appInfo = appsStore.getApp(new ComponentKey(componentName, userHandle));
+
         if (appInfo == null) {
             setVisibility(GONE);
             return;
@@ -181,7 +189,8 @@
     }
 
     private void reportEvent(int eventType) {
-        SearchTargetEvent.Builder b = new SearchTargetEvent.Builder(mSearchTarget, eventType);
+        SearchTargetEventLegacy.Builder b = new SearchTargetEventLegacy.Builder(mSearchTarget,
+                eventType);
         if (mSearchTarget.getItemType().equals(TARGET_TYPE_SHORTCUT)) {
             b.setShortcutPosition(0);
         }
@@ -191,7 +200,7 @@
 
     @Override
     public void onClick(View view) {
-        handleSelection(SearchTargetEvent.SELECT);
+        handleSelection(SearchTargetEventLegacy.SELECT);
     }
 
     @Override
@@ -199,7 +208,7 @@
         if (!supportsLongPress(mSearchTarget.getItemType())) {
             return false;
         }
-        reportEvent(SearchTargetEvent.LONG_PRESS);
+        reportEvent(SearchTargetEventLegacy.LONG_PRESS);
         return ItemLongClickListener.INSTANCE_ALL_APPS.onLongClick(view);
 
     }
diff --git a/quickstep/src/com/android/launcher3/search/SearchResultIconRow.java b/quickstep/src/com/android/launcher3/search/SearchResultIconRow.java
index b3dfbe2..8c491d2 100644
--- a/quickstep/src/com/android/launcher3/search/SearchResultIconRow.java
+++ b/quickstep/src/com/android/launcher3/search/SearchResultIconRow.java
@@ -39,8 +39,8 @@
 import com.android.launcher3.model.data.ItemInfoWithIcon;
 import com.android.launcher3.model.data.PackageItemInfo;
 import com.android.launcher3.model.data.WorkspaceItemInfo;
-import com.android.systemui.plugins.shared.SearchTarget;
-import com.android.systemui.plugins.shared.SearchTargetEvent;
+import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
+import com.android.systemui.plugins.shared.SearchTargetLegacy;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -63,7 +63,7 @@
     private TextView mDescriptionView;
     private BubbleTextView[] mShortcutViews = new BubbleTextView[2];
 
-    private SearchTarget mSearchTarget;
+    private SearchTargetLegacy mSearchTarget;
     private PackageItemInfo mProviderInfo;
 
 
@@ -100,8 +100,9 @@
             lp.width = iconSize;
             bubbleTextView.setOnClickListener(view -> {
                 WorkspaceItemInfo itemInfo = (WorkspaceItemInfo) bubbleTextView.getTag();
-                SearchTargetEvent event = new SearchTargetEvent.Builder(mSearchTarget,
-                        SearchTargetEvent.CHILD_SELECT).setShortcutPosition(itemInfo.rank).build();
+                SearchTargetEventLegacy event = new SearchTargetEventLegacy.Builder(mSearchTarget,
+                        SearchTargetEventLegacy.CHILD_SELECT).setShortcutPosition(
+                        itemInfo.rank).build();
                 SearchEventTracker.getInstance(getContext()).notifySearchTargetEvent(event);
                 mLauncher.getItemOnClickListener().onClick(view);
             });
@@ -111,7 +112,7 @@
     }
 
     @Override
-    public void applySearchTarget(SearchTarget searchTarget) {
+    public void applySearchTarget(SearchTargetLegacy searchTarget) {
         mSearchTarget = searchTarget;
         mResultIcon.applySearchTarget(searchTarget, this);
         String itemType = searchTarget.getItemType();
diff --git a/quickstep/src/com/android/launcher3/search/SearchResultPeopleView.java b/quickstep/src/com/android/launcher3/search/SearchResultPeopleView.java
index e856531..8caa51c 100644
--- a/quickstep/src/com/android/launcher3/search/SearchResultPeopleView.java
+++ b/quickstep/src/com/android/launcher3/search/SearchResultPeopleView.java
@@ -44,8 +44,8 @@
 import com.android.launcher3.R;
 import com.android.launcher3.icons.BitmapInfo;
 import com.android.launcher3.icons.LauncherIcons;
-import com.android.systemui.plugins.shared.SearchTarget;
-import com.android.systemui.plugins.shared.SearchTargetEvent;
+import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
+import com.android.systemui.plugins.shared.SearchTargetLegacy;
 
 import java.util.ArrayList;
 
@@ -66,7 +66,7 @@
     private Intent mIntent;
 
 
-    private SearchTarget mSearchTarget;
+    private SearchTargetLegacy mSearchTarget;
 
     public SearchResultPeopleView(Context context) {
         this(context, null, 0);
@@ -99,11 +99,11 @@
             button.getLayoutParams().width = mButtonSize;
             button.getLayoutParams().height = mButtonSize;
         }
-        setOnClickListener(v -> handleSelection(SearchTargetEvent.SELECT));
+        setOnClickListener(v -> handleSelection(SearchTargetEventLegacy.SELECT));
     }
 
     @Override
-    public void applySearchTarget(SearchTarget searchTarget) {
+    public void applySearchTarget(SearchTargetLegacy searchTarget) {
         mSearchTarget = searchTarget;
         Bundle payload = searchTarget.getExtras();
         mTitleView.setText(payload.getString("title"));
@@ -186,8 +186,8 @@
             Bundle bundle = new Bundle();
             bundle.putBundle("provider", provider);
             SearchEventTracker.INSTANCE.get(getContext()).notifySearchTargetEvent(
-                    new SearchTargetEvent.Builder(mSearchTarget,
-                            SearchTargetEvent.CHILD_SELECT).setExtras(bundle).build());
+                    new SearchTargetEventLegacy.Builder(mSearchTarget,
+                            SearchTargetEventLegacy.CHILD_SELECT).setExtras(bundle).build());
         });
     }
 
@@ -197,7 +197,7 @@
             Launcher launcher = Launcher.getLauncher(getContext());
             launcher.startActivitySafely(this, mIntent, null);
             SearchEventTracker.INSTANCE.get(getContext()).notifySearchTargetEvent(
-                    new SearchTargetEvent.Builder(mSearchTarget, eventType).build());
+                    new SearchTargetEventLegacy.Builder(mSearchTarget, eventType).build());
         }
     }
 }
diff --git a/quickstep/src/com/android/launcher3/search/SearchResultPlayItem.java b/quickstep/src/com/android/launcher3/search/SearchResultPlayItem.java
index 33c9330..3bb821f 100644
--- a/quickstep/src/com/android/launcher3/search/SearchResultPlayItem.java
+++ b/quickstep/src/com/android/launcher3/search/SearchResultPlayItem.java
@@ -43,8 +43,8 @@
 import com.android.launcher3.R;
 import com.android.launcher3.icons.BitmapRenderer;
 import com.android.launcher3.util.Themes;
-import com.android.systemui.plugins.shared.SearchTarget;
-import com.android.systemui.plugins.shared.SearchTargetEvent;
+import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
+import com.android.systemui.plugins.shared.SearchTargetLegacy;
 
 import java.io.IOException;
 import java.net.URL;
@@ -69,7 +69,7 @@
     private String mPackageName;
     private boolean mIsInstantGame;
 
-    private SearchTarget mSearchTarget;
+    private SearchTargetLegacy mSearchTarget;
 
 
     public SearchResultPlayItem(Context context) {
@@ -101,7 +101,7 @@
         ViewGroup.LayoutParams iconParams = mIconView.getLayoutParams();
         iconParams.height = mDeviceProfile.allAppsIconSizePx;
         iconParams.width = mDeviceProfile.allAppsIconSizePx;
-        setOnClickListener(view -> handleSelection(SearchTargetEvent.SELECT));
+        setOnClickListener(view -> handleSelection(SearchTargetEventLegacy.SELECT));
     }
 
 
@@ -127,7 +127,7 @@
 
 
     @Override
-    public void applySearchTarget(SearchTarget searchTarget) {
+    public void applySearchTarget(SearchTargetLegacy searchTarget) {
         mSearchTarget = searchTarget;
         Bundle bundle = searchTarget.getExtras();
         SearchEventTracker.INSTANCE.get(getContext()).registerWeakHandler(searchTarget, this);
@@ -193,11 +193,11 @@
         intent.putExtra("callerId", getContext().getPackageName());
         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         getContext().startActivity(intent);
-        logSearchEvent(SearchTargetEvent.CHILD_SELECT);
+        logSearchEvent(SearchTargetEventLegacy.CHILD_SELECT);
     }
 
     private void logSearchEvent(int eventType) {
         SearchEventTracker.INSTANCE.get(getContext()).notifySearchTargetEvent(
-                new SearchTargetEvent.Builder(mSearchTarget, eventType).build());
+                new SearchTargetEventLegacy.Builder(mSearchTarget, eventType).build());
     }
 }
diff --git a/quickstep/src/com/android/launcher3/search/SearchResultSettingsSlice.java b/quickstep/src/com/android/launcher3/search/SearchResultSettingsSlice.java
index 826b653..80ad305 100644
--- a/quickstep/src/com/android/launcher3/search/SearchResultSettingsSlice.java
+++ b/quickstep/src/com/android/launcher3/search/SearchResultSettingsSlice.java
@@ -32,8 +32,8 @@
 
 import com.android.launcher3.Launcher;
 import com.android.launcher3.R;
-import com.android.systemui.plugins.shared.SearchTarget;
-import com.android.systemui.plugins.shared.SearchTargetEvent;
+import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
+import com.android.systemui.plugins.shared.SearchTargetLegacy;
 
 /**
  * A slice view wrapper with settings app icon at start
@@ -50,7 +50,7 @@
     private SliceView mSliceView;
     private View mIcon;
     private LiveData<Slice> mSliceLiveData;
-    private SearchTarget mSearchTarget;
+    private SearchTargetLegacy mSearchTarget;
     private final Launcher mLauncher;
 
     public SearchResultSettingsSlice(Context context) {
@@ -77,7 +77,7 @@
     }
 
     @Override
-    public void applySearchTarget(SearchTarget searchTarget) {
+    public void applySearchTarget(SearchTargetLegacy searchTarget) {
         reset();
         mSearchTarget = searchTarget;
         try {
@@ -103,8 +103,8 @@
     @Override
     public void handleSelection(int eventType) {
         SearchEventTracker.INSTANCE.get(mLauncher).notifySearchTargetEvent(
-                new SearchTargetEvent.Builder(mSearchTarget,
-                        SearchTargetEvent.CHILD_SELECT).build());
+                new SearchTargetEventLegacy.Builder(mSearchTarget,
+                        SearchTargetEventLegacy.CHILD_SELECT).build());
     }
 
     private void reset() {
@@ -116,7 +116,7 @@
 
     @Override
     public void onSliceAction(@NonNull EventInfo eventInfo, @NonNull SliceItem sliceItem) {
-        handleSelection(SearchTargetEvent.CHILD_SELECT);
+        handleSelection(SearchTargetEventLegacy.CHILD_SELECT);
     }
 
     private Uri getSliceUri() {
diff --git a/quickstep/src/com/android/launcher3/search/SearchResultWidget.java b/quickstep/src/com/android/launcher3/search/SearchResultWidget.java
index ba26d85..4fe9229 100644
--- a/quickstep/src/com/android/launcher3/search/SearchResultWidget.java
+++ b/quickstep/src/com/android/launcher3/search/SearchResultWidget.java
@@ -36,8 +36,8 @@
 import com.android.launcher3.dragndrop.DraggableView;
 import com.android.launcher3.touch.ItemLongClickListener;
 import com.android.launcher3.widget.PendingAddWidgetInfo;
-import com.android.systemui.plugins.shared.SearchTarget;
-import com.android.systemui.plugins.shared.SearchTargetEvent;
+import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
+import com.android.systemui.plugins.shared.SearchTargetLegacy;
 
 /**
  * displays live version of a widget upon receiving {@link AppWidgetProviderInfo} from Search
@@ -58,7 +58,7 @@
     private final AppWidgetHostView mHostView;
     private final float mScaleToFit;
 
-    private SearchTarget mSearchTarget;
+    private SearchTargetLegacy mSearchTarget;
     private AppWidgetProviderInfo mProviderInfo;
 
     private SearchWidgetInfoContainer mInfoContainer;
@@ -82,7 +82,7 @@
 
         // detect tap event on widget container for search target event reporting
         mClickDetector = new GestureDetector(context,
-                new ClickListener(() -> handleSelection(SearchTargetEvent.CHILD_SELECT)));
+                new ClickListener(() -> handleSelection(SearchTargetEventLegacy.CHILD_SELECT)));
 
         mLongPressHelper = new CheckLongPressHelper(this);
         mLongPressHelper.setLongPressTimeoutFactor(1);
@@ -96,7 +96,7 @@
     }
 
     @Override
-    public void applySearchTarget(SearchTarget searchTarget) {
+    public void applySearchTarget(SearchTargetLegacy searchTarget) {
         if (searchTarget.getExtras() == null
                 || searchTarget.getExtras().getParcelable("provider") == null) {
             setVisibility(GONE);
@@ -141,7 +141,7 @@
     @Override
     public void handleSelection(int eventType) {
         SearchEventTracker.INSTANCE.get(getContext()).notifySearchTargetEvent(
-                new SearchTargetEvent.Builder(mSearchTarget, eventType).build());
+                new SearchTargetEventLegacy.Builder(mSearchTarget, eventType).build());
     }
 
     @Override
@@ -182,7 +182,7 @@
     @Override
     public boolean onLongClick(View view) {
         ItemLongClickListener.INSTANCE_ALL_APPS.onLongClick(view);
-        handleSelection(SearchTargetEvent.LONG_PRESS);
+        handleSelection(SearchTargetEventLegacy.LONG_PRESS);
         return false;
     }
 
diff --git a/quickstep/src/com/android/launcher3/search/SearchResultWidgetPreview.java b/quickstep/src/com/android/launcher3/search/SearchResultWidgetPreview.java
index 0d79025..5effbe5 100644
--- a/quickstep/src/com/android/launcher3/search/SearchResultWidgetPreview.java
+++ b/quickstep/src/com/android/launcher3/search/SearchResultWidgetPreview.java
@@ -39,8 +39,8 @@
 import com.android.launcher3.widget.PendingItemDragHelper;
 import com.android.launcher3.widget.WidgetCell;
 import com.android.launcher3.widget.WidgetImageView;
-import com.android.systemui.plugins.shared.SearchTarget;
-import com.android.systemui.plugins.shared.SearchTargetEvent;
+import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
+import com.android.systemui.plugins.shared.SearchTargetLegacy;
 
 /**
  * displays preview of a widget upon receiving {@link AppWidgetProviderInfo} from Search provider
@@ -55,7 +55,7 @@
     private WidgetCell mWidgetCell;
     private Toast mWidgetToast;
 
-    private SearchTarget mSearchTarget;
+    private SearchTargetLegacy mSearchTarget;
 
 
     public SearchResultWidgetPreview(Context context) {
@@ -83,7 +83,7 @@
     }
 
     @Override
-    public void applySearchTarget(SearchTarget searchTarget) {
+    public void applySearchTarget(SearchTargetLegacy searchTarget) {
         if (searchTarget.getExtras() == null
                 || searchTarget.getExtras().getParcelable("provider") == null) {
             setVisibility(GONE);
@@ -121,19 +121,19 @@
         new PendingItemDragHelper(mWidgetCell).startDrag(
                 imageView.getBitmapBounds(), imageView.getBitmap().getWidth(), imageView.getWidth(),
                 new Point(loc[0], loc[1]), mLauncher.getAppsView(), new DragOptions());
-        handleSelection(SearchTargetEvent.LONG_PRESS);
+        handleSelection(SearchTargetEventLegacy.LONG_PRESS);
         return true;
     }
 
     @Override
     public void onClick(View view) {
         mWidgetToast = BaseWidgetSheet.showWidgetToast(getContext(), mWidgetToast);
-        handleSelection(SearchTargetEvent.SELECT);
+        handleSelection(SearchTargetEventLegacy.SELECT);
     }
 
     @Override
     public void handleSelection(int eventType) {
         SearchEventTracker.INSTANCE.get(getContext()).notifySearchTargetEvent(
-                new SearchTargetEvent.Builder(mSearchTarget, eventType).build());
+                new SearchTargetEventLegacy.Builder(mSearchTarget, eventType).build());
     }
 }
diff --git a/quickstep/src/com/android/launcher3/search/SearchSectionHeaderView.java b/quickstep/src/com/android/launcher3/search/SearchSectionHeaderView.java
index a552366..eb40938 100644
--- a/quickstep/src/com/android/launcher3/search/SearchSectionHeaderView.java
+++ b/quickstep/src/com/android/launcher3/search/SearchSectionHeaderView.java
@@ -21,7 +21,7 @@
 
 import androidx.annotation.Nullable;
 
-import com.android.systemui.plugins.shared.SearchTarget;
+import com.android.systemui.plugins.shared.SearchTargetLegacy;
 
 /**
  * Header text view that shows a title for a given section in All apps search
@@ -44,7 +44,7 @@
     }
 
     @Override
-    public void applySearchTarget(SearchTarget searchTarget) {
+    public void applySearchTarget(SearchTargetLegacy searchTarget) {
         String title = searchTarget.getExtras().getString("title");
         if (title == null || !title.isEmpty()) {
             setText(title);
diff --git a/quickstep/src/com/android/launcher3/search/SearchSettingsRowView.java b/quickstep/src/com/android/launcher3/search/SearchSettingsRowView.java
index dc5c2f1..8306e3b 100644
--- a/quickstep/src/com/android/launcher3/search/SearchSettingsRowView.java
+++ b/quickstep/src/com/android/launcher3/search/SearchSettingsRowView.java
@@ -38,8 +38,8 @@
 import com.android.launcher3.LauncherAppState;
 import com.android.launcher3.R;
 import com.android.launcher3.model.data.PackageItemInfo;
-import com.android.systemui.plugins.shared.SearchTarget;
-import com.android.systemui.plugins.shared.SearchTargetEvent;
+import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
+import com.android.systemui.plugins.shared.SearchTargetLegacy;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -56,7 +56,7 @@
     private TextView mTitleView;
     private TextView mBreadcrumbsView;
     private Intent mIntent;
-    private SearchTarget mSearchTarget;
+    private SearchTargetLegacy mSearchTarget;
 
 
     public SearchSettingsRowView(@NonNull Context context) {
@@ -84,7 +84,7 @@
     }
 
     @Override
-    public void applySearchTarget(SearchTarget searchTarget) {
+    public void applySearchTarget(SearchTargetLegacy searchTarget) {
         mSearchTarget = searchTarget;
         Bundle bundle = searchTarget.getExtras();
         mIntent = bundle.getParcelable("intent");
@@ -108,7 +108,7 @@
 
     @Override
     public void onClick(View view) {
-        handleSelection(SearchTargetEvent.SELECT);
+        handleSelection(SearchTargetEventLegacy.SELECT);
     }
 
     @Override
@@ -120,7 +120,7 @@
         launcher.startActivityForResult(mIntent, 0);
 
         SearchEventTracker.INSTANCE.get(getContext()).notifySearchTargetEvent(
-                new SearchTargetEvent.Builder(mSearchTarget, eventType).build());
+                new SearchTargetEventLegacy.Builder(mSearchTarget, eventType).build());
     }
 
     /**
diff --git a/quickstep/src/com/android/launcher3/search/SearchTargetHandler.java b/quickstep/src/com/android/launcher3/search/SearchTargetHandler.java
index 347c7d4..9ff057f 100644
--- a/quickstep/src/com/android/launcher3/search/SearchTargetHandler.java
+++ b/quickstep/src/com/android/launcher3/search/SearchTargetHandler.java
@@ -16,7 +16,9 @@
 
 package com.android.launcher3.search;
 
-import com.android.systemui.plugins.shared.SearchTarget;
+import android.app.search.SearchTarget;
+
+import com.android.systemui.plugins.shared.SearchTargetLegacy;
 
 /**
  * An interface for supporting dynamic search results
@@ -24,9 +26,16 @@
 public interface SearchTargetHandler {
 
     /**
-     * Update view using values from {@link SearchTarget}
+     * Update view using values from {@link SearchTargetLegacy}
      */
-    void applySearchTarget(SearchTarget searchTarget);
+    void applySearchTarget(SearchTargetLegacy searchTarget);
+
+    /**
+     * Update view using values from {@link SearchTargetLegacy}
+     */
+    default void applySearchTarget(SearchTarget searchTarget){
+
+    }
 
     /**
      * Handles selection of SearchTarget
diff --git a/quickstep/src/com/android/launcher3/search/ThumbnailSearchResultView.java b/quickstep/src/com/android/launcher3/search/ThumbnailSearchResultView.java
index c100d6a..44f7057 100644
--- a/quickstep/src/com/android/launcher3/search/ThumbnailSearchResultView.java
+++ b/quickstep/src/com/android/launcher3/search/ThumbnailSearchResultView.java
@@ -35,8 +35,8 @@
 import com.android.launcher3.model.data.WorkspaceItemInfo;
 import com.android.launcher3.touch.ItemClickHandler;
 import com.android.launcher3.util.Themes;
-import com.android.systemui.plugins.shared.SearchTarget;
-import com.android.systemui.plugins.shared.SearchTargetEvent;
+import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
+import com.android.systemui.plugins.shared.SearchTargetLegacy;
 
 /**
  * A view representing a high confidence app search result that includes shortcuts
@@ -47,7 +47,7 @@
     public static final String TARGET_TYPE_SCREENSHOT = "screenshot";
     public static final String TARGET_TYPE_SCREENSHOT_LEGACY = "screenshot_legacy";
 
-    private SearchTarget mSearchTarget;
+    private SearchTargetLegacy mSearchTarget;
 
     public ThumbnailSearchResultView(Context context) {
         super(context);
@@ -72,11 +72,11 @@
             ItemClickHandler.onClickAppShortcut(this, (WorkspaceItemInfo) itemInfo, launcher);
         }
         SearchEventTracker.INSTANCE.get(getContext()).notifySearchTargetEvent(
-                new SearchTargetEvent.Builder(mSearchTarget, eventType).build());
+                new SearchTargetEventLegacy.Builder(mSearchTarget, eventType).build());
     }
 
     @Override
-    public void applySearchTarget(SearchTarget target) {
+    public void applySearchTarget(SearchTargetLegacy target) {
         mSearchTarget = target;
         Bitmap bitmap;
         if (target.getRemoteAction() != null) {
@@ -108,7 +108,7 @@
         RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(null, bitmap);
         drawable.setCornerRadius(Themes.getDialogCornerRadius(getContext()));
         setImageDrawable(drawable);
-        setOnClickListener(v -> handleSelection(SearchTargetEvent.SELECT));
+        setOnClickListener(v -> handleSelection(SearchTargetEventLegacy.SELECT));
         SearchEventTracker.INSTANCE.get(getContext()).registerWeakHandler(target, this);
     }
 }
diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java
index d345165..3be1ced 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java
@@ -42,6 +42,7 @@
 import com.android.launcher3.LauncherSettings.Favorites;
 import com.android.launcher3.LauncherState;
 import com.android.launcher3.Workspace;
+import com.android.launcher3.allapps.AllAppsContainerView;
 import com.android.launcher3.allapps.search.SearchAdapterProvider;
 import com.android.launcher3.anim.AnimatorPlaybackController;
 import com.android.launcher3.appprediction.PredictionRowView;
@@ -266,8 +267,8 @@
     }
 
     @Override
-    public SearchAdapterProvider createSearchAdapterProvider() {
-        return new DeviceSearchAdapterProvider(this);
+    public SearchAdapterProvider createSearchAdapterProvider(AllAppsContainerView appsView) {
+        return new DeviceSearchAdapterProvider(this, appsView);
     }
 
     @Override
diff --git a/src/com/android/launcher3/BaseDraggingActivity.java b/src/com/android/launcher3/BaseDraggingActivity.java
index 33af4d7..5bfde15 100644
--- a/src/com/android/launcher3/BaseDraggingActivity.java
+++ b/src/com/android/launcher3/BaseDraggingActivity.java
@@ -43,6 +43,7 @@
 import androidx.annotation.Nullable;
 
 import com.android.launcher3.LauncherSettings.Favorites;
+import com.android.launcher3.allapps.AllAppsContainerView;
 import com.android.launcher3.allapps.search.DefaultSearchAdapterProvider;
 import com.android.launcher3.allapps.search.SearchAdapterProvider;
 import com.android.launcher3.logging.InstanceId;
@@ -297,7 +298,7 @@
      * Creates and returns {@link SearchAdapterProvider} for build variant specific search result
      * views
      */
-    public SearchAdapterProvider createSearchAdapterProvider() {
+    public SearchAdapterProvider createSearchAdapterProvider(AllAppsContainerView allapps) {
         return new DefaultSearchAdapterProvider(this);
     }
 }
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index b016df1..4d51d70 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -124,7 +124,7 @@
         mLauncher = BaseDraggingActivity.fromContext(context);
         mLauncher.addOnDeviceProfileChangeListener(this);
 
-        mSearchAdapterProvider = mLauncher.createSearchAdapterProvider();
+        mSearchAdapterProvider = mLauncher.createSearchAdapterProvider(this);
         mSearchQueryBuilder = new SpannableStringBuilder();
         Selection.setSelection(mSearchQueryBuilder, 0);
 
@@ -569,6 +569,10 @@
         return null;
     }
 
+    public SearchAdapterProvider getSearchAdapterProvider() {
+        return mSearchAdapterProvider;
+    }
+
     public RecyclerViewFastScroller getScrollBar() {
         AllAppsRecyclerView rv = getActiveRecyclerView();
         return rv == null ? null : rv.getScrollbar();
diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java
index 24df653..2455706 100644
--- a/src/com/android/launcher3/config/FeatureFlags.java
+++ b/src/com/android/launcher3/config/FeatureFlags.java
@@ -98,6 +98,10 @@
     public static final BooleanFlag ENABLE_DEVICE_SEARCH = getDebugFlag(
             "ENABLE_DEVICE_SEARCH", false, "Allows on device search in all apps");
 
+    public static final BooleanFlag SEARCH_TARGET_LEGACY = getDebugFlag(
+            "SEARCH_TARGET_LEGACY", true,
+            "Use SearchTarget provided by plugin lib (only during migration)");
+
     public static final BooleanFlag DISABLE_INITIAL_IME_IN_ALLAPPS = getDebugFlag(
             "DISABLE_INITIAL_IME_IN_ALLAPPS", false, "Disable default IME state in all apps");
 
diff --git a/src_plugins/com/android/systemui/plugins/AllAppsSearchPlugin.java b/src_plugins/com/android/systemui/plugins/AllAppsSearchPlugin.java
index 5cc238d..0b48c07 100644
--- a/src_plugins/com/android/systemui/plugins/AllAppsSearchPlugin.java
+++ b/src_plugins/com/android/systemui/plugins/AllAppsSearchPlugin.java
@@ -19,11 +19,12 @@
 import android.app.Activity;
 import android.os.Bundle;
 import android.os.CancellationSignal;
+import android.os.Parcelable;
 import android.view.View;
 
 import com.android.systemui.plugins.annotations.ProvidesInterface;
-import com.android.systemui.plugins.shared.SearchTarget;
-import com.android.systemui.plugins.shared.SearchTargetEvent;
+import com.android.systemui.plugins.shared.SearchTargetEventLegacy;
+import com.android.systemui.plugins.shared.SearchTargetLegacy;
 
 import java.util.List;
 import java.util.function.Consumer;
@@ -34,20 +35,25 @@
 @ProvidesInterface(action = AllAppsSearchPlugin.ACTION, version = AllAppsSearchPlugin.VERSION)
 public interface AllAppsSearchPlugin extends Plugin {
     String ACTION = "com.android.systemui.action.PLUGIN_ALL_APPS_SEARCH_ACTIONS";
-    int VERSION = 8;
+    int VERSION = 9;
 
-    void setup(Activity activity, View view);
+    /**
+     * init plugin
+     */
+    void setup(Activity activity, View view, boolean useLegacy);
 
     /**
      * Send launcher state related signals.
      */
     void onStateTransitionStart(int fromState, int toState);
+
     void onStateTransitionComplete(int state);
 
     /**
      * Send launcher window focus and visibility changed signals.
      */
     void onWindowFocusChanged(boolean hasFocus);
+
     void onWindowVisibilityChanged(int visibility);
 
     /**
@@ -59,22 +65,41 @@
     /**
      * Main function that triggers search.
      *
-     * @param input string that has been typed by a user
-     * @param inputArgs extra info that may be relevant for the input query
-     * @param results contains the result that will be rendered in all apps search surface
+     * @param input              string that has been typed by a user
+     * @param inputArgs          extra info that may be relevant for the input query
+     * @param results            contains the result that will be rendered in all apps search
+     *                           surface
      * @param cancellationSignal {@link CancellationSignal} can be used to share status of current
      */
-    void query(String input, Bundle inputArgs, Consumer<List<SearchTarget>> results,
+    void queryLegacy(String input, Bundle inputArgs, Consumer<List<SearchTargetLegacy>> results,
+            CancellationSignal cancellationSignal);
+
+    /**
+     * Main function that triggers search.
+     *
+     * @param input              string that has been typed by a user
+     * @param inputArgs          extra info that may be relevant for the input query
+     * @param results            contains the result that will be rendered in all apps search
+     *                           surface
+     * @param cancellationSignal {@link CancellationSignal} can be used to share status of current
+     */
+    void query(String input, Bundle inputArgs, Consumer<List<Parcelable>> results,
             CancellationSignal cancellationSignal);
 
     /**
      * Send over search target interaction events to Plugin
      */
-    void notifySearchTargetEvent(SearchTargetEvent event);
+    void notifySearchTargetEventLegacy(SearchTargetEventLegacy event);
+
+    /**
+     * Send over search target interaction events to Plugin
+     */
+    void notifySearchTargetEvent(Parcelable event);
 
     /**
      * Launcher activity lifecycle callbacks
      */
     void onResume(int state);
+
     void onStop(int state);
 }
\ No newline at end of file
diff --git a/src_plugins/com/android/systemui/plugins/shared/SearchTargetEvent.java b/src_plugins/com/android/systemui/plugins/shared/SearchTargetEventLegacy.java
similarity index 75%
rename from src_plugins/com/android/systemui/plugins/shared/SearchTargetEvent.java
rename to src_plugins/com/android/systemui/plugins/shared/SearchTargetEventLegacy.java
index 290fe54..7fbd6ac 100644
--- a/src_plugins/com/android/systemui/plugins/shared/SearchTargetEvent.java
+++ b/src_plugins/com/android/systemui/plugins/shared/SearchTargetEventLegacy.java
@@ -19,8 +19,11 @@
 
 /**
  * Event used for the feedback loop to the plugin. (and future aiai)
+ *
+ * @deprecated Use SearchTargetEvent
  */
-public class SearchTargetEvent {
+@Deprecated
+public class SearchTargetEventLegacy {
     public static final int POSITION_NONE = -1;
 
     public static final int SELECT = 0;
@@ -28,12 +31,13 @@
     public static final int LONG_PRESS = 2;
     public static final int CHILD_SELECT = 3;
 
-    private final SearchTarget mSearchTarget;
+    private final SearchTargetLegacy mSearchTarget;
     private final int mEventType;
     private final int mShortcutPosition;
     private final Bundle mExtras;
 
-    public SearchTargetEvent(SearchTarget searchTarget, int eventType, int shortcutPosition,
+    public SearchTargetEventLegacy(SearchTargetLegacy searchTarget, int eventType,
+            int shortcutPosition,
             Bundle extras) {
         mSearchTarget = searchTarget;
         mEventType = eventType;
@@ -42,7 +46,7 @@
     }
 
 
-    public SearchTarget getSearchTarget() {
+    public SearchTargetLegacy getSearchTarget() {
         return mSearchTarget;
     }
 
@@ -59,15 +63,15 @@
     }
 
     /**
-     * A builder for {@link SearchTarget}
+     * A builder for {@link SearchTargetLegacy}
      */
     public static final class Builder {
-        private final SearchTarget mSearchTarget;
+        private final SearchTargetLegacy mSearchTarget;
         private final int mEventType;
         private int mShortcutPosition = POSITION_NONE;
         private Bundle mExtras;
 
-        public Builder(SearchTarget searchTarget, int eventType) {
+        public Builder(SearchTargetLegacy searchTarget, int eventType) {
             mSearchTarget = searchTarget;
             mEventType = eventType;
         }
@@ -82,8 +86,9 @@
             return this;
         }
 
-        public SearchTargetEvent build() {
-            return new SearchTargetEvent(mSearchTarget, mEventType, mShortcutPosition, mExtras);
+        public SearchTargetEventLegacy build() {
+            return new SearchTargetEventLegacy(mSearchTarget, mEventType, mShortcutPosition,
+                    mExtras);
         }
     }
 
diff --git a/src_plugins/com/android/systemui/plugins/shared/SearchTarget.java b/src_plugins/com/android/systemui/plugins/shared/SearchTargetLegacy.java
similarity index 89%
rename from src_plugins/com/android/systemui/plugins/shared/SearchTarget.java
rename to src_plugins/com/android/systemui/plugins/shared/SearchTargetLegacy.java
index 2c7972e..2a6ba88 100644
--- a/src_plugins/com/android/systemui/plugins/shared/SearchTarget.java
+++ b/src_plugins/com/android/systemui/plugins/shared/SearchTargetLegacy.java
@@ -25,8 +25,11 @@
 
 /**
  * Used to return all apps search targets.
+ *
+ * @deprecated Use SearchTarget
  */
-public class SearchTarget implements Comparable<SearchTarget> {
+@Deprecated
+public class SearchTargetLegacy implements Comparable<SearchTargetLegacy> {
 
     private final String mItemId;
     private final String mItemType;
@@ -39,7 +42,7 @@
     private final RemoteAction mRemoteAction;
     private final Bundle mExtras;
 
-    private SearchTarget(String itemId, String itemType, float score,
+    private SearchTargetLegacy(String itemId, String itemType, float score,
             ComponentName componentName, UserHandle userHandle, List<ShortcutInfo> shortcutInfos,
             RemoteAction remoteAction, Bundle extras) {
         mItemId = itemId;
@@ -85,12 +88,12 @@
     }
 
     @Override
-    public int compareTo(SearchTarget o) {
+    public int compareTo(SearchTargetLegacy o) {
         return Float.compare(o.mScore, mScore);
     }
 
     /**
-     * A builder for {@link SearchTarget}
+     * A builder for {@link SearchTargetLegacy}
      */
     public static final class Builder {
 
@@ -158,13 +161,13 @@
         }
 
         /**
-         * Builds a {@link SearchTarget}
+         * Builds a {@link SearchTargetLegacy}
          */
-        public SearchTarget build() {
+        public SearchTargetLegacy build() {
             if (mItemId == null) {
                 throw new IllegalStateException("Item ID is required for building SearchTarget");
             }
-            return new SearchTarget(mItemId, mItemType, mScore, mComponentName, mUserHandle,
+            return new SearchTargetLegacy(mItemId, mItemType, mScore, mComponentName, mUserHandle,
                     mShortcutInfos,
                     mRemoteAction, mExtras);
         }