5

When using GeckoView, is it possible to disable WebRTC? Either programmatically or at build-time (e.g. in build.gradle)?

Context:

We are building an Android app where we would like to run mini-web-apps without internet access in a webview. When using the system webview, it's not possible to restrict internet access because the webapp can always use WebRTC to circumvent the internet restriction.

So, we are thinking about switching to GeckoView, but are not sure if this will help.

Research:

In Firefox, it seems to be possible to disable WebRTC using about:config, but in GeckoView's API, I could neither find a way to set about:config preferences, nor an API that directly disables WebRTC.

For normal internet requests, it seems to be possible to block them.

Nemo
  • 728
  • 1
  • 4
  • 16

2 Answers2

5

You can disable WebRTC by setting the media.peerconnection.enabled preference to false using the GeckoView GeckoRuntimeSettings class.

GeckoRuntimeSettings.Builder builder = new GeckoRuntimeSettings.Builder();
builder.preferences().setBoolean("media.peerconnection.enabled", false);
GeckoRuntime geckoRuntime = GeckoRuntime.create(this, builder.build());

This will disable WebRTC for the entire app.

Alternatively, at build-time -- You can disable WebRTC by adding the following line to your AndroidManifest.xml file:

<meta-data android:name="org.mozilla.geckoview.WebRTC" android:value="false" />

Otherwise, you can add the following line to your build.gradle file to disable WebRTC for all flavors of your app:

android {
    defaultConfig {
        ...
        manifestPlaceholders = [geckoviewWebRTC: "false"]
    }
}

And then add the following line to your AndroidManifest.xml file:

<meta-data android:name="org.mozilla.geckoview.WebRTC" android:value="${geckoviewWebRTC}" />

This will disable WebRTC for all flavors of your app.

Shashank Raj
  • 153
  • 2
  • 12
  • Thanks a lot for the detailed answer -- pity the bounty ran out exactly the day you provided this answer ;) The other answer is also interesting, however, as it could help to reduce the apk size if one is shipping a "restricted" geckoview. – hpk42 Mar 13 '23 at 20:53
  • Thanks! The code snippet using `GeckoRuntimeSettings` doesn't compile though because [there is no `preferences()` method on `GeckoRuntimeSettings.Builder`](https://mozilla.github.io/geckoview/javadoc/mozilla-central/org/mozilla/geckoview/GeckoRuntimeSettings.Builder.html) – Nemo Mar 13 '23 at 21:52
  • Where in the AndroidManifest do I need to put the ``? Inside the `` tag? Inside the `` tag? – Nemo Mar 13 '23 at 21:56
  • @hpk42 Its okay but I had submitted the solution when the bounty was still 50 mins away till it expired. – Shashank Raj Mar 16 '23 at 15:06
2

Looking at the source code https://hg.mozilla.org/mozilla-central/file/tip/mobile/android/geckoview/build.gradle#l107 it seems possible to recompile without the MOZ_WEBRTC variable set, to exclude all WebRTC sources from the build.

It maybe worth a try.

Please take a look here to see how to rebuild the library customizing the configuration

Yngwie89
  • 1,217
  • 9
  • 17
  • 1. What's the exact text I have to put into the `mozconfig` file? I just downloaded the geckoview sources, and there is no line mentioning `MOZ_WEBRTC` or `substs` in the `mozconfig file. 2. How much do I have to compile myself for this? Is it enough to build only the Java code (i.e. artifact build) or do I need to also compile the C++ code myself? Or is it even enough to include geckoview as a dependency in my `build.gradle`, and somehow set this variable? – Nemo Mar 07 '23 at 18:01