1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package android.app.cloudsearch; 17 18 import android.annotation.NonNull; 19 import android.annotation.StringDef; 20 import android.annotation.SuppressLint; 21 import android.annotation.SystemApi; 22 import android.os.Bundle; 23 import android.os.Parcel; 24 import android.os.Parcelable; 25 26 import java.lang.annotation.Retention; 27 import java.lang.annotation.RetentionPolicy; 28 29 /** 30 * A {@link SearchResult} includes all the information for one result item. 31 * 32 * @hide 33 */ 34 @SystemApi 35 public final class SearchResult implements Parcelable { 36 37 /** 38 * List of public static KEYS for Bundles in mExtraInfos. 39 * mExtraInfos contains various information specified for different data types. 40 * 41 * @hide 42 */ 43 @Retention(RetentionPolicy.SOURCE) 44 @StringDef(prefix = {"EXTRAINFO_"}, 45 value = {EXTRAINFO_APP_DOMAIN_URL, 46 EXTRAINFO_APP_ICON, 47 EXTRAINFO_APP_DEVELOPER_NAME, 48 EXTRAINFO_APP_SIZE_BYTES, 49 EXTRAINFO_APP_STAR_RATING, 50 EXTRAINFO_APP_IARC, 51 EXTRAINFO_APP_REVIEW_COUNT, 52 EXTRAINFO_APP_CONTAINS_ADS_DISCLAIMER, 53 EXTRAINFO_APP_CONTAINS_IAP_DISCLAIMER, 54 EXTRAINFO_SHORT_DESCRIPTION, 55 EXTRAINFO_LONG_DESCRIPTION, 56 EXTRAINFO_SCREENSHOTS, 57 EXTRAINFO_APP_BADGES, 58 EXTRAINFO_ACTION_BUTTON_TEXT_PREREGISTERING, 59 EXTRAINFO_ACTION_BUTTON_IMAGE_PREREGISTERING, 60 EXTRAINFO_ACTION_APP_CARD, 61 EXTRAINFO_ACTION_INSTALL_BUTTON, 62 EXTRAINFO_APP_PACKAGE_NAME, 63 EXTRAINFO_APP_INSTALL_COUNT, 64 EXTRAINFO_WEB_URL, 65 EXTRAINFO_WEB_ICON}) 66 public @interface SearchResultExtraInfoKey { 67 } 68 69 /** This App developer website's domain URL, String value expected. */ 70 public static final String EXTRAINFO_APP_DOMAIN_URL = "android.app.cloudsearch.APP_DOMAIN_URL"; 71 /** This App icon, android.graphics.drawable.Icon expected. */ 72 public static final String EXTRAINFO_APP_ICON = "android.app.cloudsearch.APP_ICON"; 73 /** This App developer's name, String value expected. */ 74 public static final String EXTRAINFO_APP_DEVELOPER_NAME = 75 "android.app.cloudsearch.APP_DEVELOPER_NAME"; 76 /** This App's pkg size in bytes, Double value expected. */ 77 public static final String EXTRAINFO_APP_SIZE_BYTES = "android.app.cloudsearch.APP_SIZE_BYTES"; 78 /** This App developer's name, Double value expected. */ 79 public static final String EXTRAINFO_APP_STAR_RATING = 80 "android.app.cloudsearch.APP_STAR_RATING"; 81 /** 82 * This App's IARC rating, String value expected. 83 * IARC (International Age Rating Coalition) is partnered globally with major 84 * content rating organizations to provide a centralized and one-stop-shop for 85 * rating content on a global scale. 86 */ 87 public static final String EXTRAINFO_APP_IARC = "android.app.cloudsearch.APP_IARC"; 88 /** This App's review count, Double value expected. */ 89 public static final String EXTRAINFO_APP_REVIEW_COUNT = 90 "android.app.cloudsearch.APP_REVIEW_COUNT"; 91 /** If this App contains the Ads Disclaimer, Boolean value expected. */ 92 public static final String EXTRAINFO_APP_CONTAINS_ADS_DISCLAIMER = 93 "android.app.cloudsearch.APP_CONTAINS_ADS_DISCLAIMER"; 94 /** If this App contains the IAP Disclaimer, Boolean value expected. */ 95 public static final String EXTRAINFO_APP_CONTAINS_IAP_DISCLAIMER = 96 "android.app.cloudsearch.APP_CONTAINS_IAP_DISCLAIMER"; 97 /** This App's short description, String value expected. */ 98 public static final String EXTRAINFO_SHORT_DESCRIPTION = 99 "android.app.cloudsearch.SHORT_DESCRIPTION"; 100 /** This App's long description, String value expected. */ 101 public static final String EXTRAINFO_LONG_DESCRIPTION = 102 "android.app.cloudsearch.LONG_DESCRIPTION"; 103 /** This App's screenshots, {@code List<ImageLoadingBundle>} value expected. */ 104 public static final String EXTRAINFO_SCREENSHOTS = "android.app.cloudsearch.SCREENSHOTS"; 105 /** Editor's choices for this App, {@code ArrayList<String>} value expected. */ 106 public static final String EXTRAINFO_APP_BADGES = "android.app.cloudsearch.APP_BADGES"; 107 /** Pre-registration game's action button text, String value expected. */ 108 @SuppressLint("IntentName") 109 public static final String EXTRAINFO_ACTION_BUTTON_TEXT_PREREGISTERING = 110 "android.app.cloudsearch.ACTION_BUTTON_TEXT"; 111 /** Pre-registration game's action button image, ImageLoadingBundle value expected. */ 112 @SuppressLint("IntentName") 113 public static final String EXTRAINFO_ACTION_BUTTON_IMAGE_PREREGISTERING = 114 "android.app.cloudsearch.ACTION_BUTTON_IMAGE"; 115 /** Intent for tapping the app card, PendingIntent expected. */ 116 @SuppressLint("IntentName") 117 public static final String EXTRAINFO_ACTION_APP_CARD = 118 "android.app.cloudsearch.ACTION_APP_CARD"; 119 /** Intent for tapping the install button, PendingIntent expected. */ 120 @SuppressLint("IntentName") 121 public static final String EXTRAINFO_ACTION_INSTALL_BUTTON = 122 "android.app.cloudsearch.ACTION_INSTALL_BUTTON"; 123 /** App's package name, String value expected. */ 124 public static final String EXTRAINFO_APP_PACKAGE_NAME = 125 "android.app.cloudsearch.APP_PACKAGE_NAME"; 126 /** App's install count, double value expected. */ 127 public static final String EXTRAINFO_APP_INSTALL_COUNT = 128 "android.app.cloudsearch.APP_INSTALL_COUNT"; 129 /** Web content's URL, String value expected. */ 130 public static final String EXTRAINFO_WEB_URL = "android.app.cloudsearch.WEB_URL"; 131 /** Web content's domain icon, android.graphics.drawable.Icon expected. */ 132 public static final String EXTRAINFO_WEB_ICON = "android.app.cloudsearch.WEB_ICON"; 133 SearchResult()134 private SearchResult() { 135 } 136 137 /** Gets the search result title. */ 138 @NonNull getTitle()139 public String getTitle() { 140 return ""; 141 } 142 143 /** Gets the search result snippet. */ 144 @NonNull getSnippet()145 public String getSnippet() { 146 return ""; 147 } 148 149 /** Gets the ranking score provided by the original search provider. */ getScore()150 public float getScore() { 151 return 0; 152 } 153 154 /** Gets the extra information associated with the search result. */ 155 @NonNull getExtraInfos()156 public Bundle getExtraInfos() { 157 return Bundle.EMPTY; 158 } 159 160 /** 161 * @see Creator 162 */ 163 @NonNull 164 public static final Creator<SearchResult> CREATOR = new Creator<SearchResult>() { 165 @Override 166 public SearchResult createFromParcel(Parcel p) { 167 return new SearchResult(); 168 } 169 170 @Override 171 public SearchResult[] newArray(int size) { 172 return new SearchResult[size]; 173 } 174 }; 175 176 @Override writeToParcel(@onNull Parcel dest, int flags)177 public void writeToParcel(@NonNull Parcel dest, int flags) { 178 } 179 180 @Override describeContents()181 public int describeContents() { 182 return 0; 183 } 184 185 @Override equals(Object obj)186 public boolean equals(Object obj) { 187 return false; 188 } 189 190 @Override hashCode()191 public int hashCode() { 192 return 0; 193 } 194 195 /** 196 * Builder constructing SearchResult. 197 * 198 * @hide 199 */ 200 @SystemApi 201 public static final class Builder { 202 /** 203 * @param title the title to the search result. 204 * @param extraInfos the extra infos associated with the search result. 205 * @hide 206 */ 207 @SystemApi Builder(@onNull String title, @NonNull Bundle extraInfos)208 public Builder(@NonNull String title, @NonNull Bundle extraInfos) { 209 } 210 211 /** Sets the title to the search result. */ 212 @NonNull setTitle(@onNull String title)213 public Builder setTitle(@NonNull String title) { 214 return this; 215 } 216 217 /** Sets the snippet to the search result. */ 218 @NonNull setSnippet(@onNull String snippet)219 public Builder setSnippet(@NonNull String snippet) { 220 return this; 221 } 222 223 /** Sets the ranking score to the search result. */ 224 @NonNull setScore(float score)225 public Builder setScore(float score) { 226 return this; 227 } 228 229 /** Adds extra information to the search result for rendering in the UI. */ 230 @NonNull setExtraInfos(@onNull Bundle extraInfos)231 public Builder setExtraInfos(@NonNull Bundle extraInfos) { 232 return this; 233 } 234 235 /** Builds a SearchResult based-on the given parameters. */ 236 @NonNull build()237 public SearchResult build() { 238 return new SearchResult(); 239 } 240 } 241 } 242