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.
This commit is contained in:
parent
126d96e4ba
commit
7c67db22f3
@ -23,6 +23,7 @@
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user