瀏覽代碼

feat(android): check for microphone permission so ongoing service can start (#14865)

* feat(android/sdk): for API >= 33, launch JitsiOngoingConferenceService
only if POST_NOTIFICATIONS and RECORD_AUDIO permissions have been granted
factor2
Calinteodor 11 月之前
父節點
當前提交
3ae50b6c4c
沒有連結到貢獻者的電子郵件帳戶。

+ 1
- 1
android/build.gradle 查看文件

44
     googleServicesEnabled = project.file('app/google-services.json').exists() && !libreBuild
44
     googleServicesEnabled = project.file('app/google-services.json').exists() && !libreBuild
45
 
45
 
46
     //React Native Version
46
     //React Native Version
47
-    rnVersion = "0.72.9"
47
+    rnVersion = "0.72.14"
48
 }
48
 }
49
 
49
 
50
 allprojects {
50
 allprojects {

+ 41
- 12
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetOngoingConferenceService.java 查看文件

17
 package org.jitsi.meet.sdk;
17
 package org.jitsi.meet.sdk;
18
 
18
 
19
 import static android.Manifest.permission.POST_NOTIFICATIONS;
19
 import static android.Manifest.permission.POST_NOTIFICATIONS;
20
+import static android.Manifest.permission.RECORD_AUDIO;
20
 
21
 
21
 import android.app.Activity;
22
 import android.app.Activity;
22
 import android.app.Notification;
23
 import android.app.Notification;
38
 
39
 
39
 import org.jitsi.meet.sdk.log.JitsiMeetLogger;
40
 import org.jitsi.meet.sdk.log.JitsiMeetLogger;
40
 
41
 
42
+import java.util.ArrayList;
41
 import java.util.HashMap;
43
 import java.util.HashMap;
44
+import java.util.List;
42
 import java.util.Random;
45
 import java.util.Random;
43
 
46
 
44
 /**
47
 /**
57
 
60
 
58
     private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver();
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
     private boolean isAudioMuted;
65
     private boolean isAudioMuted;
63
 
66
 
95
 
98
 
96
 
99
 
97
     public static void launch(Context context, HashMap<String, Object> extraData) {
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
             JitsiMeetActivityDelegate.requestPermissions(
136
             JitsiMeetActivityDelegate.requestPermissions(
111
                 (Activity) context,
137
                 (Activity) context,
112
-                new String[]{POST_NOTIFICATIONS},
113
-                POST_NOTIFICATIONS_PERMISSION_REQUEST_CODE,
138
+                permissionsArray,
139
+                PERMISSIONS_REQUEST_CODE,
114
                 listener
140
                 listener
115
             );
141
             );
116
         } else {
142
         } else {
117
             doLaunch(context, extraData);
143
             doLaunch(context, extraData);
144
+            JitsiMeetLogger.w(TAG + " Service launched");
118
         }
145
         }
119
     }
146
     }
120
 
147
 
132
             stopSelf();
159
             stopSelf();
133
             JitsiMeetLogger.w(TAG + " Couldn't start service, notification is null");
160
             JitsiMeetLogger.w(TAG + " Couldn't start service, notification is null");
134
         } else {
161
         } else {
135
-            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
162
+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
136
                 startForeground(NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK | ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE);
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
             } else {
166
             } else {
138
                 startForeground(NOTIFICATION_ID, notification);
167
                 startForeground(NOTIFICATION_ID, notification);
139
             }
168
             }

Loading…
取消
儲存