Skip to content

Commit

Permalink
Merge pull request #40 from scribd/katherine/AND-10935-service
Browse files Browse the repository at this point in the history
[AND-10935] Fix "failed to bind service"
  • Loading branch information
kabliz authored Aug 26, 2024
2 parents d8dbb91 + 7d30d26 commit 266baa3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Armadillo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

<application>

Expand All @@ -15,7 +16,6 @@
android:exported="true"
android:stopWithTask="false"
android:foregroundServiceType="mediaPlayback"
android:permission="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"
tools:ignore="ExportedService">

<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class PlaybackService : MediaBrowserServiceCompat() {

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
// Handle media buttons when OS is below API 21
Log.v(TAG, "onStartCommand: flags $flags")
MediaButtonReceiver.handleIntent(mediaSession, intent)
return super.onStartCommand(intent, flags, startId)
}
Expand All @@ -126,6 +127,7 @@ class PlaybackService : MediaBrowserServiceCompat() {
}

override fun onLoadChildren(parentId: String, result: Result<MutableList<MediaBrowserCompat.MediaItem>>) {
Log.v(TAG, "onLoadChildren from parentId $parentId")
when (val authorizationStatus: ArmadilloMediaBrowse.Browser.AuthorizationStatus = mediaBrowser.checkAuthorization()) {
is ArmadilloMediaBrowse.Browser.AuthorizationStatus.Authorized -> {
mediaBrowser.loadChildrenOf(parentId, result)
Expand All @@ -146,6 +148,7 @@ class PlaybackService : MediaBrowserServiceCompat() {
}

override fun onGetRoot(clientPackageName: String, clientUid: Int, rootHints: Bundle?): BrowserRoot? {
Log.v(TAG, "onGetRoot from $clientPackageName")
val root = mediaBrowser.determineBrowserRoot(clientPackageName, clientUid, rootHints)
if (root != null) {
mediaBrowser.externalServiceListener = object : ArmadilloMediaBrowse.ExternalServiceListener {
Expand Down Expand Up @@ -227,6 +230,7 @@ class PlaybackService : MediaBrowserServiceCompat() {

private inner class PlaybackServiceManager : ServiceManager {
override fun startService(audiobook: AudioPlayable, currentChapterIndex: Int) {
Log.v(TAG, "startService")
val token = sessionToken ?: throw MissingDataException("The session's token is missing. Can't begin service.")
if (!isInForeground) {
ContextCompat.startForegroundService(
Expand All @@ -241,6 +245,7 @@ class PlaybackService : MediaBrowserServiceCompat() {
}

override fun updateNotificationForPause(audiobook: AudioPlayable, currentChapterIndex: Int) {
Log.v(TAG, "updateNotification")
val token = sessionToken ?: throw MissingDataException("The session's token is missing. Cannot pause the notification.")
stopForeground(false)
val notification = playbackNotificationManager.getNotification(audiobook, currentChapterIndex, false, token)
Expand All @@ -249,11 +254,13 @@ class PlaybackService : MediaBrowserServiceCompat() {
}

override fun removeNotification() {
Log.v(TAG, "removeNotification")
stopForeground(true)
isNotificationShown = false
}

override fun stopService() {
Log.v(TAG, "stopService")
onStopService()
}
}
Expand All @@ -265,6 +272,7 @@ class PlaybackService : MediaBrowserServiceCompat() {
* here first. If so, we need to clear out the player
*/
private fun onStopService(stopPlayer: Boolean = true) {
Log.v(TAG, "onStopService")
playbackNotificationManager.notificationManager.cancel(notificationBuilder.notificationId)
if (stopPlayer) {
mediaSession.controller.transportControls.stop()
Expand Down
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Project Armadillo Release Notes

## 1.5.2
Fixes "Failed to Bind Service" issue introduced in 1.4, affecting MediaBrowser services.

## 1.5.1
- Adds DrmState to ArmadilloState, giving full visibility into DRM status to the client, including the expiration date for content.
- Splits SocketTimeout from HttpResponseCodeException, into ConnectivityException to better differentiate connectivity difficulties from
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ org.gradle.jvmargs=-Xmx1536m
# org.gradle.parallel=true
PACKAGE_NAME=com.scribd.armadillo
GRADLE_PLUGIN_VERSION=7.2.0
LIBRARY_VERSION=1.5.1
LIBRARY_VERSION=1.5.2
EXOPLAYER_VERSION=2.19.1
RXJAVA_VERSION=2.2.4
RXANDROID_VERSION=2.0.1
Expand Down

0 comments on commit 266baa3

Please sign in to comment.