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

Commit f37d295d authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 9618620 from 105ff0d3 to tm-qpr3-release

Change-Id: I07a0f3838b904dcee8a6641e0a62b06622721890
parents 0ea59e61 105ff0d3
Loading
Loading
Loading
Loading
+67 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.app.search;

import static com.android.app.search.LayoutType.SMALL_ICON_HORIZONTAL_TEXT;
import static com.android.app.search.SearchActionExtras.BUNDLE_EXTRA_HIDE_ICON;
import static com.android.app.search.SearchActionExtras.BUNDLE_EXTRA_HIDE_SUBTITLE;
import static com.android.app.search.SearchTargetExtras.BUNDLE_EXTRA_CLASS;
import static com.android.app.search.SearchTargetExtras.BUNDLE_EXTRA_SUBTITLE_OVERRIDE;
import static com.android.app.search.SearchTargetExtras.BUNDLE_EXTRA_SUPPORT_QUERY_BUILDER;

import android.app.search.SearchAction;
import android.app.search.SearchTarget;
import android.content.pm.ShortcutInfo;
import android.os.Bundle;

public class SearchTargetConverter {
    /**
     * Generate a searchTarget that uses {@link LayoutType#SMALL_ICON_HORIZONTAL_TEXT} from a
     * searchTarget where original layout type may not have been SMALL_ICON_HORIZONTAL_TEXT. Only
     * possible if the given SearchTarget contains a searchAction or shortcutInfo, otherwise the
     * original searchTarget will be returned.
     */
    public static SearchTarget convertLayoutTypeToSmallIconHorizontalText(
            SearchTarget searchTarget) {
        SearchAction searchTargetAction = searchTarget.getSearchAction();
        ShortcutInfo shortcutInfo = searchTarget.getShortcutInfo();
        int resultType = searchTarget.getResultType();
        String subtitle = "";

        Bundle searchTargetBundle = searchTarget.getExtras();
        searchTargetBundle.putString(BUNDLE_EXTRA_CLASS,
                searchTargetBundle.getString(BUNDLE_EXTRA_CLASS));
        searchTargetBundle.putBoolean(BUNDLE_EXTRA_SUPPORT_QUERY_BUILDER, true);
        searchTargetBundle.putBoolean(BUNDLE_EXTRA_HIDE_SUBTITLE, false);
        searchTargetBundle.putString(BUNDLE_EXTRA_SUBTITLE_OVERRIDE, subtitle);
        searchTargetBundle.putBoolean(BUNDLE_EXTRA_HIDE_ICON, false);

        SearchTarget.Builder builder = new SearchTarget.Builder(resultType,
                SMALL_ICON_HORIZONTAL_TEXT, searchTarget.getId())
                .setPackageName(searchTarget.getPackageName())
                .setExtras(searchTargetBundle)
                .setUserHandle(searchTarget.getUserHandle());
        if (searchTargetAction != null) {
            builder.setSearchAction(searchTargetAction);
        } else if (shortcutInfo != null) {
            builder.setShortcutInfo(shortcutInfo);
        } else {
            return searchTarget;
        }
        return builder.build();
    }
}
+74 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.app.search;

import static com.android.app.search.SearchTargetExtras.isRichAnswer;

import android.app.search.SearchTarget;
import android.content.ComponentName;
import android.os.Process;

import androidx.annotation.Nullable;

/**
 * Helper class that defines helper methods for {@link android.app.search.SearchTargetEvent} to
 * define the contract between Launcher and AiAi for notifyEvent.
 */

public class SearchTargetEventHelper {

    /**
     * Generate web target id similar to AiAi targetId for logging both 0-state and n-state.
     * AiAi target id is of format "resultType:userId:packageName:extraInfo"
     *
     * @return string webTargetId
     * Example webTargetId for
     * web suggestion - WEB_SUGGEST:0:com.google.android.googlequicksearchbox:SUGGESTION
     * rich answer - WEB_SUGGEST:0:com.google.android.googlequicksearchbox:RICH_ANSWER
     */
    public static String generateWebTargetIdForLogging(SearchTarget webTarget) {
        StringBuilder webTargetId = new StringBuilder(
                "WEB_SUGGEST" + ":" + Process.myUserHandle().getIdentifier() + ":"
                        + webTarget.getPackageName());
        if (isRichAnswer(webTarget)) {
            webTargetId.append(":RICH_ANSWER");
        } else {
            webTargetId.append(":SUGGESTION");
        }
        return webTargetId.toString();
    }

    /**
     * Generate application target id similar to AiAi targetId for logging only 0-state.
     * For n-state, AiAi already populates the target id in right format.
     * AiAi target id is of format "resultType:userId:packageName:extraInfo"
     *
     * When the apps from AiAi's AppPredictionService are converted to {@link SearchTarget}, we need
     * to construct the targetId using componentName.
     *
     * @return string appTargetId
     * Example appTargetId for
     * maps - APPLICATION:0:com.google.android.apps.maps:com.google.android.maps.MapsActivity
     * clock - APPLICATION:0:com.google.android.deskclock:com.android.deskclock.DeskClock
     */
    public static String generateAppTargetIdForLogging(@Nullable ComponentName appComponentName) {
        StringBuilder appTargetId = new StringBuilder(
                "APPLICATION" + ":" + Process.myUserHandle().getIdentifier() + ":");
        if (appComponentName == null) return appTargetId.append(" : ").toString();
        return appTargetId + appComponentName.getPackageName() + ":"
                + appComponentName.getClassName();
    }
}
+15 −3
Original line number Diff line number Diff line
@@ -19,8 +19,8 @@ package com.android.app.search;
import static com.android.app.search.LayoutType.TALL_CARD_WITH_IMAGE_NO_ICON;

import android.app.blob.BlobHandle;
import android.app.search.SearchAction;
import android.app.search.SearchTarget;
import android.os.Bundle;
import android.text.TextUtils;

import androidx.annotation.Nullable;
@@ -42,10 +42,13 @@ public class SearchTargetExtras {
    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.
    // 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 if subtitle view should be overridden to string that is not natively defined by the
    // search target.
    public static final String BUNDLE_EXTRA_SUBTITLE_OVERRIDE = "subtitle_override";

    // Used for logging. Returns whether spelling correction was applied.
    public static final String BUNDLE_EXTRA_IS_QUERY_CORRECTED = "is_query_corrected";
@@ -112,10 +115,19 @@ public class SearchTargetExtras {
     *  When this flag is false, thumbnails will always be cropped to a square ratio even if
     *  there aren't enough thumbnails to fill the container.
     *
     *  Only relevant in {@link LayoutType.THUMBNAIL_CONTAINER} and {@link LayoutType.THUMBNAIL}.
     *  Only relevant in {@link LayoutType#THUMBNAIL_CONTAINER} and {@link LayoutType#THUMBNAIL}.
     */
    public static final String BUNDLE_EXTRA_SHOULD_FILL_CONTAINER_WIDTH =
            "should_fill_container_width";
    /**
     *  Flag to control whether the SearchTarget's label should be hidden.
     *  When this flag is true, label will be hidden.
     *  When this flag is false (or omitted), {@link SearchAction#mTitle} will be shown.
     */
    public static final String BUNDLE_EXTRA_HIDE_LABEL =
            "hide_label";
    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";