Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): add back option to remove notification #1730

Merged
merged 21 commits into from
Sep 22, 2022

Conversation

mpivchev
Copy link
Contributor

@mpivchev mpivchev commented Sep 14, 2022

This adds an AndroidOptions interface to RN that adds optional flags specifically for Android.
It also adds the android flag stoppingAppRemovesNotification which will remove the notification when the app is killed.

@mpivchev mpivchev self-assigned this Sep 14, 2022
@mpivchev mpivchev changed the title Add back option to remove notification fix(android): add back option to remove notification Sep 14, 2022
@mpivchev mpivchev marked this pull request as ready for review September 14, 2022 14:35
@mpivchev mpivchev requested a review from dcvz as a code owner September 14, 2022 14:35
@@ -379,6 +387,7 @@ class MusicService : HeadlessJsTaskService() {
}
is NotificationState.CANCELLED -> {
stopForeground(true)
stopSelf()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though Android does not completely kill the app process, it's still good to call this.

@jspizziri jspizziri changed the title fix(android): add back option to remove notification feat(android): add back option to remove notification Sep 14, 2022
@jspizziri jspizziri linked an issue Sep 14, 2022 that may be closed by this pull request
Copy link
Contributor

@dcvz dcvz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks solid overall. Left a couple of comments

@mpivchev
Copy link
Contributor Author

After quitting, then pressing play from the notification player, then tapping the notification to open the app:

  • The progress bar doesn't update appropriately.
  • The play/pause button in the app is in the wrong state.

Just merged rebased to main and it seems like this bug has been fixed in some of the commits. You can try now.

@jspizziri
Copy link
Collaborator

@mpivchev @dcvz I can confirm that after the rebase the state is tracking properly.

repositories {
mavenLocal()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we using 1.7.10 features? What will happen now if someone is not on 1.7.10 yet? Will it cause compilation errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, they'll just have to update Kotlin

@@ -0,0 +1,17 @@
---
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We seem to only have migration docs for the major versions, but not for the minor. I added this for that reason. Not sure if there is a better way to go about this.

dcvz
dcvz previously approved these changes Sep 22, 2022
@mpivchev mpivchev merged commit 82a5df9 into main Sep 22, 2022
@mpivchev mpivchev deleted the option-remove-notification branch September 22, 2022 14:47
@mmmoussa
Copy link
Contributor

@mpivchev I tested this in my app with v3.2.0 using appKilledPlaybackBehavior: AppKilledPlaybackBehavior.StopPlaybackAndRemoveNotification but the notification is not being removed when I remove the app from recents, and when I re-open the app I find that playback was only paused, not stopped. Is there something I'm missing?

@jspizziri
Copy link
Collaborator

@mmmoussa what version of Android and device are you on?

@mmmoussa
Copy link
Contributor

Moto G Fast running Android 11

@jspizziri
Copy link
Collaborator

@mmmoussa fascinating... I'm on a Moto G Power running Android 11 and I'm not getting the issue you mentioned. Can you try clearing your cache and rebuilding?

@mmmoussa
Copy link
Contributor

Cleared cache and did a fresh install but still having the same issue. I am entirely unfamiliar with Kotlin but will try to debug.

@jspizziri
Copy link
Collaborator

@mmmoussa if you create a repro based on a fork of this lib in the example project I can take a look at it too (but I encourage you to do so as well)

@mmmoussa
Copy link
Contributor

mmmoussa commented Sep 27, 2022

With the example app, when I run the app in debug mode after modifying the appKilledPlaybackBehavior value it does work the first time I close the app but then when I open the app again, start plaback, then close it again it continues playing and doesn't dismiss the notification. I wanted to test with a release build but the task :app:checkReleaseDuplicateClasses fails with the following:

Execution failed for task ':app:checkReleaseDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class androidx.appcompat.content.res.AppCompatResources found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.content.res.AppCompatResources$ColorStateListCacheEntry found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat$1 found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat$AnimatableTransition found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat$AnimatedStateListState found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat$AnimatedVectorDrawableTransition found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat$AnimationDrawableTransition found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat$FrameInterpolator found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat$Transition found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.graphics.drawable.DrawableContainer found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.graphics.drawable.DrawableContainer$1 found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.graphics.drawable.DrawableContainer$BlockInvalidateCallback found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.graphics.drawable.DrawableContainer$DrawableContainerState found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.graphics.drawable.DrawableWrapper found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.graphics.drawable.StateListDrawable found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.graphics.drawable.StateListDrawable$StateListState found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.widget.DrawableUtils found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.widget.ResourcesWrapper found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.widget.TintContextWrapper found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.widget.TintInfo found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.widget.TintResources found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)
     Duplicate class androidx.appcompat.widget.VectorEnabledTintResources found in modules appcompat-1.0.2-runtime (androidx.appcompat:appcompat:1.0.2) and jetified-appcompat-resources-1.3.1-runtime (androidx.appcompat:appcompat-resources:1.3.1)

In the case of my app, the release build does stop the audio playback but the notification remains. However, the debug build behaviour also has the notification get removed like with the example app.

@mmmoussa
Copy link
Contributor

Seems that the old functionality was to unbind the service based on 3c292a8 and that is no longer the approach, so I'm not sure where to start looking for the issue. What would be helpful is if the example app could be bundled for release and tested to determine if the expected functionality even works in that app correctly.

@jspizziri
Copy link
Collaborator

@mmmoussa you can execute a release build locally and install it on your phone I believe if that's a concern. At the moment I'm skeptical that this is something related to release or dev mode. I'm going to try and test the example app to see if I get the same results as you.

@mmmoussa
Copy link
Contributor

@jspizziri that is what I tried to do but I encountered the above issue for the release build. I am looking into resolving it. Is the release build of the example app working for you?

@mmmoussa
Copy link
Contributor

I got the release build of the example app working and found the behaviour to be the same as debug, which is still broken. You can see this yourself if you take a look at #1758.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

[Feature Request] Bring back ability to remove notification
4 participants