diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetOngoingConferenceService.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetOngoingConferenceService.java index 814472036..b93b285fa 100644 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetOngoingConferenceService.java +++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetOngoingConferenceService.java @@ -24,23 +24,21 @@ import android.content.Intent; import android.os.IBinder; import android.util.Log; -import java.util.Random; -public class JitsiMeetOngoingConferenceService extends Service implements OngoingConferenceTracker.OngoingConferenceListener { +public class JitsiMeetOngoingConferenceService extends Service + implements OngoingConferenceTracker.OngoingConferenceListener { private static final String TAG = JitsiMeetOngoingConferenceService.class.getSimpleName(); - private static final int NOTIFICATION_ID = new Random().nextInt(99999) + 10000; - static final class Actions { - static final String ONGOING_CONFERENCE = TAG + ":ONGOING_CONFERENCE"; + static final String START = TAG + ":START"; static final String HANGUP = TAG + ":HANGUP"; } static void launch(Context context) { - NotificationUtils.createOngoingConferenceNotificationChannel(); + OngoingNotification.createOngoingConferenceNotificationChannel(); Intent intent = new Intent(context, JitsiMeetOngoingConferenceService.class); - intent.setAction(Actions.ONGOING_CONFERENCE); + intent.setAction(Actions.START); ComponentName componentName = context.startService(intent); if (componentName == null) { @@ -70,10 +68,9 @@ public class JitsiMeetOngoingConferenceService extends Service implements Ongoin @Override public int onStartCommand(Intent intent, int flags, int startId) { final String action = intent.getAction(); - if (action.equals(Actions.ONGOING_CONFERENCE)) { - Notification notification - = NotificationUtils.buildOngoingConferenceNotification(); - startForeground(NOTIFICATION_ID, notification); + if (action.equals(Actions.START)) { + Notification notification = OngoingNotification.buildOngoingConferenceNotification(); + startForeground(OngoingNotification.NOTIFICATION_ID, notification); Log.i(TAG, "Service started"); } else if (action.equals(Actions.HANGUP)) { Log.i(TAG, "Hangup requested"); @@ -81,6 +78,7 @@ public class JitsiMeetOngoingConferenceService extends Service implements Ongoin if (AudioModeModule.useConnectionService()) { ConnectionService.abortConnections(); } + stopSelf(); } else { Log.w(TAG, "Unknown action received: " + action); stopSelf(); diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/NotificationUtils.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/OngoingNotification.java similarity index 84% rename from android/sdk/src/main/java/org/jitsi/meet/sdk/NotificationUtils.java rename to android/sdk/src/main/java/org/jitsi/meet/sdk/OngoingNotification.java index 63484e2ec..d9eafa349 100644 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/NotificationUtils.java +++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/OngoingNotification.java @@ -26,12 +26,17 @@ import android.os.Build; import android.support.v4.app.NotificationCompat; import android.util.Log; +import java.util.Random; -class NotificationUtils { - private static final String TAG = NotificationUtils.class.getSimpleName(); - private static final String ONGOING_CONFERENCEE_CHANNEL_ID = "JitsiNotificationChannel"; - private static final String ONGOING_CONFERENCEE_CHANNEL_NAME = "Ongoing Conference Notifications"; +class OngoingNotification { + private static final String TAG = OngoingNotification.class.getSimpleName(); + + private static final String CHANNEL_ID = "JitsiNotificationChannel"; + private static final String CHANNEL_NAME = "Ongoing Conference Notifications"; + + static final int NOTIFICATION_ID = new Random().nextInt(99999) + 10000; + static void createOngoingConferenceNotificationChannel() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { @@ -48,16 +53,13 @@ class NotificationUtils { = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationChannel channel - = notificationManager.getNotificationChannel(ONGOING_CONFERENCEE_CHANNEL_ID); + = notificationManager.getNotificationChannel(CHANNEL_ID); if (channel != null) { // The channel was already created, no need to do it again. return; } - channel = new NotificationChannel( - ONGOING_CONFERENCEE_CHANNEL_ID, - ONGOING_CONFERENCEE_CHANNEL_NAME, - NotificationManager.IMPORTANCE_DEFAULT); + channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT); channel.enableLights(false); channel.enableVibration(false); channel.setShowBadge(false); @@ -77,7 +79,7 @@ class NotificationUtils { NotificationCompat.Builder builder; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - builder = new NotificationCompat.Builder(context, ONGOING_CONFERENCEE_CHANNEL_ID); + builder = new NotificationCompat.Builder(context, CHANNEL_ID); } else { builder = new NotificationCompat.Builder(context); }