Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c1caa7c authored by Hyunyoung Song's avatar Hyunyoung Song Committed by Android (Google) Code Review
Browse files

Merge "Setup SearchTarget[Extras|Generator|Processor]" into tm-qpr-dev

parents 3b840087 4fb26a05
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -19,9 +19,11 @@ package {
android_library {
    name: "search_ui",

    sdk_version: "current",
    min_sdk_version: "26",
    sdk_version: "system_current",

    static_libs: [
        "androidx.annotation_annotation",
    ],
    srcs: [
        "src/**/*.java",
    ],
+0 −3
Original line number Diff line number Diff line
@@ -73,9 +73,6 @@ public class LayoutType {
    // text based header to group various layouts in low confidence section of the results.
    public static final String TEXT_HEADER = "header";

    // horizontal bar to be inserted between fallback search results and low confidence section
    public static final String DIVIDER = "divider";

    // horizontal bar to be inserted between fallback search results and low confidence section
    public static final String EMPTY_DIVIDER = "empty_divider";

+38 −0
Original line number Diff line number Diff line
@@ -51,4 +51,42 @@ public class ResultType {
    public static final int EDUCARD = 1 << 19;
    public static final int SYSTEM_POINTER = 1 << 20;
    public static final int VIDEO = 1 << 21;

    public static final int PUBLIC_DATA_TYPE = APPLICATION | SETTING | PLAY | WEB_SUGGEST;
    public static final int PRIMITIVE_TYPE = APPLICATION | SLICE | SHORTCUT | WIDGETS | ACTION |
            LEGACY_SHORTCUT;
    public static final int CORPUS_TYPE = SETTING | IMAGE | PLAY | SUGGEST | ASSISTANT | CHROMETAB |
            NAVVYSITE | TIPS | PEOPLE_TILE | MEMORY | WEB_SUGGEST | VIDEO;
    public static final int RANK_TYPE = SYSTEM_POINTER;
    public static final int UI_TYPE = EDUCARD | NO_FULFILLMENT;

    public static boolean isSlice(int resultType) {
        return (resultType & SLICE) != 0;
    }

    public static boolean isSystemPointer(int resultType) {
        return (resultType & SYSTEM_POINTER) != 0;
    }

    /**
     * Returns result type integer where only {@code #CORPUS_TYPE} bit will turned on.
     */
    public static int getCorpusType(int resultType) {
        return (resultType & CORPUS_TYPE);
    }

    /**
     * Returns result type integer where only {@code #PRIMITIVE_TYPE} bit will be turned on.
     */
    public static int getPrimitiveType(int resultType) {
        return (resultType & PRIMITIVE_TYPE);
    }


    /**
     * Returns whether the given result type is not privacy sensitive.
     */
    public static boolean isPrivacySafe(int resultType) {
        return (resultType & PUBLIC_DATA_TYPE) != 0;
    }
}
+22 −0
Original line number Diff line number Diff line
package com.android.app.search;

import android.app.search.SearchAction;

/**
 * Helper class that defines key string value for {@link SearchAction#getExtras()}
 */
public class SearchActionExtras {
    public static final String BUNDLE_EXTRA_HIDE_SUBTITLE = "hide_subtitle";
    public static final String BUNDLE_EXTRA_HIDE_ICON = "hide_icon";
    public static final String BUNDLE_EXTRA_ALLOW_PINNING = "allow_pinning";
    public static final String BUNDLE_EXTRA_BADGE_WITH_PACKAGE = "badge_with_package";
    public static final String BUNDLE_EXTRA_PRIMARY_ICON_FROM_TITLE = "primary_icon_from_title";
    public static final String BUNDLE_EXTRA_IS_SEARCH_IN_APP = "is_search_in_app";
    public static final String BUNDLE_EXTRA_BADGE_WITH_COMPONENT_NAME = "badge_with_component_name";
    public static final String BUNDLE_EXTRA_ICON_CACHE_KEY = "icon_cache_key";
    public static final String BUNDLE_EXTRA_SHOULD_START = "should_start";
    public static final String BUNDLE_EXTRA_SHOULD_START_FOR_RESULT = "should_start_for_result";
    public static final String BUNDLE_EXTRA_SUGGEST_OPEN_DEFAULT_BROWSER =
            "suggest_open_default_browser";

}
+96 −0
Original line number Diff line number Diff line
package com.android.app.search;

import static com.android.app.search.LayoutType.TALL_CARD_WITH_IMAGE_NO_ICON;

import android.app.search.SearchTarget;
import android.text.TextUtils;

import androidx.annotation.Nullable;

/**
 * Helper class that defines key string value for {@link SearchTarget#getExtras()}
 * and also defines helper methods
 */
public class SearchTargetExtras {

    /** on device data related extras and helper methods */
    // Used to extra component name
    public static final String BUNDLE_EXTRA_CLASS = "class";

    // Used for UI treatment. Labels whether search target should support quick launch
    public static final String BUNDLE_EXTRA_QUICK_LAUNCH = "quick_launch";
    // Used for UI treatment. Targets grouped with same group id are decorated together.
    public static final String BUNDLE_EXTRA_GROUP_ID = "group_id";
    public static final String BUNDLE_EXTRA_GROUP_DECORATE_TOGETHER = "decorate_together";
    // Used if slice title should be rendered else where outside of slice (e.g., edit text)
    public static final String BUNDLE_EXTRA_SLICE_TITLE = "slice_title";
    // USed if slice view should be rendered using full height mode.
    public static final String BUNDLE_EXTRA_USE_FULL_HEIGHT = "use_full_height";
    public static final String BUNDLE_EXTRA_IS_NON_TAPPABLE = "is_non_tappable";
    public static final String BUNDLE_EXTRA_TITLE_OVERWRITE = "title_overwrite";

    // Used for logging. Returns whether spelling correction was applied.
    public static final String BUNDLE_EXTRA_IS_QUERY_CORRECTED = "is_query_corrected";
    // Used for logging. Returns whether the result matched block title or the inline item.
    public static final String BUNDLE_EXTRA_RESULT_MATCH_USER_TYPED = "result_match_user_typed";
    // Used for logging. Returns the timestamp when system service received the data.
    public static final String BUNDLE_EXTRA_START_TIMESTAMP = "start_timestamp";
    // Indicates the search result app location column
    public static final String BUNDLE_EXTRA_RESULT_APP_GRIDX = "app_gridx";

    public static final int GROUPING = 1 << 1;

    @Nullable
    public static String getDecoratorId(@Nullable SearchTarget target) {
        return (target == null || target.getExtras() == null) ? null :
                target.getExtras().getString(BUNDLE_EXTRA_GROUP_ID);
    }

    public static int getDecoratorType(@Nullable SearchTarget target) {
        int type = 0;
        if (target == null || target.getExtras() == null) {
            return type;
        }
        if (!TextUtils.isEmpty(target.getExtras().getString(BUNDLE_EXTRA_GROUP_ID))) {
            type |= GROUPING;
        }
        return type;
    }

    /** Web data related extras and helper methods */
    public static final String BUNDLE_EXTRA_PROXY_WEB_ITEM = "proxy_web_item";
    public static final String BUNDLE_EXTRA_ENTITY = "is_entity";
    public static final String BUNDLE_EXTRA_ANSWER = "is_answer";
    public static final String BUNDLE_EXTRA_RESPONSE_ID = "response_id";
    public static final String BUNDLE_EXTRA_LEARN_MORE_URL = "learn_more_url";
    public static final String BUNDLE_EXTRA_PERSONAL = "is_personal";
    public static final String BUNDLE_EXTRA_SUGGESTION_TYPE = "suggestion_type";
    public static final String BUNDLE_EXTRA_SUGGEST_RENDER_TEXT = "suggest_render_text";
    public static final String BUNDLE_EXTRA_ZERO_STATE_CACHE = "zero_state_cache";
    public static final String BUNDLE_EXTRA_TALL_CARD_HEADER = "tall_card_header";
    public static final String BUNDLE_EXTRA_TALL_CARD_IMAGE_DESCRIPTION =
            "tall_card_image_description";
    public static final String BUNDLE_EXTRA_BITMAP_URL = "bitmap_url";
    public static final String BUNDLE_EXTRA_SUGGESTION_ACTION_TEXT = "suggestion_action_text";
    public static final String BUNDLE_EXTRA_SUGGESTION_ACTION_RPC = "suggestion_action_rpc";
    public static final String BUNDLE_EXTRA_SUPPORT_QUERY_BUILDER = "support_query_builder";
    public static final String BUNDLE_EXTRA_SUGGEST_RAW_TEXT = "suggest_raw_text";
    public static final String BUNDLE_EXTRA_SUGGEST_TRUNCATE_START = "suggest_truncate_start";

    /** Web data related helper methods */
    public static boolean isEntity(@Nullable SearchTarget target) {
        return target != null && target.getExtras() != null
                && target.getExtras().getBoolean(BUNDLE_EXTRA_ENTITY);
    }

    public static boolean isAnswer(@Nullable SearchTarget target) {
        return target != null && target.getExtras() != null
                && target.getExtras().getBoolean(BUNDLE_EXTRA_ANSWER);
    }

    /** Whether the search target is a rich answer web result. */
    public static boolean isRichAnswer(@Nullable SearchTarget target) {
        return target !=null && isAnswer(target)
                && target.getLayoutType().equals(TALL_CARD_WITH_IMAGE_NO_ICON);
    }
}
Loading