From 7c67db22f31a507506950e533bee08abf1398d9a Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Fri, 24 Jan 2014 11:08:15 -0500 Subject: [PATCH] reformat repo URIs to allow wifi, fingerprint, etc. in query string Instead of ramming the fingerprint in the user field of the URI, use the query string. Having the fingerprint in the user field was confusing some browsers because it was trying to log in. The query string is the standard place for such meta data, and has lots of room for expansion including things like wifi network names. This will be useful later to determine if both devices are currently on the same wifi network, and if they are local repos, they should try syncing. --- AndroidManifest.xml | 1 + src/org/fdroid/fdroid/ManageRepo.java | 24 ++++++++------ .../fdroid/views/RepoDetailsActivity.java | 32 +++++++++++++++++-- 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index f25b64016..44248cfcf 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -23,6 +23,7 @@ + diff --git a/src/org/fdroid/fdroid/ManageRepo.java b/src/org/fdroid/fdroid/ManageRepo.java index 8bc0735c3..47beedbf4 100644 --- a/src/org/fdroid/fdroid/ManageRepo.java +++ b/src/org/fdroid/fdroid/ManageRepo.java @@ -237,27 +237,31 @@ class RepoListFragment extends ListFragment Toast.makeText(getActivity(), msg, Toast.LENGTH_LONG).show(); return; } + if (scheme.equals("FDROIDREPO") || scheme.equals("FDROIDREPOS")) { + /* + * QRCodes are more efficient in all upper case, so QR URIs are + * encoded in all upper case, then forced to lower case. + * Checking if the special F-Droid scheme being all is upper + * case means it should be downcased. + */ + uri = Uri.parse(uri.toString().toLowerCase(Locale.ENGLISH)); + } + // make scheme and host lowercase so they're readable in dialogs scheme = scheme.toLowerCase(Locale.ENGLISH); host = host.toLowerCase(Locale.ENGLISH); - String fingerprint = uri.getUserInfo(); + String fingerprint = uri.getQueryParameter("fingerprint"); if (scheme.equals("fdroidrepos") || scheme.equals("fdroidrepo") || scheme.equals("https") || scheme.equals("http")) { isImportingRepo = true; - // QRCode are more efficient in all upper case, so some incoming - // URLs might be encoded in all upper case. Therefore, we allow - // the standard paths to be encoded all upper case, then they'll - // be forced to lower case. The scheme and host are downcased - // just to make them more readable in the dialog. + /* sanitize and format for function and readability */ String uriString = uri.toString() - .replace(fingerprint + "@", "") // remove fingerprint + .replaceAll("\\?.*$", "") // remove the whole query .replaceAll("/*$", "") // remove all trailing slashes - .replaceAll("/FDROID/REPO$", "/fdroid/repo") - .replaceAll("/FDROID/ARCHIVE$", "/fdroid/archive") .replace(uri.getHost(), host) // downcase host name .replace(intent.getScheme(), scheme) // downcase scheme - .replace("fdroidrepo", "http"); // make proper URL + .replace("fdroidrepo", "http"); // proper repo address showAddRepo(uriString, fingerprint); } } diff --git a/src/org/fdroid/fdroid/views/RepoDetailsActivity.java b/src/org/fdroid/fdroid/views/RepoDetailsActivity.java index 988138591..2ec73b7b7 100644 --- a/src/org/fdroid/fdroid/views/RepoDetailsActivity.java +++ b/src/org/fdroid/fdroid/views/RepoDetailsActivity.java @@ -1,7 +1,12 @@ + package org.fdroid.fdroid.views; +import android.net.Uri; +import android.net.wifi.WifiInfo; +import android.net.wifi.WifiManager; import android.os.Bundle; import android.support.v4.app.FragmentActivity; +import android.text.TextUtils; import org.fdroid.fdroid.compat.ActionBarCompat; import org.fdroid.fdroid.data.Repo; @@ -10,6 +15,9 @@ import org.fdroid.fdroid.views.fragments.RepoDetailsFragment; public class RepoDetailsActivity extends FragmentActivity { + private WifiManager wifiManager; + private Repo repo; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -25,11 +33,31 @@ public class RepoDetailsActivity extends FragmentActivity { .commit(); } - String[] projection = new String[] { RepoProvider.DataColumns.NAME }; - Repo repo = RepoProvider.Helper.findById(getContentResolver(), repoId, projection); + String[] projection = new String[] { + RepoProvider.DataColumns.NAME, + RepoProvider.DataColumns.ADDRESS, + RepoProvider.DataColumns.FINGERPRINT + }; + repo = RepoProvider.Helper.findById(getContentResolver(), repoId, projection); ActionBarCompat.create(this).setDisplayHomeAsUpEnabled(true); setTitle(repo.getName()); + + wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); } + protected Uri getSharingUri() { + Uri uri = Uri.parse(repo.address.replaceFirst("http", "fdroidrepo")); + Uri.Builder b = uri.buildUpon(); + b.appendQueryParameter("fingerprint", repo.fingerprint); + WifiInfo wifiInfo = wifiManager.getConnectionInfo(); + String ssid = wifiInfo.getSSID().replaceAll("^\"(.*)\"$", "$1"); + String bssid = wifiInfo.getBSSID(); + if (!TextUtils.isEmpty(bssid)) { + b.appendQueryParameter("bssid", Uri.encode(bssid)); + if (!TextUtils.isEmpty(ssid)) + b.appendQueryParameter("ssid", Uri.encode(ssid)); + } + return b.build(); + } }