Skip to content

Commit

Permalink
Add provision for custom package name while launching output switcher (
Browse files Browse the repository at this point in the history
…#2471)

* Add provision for custom package name while launching output switcher.

* Add provision for custom package name while launching output switcher.
  • Loading branch information
anubhavkakkar authored Dec 3, 2024
1 parent 47b08c4 commit 637cf60
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 23 deletions.
2 changes: 1 addition & 1 deletion media/audio-ui-model/api/current.api
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ package com.google.android.horologist.audio.ui {
method public final kotlinx.coroutines.flow.StateFlow<com.google.android.horologist.audio.ui.VolumeUiState> getVolumeUiState();
method public final void increaseVolume();
method public final void increaseVolumeWithHaptics();
method public final void launchOutputSelection();
method public final void launchOutputSelection(optional String? clientPackageName);
method public final void onVolumeChangeByScroll(float pixels);
method public final void setVolume(int volume);
property public final kotlinx.coroutines.flow.StateFlow<com.google.android.horologist.audio.AudioOutput> audioOutput;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ public open class VolumeViewModel(
volumeRepository.decreaseVolume()
}

public fun launchOutputSelection() {
audioOutputRepository.launchOutputSelection(closeOnConnect = false)
public fun launchOutputSelection(clientPackageName: String? = null) {
audioOutputRepository.launchOutputSelection(
closeOnConnect = false,
clientPackageName = clientPackageName,
)
}

override fun onCleared() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class FakeAudioOutputRepository : AudioOutputRepository {
override val audioOutput: MutableStateFlow<AudioOutput> = MutableStateFlow(AudioOutput.None)
override val available: MutableStateFlow<List<AudioOutput>> = MutableStateFlow(listOf())

override fun launchOutputSelection(closeOnConnect: Boolean) {
override fun launchOutputSelection(closeOnConnect: Boolean, clientPackageName: String?) {
}

override fun close() {
Expand Down
6 changes: 3 additions & 3 deletions media/audio/api/current.api
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ package com.google.android.horologist.audio {
public interface AudioOutputRepository extends java.lang.AutoCloseable {
method public kotlinx.coroutines.flow.StateFlow<com.google.android.horologist.audio.AudioOutput> getAudioOutput();
method public kotlinx.coroutines.flow.StateFlow<java.util.List<com.google.android.horologist.audio.AudioOutput>> getAvailable();
method public void launchOutputSelection(boolean closeOnConnect);
method public void launchOutputSelection(boolean closeOnConnect, optional String? clientPackageName);
property public abstract kotlinx.coroutines.flow.StateFlow<com.google.android.horologist.audio.AudioOutput> audioOutput;
property public abstract kotlinx.coroutines.flow.StateFlow<java.util.List<com.google.android.horologist.audio.AudioOutput>> available;
}
Expand All @@ -91,7 +91,7 @@ package com.google.android.horologist.audio {
}

public final class OutputSwitcher {
method public boolean launchSystemMediaOutputSwitcherUi(android.content.Context);
method public boolean launchSystemMediaOutputSwitcherUi(android.content.Context, optional String? callingPkgName);
field public static final com.google.android.horologist.audio.OutputSwitcher INSTANCE;
}

Expand All @@ -103,7 +103,7 @@ package com.google.android.horologist.audio {
method public kotlinx.coroutines.flow.StateFlow<java.util.List<com.google.android.horologist.audio.AudioOutput>> getAvailable();
method public kotlinx.coroutines.flow.StateFlow<com.google.android.horologist.audio.VolumeState> getVolumeState();
method public void increaseVolume();
method public void launchOutputSelection(boolean closeOnConnect);
method public void launchOutputSelection(boolean closeOnConnect, String? clientPackageName);
method public void setVolume(int volume);
property public kotlinx.coroutines.flow.StateFlow<com.google.android.horologist.audio.AudioOutput> audioOutput;
property public kotlinx.coroutines.flow.StateFlow<java.util.List<com.google.android.horologist.audio.AudioOutput>> available;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ public interface AudioOutputRepository : AutoCloseable {
/**
* Action to launch output selection by the user.
*/
public fun launchOutputSelection(closeOnConnect: Boolean)
public fun launchOutputSelection(closeOnConnect: Boolean, clientPackageName: String? = null)
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public object OutputSwitcher {
/**
* Open the Output Switcher Dialog.
*/
public fun Context.launchSystemMediaOutputSwitcherUi(): Boolean {
public fun Context.launchSystemMediaOutputSwitcherUi(callingPkgName: String? = null): Boolean {
val outputSwitcherLaunchIntent: Intent = Intent(OUTPUT_SWITCHER_INTENT_ACTION_NAME)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(EXTRA_OUTPUT_SWITCHER_PACKAGE_NAME, packageName)
.putExtra(EXTRA_OUTPUT_SWITCHER_PACKAGE_NAME, callingPkgName ?: packageName)
val outputSwitcherSystemComponentName =
getSystemOrSystemUpdatedAppComponent(outputSwitcherLaunchIntent)
if (outputSwitcherSystemComponentName != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ public class SystemAudioRepository(
}
}

override fun launchOutputSelection(closeOnConnect: Boolean) {
if (!application.launchSystemMediaOutputSwitcherUi()) {
override fun launchOutputSelection(closeOnConnect: Boolean, clientPackageName: String?) {
if (!application.launchSystemMediaOutputSwitcherUi(clientPackageName)) {
application.launchBluetoothSettings(closeOnConnect)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ open class FakeAudioOutputRepository : AudioOutputRepository {
override val audioOutput: MutableStateFlow<AudioOutput> = MutableStateFlow(AudioOutput.None)
override val available: MutableStateFlow<List<AudioOutput>> = MutableStateFlow(listOf())

override fun launchOutputSelection(closeOnConnect: Boolean) {
override fun launchOutputSelection(closeOnConnect: Boolean, clientPackageName: String?) {
}

override fun close() {
Expand Down
11 changes: 7 additions & 4 deletions media/core/api/current.api
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@ package com.google.android.horologist.media.model {
}

public final class Media {
ctor public Media(String id, String uri, String title, String artist, optional String? artworkUri, optional Integer? artworkColor, optional java.util.Map<java.lang.String,?> extras);
ctor public Media(String id, String uri, String title, String artist, optional String? clientPackageName, optional String? artworkUri, optional Integer? artworkColor, optional java.util.Map<java.lang.String,?> extras);
method public String component1();
method public String component2();
method public String component3();
method public String component4();
method public String? component5();
method public Integer? component6();
method public java.util.Map<java.lang.String,java.lang.Object> component7();
method public com.google.android.horologist.media.model.Media copy(String id, String uri, String title, String artist, String? artworkUri, Integer? artworkColor, java.util.Map<java.lang.String,?> extras);
method public String? component6();
method public Integer? component7();
method public java.util.Map<java.lang.String,java.lang.Object> component8();
method public com.google.android.horologist.media.model.Media copy(String id, String uri, String title, String artist, String? clientPackageName, String? artworkUri, Integer? artworkColor, java.util.Map<java.lang.String,?> extras);
method public boolean equals(Object? other);
method public String getArtist();
method public Integer? getArtworkColor();
method public String? getArtworkUri();
method public String? getClientPackageName();
method public java.util.Map<java.lang.String,java.lang.Object> getExtras();
method public String getId();
method public String getTitle();
Expand All @@ -47,6 +49,7 @@ package com.google.android.horologist.media.model {
property public final String artist;
property public final Integer? artworkColor;
property public final String? artworkUri;
property public final String? clientPackageName;
property public final java.util.Map<java.lang.String,java.lang.Object> extras;
property public final String id;
property public final String title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public data class Media(
val uri: String,
val title: String,
val artist: String,
val clientPackageName: String? = null,
val artworkUri: String? = null,
val artworkColor: Int? = null,
val extras: Map<String, Any> = emptyMap(),
Expand Down
13 changes: 8 additions & 5 deletions media/ui-model/api/current.api
Original file line number Diff line number Diff line change
Expand Up @@ -270,22 +270,25 @@ package com.google.android.horologist.media.ui.state.model {
}

public static final class MediaUiModel.Ready extends com.google.android.horologist.media.ui.state.model.MediaUiModel {
ctor public MediaUiModel.Ready(String id, String title, optional String subtitle, optional com.google.android.horologist.images.base.paintable.Paintable? artwork, optional androidx.compose.ui.graphics.Color? artworkColor, optional com.google.android.horologist.images.base.paintable.Paintable? titleIcon);
ctor public MediaUiModel.Ready(String id, String title, optional String subtitle, optional String? clientPackageName, optional com.google.android.horologist.images.base.paintable.Paintable? artwork, optional androidx.compose.ui.graphics.Color? artworkColor, optional com.google.android.horologist.images.base.paintable.Paintable? titleIcon);
method public String component1();
method public String component2();
method public String component3();
method public com.google.android.horologist.images.base.paintable.Paintable? component4();
method public androidx.compose.ui.graphics.Color? component5-QN2ZGVo();
method public com.google.android.horologist.images.base.paintable.Paintable? component6();
method public com.google.android.horologist.media.ui.state.model.MediaUiModel.Ready copy-gCxFOHY(String id, String title, String subtitle, com.google.android.horologist.images.base.paintable.Paintable? artwork, androidx.compose.ui.graphics.Color? artworkColor, com.google.android.horologist.images.base.paintable.Paintable? titleIcon);
method public String? component4();
method public com.google.android.horologist.images.base.paintable.Paintable? component5();
method public androidx.compose.ui.graphics.Color? component6-QN2ZGVo();
method public com.google.android.horologist.images.base.paintable.Paintable? component7();
method public com.google.android.horologist.media.ui.state.model.MediaUiModel.Ready copy-lMAxDYE(String id, String title, String subtitle, String? clientPackageName, com.google.android.horologist.images.base.paintable.Paintable? artwork, androidx.compose.ui.graphics.Color? artworkColor, com.google.android.horologist.images.base.paintable.Paintable? titleIcon);
method public com.google.android.horologist.images.base.paintable.Paintable? getArtwork();
method public androidx.compose.ui.graphics.Color? getArtworkColor();
method public String? getClientPackageName();
method public String getId();
method public String getSubtitle();
method public String getTitle();
method public com.google.android.horologist.images.base.paintable.Paintable? getTitleIcon();
property public final com.google.android.horologist.images.base.paintable.Paintable? artwork;
property public final androidx.compose.ui.graphics.Color? artworkColor;
property public final String? clientPackageName;
property public final String id;
property public final String subtitle;
property public final String title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public object MediaUiModelMapper {
id = media.id,
title = title,
subtitle = artist,
clientPackageName = media.clientPackageName,
artwork = media.artworkUri?.let { CoilPaintable(it) },
artworkColor = media.artworkColor?.let { Color(it) },
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public sealed class MediaUiModel {
val id: String,
val title: String,
val subtitle: String = "",
val clientPackageName: String? = null,
val artwork: Paintable? = null,
val artworkColor: Color? = null,
val titleIcon: Paintable? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FakeAudioOutputRepository : AudioOutputRepository {
override val audioOutput: MutableStateFlow<AudioOutput> = MutableStateFlow(AudioOutput.None)
override val available: MutableStateFlow<List<AudioOutput>> = MutableStateFlow(listOf())

override fun launchOutputSelection(closeOnConnect: Boolean) {
override fun launchOutputSelection(closeOnConnect: Boolean, clientPackageName: String?) {
}

override fun close() {
Expand Down

0 comments on commit 637cf60

Please sign in to comment.