Bug 1858377 Comment 3 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

I made a [modified geckoview example apk](https://send.ephemeral.land/download/4ab17c82f5f6b46a/#yot_thJjp4EOzUFECkJPbw) (Note: the link will be expired in 1w or 20 downloads) with following changes:
```diff
diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
index e55e7ba8d3e67..0a16d7c00669f 100644
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
@@ -56,6 +56,7 @@ import android.webkit.MimeTypeMap;
 import androidx.annotation.Nullable;
 import androidx.collection.SimpleArrayMap;
 import androidx.core.content.res.ResourcesCompat;
+import java.net.InetSocketAddress;
 import java.net.Proxy;
 import java.nio.ByteBuffer;
 import java.util.List;
@@ -1300,11 +1301,15 @@ public class GeckoAppShell {
       return "DIRECT";
     }

+    final InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
+    final String proxyHost = proxyAddress.getHostString();
+    final int proxyPort = proxyAddress.getPort();
+
     switch (proxy.type()) {
       case HTTP:
-        return "PROXY " + proxy.address().toString();
+        return "PROXY " + String.format("%s:%d", proxyHost, proxyPort);
       case SOCKS:
-        return "SOCKS " + proxy.address().toString();
+        return "SOCKS " + String.format("%s:%d", proxyHost, proxyPort);
     }

     return "DIRECT";
```


I'm not sure whether geckoview_exmaple apk will also trigger this bug. but you can install the [offical built one](https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.v2.mozilla-central.geckoview-version.120.0.20231014091439.mobile.android-aarch64-opt/artifacts/public%2Fbuild%2Fgeckoview_example.apk) first and see if the bug exists and then uninstall it (because mine is self signed) and then install the modified one.

If the offical one cannot trigger this bug ,then i will build a modified fenix packaging modified geckoview.

Besides, there's a concern about getHostString , it is introduced in API 19 , which is higher than the min sdk (API 16) requirement of Geckoview. We need a condition to protect this.
I made a [modified geckoview example apk](https://send.ephemeral.land/download/4ab17c82f5f6b46a/#yot_thJjp4EOzUFECkJPbw) (Note: the link will be expired in 1w or 20 downloads) with following changes:
```diff
diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
index e55e7ba8d3e67..0a16d7c00669f 100644
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
@@ -56,6 +56,7 @@ import android.webkit.MimeTypeMap;
 import androidx.annotation.Nullable;
 import androidx.collection.SimpleArrayMap;
 import androidx.core.content.res.ResourcesCompat;
+import java.net.InetSocketAddress;
 import java.net.Proxy;
 import java.nio.ByteBuffer;
 import java.util.List;
@@ -1300,11 +1301,15 @@ public class GeckoAppShell {
       return "DIRECT";
     }

+    final InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
+    final String proxyHost = proxyAddress.getHostString();
+    final int proxyPort = proxyAddress.getPort();
+
     switch (proxy.type()) {
       case HTTP:
-        return "PROXY " + proxy.address().toString();
+        return "PROXY " + String.format("%s:%d", proxyHost, proxyPort);
       case SOCKS:
-        return "SOCKS " + proxy.address().toString();
+        return "SOCKS " + String.format("%s:%d", proxyHost, proxyPort);
     }

     return "DIRECT";
```


I'm not sure whether geckoview_exmaple apk will also trigger this bug. but you can install the [offical built one](https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.v2.mozilla-central.geckoview-version.120.0.20231014091439.mobile.android-aarch64-opt/artifacts/public%2Fbuild%2Fgeckoview_example.apk) first and see if the bug exists and then uninstall it (because mine is self signed) and then install the modified one.

If the offical one cannot trigger this bug ,then i will build a modified fenix packaging modified geckoview.

---------------------
Besides, there's a concern about getHostString , it is introduced in API 19 , which is higher than the min sdk (API 16) requirement of Geckoview. We need a condition to protect this.

could be:
```diff
diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
index e55e7ba8d3e67..df8491b6f01c5 100644
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
@@ -56,6 +56,7 @@ import android.webkit.MimeTypeMap;
 import androidx.annotation.Nullable;
 import androidx.collection.SimpleArrayMap;
 import androidx.core.content.res.ResourcesCompat;
+import java.net.InetSocketAddress;
 import java.net.Proxy;
 import java.nio.ByteBuffer;
 import java.util.List;
@@ -1300,11 +1301,21 @@ public class GeckoAppShell {
       return "DIRECT";
     }

+    final String proxyString;
+    if ( Build.VERSION.SDK_INT >= 19) {
+      final InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
+      final String proxyHost = proxyAddress.getHostString();
+      final int proxyPort = proxyAddress.getPort();
+      proxyString = String.format("%s:%d", proxyHost, proxyPort);
+    } else {
+      proxyString = proxy.address().toString();
+    }
+
     switch (proxy.type()) {
       case HTTP:
-        return "PROXY " + proxy.address().toString();
+        return "PROXY " + proxyString;
       case SOCKS:
-        return "SOCKS " + proxy.address().toString();
+        return "SOCKS " + proxyString;
     }

     return "DIRECT";
```

Back to Bug 1858377 Comment 3