From 6928bd1244c176d8c74481957e5f4e0cedbb6f0b Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 19 Nov 2013 10:56:38 -0500 Subject: [PATCH 1/5] accept froidrepo and fdroidrepos URIs, which can be scanned via QRCode, etc This patch makes F-Droid register with Android that it accepts the URI schemes of fdroidrepo (HTTP) and fdroidrepos(HTTPS). When F-Droid receives one of these URIs, it launches the ManageRepo Activity and then launches the New Repository dialog. refs #2454 --- AndroidManifest.xml | 12 ++++ src/org/fdroid/fdroid/ManageRepo.java | 84 ++++++++++++++++++--------- 2 files changed, 69 insertions(+), 27 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 149db63c3..deebd53ef 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -71,6 +71,18 @@ + + + + + + + + + + + + (); reposToDisable = new ArrayList(); + + /* let's see if someone is trying to send us a new repo */ + Intent intent = getIntent(); + /* an URL from a click or a QRCode scan */ + Uri uri = intent.getData(); + if (uri != null) { + // scheme should only ever be pure ASCII: + String scheme = intent.getScheme().toLowerCase(Locale.ENGLISH); + String fingerprint = uri.getUserInfo(); + if (scheme.equals("fdroidrepos") || scheme.equals("fdroidrepo") + || scheme.equals("https") || scheme.equals("http")) { + String uriString = uri.toString().replace("fdroidrepo", "http"). + replace(fingerprint + "@", ""); + showAddRepo(uriString); + Log.i("ManageRepo", uriString + " fingerprint: " + fingerprint); + } + } } @Override @@ -211,40 +230,51 @@ public class ManageRepo extends ListActivity { return super.onOptionsItemSelected(item); } + private void showAddRepo(String uriString) { + LayoutInflater li = LayoutInflater.from(this); + View view = li.inflate(R.layout.addrepo, null); + Builder p = new AlertDialog.Builder(this).setView(view); + final AlertDialog alrt = p.create(); + + if (uriString != null) { + EditText uriEditText = (EditText) view.findViewById(R.id.edit_uri); + uriEditText.setText(uriString); + } + + alrt.setIcon(android.R.drawable.ic_menu_add); + alrt.setTitle(getString(R.string.repo_add_title)); + alrt.setButton(DialogInterface.BUTTON_POSITIVE, + getString(R.string.repo_add_add), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + EditText uri = (EditText) alrt + .findViewById(R.id.edit_uri); + addRepo(uri.getText().toString()); + changed = true; + redraw(); + } + }); + + alrt.setButton(DialogInterface.BUTTON_NEGATIVE, + getString(R.string.cancel), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + return; + } + }); + alrt.show(); + } + @Override public boolean onMenuItemSelected(int featureId, MenuItem item) { super.onMenuItemSelected(featureId, item); - LayoutInflater li = LayoutInflater.from(this); switch (item.getItemId()) { case ADD_REPO: - View view = li.inflate(R.layout.addrepo, null); - Builder p = new AlertDialog.Builder(this).setView(view); - final AlertDialog alrt = p.create(); - - alrt.setIcon(android.R.drawable.ic_menu_add); - alrt.setTitle(getString(R.string.repo_add_title)); - alrt.setButton(DialogInterface.BUTTON_POSITIVE, - getString(R.string.repo_add_add), - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - EditText uri = (EditText) alrt - .findViewById(R.id.edit_uri); - addRepo(uri.getText().toString()); - changed = true; - redraw(); - } - }); - - alrt.setButton(DialogInterface.BUTTON_NEGATIVE, - getString(R.string.cancel), - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - return; - } - }); - alrt.show(); + showAddRepo(null); return true; case REM_REPO: From 3301a57a01a398057269c1857ecc851d2de7ebab Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 19 Nov 2013 14:29:07 -0500 Subject: [PATCH 2/5] handle incoming URIs based on patterns: "^https?://.*/(repo|archive)/*$" This allows for clickable/scannable URIs for adding repos to F-Droid. --- AndroidManifest.xml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index deebd53ef..601736044 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -71,6 +71,22 @@ + + + + + + + + + + + + + + + + From f5ce7d8588add3c5901bdc423d73d8dbb4615db9 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 19 Nov 2013 20:02:11 -0500 Subject: [PATCH 3/5] simplify browse URL IntentFilter data for readability Each piece of applies to the whole IntentFilter, so each scheme, host, or pathPattern only needs to be stated once per IntentFilter. --- AndroidManifest.xml | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 601736044..ac8ee383a 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -49,14 +49,11 @@ - - - - + + + + + - - - - + + + + + Date: Tue, 19 Nov 2013 23:47:05 -0500 Subject: [PATCH 4/5] add fingerprint field to Add Repo dialog, and alert if repo already exists Previously, anything added via the Add New Repository dialog would just overwrite any existing repo config that was there. This has become a bigger issue with the QR Code scanning since it could become an attack vector. This is the first step towards making this Add Repo dialog give more info to the user about the state of things, and what the user might replace by clicking OK. --- res/layout/addrepo.xml | 67 +++++++++++++++++++-------- res/values/strings.xml | 2 + res/values/styles.xml | 1 + src/org/fdroid/fdroid/ManageRepo.java | 52 ++++++++++++++++----- 4 files changed, 91 insertions(+), 31 deletions(-) diff --git a/res/layout/addrepo.xml b/res/layout/addrepo.xml index 72ab28cc4..ac4936303 100644 --- a/res/layout/addrepo.xml +++ b/res/layout/addrepo.xml @@ -1,24 +1,51 @@ - - - - - -