Add equalizer/sound settings icon

Fixes: 140069125
Test: Manual

Change-Id: Ie271203fb26657cfe47e1533114a6b1b7d54ad3b
diff --git a/res/values/bools.xml b/res/values/bools.xml
index 21d6c14..16d7dfa 100644
--- a/res/values/bools.xml
+++ b/res/values/bools.xml
@@ -22,4 +22,6 @@
     <bool name="switch_to_playback_view_when_playable_item_is_clicked">true</bool>
     <bool name="show_thumbnail_for_queue_list_item">true</bool>
     <bool name="show_subtitle_for_queue_list_item">false</bool>
+    <!-- Override this flag to show an icon that launches sound settings (equalizer) -->
+    <bool name="show_sound_settings">false</bool>
 </resources>
diff --git a/src/com/android/car/media/MediaActivity.java b/src/com/android/car/media/MediaActivity.java
index 44b604d..fcbf127 100644
--- a/src/com/android/car/media/MediaActivity.java
+++ b/src/com/android/car/media/MediaActivity.java
@@ -26,6 +26,7 @@
 import android.content.Intent;
 import android.content.pm.ResolveInfo;
 import android.graphics.drawable.BitmapDrawable;
+import android.media.audiofx.AudioEffect;
 import android.os.Bundle;
 import android.support.v4.media.session.PlaybackStateCompat;
 import android.text.TextUtils;
@@ -103,6 +104,8 @@
     private Mode mMode;
     private Intent mCurrentSourcePreferences;
     private boolean mCanShowMiniPlaybackControls;
+    private boolean mShouldShowSoundSettings;
+
     private PlaybackViewModel.PlaybackStateWrapper mCurrentPlaybackStateWrapper;
     /**
      * Media items to display as tabs. If null, it means we haven't finished loading them yet. If
@@ -138,6 +141,14 @@
         }
 
         @Override
+        public void onEqualizerSelection() {
+            Intent i = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
+            // Using startActivityForResult so that the control panel app can track changes for
+            // the launching package name.
+            startActivityForResult(i, 0);
+        }
+
+        @Override
         public void onSettingsSelection() {
             if (Log.isLoggable(TAG, Log.DEBUG)) {
                 Log.d(TAG, "onSettingsSelection");
@@ -297,6 +308,7 @@
         mCarUxRestrictionsUtil = CarUxRestrictionsUtil.getInstance(this);
         mRestrictions = CarUxRestrictions.UX_RESTRICTIONS_NO_SETUP;
         mCarUxRestrictionsUtil.register(mListener);
+        mShouldShowSoundSettings = getResources().getBoolean(R.bool.show_sound_settings);
 
         mPlaybackContainer.setOnTouchListener(new ClosePlaybackDetector(this));
         mAppSelectorIntent = MediaSource.getSourceSelectorIntent(this, false);
@@ -484,6 +496,7 @@
             }
         }
         mAppBarView.setHasSettings(mCurrentSourcePreferences != null);
+        mAppBarView.setHasEqualizer(mShouldShowSoundSettings);
     }
 
 
diff --git a/src/com/android/car/media/widgets/AppBarView.java b/src/com/android/car/media/widgets/AppBarView.java
index 014896b..78bd0ce 100644
--- a/src/com/android/car/media/widgets/AppBarView.java
+++ b/src/com/android/car/media/widgets/AppBarView.java
@@ -30,6 +30,7 @@
     private AppBarListener mListener = DEFAULT_APPBAR_LISTENER;
     private MenuItem mSearch;
     private MenuItem mSettings;
+    private MenuItem mEqualizer;
     private MenuItem mAppSelector;
 
     /**
@@ -52,6 +53,11 @@
         void onSettingsSelection();
 
         /**
+         * Invoked when the user clicks on the equalizer button.
+         */
+        void onEqualizerSelection();
+
+        /**
          * Invoked when the user submits a search query.
          */
         void onSearch(String query);
@@ -83,6 +89,9 @@
         public void onSettingsSelection() {}
 
         @Override
+        public void onEqualizerSelection() {}
+
+        @Override
         public void onSearch(String query) {}
 
         @Override
@@ -121,11 +130,13 @@
         registerToolbarHeightChangeListener(height -> mListener.onHeightChanged(height));
         mSearch = MenuItem.Builder.createSearch(context, v -> mListener.onSearchSelection());
         mSettings = MenuItem.Builder.createSettings(context, v -> mListener.onSettingsSelection());
+        mEqualizer = MenuItem.Builder.createSoundSettings(context,
+                v -> mListener.onEqualizerSelection());
         mAppSelector = new MenuItem.Builder(context)
                 .setIcon(R.drawable.ic_app_switch)
                 .setOnClickListener(m -> mListener.onAppSwitch())
                 .build();
-        setMenuItems(Arrays.asList(mSearch, mSettings, mAppSelector));
+        setMenuItems(Arrays.asList(mSearch, mEqualizer, mSettings, mAppSelector));
     }
 
     /**
@@ -162,6 +173,11 @@
         mSettings.setVisible(hasSettings);
     }
 
+    /** Sets whether the source has equalizer support. */
+    public void setHasEqualizer(boolean hasEqualizer) {
+        mEqualizer.setVisible(hasEqualizer);
+    }
+
     /**
      * Sets whether the search box should be shown
      */