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
fix(android): correct text sizing and keep the call when moving to an external display (DeX) (#17844)
Marco Castignoli94f618287bf0
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xmlindex 04114e6fc9..26dea7b703 100644--- a/android/app/src/main/AndroidManifest.xml+++ b/android/app/src/main/AndroidManifest.xml@@ -12,7 +12,7 @@android:name="android.content.APP_RESTRICTIONS"android:resource="@xml/app_restrictions" /><activity- android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"+ android:configChanges="density|fontScale|keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"android:exported="true"android:label="@string/app_name"android:launchMode="singleInstance"diff --git a/android/sdk/src/main/AndroidManifest.xml b/android/sdk/src/main/AndroidManifest.xmlindex 99d6d3eefc..74e56f75d6 100644--- a/android/sdk/src/main/AndroidManifest.xml+++ b/android/sdk/src/main/AndroidManifest.xml@@ -44,7 +44,7 @@android:supportsRtl="true"><activityandroid:name=".JitsiMeetActivity"- android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"+ android:configChanges="density|fontScale|keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"android:launchMode="singleTask"android:theme="@style/JitsiMeetActivityStyle"android:resizeableActivity="true"diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/DisplayMetricsSync.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/DisplayMetricsSync.javanew file mode 100644index 0000000000..16d75cb1b7--- /dev/null+++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/DisplayMetricsSync.java@@ -0,0 +1,106 @@+/*+ * Copyright @ 2026-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.content.Context;+import android.os.Build;+import android.util.DisplayMetrics;+import android.view.Display;+import android.view.WindowManager;++import androidx.annotation.NonNull;++import com.facebook.react.uimanager.DisplayMetricsHolder;++import org.jitsi.meet.sdk.log.JitsiMeetLogger;++/**+ * Keeps React Native's {@link DisplayMetricsHolder} in sync with the display the UI is actually+ * shown on.+ *+ * React Native initializes {@link DisplayMetricsHolder} from the application {@link Context},+ * which reports the metrics of the default (built-in) display. Yoga, however, lays views out with+ * the density of the {@code Activity} the surface lives in. As soon as the {@code Activity} sits on+ * a display with another density (Samsung DeX, an external monitor, a desktop window) the two+ * disagree: boxes are sized for one density while text, borders and everything else that goes+ * through {@code PixelUtil} is sized for the other.+ */+final class DisplayMetricsSync {+ private static final String TAG = DisplayMetricsSync.class.getSimpleName();++ private DisplayMetricsSync() {+ }++ /**+ * Points {@link DisplayMetricsHolder} at the metrics of the given UI {@link Context}.+ *+ * @param context a visual {@link Context}, i.e. the {@code Activity} hosting the React surface.+ * @return {@code true} if the metrics known to React Native changed.+ */+ @SuppressWarnings("deprecation")+ static boolean apply(@NonNull Context context) {+ // A live object: Android updates it in place on configuration changes.+ DisplayMetrics window = context.getResources().getDisplayMetrics();+ DisplayMetrics screen = new DisplayMetrics();++ screen.setTo(window);++ try {+ Display display+ = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R+ ? context.getDisplay()+ : ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();++ if (display != null) {+ display.getRealMetrics(screen);+ }+ } catch (RuntimeException e) {+ JitsiMeetLogger.w(e, TAG + " Cannot read the metrics of the display, using the window's");+ }++ // Layout happens with the density of the window's resources, so that is the one everything+ // else has to agree with.+ screen.density = window.density;+ screen.densityDpi = window.densityDpi;+ screen.scaledDensity = window.scaledDensity;+ screen.xdpi = window.xdpi;+ screen.ydpi = window.ydpi;++ DisplayMetrics previousWindow = getOrNull(true);+ DisplayMetrics previousScreen = getOrNull(false);++ if (previousWindow == window && screen.equals(previousScreen)) {+ return false;+ }++ DisplayMetricsHolder.setWindowDisplayMetrics(window);+ DisplayMetricsHolder.setScreenDisplayMetrics(screen);++ return true;+ }++ private static DisplayMetrics getOrNull(boolean window) {+ try {+ return window+ ? DisplayMetricsHolder.getWindowDisplayMetrics()+ : DisplayMetricsHolder.getScreenDisplayMetrics();+ } catch (RuntimeException e) {+ // Not initialized yet.+ return null;+ }+ }+}diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.javaindex 7a60473176..636741865e 100644--- a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java+++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java@@ -18,9 +18,12 @@ package org.jitsi.meet.sdk;import android.app.Activity;import android.content.Context;+import android.content.res.Configuration;import android.os.Bundle;import android.util.AttributeSet;+import android.view.View;import android.view.ViewGroup;+import android.view.ViewTreeObserver;import android.widget.FrameLayout;import androidx.annotation.NonNull;@@ -203,6 +206,15 @@ public class JitsiMeetView extends FrameLayout {reactSurface = (ReactSurfaceImpl) reactHost.createSurface(getContext(), appName, props);ViewGroup surfaceView = reactSurface.getView();++ // Creating the surface view makes React Native read the metrics of the default+ // display again, so this has to come after it and before anything is measured.+ DisplayMetricsSync.apply(getContext());++ if (surfaceView != null) {+ surfaceView.addOnAttachStateChangeListener(surfaceAttachListener);+ }+if (surfaceView != null) {surfaceView.setBackgroundColor(BACKGROUND_COLOR);addView(surfaceView);@@ -246,6 +258,46 @@ public class JitsiMeetView extends FrameLayout {createReactRootView("App", props);}+ /**+ * React Native's own global layout listener resets the metrics to those of the default display+ * whenever the rotation changes. Listeners run in the order they were added, so this one is+ * added once the surface view has added React Native's: the metrics of the display this view+ * is on always win.+ */+ private final ViewTreeObserver.OnGlobalLayoutListener displayMetricsListener+ = this::syncDisplayMetrics;++ private final OnAttachStateChangeListener surfaceAttachListener = new OnAttachStateChangeListener() {+ @Override+ public void onViewAttachedToWindow(@NonNull View v) {+ syncDisplayMetrics();+ v.getViewTreeObserver().addOnGlobalLayoutListener(displayMetricsListener);+ }++ @Override+ public void onViewDetachedFromWindow(@NonNull View v) {+ v.getViewTreeObserver().removeOnGlobalLayoutListener(displayMetricsListener);+ }+ };++ private void syncDisplayMetrics() {+ if (DisplayMetricsSync.apply(getContext()) && reactSurface != null) {+ ViewGroup surfaceView = reactSurface.getView();++ if (surfaceView != null) {+ // Lays the surface out again with the new density, which also makes React Native+ // tell JavaScript about the new Dimensions.+ surfaceView.requestLayout();+ }+ }+ }++ @Override+ protected void onConfigurationChanged(Configuration newConfig) {+ super.onConfigurationChanged(newConfig);+ syncDisplayMetrics();+ }+@Overrideprotected void onDetachedFromWindow() {dispose();