From 863e0201818e729fda43c18766b90afaff7ffc23 Mon Sep 17 00:00:00 2001 From: Daniel Lublin Date: Tue, 16 Jan 2024 11:08:56 +0100 Subject: Set foreground service type, required on SDK 34/UPSIDE_DOWN_CAKE/Android 14 --- .gitlab-ci.yml | 2 +- app/src/main/AndroidManifest.xml | 4 +++- .../java/se/lublin/mumla/channel/ChannelListFragment.java | 9 ++++++++- .../lublin/mumla/service/MumlaConnectionNotification.java | 15 +++++++++++++-- .../lublin/mumla/service/MumlaReconnectNotification.java | 7 ++++++- .../main/java/se/lublin/mumla/service/MumlaService.java | 6 +++++- 6 files changed, 36 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 839ad7a..51a5a44 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: docker.io/quite/android-sdk-ndk:6 +image: docker.io/quite/android-sdk-ndk:7 variables: # get those pesky submodules diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05071bb..e461adc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -23,6 +23,7 @@ android:required="false" /> + + android:enabled="true" + android:foregroundServiceType="microphone" /> = Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + getActivity().registerReceiver(mBluetoothReceiver, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED), RECEIVER_NOT_EXPORTED); + } else { + getActivity().registerReceiver(mBluetoothReceiver, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED)); + } } @Override diff --git a/app/src/main/java/se/lublin/mumla/service/MumlaConnectionNotification.java b/app/src/main/java/se/lublin/mumla/service/MumlaConnectionNotification.java index 46834ec..64f180f 100644 --- a/app/src/main/java/se/lublin/mumla/service/MumlaConnectionNotification.java +++ b/app/src/main/java/se/lublin/mumla/service/MumlaConnectionNotification.java @@ -19,6 +19,8 @@ package se.lublin.mumla.service; import static android.app.PendingIntent.FLAG_CANCEL_CURRENT; import static android.app.PendingIntent.FLAG_IMMUTABLE; +import static android.content.Context.RECEIVER_NOT_EXPORTED; +import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE; import android.app.Notification; import android.app.NotificationChannel; @@ -29,6 +31,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.ServiceInfo; import android.os.Build; import androidx.core.app.NotificationCompat; @@ -109,7 +112,11 @@ public class MumlaConnectionNotification { filter.addAction(BROADCAST_MUTE); filter.addAction(BROADCAST_OVERLAY); try { - mService.registerReceiver(mNotificationReceiver, filter); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + mService.registerReceiver(mNotificationReceiver, filter, RECEIVER_NOT_EXPORTED); + } else { + mService.registerReceiver(mNotificationReceiver, filter); + } } catch (IllegalArgumentException e) { // Thrown if receiver is already registered. e.printStackTrace(); @@ -181,7 +188,11 @@ public class MumlaConnectionNotification { builder.setContentIntent(pendingIntent); Notification notification = builder.build(); - mService.startForeground(NOTIFICATION_ID, notification); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + mService.startForeground(NOTIFICATION_ID, notification, FOREGROUND_SERVICE_TYPE_MICROPHONE); + } else { + mService.startForeground(NOTIFICATION_ID, notification); + } return notification; } diff --git a/app/src/main/java/se/lublin/mumla/service/MumlaReconnectNotification.java b/app/src/main/java/se/lublin/mumla/service/MumlaReconnectNotification.java index 767586a..86c9f86 100644 --- a/app/src/main/java/se/lublin/mumla/service/MumlaReconnectNotification.java +++ b/app/src/main/java/se/lublin/mumla/service/MumlaReconnectNotification.java @@ -19,6 +19,7 @@ package se.lublin.mumla.service; import static android.app.PendingIntent.FLAG_CANCEL_CURRENT; import static android.app.PendingIntent.FLAG_IMMUTABLE; +import static android.content.Context.RECEIVER_NOT_EXPORTED; import android.app.NotificationChannel; import android.app.NotificationManager; @@ -81,7 +82,11 @@ public class MumlaReconnectNotification { filter.addAction(BROADCAST_RECONNECT); filter.addAction(BROADCAST_CANCEL_RECONNECT); try { - mContext.registerReceiver(mNotificationReceiver, filter); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + mContext.registerReceiver(mNotificationReceiver, filter, RECEIVER_NOT_EXPORTED); + } else { + mContext.registerReceiver(mNotificationReceiver, filter); + } } catch (IllegalArgumentException e) { // Thrown if receiver is already registered. e.printStackTrace(); diff --git a/app/src/main/java/se/lublin/mumla/service/MumlaService.java b/app/src/main/java/se/lublin/mumla/service/MumlaService.java index d20e5e5..c852dc6 100644 --- a/app/src/main/java/se/lublin/mumla/service/MumlaService.java +++ b/app/src/main/java/se/lublin/mumla/service/MumlaService.java @@ -357,7 +357,11 @@ public class MumlaService extends HumlaService implements setSelfMuteDeafState(mSettings.isMuted(), mSettings.isDeafened()); } - registerReceiver(mTalkReceiver, new IntentFilter(TalkBroadcastReceiver.BROADCAST_TALK)); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + registerReceiver(mTalkReceiver, new IntentFilter(TalkBroadcastReceiver.BROADCAST_TALK), RECEIVER_EXPORTED); + } else { + registerReceiver(mTalkReceiver, new IntentFilter(TalkBroadcastReceiver.BROADCAST_TALK)); + } if (mSettings.isHotCornerEnabled()) { mHotCorner.setShown(true); -- cgit v1.2.3