Merge "All Apps Search API council feedback (second round)" into sc-dev
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index e80615a..96a23b2 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -1528,6 +1528,9 @@
     method public boolean shouldHide();
     method public void writeToParcel(@NonNull android.os.Parcel, int);
     field @NonNull public static final android.os.Parcelable.Creator<android.app.search.SearchTarget> CREATOR;
+    field public static final String LAYOUT_TYPE_ICON = "icon";
+    field public static final String LAYOUT_TYPE_ICON_ROW = "icon_row";
+    field public static final String LAYOUT_TYPE_SHORT_ICON_ROW = "short_icon_row";
     field public static final int RESULT_TYPE_APPLICATION = 1; // 0x1
     field public static final int RESULT_TYPE_SHORTCUT = 2; // 0x2
     field public static final int RESULT_TYPE_SLICE = 4; // 0x4
@@ -1541,7 +1544,7 @@
     method @NonNull public android.app.search.SearchTarget.Builder setExtras(@NonNull android.os.Bundle);
     method @NonNull public android.app.search.SearchTarget.Builder setPackageName(@NonNull String);
     method @NonNull public android.app.search.SearchTarget.Builder setParentId(@NonNull String);
-    method @NonNull public android.app.search.SearchTarget.Builder setScore(float);
+    method @NonNull public android.app.search.SearchTarget.Builder setScore(@FloatRange(from=0.0f, to=1.0f) float);
     method @NonNull public android.app.search.SearchTarget.Builder setSearchAction(@Nullable android.app.search.SearchAction);
     method @NonNull public android.app.search.SearchTarget.Builder setShortcutInfo(@NonNull android.content.pm.ShortcutInfo);
     method @NonNull public android.app.search.SearchTarget.Builder setShouldHide(boolean);
diff --git a/core/java/android/app/search/SearchContext.java b/core/java/android/app/search/SearchContext.java
index 3e345fa..8f584cc 100644
--- a/core/java/android/app/search/SearchContext.java
+++ b/core/java/android/app/search/SearchContext.java
@@ -62,7 +62,7 @@
      * @param resultTypes {@link SearchTarget.SearchResultType}s combined using bit OR operation
      * @param timeoutMillis timeout before client renders its own fallback result
      */
-    public SearchContext(int resultTypes, int timeoutMillis) {
+    public SearchContext(@SearchTarget.SearchResultType int resultTypes, int timeoutMillis) {
         this(resultTypes, timeoutMillis, new Bundle());
     }
 
diff --git a/core/java/android/app/search/SearchTarget.java b/core/java/android/app/search/SearchTarget.java
index 56c5ddf..6d638d4 100644
--- a/core/java/android/app/search/SearchTarget.java
+++ b/core/java/android/app/search/SearchTarget.java
@@ -15,9 +15,11 @@
  */
 package android.app.search;
 
+import android.annotation.FloatRange;
 import android.annotation.IntDef;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
+import android.annotation.StringDef;
 import android.annotation.SystemApi;
 import android.app.slice.SliceManager;
 import android.appwidget.AppWidgetProviderInfo;
@@ -66,6 +68,24 @@
     public static final int RESULT_TYPE_SHORTCUT = 1 << 1;
     public static final int RESULT_TYPE_SLICE = 1 << 2;
     public static final int RESULT_TYPE_WIDGETS = 1 << 3;
+
+    //     ------
+    //    | icon |
+    //     ------
+    //      text
+    public static final String LAYOUT_TYPE_ICON = "icon";
+
+    //     ------                            ------   ------
+    //    |      | title                    |(opt)|  |(opt)|
+    //    | icon | subtitle (optional)      | icon|  | icon|
+    //     ------                            ------  ------
+    public static final String LAYOUT_TYPE_ICON_ROW = "icon_row";
+
+    //     ------
+    //    | icon | title / subtitle (optional)
+    //     ------
+    public static final String LAYOUT_TYPE_SHORT_ICON_ROW = "short_icon_row";
+
     /**
      * @hide
      */
@@ -80,6 +100,17 @@
     private final int mResultType;
 
     /**
+     * @hide
+     */
+    @StringDef(prefix = {"LAYOUT_TYPE_"}, value = {
+            LAYOUT_TYPE_ICON,
+            LAYOUT_TYPE_ICON_ROW,
+            LAYOUT_TYPE_SHORT_ICON_ROW,
+    })
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface SearchLayoutType {}
+
+    /**
      * Constant to express how the group of {@link SearchTarget} should be rendered on
      * the client side. (e.g., "icon", "icon_row", "short_icon_row")
      */
@@ -178,7 +209,7 @@
      * Retrieves the layout type.
      */
     @NonNull
-    public String getLayoutType() {
+    public @SearchLayoutType String getLayoutType() {
         return mLayoutType;
     }
 
@@ -337,7 +368,7 @@
         private Bundle mExtras;
 
         public Builder(@SearchResultType int resultType,
-                @NonNull String layoutType,
+                @SearchLayoutType @NonNull String layoutType,
                 @NonNull String id) {
             mId = id;
             mLayoutType = Objects.requireNonNull(layoutType);
@@ -433,13 +464,13 @@
          * Sets the score of the object.
          */
         @NonNull
-        public Builder setScore(float score) {
+        public Builder setScore(@FloatRange(from = 0.0f, to = 1.0f) float score) {
             mScore = score;
             return this;
         }
 
         /**
-         * Sets whether the result should be hidden by default inside client.
+         * Sets whether the result should be hidden (e.g. not visible) by default inside client.
          */
         @NonNull
         public Builder setShouldHide(boolean shouldHide) {