From 407e7662e959f736c992f921b7fd98fadbf10d6b Mon Sep 17 00:00:00 2001
From: Hans-Christoph Steiner <hans@eds.org>
Date: Mon, 7 Apr 2014 21:07:01 -0400
Subject: [PATCH] support QR scanners that do not respect custom URI schemes

Some QR Code scanners don't respect custom schemes like fdroidrepo://, so
this is a workaround, since the local repo URI is all uppercase in the QR
Code for sending the local repo to another device.  This way, the QR Code
can still be all uppercase and use HTTP:// and Android will still route it
to FDroid, but via the Just Once/Always chooser (fdroidrepo:// goes
directly to FDroid with no prompt, when it works)
---
 AndroidManifest.xml                                       | 6 ++++++
 .../fdroid/fdroid/views/fragments/RepoListFragment.java   | 8 ++++++++
 2 files changed, 14 insertions(+)

diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 4d3db9f80..cafacbd19 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -129,6 +129,12 @@
                 <data android:pathPattern="/.*/.*/fdroid/archive/*" />
                 <data android:pathPattern="/.*/.*/.*/fdroid/archive" />
                 <data android:pathPattern="/.*/.*/.*/fdroid/archive/*" />
+                <!--
+                Some QR Code scanners don't respect custom schemes like fdroidrepo://,
+                so this is a workaround, since the local repo URL is all uppercase in
+                the QR Code for sending the local repo to another device.
+                -->
+                <data android:path="/FDROID/REPO" />
             </intent-filter>
             <intent-filter>
                 <action android:name="android.intent.action.VIEW" />
diff --git a/src/org/fdroid/fdroid/views/fragments/RepoListFragment.java b/src/org/fdroid/fdroid/views/fragments/RepoListFragment.java
index c30f23397..fa43cb82b 100644
--- a/src/org/fdroid/fdroid/views/fragments/RepoListFragment.java
+++ b/src/org/fdroid/fdroid/views/fragments/RepoListFragment.java
@@ -208,6 +208,14 @@ public class RepoListFragment extends ListFragment
                  * case means it should be downcased.
                  */
                 uri = Uri.parse(uri.toString().toLowerCase(Locale.ENGLISH));
+            } else if (uri.getPath().startsWith("/FDROID/REPO")) {
+                /*
+                 * some QR scanners chop off the fdroidrepo:// and just try
+                 * http://, then the incoming URI does not get downcased
+                 * properly, and the query string is stripped off. So just
+                 * downcase the path, and carry on to get something working.
+                 */
+                uri = Uri.parse(uri.toString().toLowerCase(Locale.ENGLISH));
             }
             // make scheme and host lowercase so they're readable in dialogs
             scheme = scheme.toLowerCase(Locale.ENGLISH);