From 73f5e04e0ddd23a8477ee0c9c4b3364817addede Mon Sep 17 00:00:00 2001 From: Glenn Guy Date: Thu, 11 Oct 2018 23:38:40 +1100 Subject: Remove registerMediaButtonEventReceiver for API >= 21 Finally figured out that this was causing an extra controller to be registered with the AVRCP module. With DSub as the only media app running the log would show `V/NewAvrcpMediaPlayerList: onActiveSessionsChanged: number of controllers: 0` on entry into the app and would increase to 2 shortly after. On Android Pie this causes problems as the new AVRCP module's logic is causing the metadata to be sent through to the wrong controller. I'm not sure if you think I've gone about it in the correct way but I've removed the setting for media buttons as well for Lollipop onwards, considering that this setting has no effect anyway on >= 21. --- .../java/github/daneren2005/dsub/fragments/SettingsFragment.java | 9 +++++++++ app/src/main/java/github/daneren2005/dsub/util/Util.java | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'app/src/main/java/github') diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java index 94c9b7fc..f7031146 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java @@ -24,6 +24,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.preference.CheckBoxPreference; import android.preference.EditTextPreference; @@ -109,6 +110,14 @@ public class SettingsFragment extends PreferenceCompatFragment implements Shared public void onCreate(Bundle bundle) { super.onCreate(bundle); + if(Build.VERSION.SDK_INT >= 21) { + CheckBoxPreference mediaButtons = (CheckBoxPreference) findPreference("mediaButtons"); + if (mediaButtons != null) { + PreferenceCategory otherCategory = (PreferenceCategory) findPreference("otherSettings"); + otherCategory.removePreference(mediaButtons); + } + } + int instance = this.getArguments().getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, -1); if (instance != -1) { PreferenceScreen preferenceScreen = expandServer(instance); diff --git a/app/src/main/java/github/daneren2005/dsub/util/Util.java b/app/src/main/java/github/daneren2005/dsub/util/Util.java index 5699cdf9..a02e7ded 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Util.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Util.java @@ -1294,11 +1294,11 @@ public final class Util { public static void registerMediaButtonEventReceiver(Context context) { - // Only do it if enabled in the settings. + // Only do it if enabled in the settings and api < 21 SharedPreferences prefs = getPreferences(context); boolean enabled = prefs.getBoolean(Constants.PREFERENCES_KEY_MEDIA_BUTTONS, true); - if (enabled) { + if (enabled && Build.VERSION.SDK_INT < 21) { // AudioManager.registerMediaButtonEventReceiver() was introduced in Android 2.2. // Use reflection to maintain compatibility with 1.5. -- cgit v1.2.3