DO NOT MERGE: Merge Oreo MR1 into master

Exempt-From-Owner-Approval: Changes already landed internally
Change-Id: I8b8efc4ef2735ef1c946c36c6d4d66363684a31d
diff --git a/Android.mk b/Android.mk
index 4a0095d..85f4710 100644
--- a/Android.mk
+++ b/Android.mk
@@ -14,6 +14,8 @@
 # limitations under the License.
 #
 
+ifneq ($(TARGET_BUILD_PDK), true)
+
 LOCAL_PATH:= $(call my-dir)
 
 include $(CLEAR_VARS)
@@ -56,3 +58,5 @@
 include packages/services/Car/car-support-lib/car-support.mk
 
 include $(BUILD_PACKAGE)
+
+endif
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index e7d0c10..fea3fbf 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -24,6 +24,7 @@
     <!-- This permission is required to allow the radio to be muted. -->
     <uses-permission android:name="android.car.permission.CAR_CONTROL_AUDIO_VOLUME" />
     <uses-permission android:name="android.car.permission.CAR_RADIO" />
+    <uses-permission android:name="android.permission.ACCESS_BROADCAST_RADIO" />
     <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
 
     <application android:label="@string/app_name"
diff --git a/res/layout/radio_presets_list.xml b/res/layout/radio_presets_list.xml
index ca6cddb..06ce6ab 100644
--- a/res/layout/radio_presets_list.xml
+++ b/res/layout/radio_presets_list.xml
@@ -48,7 +48,11 @@
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:visibility="gone"
-        app:offsetRows="true"/>
+        app:offsetRows="true"
+        app:showDivider="true"
+        app:dividerStartMargin="@dimen/stream_card_keyline_3"
+        app:alignDividerEndTo="@id/preset_card"
+        app:alignDividerStartTo="@id/preset_card" />
 
     <android.support.v7.widget.CardView
         android:id="@+id/current_radio_station_card"
diff --git a/src/com/android/car/radio/PrescannedRadioStationAdapter.java b/src/com/android/car/radio/PrescannedRadioStationAdapter.java
index 13a3e21..c75d325 100644
--- a/src/com/android/car/radio/PrescannedRadioStationAdapter.java
+++ b/src/com/android/car/radio/PrescannedRadioStationAdapter.java
@@ -154,7 +154,7 @@
             Log.d(TAG, "bindView(); position: " + position + "; isFirstView: " + isFirstView);
         }
 
-        if (mStations == null || position >= mStations.size()) {
+        if (mStations == null || position < 0 || position >= mStations.size()) {
             return;
         }
 
diff --git a/src/com/android/car/radio/RadioPresetsFragment.java b/src/com/android/car/radio/RadioPresetsFragment.java
index 455e7c5..44d5000 100644
--- a/src/com/android/car/radio/RadioPresetsFragment.java
+++ b/src/com/android/car/radio/RadioPresetsFragment.java
@@ -20,11 +20,8 @@
 import android.animation.AnimatorSet;
 import android.animation.ObjectAnimator;
 import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Canvas;
 import android.os.Bundle;
 import android.support.v4.app.Fragment;
-import android.support.v7.widget.RecyclerView;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -100,7 +97,6 @@
 
         mPresetsList = mRootView.findViewById(R.id.presets_list);
         mPresetsList.setLightMode();
-        mPresetsList.setDefaultItemDecoration(new ItemSpacingDecoration(context));
         mPresetsList.setAdapter(mPresetsAdapter);
         mPresetsList.getLayoutManager().setOffsetRows(false);
         mPresetsList.getRecyclerView().addOnScrollListener(new PresetListScrollListener(
@@ -270,45 +266,6 @@
     }
 
     /**
-     * A {@link com.android.car.view.PagedListView.Decoration} that draws a line between
-     * the items.
-     */
-    public static class ItemSpacingDecoration extends PagedListView.DividerDecoration {
-        private final int mLineStart;
-
-        public ItemSpacingDecoration(Context context) {
-            super(context);
-            Resources res = context.getResources();
-            mLineStart = res.getDimensionPixelSize(R.dimen.stream_card_keyline_3);
-        }
-
-        @Override
-        public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
-            View presetCard = parent.findViewById(R.id.preset_card);
-
-            if (presetCard == null) {
-                return;
-            }
-
-            int left = mLineStart + presetCard.getLeft();
-            int right = presetCard.getRight();
-            int childCount = parent.getChildCount();
-
-            for (int i = 0; i < childCount; i++) {
-                View child = parent.getChildAt(i);
-                int bottom = child.getBottom();
-                int top = bottom - mDividerHeight;
-
-                // Draw a divider line between each item. No need to draw the line for the last
-                // item.
-                if (i != childCount - 1) {
-                    c.drawRect(left, top, right, bottom, mPaint);
-                }
-            }
-        }
-    }
-
-    /**
      * Returns a new instance of the {@link RadioPresetsFragment}.
      *
      * @param radioController The {@link RadioController} that is responsible for updating the UI
diff --git a/src/com/android/car/radio/RadioService.java b/src/com/android/car/radio/RadioService.java
index 90a12b6..9e35faa 100644
--- a/src/com/android/car/radio/RadioService.java
+++ b/src/com/android/car/radio/RadioService.java
@@ -185,11 +185,11 @@
                 Log.d(TAG, "loading band: " + band.toString());
             }
 
-            if (mFmDescriptor == null && band.getType() == RadioManager.BAND_FM) {
+            if (mFmDescriptor == null && band.isFmBand()) {
                 mFmDescriptor = (RadioManager.FmBandDescriptor) band;
             }
 
-            if (mAmDescriptor == null && band.getType() == RadioManager.BAND_AM) {
+            if (mAmDescriptor == null && band.isAmBand()) {
                 mAmDescriptor = (RadioManager.AmBandDescriptor) band;
             }
         }
@@ -208,14 +208,8 @@
                 .build();
 
         // If there is a second tuner on the device, then set it up as the background scanner.
-        if (mModules.size() >= 2) {
-            if (isDebugLoggable) {
-                Log.d(TAG, "Second tuner detected on device; setting up background scanner");
-            }
-
-            mBackgroundScanner = new RadioBackgroundScanner(this /* context */, mRadioManager,
-                    mAmConfig, mFmConfig, mModules.get(1));
-        }
+        // TODO(b/63101896): we don't know if the second tuner is for the same medium, so we don't
+        // set background scanner for now.
 
         mRadioSuccessfullyInitialized = true;
     }
@@ -336,12 +330,12 @@
     private RadioManager.BandConfig getRadioConfig(int selectedRadioBand) {
         switch (selectedRadioBand) {
             case RadioManager.BAND_AM:
+            case RadioManager.BAND_AM_HD:
                 return mAmConfig;
             case RadioManager.BAND_FM:
+            case RadioManager.BAND_FM_HD:
                 return mFmConfig;
 
-            // TODO: Support BAND_FM_HD and BAND_AM_HD.
-
             default:
                 return null;
         }