Pārlūkot izejas kodu

feat(android): separate MediaProjection and OngoingConference notifications (#14363)

* feat(android): separate MediaProjection and OngoingConference notifications
factor2
Calinteodor 1 gadu atpakaļ
vecāks
revīzija
ba20fc71a8
Revīzijas autora e-pasta adrese nav piesaistīta nevienam kontam

+ 3
- 1
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetMediaProjectionModule.java Parādīt failu

@@ -1,5 +1,6 @@
1 1
 package org.jitsi.meet.sdk;
2 2
 
3
+import android.app.Activity;
3 4
 import android.content.Context;
4 5
 
5 6
 import androidx.annotation.NonNull;
@@ -23,8 +24,9 @@ class JitsiMeetMediaProjectionModule
23 24
     @ReactMethod
24 25
     public void launch() {
25 26
         Context context = getReactApplicationContext();
27
+        Activity currentActivity = getCurrentActivity();
26 28
 
27
-        JitsiMeetMediaProjectionService.launch(context);
29
+        JitsiMeetMediaProjectionService.launch(context, currentActivity);
28 30
     }
29 31
 
30 32
     @ReactMethod

+ 7
- 6
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetMediaProjectionService.java Parādīt failu

@@ -17,6 +17,7 @@
17 17
 package org.jitsi.meet.sdk;
18 18
 
19 19
 
20
+import android.app.Activity;
20 21
 import android.app.Notification;
21 22
 import android.app.Service;
22 23
 import android.content.ComponentName;
@@ -30,7 +31,6 @@ import org.jitsi.meet.sdk.log.JitsiMeetLogger;
30 31
 
31 32
 import java.util.Random;
32 33
 
33
-
34 34
 /**
35 35
  * This class implements an Android {@link Service}, a foreground one specifically, and it's
36 36
  * responsible for presenting an ongoing notification when a conference is in progress.
@@ -43,8 +43,9 @@ public class JitsiMeetMediaProjectionService extends Service {
43 43
 
44 44
     static final int NOTIFICATION_ID = new Random().nextInt(99999) + 10000;
45 45
 
46
-    public static void launch(Context context) {
47
-        OngoingNotification.createOngoingConferenceNotificationChannel();
46
+    public static void launch(Context context, Activity currentActivity) {
47
+
48
+        NotificationUtils.createNotificationChannel(currentActivity);
48 49
 
49 50
         Intent intent = new Intent(context, JitsiMeetMediaProjectionService.class);
50 51
 
@@ -59,12 +60,12 @@ public class JitsiMeetMediaProjectionService extends Service {
59 60
         } catch (RuntimeException e) {
60 61
             // Avoid crashing due to ForegroundServiceStartNotAllowedException (API level 31).
61 62
             // See: https://developer.android.com/guide/components/foreground-services#background-start-restrictions
62
-            JitsiMeetLogger.w(TAG + " Ongoing conference service not started", e);
63
+            JitsiMeetLogger.w(TAG + "Media projection service not started", e);
63 64
             return;
64 65
         }
65 66
 
66 67
         if (componentName == null) {
67
-            JitsiMeetLogger.w(TAG + " Ongoing conference service not started");
68
+            JitsiMeetLogger.w(TAG + "Media projection service not started");
68 69
         }
69 70
     }
70 71
 
@@ -81,7 +82,7 @@ public class JitsiMeetMediaProjectionService extends Service {
81 82
     @Override
82 83
     public int onStartCommand(Intent intent, int flags, int startId) {
83 84
 
84
-        Notification notification = OngoingNotification.buildOngoingConferenceNotification(null);
85
+        Notification notification = MediaProjectionNotification.buildMediaProjectionNotification();
85 86
 
86 87
         if (notification == null) {
87 88
             stopSelf();

+ 6
- 4
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetOngoingConferenceService.java Parādīt failu

@@ -16,6 +16,7 @@
16 16
 
17 17
 package org.jitsi.meet.sdk;
18 18
 
19
+import android.app.Activity;
19 20
 import android.app.Notification;
20 21
 import android.app.NotificationManager;
21 22
 import android.app.Service;
@@ -57,7 +58,8 @@ public class JitsiMeetOngoingConferenceService extends Service
57 58
 
58 59
 
59 60
     public static void launch(Context context, HashMap<String, Object> extraData) {
60
-        OngoingNotification.createOngoingConferenceNotificationChannel();
61
+        
62
+        NotificationUtils.createNotificationChannel((Activity) context);
61 63
 
62 64
         Intent intent = new Intent(context, JitsiMeetOngoingConferenceService.class);
63 65
 
@@ -94,7 +96,7 @@ public class JitsiMeetOngoingConferenceService extends Service
94 96
     public void onCreate() {
95 97
         super.onCreate();
96 98
 
97
-        Notification notification = OngoingNotification.buildOngoingConferenceNotification(isAudioMuted);
99
+        Notification notification = OngoingNotification.buildOngoingConferenceNotification(isAudioMuted, this);
98 100
         if (notification == null) {
99 101
             stopSelf();
100 102
             JitsiMeetLogger.w(TAG + " Couldn't start service, notification is null");
@@ -134,7 +136,7 @@ public class JitsiMeetOngoingConferenceService extends Service
134 136
         if (isAudioMuted != null) {
135 137
             this.isAudioMuted = Boolean.parseBoolean(intent.getStringExtra("muted"));
136 138
 
137
-            Notification notification = OngoingNotification.buildOngoingConferenceNotification(isAudioMuted);
139
+            Notification notification = OngoingNotification.buildOngoingConferenceNotification(isAudioMuted, this);
138 140
             if (notification == null) {
139 141
                 stopSelf();
140 142
                 JitsiMeetLogger.w(TAG + " Couldn't start service, notification is null");
@@ -220,7 +222,7 @@ public class JitsiMeetOngoingConferenceService extends Service
220 222
         @Override
221 223
         public void onReceive(Context context, Intent intent) {
222 224
             isAudioMuted = Boolean.parseBoolean(intent.getStringExtra("muted"));
223
-            Notification notification = OngoingNotification.buildOngoingConferenceNotification(isAudioMuted);
225
+            Notification notification = OngoingNotification.buildOngoingConferenceNotification(isAudioMuted, context);
224 226
             if (notification == null) {
225 227
                 stopSelf();
226 228
                 JitsiMeetLogger.w(TAG + " Couldn't update service, notification is null");

+ 59
- 0
android/sdk/src/main/java/org/jitsi/meet/sdk/MediaProjectionNotification.java Parādīt failu

@@ -0,0 +1,59 @@
1
+/*
2
+ * Copyright @ 2019-present 8x8, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+package org.jitsi.meet.sdk;
18
+
19
+import static org.jitsi.meet.sdk.NotificationChannels.ONGOING_CONFERENCE_CHANNEL_ID;
20
+
21
+import android.app.Notification;
22
+import android.content.Context;
23
+
24
+import androidx.core.app.NotificationCompat;
25
+
26
+import org.jitsi.meet.sdk.log.JitsiMeetLogger;
27
+
28
+/**
29
+ * Helper class for creating the media projection notification which is used with
30
+ * {@link JitsiMeetMediaProjectionService}.
31
+ */
32
+class MediaProjectionNotification {
33
+    private static final String TAG = MediaProjectionNotification.class.getSimpleName();
34
+
35
+    static Notification buildMediaProjectionNotification() {
36
+        Context context = ReactInstanceManagerHolder.getCurrentActivity();
37
+
38
+        if (context == null) {
39
+            JitsiMeetLogger.d(TAG, " Cannot create notification: no current context");
40
+            return null;
41
+        }
42
+
43
+        NotificationCompat.Builder builder = new NotificationCompat.Builder(context, ONGOING_CONFERENCE_CHANNEL_ID);
44
+
45
+        builder
46
+            .setCategory(NotificationCompat.CATEGORY_CALL)
47
+            .setContentTitle(context.getString(R.string.media_projection_notification_title))
48
+            .setContentText(context.getString(R.string.media_projection_notification_text))
49
+            .setPriority(NotificationCompat.PRIORITY_LOW)
50
+            .setOngoing(false)
51
+            .setUsesChronometer(false)
52
+            .setAutoCancel(true)
53
+            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
54
+            .setOnlyAlertOnce(true)
55
+            .setSmallIcon(context.getResources().getIdentifier("ic_notification", "drawable", context.getPackageName()));
56
+
57
+        return builder.build();
58
+    }
59
+}

+ 45
- 0
android/sdk/src/main/java/org/jitsi/meet/sdk/NotificationUtils.java Parādīt failu

@@ -0,0 +1,45 @@
1
+package org.jitsi.meet.sdk;
2
+
3
+import static org.jitsi.meet.sdk.NotificationChannels.ONGOING_CONFERENCE_CHANNEL_ID;
4
+
5
+import android.app.Activity;
6
+import android.app.NotificationChannel;
7
+import android.app.NotificationManager;
8
+import android.content.Context;
9
+import android.os.Build;
10
+
11
+import org.jitsi.meet.sdk.log.JitsiMeetLogger;
12
+
13
+class NotificationUtils {
14
+
15
+    private static final String TAG = NotificationUtils.class.getSimpleName();
16
+
17
+    static void createNotificationChannel(Activity context) {
18
+        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
19
+            return;
20
+        }
21
+
22
+        if (context == null) {
23
+            JitsiMeetLogger.w(TAG + " Cannot create notification channel: no current context");
24
+            return;
25
+        }
26
+
27
+        NotificationManager notificationManager
28
+            = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
29
+
30
+        NotificationChannel channel
31
+            = notificationManager.getNotificationChannel(ONGOING_CONFERENCE_CHANNEL_ID);
32
+
33
+        if (channel != null) {
34
+            // The channel was already created, no need to do it again.
35
+            return;
36
+        }
37
+
38
+        channel = new NotificationChannel(ONGOING_CONFERENCE_CHANNEL_ID, context.getString(R.string.ongoing_notification_channel_name), NotificationManager.IMPORTANCE_DEFAULT);
39
+        channel.enableLights(false);
40
+        channel.enableVibration(false);
41
+        channel.setShowBadge(false);
42
+
43
+        notificationManager.createNotificationChannel(channel);
44
+    }
45
+}

+ 2
- 40
android/sdk/src/main/java/org/jitsi/meet/sdk/OngoingNotification.java Parādīt failu

@@ -19,20 +19,15 @@ package org.jitsi.meet.sdk;
19 19
 import static org.jitsi.meet.sdk.NotificationChannels.ONGOING_CONFERENCE_CHANNEL_ID;
20 20
 
21 21
 import android.app.Notification;
22
-import android.app.NotificationChannel;
23
-import android.app.NotificationManager;
24 22
 import android.app.PendingIntent;
25 23
 import android.content.Context;
26 24
 import android.content.Intent;
27
-import android.os.Build;
28 25
 
29 26
 import androidx.annotation.StringRes;
30 27
 import androidx.core.app.NotificationCompat;
31 28
 
32 29
 import org.jitsi.meet.sdk.log.JitsiMeetLogger;
33 30
 
34
-import java.util.Random;
35
-
36 31
 /**
37 32
  * Helper class for creating the ongoing notification which is used with
38 33
  * {@link JitsiMeetOngoingConferenceService}. It allows the user to easily get back to the app
@@ -43,37 +38,8 @@ class OngoingNotification {
43 38
 
44 39
     private static long startingTime = 0;
45 40
 
46
-    static void createOngoingConferenceNotificationChannel() {
47
-        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
48
-            return;
49
-        }
41
+    static Notification buildOngoingConferenceNotification(Boolean isMuted, Context context) {
50 42
 
51
-        Context context = ReactInstanceManagerHolder.getCurrentActivity();
52
-        if (context == null) {
53
-            JitsiMeetLogger.w(TAG + " Cannot create notification channel: no current context");
54
-            return;
55
-        }
56
-
57
-        NotificationManager notificationManager
58
-            = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
59
-
60
-        NotificationChannel channel
61
-            = notificationManager.getNotificationChannel(ONGOING_CONFERENCE_CHANNEL_ID);
62
-        if (channel != null) {
63
-            // The channel was already created, no need to do it again.
64
-            return;
65
-        }
66
-
67
-        channel = new NotificationChannel(ONGOING_CONFERENCE_CHANNEL_ID, context.getString(R.string.ongoing_notification_action_unmute), NotificationManager.IMPORTANCE_DEFAULT);
68
-        channel.enableLights(false);
69
-        channel.enableVibration(false);
70
-        channel.setShowBadge(false);
71
-
72
-        notificationManager.createNotificationChannel(channel);
73
-    }
74
-
75
-    static Notification buildOngoingConferenceNotification(Boolean isMuted) {
76
-        Context context = ReactInstanceManagerHolder.getCurrentActivity();
77 43
         if (context == null) {
78 44
             JitsiMeetLogger.w(TAG + " Cannot create notification: no current context");
79 45
             return null;
@@ -91,7 +57,7 @@ class OngoingNotification {
91 57
         builder
92 58
             .setCategory(NotificationCompat.CATEGORY_CALL)
93 59
             .setContentTitle(context.getString(R.string.ongoing_notification_title))
94
-            .setContentText(isMuted != null ? context.getString(R.string.ongoing_notification_text) : context.getString(R.string.ongoing_notification_action_screenshare))
60
+            .setContentText(context.getString(R.string.ongoing_notification_text))
95 61
             .setPriority(NotificationCompat.PRIORITY_DEFAULT)
96 62
             .setContentIntent(pendingIntent)
97 63
             .setOngoing(true)
@@ -102,10 +68,6 @@ class OngoingNotification {
102 68
             .setOnlyAlertOnce(true)
103 69
             .setSmallIcon(context.getResources().getIdentifier("ic_notification", "drawable", context.getPackageName()));
104 70
 
105
-        if (isMuted == null) {
106
-            return builder.build();
107
-        }
108
-
109 71
         NotificationCompat.Action hangupAction = createAction(context, JitsiMeetOngoingConferenceService.Action.HANGUP, R.string.ongoing_notification_action_hang_up);
110 72
 
111 73
         JitsiMeetOngoingConferenceService.Action toggleAudioAction = isMuted

+ 2
- 1
android/sdk/src/main/res/values/strings.xml Parādīt failu

@@ -1,11 +1,12 @@
1 1
 <resources>
2 2
     <string name="app_name">Jitsi Meet SDK</string>
3 3
     <string name="dropbox_app_key"></string>
4
+    <string name="media_projection_notification_title">Media projection</string>
5
+    <string name="media_projection_notification_text">You are currently sharing your screen.</string>
4 6
     <string name="ongoing_notification_title">Ongoing meeting</string>
5 7
     <string name="ongoing_notification_text">You are currently in a meeting. Tap to return to it.</string>
6 8
     <string name="ongoing_notification_action_hang_up">Hang up</string>
7 9
     <string name="ongoing_notification_action_mute">Mute</string>
8
-    <string name="ongoing_notification_action_screenshare">You are currently screen-sharing. Tap to return to the meeting.</string>
9 10
     <string name="ongoing_notification_action_unmute">Unmute</string>
10 11
     <string name="ongoing_notification_channel_name">Ongoing Conference Notifications</string>
11 12
 </resources>

Notiek ielāde…
Atcelt
Saglabāt