From 5191fe9ba04f141a95692a242ec499a53f93b117 Mon Sep 17 00:00:00 2001 From: Hyunyoung Song Date: Mon, 24 Aug 2020 16:38:02 -0700 Subject: [PATCH] SearchTarget/SearchTargetEvent API Bug: 165869384 Bug: 161599758 TL;DR;; Also introduce some additional methods for - all apps start and stop - metrics logging Change-Id: I666ff5a27a5f8befdb0db483ebb07344a90e96bc --- quickstep/res/values/override.xml | 2 - .../search/AllAppsSearchBarController.java | 8 +- .../systemui/plugins/AllAppsSearchPlugin.java | 25 +++-- .../com/android/systemui/plugins/OWNERS | 4 - .../systemui/plugins/shared/SearchTarget.java | 99 +++++++++++++++++++ .../plugins/shared/SearchTargetEvent.java | 39 ++++++++ 6 files changed, 164 insertions(+), 13 deletions(-) delete mode 100644 src_plugins/com/android/systemui/plugins/OWNERS create mode 100644 src_plugins/com/android/systemui/plugins/shared/SearchTarget.java create mode 100644 src_plugins/com/android/systemui/plugins/shared/SearchTargetEvent.java diff --git a/quickstep/res/values/override.xml b/quickstep/res/values/override.xml index 8f4ce4343b..605774dd9c 100644 --- a/quickstep/res/values/override.xml +++ b/quickstep/res/values/override.xml @@ -25,8 +25,6 @@ com.android.quickstep.QuickstepProcessInitializer - com.android.quickstep.logging.UserEventDispatcherExtension - com.android.launcher3.model.QuickstepModelDelegate diff --git a/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java b/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java index 2e5ed3ec35..29e340480d 100644 --- a/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java +++ b/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java @@ -79,7 +79,7 @@ public class AllAppsSearchBarController public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { if (mSearchAlgorithm instanceof PluginWrapper) { ((PluginWrapper) mSearchAlgorithm).runOnPluginIfConnected( - AllAppsSearchPlugin::startedTyping); + AllAppsSearchPlugin::startedSearchSession); } } @@ -113,7 +113,13 @@ public class AllAppsSearchBarController public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (FeatureFlags.ENABLE_DEVICE_SEARCH.get()) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { + // selectFocusedView should return SearchTargetEvent that is passed onto onClick if (Launcher.getLauncher(mLauncher).getAppsView().selectFocusedView(v)) { + if (mSearchAlgorithm instanceof PluginWrapper) { + ((PluginWrapper) mSearchAlgorithm).runOnPluginIfConnected(plugin -> { + plugin.onClick(false, null); + }); + } return true; } } diff --git a/src_plugins/com/android/systemui/plugins/AllAppsSearchPlugin.java b/src_plugins/com/android/systemui/plugins/AllAppsSearchPlugin.java index be20e2dbe6..9949678458 100644 --- a/src_plugins/com/android/systemui/plugins/AllAppsSearchPlugin.java +++ b/src_plugins/com/android/systemui/plugins/AllAppsSearchPlugin.java @@ -16,9 +16,9 @@ package com.android.systemui.plugins; -import android.os.Bundle; - import com.android.systemui.plugins.annotations.ProvidesInterface; +import com.android.systemui.plugins.shared.SearchTarget; +import com.android.systemui.plugins.shared.SearchTargetEvent; import java.util.List; import java.util.function.Consumer; @@ -29,15 +29,28 @@ import java.util.function.Consumer; @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 = 4; + int VERSION = 5; + + + /** + * Send signal when user enters all apps. + */ + void startAllAppsSession(); /** * Send signal when user starts typing. */ - void startedTyping(); + void startedSearchSession(); /** * Send over the query and get the search results. */ - void performSearch(String query, Consumer> results); -} + void performSearch(String query, Consumer> results); + + void onClick(boolean isTouch, SearchTargetEvent event); + + /** + * Send signal when user exits all apps. + */ + void endAllAppsSession(); +} \ No newline at end of file diff --git a/src_plugins/com/android/systemui/plugins/OWNERS b/src_plugins/com/android/systemui/plugins/OWNERS deleted file mode 100644 index 0514999392..0000000000 --- a/src_plugins/com/android/systemui/plugins/OWNERS +++ /dev/null @@ -1,4 +0,0 @@ -# When changing interface for this plugin OR when increasing version code, please add Alex -# Only add other owners if Alex is not available -per-file AllAppsSearchPlugin.java, globs = set noparent -per-file AllAppsSearchPlugin.java = alexmang@google.com, hyunyoungs@google.com, sunnygoyal@google.com, twickham@google.com diff --git a/src_plugins/com/android/systemui/plugins/shared/SearchTarget.java b/src_plugins/com/android/systemui/plugins/shared/SearchTarget.java new file mode 100644 index 0000000000..913fc0ed7c --- /dev/null +++ b/src_plugins/com/android/systemui/plugins/shared/SearchTarget.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.systemui.plugins.shared; + +import android.content.pm.ShortcutInfo; +import android.os.Bundle; + +import java.util.List; + +/** + * Used to return all apps search targets. + */ +public class SearchTarget implements Comparable { + + public enum ViewType { + TOP_HIT(0), + HERO(1), + DETAIL(2), + ROW(3), + ROW_WITH_BUTTON(4), + SLICE(5); + + private final int mId; + ViewType(int id) { + mId = id; + } + + public int get() { + return mId; + } + } + + public enum ItemType { + PLAY_RESULTS(0, "Play Store", ViewType.DETAIL), + SETTINGS_ROW(1, "Settings", ViewType.ROW), + SETTINGS_SLICE(2, "Settings", ViewType.SLICE), + APP(3, "", ViewType.TOP_HIT), + APP_HERO(4, "", ViewType.HERO); + + private final int mId; + private final String mTitle; + private final ViewType mViewType; + + ItemType(int id, String title, ViewType type) { + mId = id; + mTitle = title; + mViewType = type; + } + + public ViewType getViewType() { + return mViewType; + } + + public String getTitle() { + return mTitle; + } + + public int getId() { + return mId; + } + } + + public ItemType type; + public List shortcuts; + public Bundle bundle; + public float score; + + /** + * Constructor to create the search target. Bundle is currently temporary to hold + * search target primitives that cannot be expressed as java primitive objects + * or AOSP native objects. + * + */ + public SearchTarget(ItemType itemType, List shortcuts, + Bundle bundle, float score) { + this.type = itemType; + this.shortcuts = shortcuts; + this.bundle = bundle; + this.score = score; + } + + @Override + public int compareTo(SearchTarget o) { + return Float.compare(o.score, score); + } +} diff --git a/src_plugins/com/android/systemui/plugins/shared/SearchTargetEvent.java b/src_plugins/com/android/systemui/plugins/shared/SearchTargetEvent.java new file mode 100644 index 0000000000..00aacd0543 --- /dev/null +++ b/src_plugins/com/android/systemui/plugins/shared/SearchTargetEvent.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.systemui.plugins.shared; + +import android.content.pm.ShortcutInfo; +import android.os.Bundle; + +/** + * Event used for the feedback loop to the plugin. (and future aiai) + */ +public class SearchTargetEvent { + public SearchTarget.ItemType type; + public ShortcutInfo shortcut; + public Bundle bundle; + public float score; + + public SearchTargetEvent(SearchTarget.ItemType itemType, + ShortcutInfo shortcut, + Bundle bundle, + float score) { + this.type = itemType; + this.shortcut = shortcut; + this.bundle = bundle; + this.score = score; + } +}