Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
feat(android): fix screen sharing for android 14 (#14419)
Calinteodor6a3c12b31647
diff --git a/android/build.gradle b/android/build.gradleindex 4d525c6662..ffbc66f191 100644--- a/android/build.gradle+++ b/android/build.gradle@@ -19,9 +19,9 @@ buildscript {ext {kotlinVersion = "1.7.0"buildToolsVersion = "33.0.2"- compileSdkVersion = 33+ compileSdkVersion = 34minSdkVersion = 24- targetSdkVersion = 33+ targetSdkVersion = 34supportLibVersion = "28.0.0"// We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.diff --git a/android/sdk/src/main/AndroidManifest.xml b/android/sdk/src/main/AndroidManifest.xmlindex f0f9a82c03..df494a4613 100644--- a/android/sdk/src/main/AndroidManifest.xml+++ b/android/sdk/src/main/AndroidManifest.xml@@ -12,7 +12,6 @@<uses-permission android:name="android.permission.WAKE_LOCK" /><uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /><uses-permission android:name="android.permission.FOREGROUND_SERVICE" />- <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" /><uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" /><uses-feature@@ -51,10 +50,6 @@android:name="org.jitsi.meet.sdk.JitsiMeetOngoingConferenceService"android:foregroundServiceType="mediaPlayback" />- <service- android:name="org.jitsi.meet.sdk.JitsiMeetMediaProjectionService"- android:foregroundServiceType="mediaProjection" />-<providerandroid:name="com.reactnativecommunity.webview.RNCWebViewFileProvider"android:authorities="${applicationId}.fileprovider"diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetMediaProjectionModule.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetMediaProjectionModule.javadeleted file mode 100644index 3d4224aea6..0000000000--- a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetMediaProjectionModule.java+++ /dev/null@@ -1,44 +0,0 @@-package org.jitsi.meet.sdk;--import android.app.Activity;-import android.content.Context;--import androidx.annotation.NonNull;--import com.facebook.react.bridge.ReactApplicationContext;-import com.facebook.react.bridge.ReactContextBaseJavaModule;-import com.facebook.react.bridge.ReactMethod;-import com.facebook.react.module.annotations.ReactModule;---@ReactModule(name = JitsiMeetMediaProjectionModule.NAME)-class JitsiMeetMediaProjectionModule- extends ReactContextBaseJavaModule {-- public static final String NAME = "JitsiMeetMediaProjectionModule";-- public JitsiMeetMediaProjectionModule(ReactApplicationContext reactContext) {- super(reactContext);- }-- @ReactMethod- public void launch() {- Context context = getReactApplicationContext();- Activity currentActivity = getCurrentActivity();-- JitsiMeetMediaProjectionService.launch(context, currentActivity);- }-- @ReactMethod- public void abort() {- Context context = getReactApplicationContext();-- JitsiMeetMediaProjectionService.abort(context);- }-- @NonNull- @Override- public String getName() {- return NAME;- }-}diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetMediaProjectionService.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetMediaProjectionService.javadeleted file mode 100644index e452d054fa..0000000000--- a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetMediaProjectionService.java+++ /dev/null@@ -1,102 +0,0 @@-/*- * Copyright @ 2019-present 8x8, Inc.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--package org.jitsi.meet.sdk;---import android.app.Activity;-import android.app.Notification;-import android.app.Service;-import android.content.ComponentName;-import android.content.Context;-import android.content.Intent;-import android.content.pm.ServiceInfo;-import android.os.Build;-import android.os.IBinder;--import org.jitsi.meet.sdk.log.JitsiMeetLogger;--import java.util.Random;--/**- * This class implements an Android {@link Service}, a foreground one specifically, and it's- * responsible for presenting an ongoing notification when a conference is in progress.- * The service will help keep the app running while in the background.- *- * See: https://developer.android.com/guide/components/services- */-public class JitsiMeetMediaProjectionService extends Service {- private static final String TAG = JitsiMeetMediaProjectionService.class.getSimpleName();-- static final int NOTIFICATION_ID = new Random().nextInt(99999) + 10000;-- public static void launch(Context context, Activity currentActivity) {-- NotificationUtils.createNotificationChannel(currentActivity);-- Intent intent = new Intent(context, JitsiMeetMediaProjectionService.class);-- ComponentName componentName;-- try {- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {- componentName = context.startForegroundService(intent);- } else {- componentName = context.startService(intent);- }- } catch (RuntimeException e) {- // Avoid crashing due to ForegroundServiceStartNotAllowedException (API level 31).- // See: https://developer.android.com/guide/components/foreground-services#background-start-restrictions- JitsiMeetLogger.w(TAG + "Media projection service not started", e);- return;- }-- if (componentName == null) {- JitsiMeetLogger.w(TAG + "Media projection service not started");- }- }-- public static void abort(Context context) {- Intent intent = new Intent(context, JitsiMeetMediaProjectionService.class);- context.stopService(intent);- }-- @Override- public IBinder onBind(Intent intent) {- return null;- }-- @Override- public int onStartCommand(Intent intent, int flags, int startId) {-- Notification notification = MediaProjectionNotification.buildMediaProjectionNotification(this);-- if (notification == null) {- stopSelf();- JitsiMeetLogger.w(TAG + " Couldn't start service, notification is null");-- return START_NOT_STICKY;- }-- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {- startForeground(NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION);- } else {- startForeground(NOTIFICATION_ID, notification);- }-- return START_NOT_STICKY;- }-}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.javaindex 1b37db7476..779fc2599e 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@@ -58,8 +58,8 @@ public class JitsiMeetOngoingConferenceService extends Servicepublic static void launch(Context context, HashMap<String, Object> extraData) {-- NotificationUtils.createNotificationChannel((Activity) context);++ OngoingNotification.createNotificationChannel((Activity) context);Intent intent = new Intent(context, JitsiMeetOngoingConferenceService.class);diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/MediaProjectionNotification.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/MediaProjectionNotification.javadeleted file mode 100644index eb5b24aa14..0000000000--- a/android/sdk/src/main/java/org/jitsi/meet/sdk/MediaProjectionNotification.java+++ /dev/null@@ -1,58 +0,0 @@-/*- * Copyright @ 2019-present 8x8, Inc.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--package org.jitsi.meet.sdk;--import static org.jitsi.meet.sdk.NotificationUtils.ONGOING_CONFERENCE_CHANNEL_ID;--import android.app.Notification;-import android.content.Context;--import androidx.core.app.NotificationCompat;--import org.jitsi.meet.sdk.log.JitsiMeetLogger;--/**- * Helper class for creating the media projection notification which is used with- * {@link JitsiMeetMediaProjectionService}.- */-class MediaProjectionNotification {- private static final String TAG = MediaProjectionNotification.class.getSimpleName();-- static Notification buildMediaProjectionNotification(Context context) {-- if (context == null) {- JitsiMeetLogger.d(TAG, " Cannot create notification: no current context");- return null;- }-- NotificationCompat.Builder builder = new NotificationCompat.Builder(context, ONGOING_CONFERENCE_CHANNEL_ID);-- builder- .setCategory(NotificationCompat.CATEGORY_CALL)- .setContentTitle(context.getString(R.string.media_projection_notification_title))- .setContentText(context.getString(R.string.media_projection_notification_text))- .setPriority(NotificationCompat.PRIORITY_LOW)- .setOngoing(false)- .setUsesChronometer(false)- .setAutoCancel(true)- .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)- .setOnlyAlertOnce(true)- .setSmallIcon(context.getResources().getIdentifier("ic_notification", "drawable", context.getPackageName()));-- return builder.build();- }-}diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/NotificationUtils.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/NotificationUtils.javadeleted file mode 100644index 7cb4e08bc5..0000000000--- a/android/sdk/src/main/java/org/jitsi/meet/sdk/NotificationUtils.java+++ /dev/null@@ -1,50 +0,0 @@-package org.jitsi.meet.sdk;--import android.app.Activity;-import android.app.NotificationChannel;-import android.app.NotificationManager;-import android.content.Context;-import android.os.Build;--import org.jitsi.meet.sdk.log.JitsiMeetLogger;--import java.util.ArrayList;-import java.util.List;--class NotificationUtils {-- static final String ONGOING_CONFERENCE_CHANNEL_ID = "JitsiOngoingConferenceChannel";-- public static List<String> allIds = new ArrayList<String>() {{ add(ONGOING_CONFERENCE_CHANNEL_ID); }};-- private static final String TAG = NotificationUtils.class.getSimpleName();-- static void createNotificationChannel(Activity context) {- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {- return;- }-- if (context == null) {- JitsiMeetLogger.w(TAG + " Cannot create notification channel: no current context");- return;- }-- NotificationManager notificationManager- = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);-- NotificationChannel channel- = notificationManager.getNotificationChannel(ONGOING_CONFERENCE_CHANNEL_ID);-- if (channel != null) {- // The channel was already created, no need to do it again.- return;- }-- channel = new NotificationChannel(ONGOING_CONFERENCE_CHANNEL_ID, context.getString(R.string.ongoing_notification_channel_name), NotificationManager.IMPORTANCE_DEFAULT);- channel.enableLights(false);- channel.enableVibration(false);- channel.setShowBadge(false);-- notificationManager.createNotificationChannel(channel);- }-}diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/OngoingNotification.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/OngoingNotification.javaindex 12ce0d999e..82a38a391a 100644--- a/android/sdk/src/main/java/org/jitsi/meet/sdk/OngoingNotification.java+++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/OngoingNotification.java@@ -16,8 +16,11 @@package org.jitsi.meet.sdk;-import static org.jitsi.meet.sdk.NotificationUtils.ONGOING_CONFERENCE_CHANNEL_ID;+import org.jitsi.meet.sdk.log.JitsiMeetLogger;+import android.app.Activity;+import android.app.NotificationChannel;+import android.app.NotificationManager;import android.app.Notification;import android.app.PendingIntent;import android.content.Context;@@ -26,7 +29,8 @@ import android.content.Intent;import androidx.annotation.StringRes;import androidx.core.app.NotificationCompat;-import org.jitsi.meet.sdk.log.JitsiMeetLogger;+import android.os.Build;+/*** Helper class for creating the ongoing notification which is used with@@ -38,6 +42,37 @@ class OngoingNotification {private static long startingTime = 0;+ static final String ONGOING_CONFERENCE_CHANNEL_ID = "JitsiOngoingConferenceChannel";++ static void createNotificationChannel(Activity context) {+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {+ return;+ }++ if (context == null) {+ JitsiMeetLogger.w(TAG + " Cannot create notification channel: no current context");+ return;+ }++ NotificationManager notificationManager+ = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);++ NotificationChannel channel+ = notificationManager.getNotificationChannel(ONGOING_CONFERENCE_CHANNEL_ID);++ if (channel != null) {+ // The channel was already created, no need to do it again.+ return;+ }++ channel = new NotificationChannel(ONGOING_CONFERENCE_CHANNEL_ID, context.getString(R.string.ongoing_notification_channel_name), NotificationManager.IMPORTANCE_DEFAULT);+ channel.enableLights(false);+ channel.enableVibration(false);+ channel.setShowBadge(false);++ notificationManager.createNotificationChannel(channel);+ }+static Notification buildOngoingConferenceNotification(Boolean isMuted, Context context) {if (context == null) {diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.javaindex d5bb08b579..d04147c017 100644--- a/android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java+++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java@@ -37,6 +37,7 @@ import com.oney.WebRTCModule.webrtcutils.H264AndSoftwareVideoEncoderFactory;import org.devio.rn.splashscreen.SplashScreenModule;import org.webrtc.EglBase;+import org.webrtc.Logging;import java.lang.reflect.Constructor;import java.util.ArrayList;@@ -67,7 +68,6 @@ class ReactInstanceManagerHolder {new DropboxModule(reactContext),new ExternalAPIModule(reactContext),new JavaScriptSandboxModule(reactContext),- new JitsiMeetMediaProjectionModule(reactContext),new LocaleDetector(reactContext),new LogBridgeModule(reactContext),new SplashScreenModule(reactContext),@@ -241,6 +241,8 @@ class ReactInstanceManagerHolder {options.videoDecoderFactory = new H264AndSoftwareVideoDecoderFactory(eglContext);options.videoEncoderFactory = new H264AndSoftwareVideoEncoderFactory(eglContext);+ options.enableMediaProjectionService = true;+// options.loggingSeverity = Logging.Severity.LS_INFO;Log.d(TAG, "initializing RN with Activity");diff --git a/react/features/base/tracks/actions.native.ts b/react/features/base/tracks/actions.native.tsindex 61be970e83..ec0174840b 100644--- a/react/features/base/tracks/actions.native.ts+++ b/react/features/base/tracks/actions.native.ts@@ -1,5 +1,3 @@-import { NativeModules, Platform } from 'react-native';-import { IReduxState, IStore } from '../../app/types';import { setPictureInPictureEnabled } from '../../mobile/picture-in-picture/functions';import { showNotification } from '../../notifications/actions';@@ -16,7 +14,6 @@ import { VIDEO_MUTISM_AUTHORITY } from '../media/constants';import { addLocalTrack, replaceLocalTrack } from './actions.any';import { getLocalDesktopTrack, getTrackState, isLocalVideoTrackDesktop } from './functions.native';-const { JitsiMeetMediaProjectionModule } = NativeModules;export * from './actions.any';@@ -35,10 +32,7 @@ export function toggleScreensharing(enabled: boolean, _ignore1?: boolean, _ignorif (enabled) {const isSharing = isLocalVideoTrackDesktop(state);- if (isSharing) {- Platform.OS === 'android' && JitsiMeetMediaProjectionModule.abort();- } else {- Platform.OS === 'android' && JitsiMeetMediaProjectionModule.launch();+ if (!isSharing) {_startScreenSharing(dispatch, state);}} else {