diff options
author | Tim Peng <timhypeng@google.com> | 2020-05-06 13:52:24 +0800 |
---|---|---|
committer | Tim Peng <timhypeng@google.com> | 2020-05-08 12:15:11 +0800 |
commit | f392eae213d28261b9e544bd5b801f2c7628fc39 (patch) | |
tree | 443bb99fac8dd789d651269ef988d2bdbaa9b743 /src/com/android/settings/sound | |
parent | 032f77052b19b818cb1893b2f739d25be0fff373 (diff) | |
download | packages_apps_Settings-f392eae213d28261b9e544bd5b801f2c7628fc39.tar.gz packages_apps_Settings-f392eae213d28261b9e544bd5b801f2c7628fc39.tar.bz2 packages_apps_Settings-f392eae213d28261b9e544bd5b801f2c7628fc39.zip |
Update "Play media to" in Sound Settings
-Change string to "Play <APP Label> on"
-Hide it when there is no local playback
-Disable search index
-Add test cases
Bug: 155720628
Test: make -j50 RunSettingsRoboTests
Change-Id: Id104d5b49c069a761e4cf82385bf1225d494c95e
Diffstat (limited to 'src/com/android/settings/sound')
-rw-r--r-- | src/com/android/settings/sound/MediaOutputPreferenceController.java | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/com/android/settings/sound/MediaOutputPreferenceController.java b/src/com/android/settings/sound/MediaOutputPreferenceController.java index c731bc3385..da92b2be42 100644 --- a/src/com/android/settings/sound/MediaOutputPreferenceController.java +++ b/src/com/android/settings/sound/MediaOutputPreferenceController.java @@ -20,8 +20,12 @@ import android.bluetooth.BluetoothDevice; import android.content.Context; import android.content.Intent; import android.media.AudioManager; +import android.media.session.MediaController; +import android.media.session.MediaSessionManager; +import android.media.session.PlaybackState; import android.text.TextUtils; +import androidx.annotation.Nullable; import androidx.preference.Preference; import androidx.preference.PreferenceScreen; @@ -43,15 +47,18 @@ import java.util.List; */ public class MediaOutputPreferenceController extends AudioSwitchPreferenceController { + private MediaController mMediaController; + public MediaOutputPreferenceController(Context context, String key) { super(context, key); + mMediaController = getActiveLocalMediaController(); } @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); - if (!Utils.isAudioModeOngoingCall(mContext)) { + if (!Utils.isAudioModeOngoingCall(mContext) && mMediaController != null) { mPreference.setVisible(true); } } @@ -63,6 +70,11 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro return; } + if (mMediaController == null) { + // No active local playback + return; + } + if (Utils.isAudioModeOngoingCall(mContext)) { // Ongoing call status, switch entry for media will be disabled. mPreference.setVisible(false); @@ -81,6 +93,9 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro || (connectedHADevices != null && !connectedHADevices.isEmpty()))) { activeDevice = findActiveDevice(); } + mPreference.setTitle(mContext.getString(R.string.media_output_label_title, + com.android.settings.Utils.getApplicationLabel(mContext, + mMediaController.getPackageName()))); mPreference.setSummary((activeDevice == null) ? mContext.getText(R.string.media_output_default_summary) : activeDevice.getAlias()); @@ -126,4 +141,26 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro } return false; } + + @Nullable + MediaController getActiveLocalMediaController() { + final MediaSessionManager mMediaSessionManager = mContext.getSystemService( + MediaSessionManager.class); + + for (MediaController controller : mMediaSessionManager.getActiveSessions(null)) { + final MediaController.PlaybackInfo pi = controller.getPlaybackInfo(); + if (pi == null) { + return null; + } + final PlaybackState playbackState = controller.getPlaybackState(); + if (playbackState == null) { + return null; + } + if (pi.getPlaybackType() == MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL + && playbackState.getState() == PlaybackState.STATE_PLAYING) { + return controller; + } + } + return null; + } } |