|
@@ -17,6 +17,7 @@
|
17
|
17
|
package org.jitsi.meet.sdk;
|
18
|
18
|
|
19
|
19
|
import static android.Manifest.permission.POST_NOTIFICATIONS;
|
|
20
|
+import static android.Manifest.permission.RECORD_AUDIO;
|
20
|
21
|
|
21
|
22
|
import android.app.Activity;
|
22
|
23
|
import android.app.Notification;
|
|
@@ -38,7 +39,9 @@ import com.facebook.react.modules.core.PermissionListener;
|
38
|
39
|
|
39
|
40
|
import org.jitsi.meet.sdk.log.JitsiMeetLogger;
|
40
|
41
|
|
|
42
|
+import java.util.ArrayList;
|
41
|
43
|
import java.util.HashMap;
|
|
44
|
+import java.util.List;
|
42
|
45
|
import java.util.Random;
|
43
|
46
|
|
44
|
47
|
/**
|
|
@@ -57,7 +60,7 @@ public class JitsiMeetOngoingConferenceService extends Service
|
57
|
60
|
|
58
|
61
|
private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver();
|
59
|
62
|
|
60
|
|
- private static final int POST_NOTIFICATIONS_PERMISSION_REQUEST_CODE = (int) (Math.random() * Short.MAX_VALUE);
|
|
63
|
+ private static final int PERMISSIONS_REQUEST_CODE = (int) (Math.random() * Short.MAX_VALUE);
|
61
|
64
|
|
62
|
65
|
private boolean isAudioMuted;
|
63
|
66
|
|
|
@@ -95,26 +98,50 @@ public class JitsiMeetOngoingConferenceService extends Service
|
95
|
98
|
|
96
|
99
|
|
97
|
100
|
public static void launch(Context context, HashMap<String, Object> extraData) {
|
98
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
99
|
|
- PermissionListener listener = new PermissionListener() {
|
100
|
|
- @Override
|
101
|
|
- public boolean onRequestPermissionsResult(int i, String[] strings, int[] results) {
|
102
|
|
- if (results.length > 0 && results[0] == PackageManager.PERMISSION_GRANTED) {
|
103
|
|
- doLaunch(context, extraData);
|
|
101
|
+ List<String> permissionsList = new ArrayList<>();
|
|
102
|
+
|
|
103
|
+ PermissionListener listener = new PermissionListener() {
|
|
104
|
+ @Override
|
|
105
|
+ public boolean onRequestPermissionsResult(int i, String[] strings, int[] results) {
|
|
106
|
+ int counter = 0;
|
|
107
|
+
|
|
108
|
+ if (results.length > 0) {
|
|
109
|
+ for (int result : results) {
|
|
110
|
+ if (result == PackageManager.PERMISSION_GRANTED) {
|
|
111
|
+ counter++;
|
|
112
|
+ }
|
104
|
113
|
}
|
105
|
114
|
|
106
|
|
- return true;
|
|
115
|
+ if (counter == results.length){
|
|
116
|
+ doLaunch(context, extraData);
|
|
117
|
+ JitsiMeetLogger.w(TAG + " Service launched, permissions were granted");
|
|
118
|
+ } else {
|
|
119
|
+ JitsiMeetLogger.w(TAG + " Couldn't launch service, permissions were not granted");
|
|
120
|
+ }
|
107
|
121
|
}
|
108
|
|
- };
|
109
|
122
|
|
|
123
|
+ return true;
|
|
124
|
+ }
|
|
125
|
+ };
|
|
126
|
+
|
|
127
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
128
|
+ permissionsList.add(POST_NOTIFICATIONS);
|
|
129
|
+ permissionsList.add(RECORD_AUDIO);
|
|
130
|
+ }
|
|
131
|
+
|
|
132
|
+ String[] permissionsArray = new String[ permissionsList.size() ];
|
|
133
|
+ permissionsArray = permissionsList.toArray( permissionsArray );
|
|
134
|
+
|
|
135
|
+ if (permissionsArray.length > 0) {
|
110
|
136
|
JitsiMeetActivityDelegate.requestPermissions(
|
111
|
137
|
(Activity) context,
|
112
|
|
- new String[]{POST_NOTIFICATIONS},
|
113
|
|
- POST_NOTIFICATIONS_PERMISSION_REQUEST_CODE,
|
|
138
|
+ permissionsArray,
|
|
139
|
+ PERMISSIONS_REQUEST_CODE,
|
114
|
140
|
listener
|
115
|
141
|
);
|
116
|
142
|
} else {
|
117
|
143
|
doLaunch(context, extraData);
|
|
144
|
+ JitsiMeetLogger.w(TAG + " Service launched");
|
118
|
145
|
}
|
119
|
146
|
}
|
120
|
147
|
|
|
@@ -132,8 +159,10 @@ public class JitsiMeetOngoingConferenceService extends Service
|
132
|
159
|
stopSelf();
|
133
|
160
|
JitsiMeetLogger.w(TAG + " Couldn't start service, notification is null");
|
134
|
161
|
} else {
|
135
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
162
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
136
|
163
|
startForeground(NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK | ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE);
|
|
164
|
+ } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
|
|
165
|
+ startForeground(NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK);
|
137
|
166
|
} else {
|
138
|
167
|
startForeground(NOTIFICATION_ID, notification);
|
139
|
168
|
}
|