Merge "[webkit] add feature flag for ServiceWorkerClien..shouldInterceptRequest" into pi-androidx-dev
diff --git a/car/car-stubs/android.car.jar b/car/car-stubs/android.car.jar
index 01f5cd9..4a1d441 100644
--- a/car/car-stubs/android.car.jar
+++ b/car/car-stubs/android.car.jar
Binary files differ
diff --git a/car/src/androidTest/java/androidx/car/utils/CarUxRestrictionsTestUtils.java b/car/src/androidTest/java/androidx/car/utils/CarUxRestrictionsTestUtils.java
index 7100488..bc1377f 100644
--- a/car/src/androidTest/java/androidx/car/utils/CarUxRestrictionsTestUtils.java
+++ b/car/src/androidTest/java/androidx/car/utils/CarUxRestrictionsTestUtils.java
@@ -27,10 +27,12 @@
     private CarUxRestrictionsTestUtils() {};
 
     public static CarUxRestrictions getFullyRestricted() {
-        return new CarUxRestrictions(true, CarUxRestrictions.UX_RESTRICTIONS_FULLY_RESTRICTED, 0);
+        return new CarUxRestrictions.Builder(
+                true, CarUxRestrictions.UX_RESTRICTIONS_FULLY_RESTRICTED, 0).build();
     }
 
     public static CarUxRestrictions getBaseline() {
-        return new CarUxRestrictions(false, CarUxRestrictions.UX_RESTRICTIONS_BASELINE, 0);
+        return new CarUxRestrictions.Builder(
+                false, CarUxRestrictions.UX_RESTRICTIONS_BASELINE, 0).build();
     }
 }
diff --git a/leanback/src/main/java/androidx/leanback/system/Settings.java b/leanback/src/main/java/androidx/leanback/system/Settings.java
index 04f66d1..011c6a5 100644
--- a/leanback/src/main/java/androidx/leanback/system/Settings.java
+++ b/leanback/src/main/java/androidx/leanback/system/Settings.java
@@ -43,7 +43,7 @@
     // The intent action that must be provided by a broadcast receiver
     // in a customization package.
     private static final String ACTION_PARTNER_CUSTOMIZATION =
-            "androidx.leanback.action.PARTNER_CUSTOMIZATION";
+            "android.support.v17.leanback.action.PARTNER_CUSTOMIZATION";
 
     public static final String PREFER_STATIC_SHADOWS = "PREFER_STATIC_SHADOWS";
 
diff --git a/slices/view/src/main/java/androidx/slice/widget/ListContent.java b/slices/view/src/main/java/androidx/slice/widget/ListContent.java
index b728a69..ee3c2e4 100644
--- a/slices/view/src/main/java/androidx/slice/widget/ListContent.java
+++ b/slices/view/src/main/java/androidx/slice/widget/ListContent.java
@@ -102,12 +102,20 @@
     }
 
     /**
+     * Expects the provided list of items to be filtered (i.e. only things that can be turned into
+     * GridContent or RowContent) and in order (i.e. first item could be a header).
+     *
      * @return the total height of all the rows contained in the provided list.
      */
     public static int getListHeight(Context context, List<SliceItem> listItems) {
         int height = 0;
+        boolean hasRealHeader = false;
+        if (listItems.size() > 0) {
+            SliceItem maybeHeader = listItems.get(0);
+            hasRealHeader = !maybeHeader.hasAnyHints(HINT_LIST_ITEM, HINT_HORIZONTAL);
+        }
         for (int i = 0; i < listItems.size(); i++) {
-            height += getHeight(context, listItems.get(i), i == 0 /* isHeader */);
+            height += getHeight(context, listItems.get(i), i == 0 && hasRealHeader /* isHeader */);
         }
         return height;
     }
diff --git a/slices/view/src/main/java/androidx/slice/widget/RowContent.java b/slices/view/src/main/java/androidx/slice/widget/RowContent.java
index 0076a3e..bc3826f 100644
--- a/slices/view/src/main/java/androidx/slice/widget/RowContent.java
+++ b/slices/view/src/main/java/androidx/slice/widget/RowContent.java
@@ -75,14 +75,14 @@
     private int mLineCount = 0;
     private int mMaxHeight;
     private int mMinHeight;
-    private int mMaxRangeHeight;
+    private int mRangeHeight;
 
     public RowContent(Context context, SliceItem rowSlice, boolean isHeader) {
         populate(rowSlice, isHeader);
         mMaxHeight = context.getResources().getDimensionPixelSize(R.dimen.abc_slice_row_max_height);
         mMinHeight = context.getResources().getDimensionPixelSize(R.dimen.abc_slice_row_min_height);
-        mMaxRangeHeight = context.getResources().getDimensionPixelSize(
-                R.dimen.abc_slice_row_range_max_height);
+        mRangeHeight = context.getResources().getDimensionPixelSize(
+                R.dimen.abc_slice_row_range_height);
     }
 
     /**
@@ -278,8 +278,8 @@
      * @return the height to display a row at when it is used as a small template.
      */
     public int getSmallHeight() {
-        return (getRange() != null && mLineCount > 1)
-                ? mMaxRangeHeight
+        return getRange() != null
+                ? getActualHeight()
                 : mMaxHeight;
     }
 
@@ -290,10 +290,15 @@
         if (!isValid()) {
             return 0;
         }
-        if (getRange() != null && mLineCount > 1) {
-            return mMaxRangeHeight;
+        int rowHeight = (getLineCount() > 1 || mIsHeader) ? mMaxHeight : mMinHeight;
+        if (getRange() != null) {
+            if (getLineCount() > 0) {
+                rowHeight += mRangeHeight;
+            } else {
+                rowHeight = mIsHeader ? mMaxHeight : mRangeHeight;
+            }
         }
-        return (getLineCount() > 1 || mIsHeader) ? mMaxHeight : mMinHeight;
+        return rowHeight;
     }
 
     private static boolean hasText(SliceItem textSlice) {
@@ -319,6 +324,7 @@
                 || mTitleItem != null
                 || mSubtitleItem != null
                 || mEndItems.size() > 0
+                || mRange != null
                 || isDefaultSeeMore();
     }
 
diff --git a/slices/view/src/main/java/androidx/slice/widget/RowView.java b/slices/view/src/main/java/androidx/slice/widget/RowView.java
index 2c3c53d..28728d8 100644
--- a/slices/view/src/main/java/androidx/slice/widget/RowView.java
+++ b/slices/view/src/main/java/androidx/slice/widget/RowView.java
@@ -95,8 +95,7 @@
     private View mDivider;
     private ArrayList<SliceActionView> mToggles = new ArrayList<>();
     private LinearLayout mEndContainer;
-    private SeekBar mSeekBar;
-    private ProgressBar mProgressBar;
+    private ProgressBar mRangeBar;
     private View mSeeMoreView;
 
     private int mRowIndex;
@@ -107,14 +106,16 @@
 
     private int mImageSize;
     private int mIconSize;
+    private int mRangeHeight;
 
     public RowView(Context context) {
         super(context);
         mIconSize = getContext().getResources().getDimensionPixelSize(R.dimen.abc_slice_icon_size);
         mImageSize = getContext().getResources().getDimensionPixelSize(
                 R.dimen.abc_slice_small_image_size);
-        inflate(context, R.layout.abc_slice_small_template, this);
-        mRootView = findViewById(R.id.row_view);
+        mRootView = (LinearLayout) LayoutInflater.from(context).inflate(
+                R.layout.abc_slice_small_template, this, false);
+        addView(mRootView);
 
         mStartContainer = (LinearLayout) findViewById(R.id.icon_frame);
         mContent = (LinearLayout) findViewById(android.R.id.content);
@@ -123,8 +124,9 @@
         mLastUpdatedText = (TextView) findViewById(R.id.last_updated);
         mDivider = findViewById(R.id.divider);
         mEndContainer = (LinearLayout) findViewById(android.R.id.widget_frame);
-        mSeekBar = (SeekBar) findViewById(R.id.seek_bar);
-        mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
+
+        mRangeHeight = context.getResources().getDimensionPixelSize(
+                R.dimen.abc_slice_row_range_height);
     }
 
 
@@ -138,6 +140,16 @@
     public int getActualHeight() {
         return mRowContent != null && mRowContent.isValid() ? mRowContent.getActualHeight() : 0;
     }
+    /**
+     * @return height row content (i.e. title, subtitle) without the height of the range element.
+     */
+    private int getRowContentHeight() {
+        int rowHeight = getMode() == MODE_SMALL ? getSmallHeight() : getActualHeight();
+        if (mRangeBar != null) {
+            rowHeight -= mRangeHeight;
+        }
+        return rowHeight;
+    }
 
     @Override
     public void setTint(@ColorInt int tintColor) {
@@ -166,9 +178,31 @@
 
     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
-        int height = getMode() == MODE_SMALL ? getSmallHeight() : getActualHeight();
-        heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
-        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+        int totalHeight = getMode() == MODE_SMALL ? getSmallHeight() : getActualHeight();
+        int rowHeight = getRowContentHeight();
+        if (rowHeight != 0 && mRootView.getVisibility() != View.GONE) {
+            // Might be gone if we have range / progress but nothing else
+            heightMeasureSpec = MeasureSpec.makeMeasureSpec(rowHeight, MeasureSpec.EXACTLY);
+            measureChild(mRootView, widthMeasureSpec, heightMeasureSpec);
+        } else {
+            mRootView.setVisibility(View.GONE);
+        }
+        if (mRangeBar != null) {
+            int rangeMeasureSpec = MeasureSpec.makeMeasureSpec(mRangeHeight, MeasureSpec.EXACTLY);
+            measureChild(mRangeBar, widthMeasureSpec, rangeMeasureSpec);
+        }
+
+        int totalHeightSpec = MeasureSpec.makeMeasureSpec(totalHeight, MeasureSpec.EXACTLY);
+        super.onMeasure(widthMeasureSpec, totalHeightSpec);
+    }
+
+    @Override
+    protected void onLayout(boolean changed, int l, int t, int r, int b) {
+        mRootView.layout(l, t, l + mRootView.getMeasuredWidth(), t + getRowContentHeight());
+        if (mRangeBar != null) {
+            mRangeBar.layout(l, t + getRowContentHeight(), l + mRangeBar.getMeasuredWidth(),
+                    t + getRowContentHeight() + mRangeHeight);
+        }
     }
 
     @Override
@@ -326,7 +360,9 @@
 
     private void addRange(final SliceItem range) {
         final boolean isSeekBar = FORMAT_ACTION.equals(range.getFormat());
-        final ProgressBar progressBar = isSeekBar ? mSeekBar : mProgressBar;
+        final ProgressBar progressBar = isSeekBar
+                ? new SeekBar(getContext())
+                : new ProgressBar(getContext(), null, android.R.attr.progressBarStyleHorizontal);
         if (mTintColor != -1) {
             Drawable drawable = DrawableCompat.wrap(progressBar.getProgressDrawable());
             DrawableCompat.setTint(drawable, mTintColor);
@@ -347,18 +383,21 @@
             progressBar.setProgress(progress.getInt() - minValue);
         }
         progressBar.setVisibility(View.VISIBLE);
+        addView(progressBar);
+        mRangeBar = progressBar;
         if (isSeekBar) {
             SliceItem thumb = SliceQuery.find(range, FORMAT_IMAGE);
+            SeekBar seekBar = (SeekBar) mRangeBar;
             if (thumb != null) {
-                mSeekBar.setThumb(thumb.getIcon().loadDrawable(getContext()));
+                seekBar.setThumb(thumb.getIcon().loadDrawable(getContext()));
             }
             if (mTintColor != -1) {
-                Drawable drawable = DrawableCompat.wrap(mSeekBar.getThumb());
+                Drawable drawable = DrawableCompat.wrap(seekBar.getThumb());
                 DrawableCompat.setTint(drawable, mTintColor);
-                mSeekBar.setThumb(drawable);
+                seekBar.setThumb(drawable);
             }
             final int finalMinValue = minValue;
-            mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+            seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                 @Override
                 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                     progress += finalMinValue;
@@ -506,6 +545,7 @@
 
     @Override
     public void resetView() {
+        mRootView.setVisibility(View.VISIBLE);
         setViewClickable(mRootView, false);
         setViewClickable(mContent, false);
         mStartContainer.removeAllViews();
@@ -515,8 +555,9 @@
         mToggles.clear();
         mRowAction = null;
         mDivider.setVisibility(View.GONE);
-        mSeekBar.setVisibility(View.GONE);
-        mProgressBar.setVisibility(View.GONE);
+        if (mRangeBar != null) {
+            removeView(mRangeBar);
+        }
         if (mSeeMoreView != null) {
             removeView(mSeeMoreView);
         }
diff --git a/slices/view/src/main/res/layout/abc_slice_small_template.xml b/slices/view/src/main/res/layout/abc_slice_small_template.xml
index 867de1f..b1aea3f 100644
--- a/slices/view/src/main/res/layout/abc_slice_small_template.xml
+++ b/slices/view/src/main/res/layout/abc_slice_small_template.xml
@@ -67,19 +67,6 @@
 
         </LinearLayout>
 
-        <SeekBar
-            android:id="@+id/seek_bar"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:visibility="gone" />
-
-        <ProgressBar
-            android:id="@+id/progress_bar"
-            style="?android:attr/progressBarStyleHorizontal"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:visibility="gone" />
-
     </LinearLayout>
 
     <View
diff --git a/slices/view/src/main/res/values/dimens.xml b/slices/view/src/main/res/values/dimens.xml
index 19e3327..f3313bf 100644
--- a/slices/view/src/main/res/values/dimens.xml
+++ b/slices/view/src/main/res/values/dimens.xml
@@ -38,12 +38,12 @@
     <!-- Row view sizes-->
     <!-- Min height of row view; default size if one line of text -->
     <dimen name="abc_slice_row_min_height">48dp</dimen>
-    <!-- Max height of row view; default size if two lines of text -->
+    <!-- Size of row view with two lines of text -->
     <dimen name="abc_slice_row_max_height">60dp</dimen>
     <!-- Min height of a row showing an input field that is active -->
     <dimen name="abc_slice_row_active_input_height">120dp</dimen>
-    <!-- Max height of of a row view with a range element -->
-    <dimen name="abc_slice_row_range_max_height">86dp</dimen>
+    <!-- Height to fit a range element (slider, progress) -->
+    <dimen name="abc_slice_row_range_height">48dp</dimen>
 
     <!-- Grid view sizes-->
     <!-- Height of a grid row displaying only text or only small images (but not both) -->
diff --git a/webkit/build.gradle b/webkit/build.gradle
index 78a585e..d610dad 100644
--- a/webkit/build.gradle
+++ b/webkit/build.gradle
@@ -51,5 +51,4 @@
     mavenGroup = LibraryGroups.WEBKIT
     inceptionYear = "2017"
     description = "The WebView Support Library is a static library you can add to your Android application in order to use android.webkit APIs that are not available for older platform versions."
-    failOnUncheckedWarnings = false
 }
diff --git a/webkit/src/main/java/androidx/webkit/WebViewCompat.java b/webkit/src/main/java/androidx/webkit/WebViewCompat.java
index 273a79d..6e82a69 100644
--- a/webkit/src/main/java/androidx/webkit/WebViewCompat.java
+++ b/webkit/src/main/java/androidx/webkit/WebViewCompat.java
@@ -280,7 +280,7 @@
     private static PackageInfo getLoadedWebViewPackageInfo()
             throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException,
             IllegalAccessException {
-        Class webViewFactoryClass = Class.forName("android.webkit.WebViewFactory");
+        Class<?> webViewFactoryClass = Class.forName("android.webkit.WebViewFactory");
         PackageInfo webviewPackageInfo =
                 (PackageInfo) webViewFactoryClass.getMethod(
                         "getLoadedPackageInfo").invoke(null);
@@ -296,13 +296,13 @@
         try {
             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
                     && Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
-                Class webViewFactoryClass = null;
+                Class<?> webViewFactoryClass = null;
                 webViewFactoryClass = Class.forName("android.webkit.WebViewFactory");
 
                 webviewPackageName = (String) webViewFactoryClass.getMethod(
                         "getWebViewPackageName").invoke(null);
             } else {
-                Class webviewUpdateServiceClass =
+                Class<?> webviewUpdateServiceClass =
                         Class.forName("android.webkit.WebViewUpdateService");
                 webviewPackageName = (String) webviewUpdateServiceClass.getMethod(
                         "getCurrentWebViewPackageName").invoke(null);