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.
This commit is contained in:
Hans-Christoph Steiner 2013-11-19 23:47:05 -05:00
parent f5ce7d8588
commit 14c525e7ff
4 changed files with 91 additions and 31 deletions

View File

@ -1,24 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:orientation="vertical" >
android:orientation="vertical">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="match_parent"
android:ems="20" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:text="@string/repo_add_url"/> android:ems="20"
android:text="@string/repo_add_url" />
<EditText
android:id="@+id/edit_uri" <EditText
android:inputType="textUri" android:id="@+id/edit_uri"
android:maxLines="1" android:layout_width="match_parent"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:ems="20" android:ems="20"
android:layout_height="wrap_content" android:inputType="textUri"
android:text="https://"/> android:maxLines="1"
</LinearLayout> android:text="https://" />
<!--
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="20"
android:text="@string/repo_add_fingerprint" />
<EditText
android:id="@+id/edit_fingerprint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="0123456789ABCDEFabcedf: "
android:ems="20"
android:inputType="textNoSuggestions"
android:maxLines="1"
android:typeface="monospace" />
<TextView
android:id="@+id/repo_alert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@android:drawable/ic_dialog_alert"
android:gravity="center"
android:textColor="@color/red"
android:textAppearance="@android:style/TextAppearance.Large"
android:visibility="gone" />
</LinearLayout><!--
* Copyright (C) 2009 Roberto Jacinto * Copyright (C) 2009 Roberto Jacinto
* roberto.jacinto@caixamagica.pt * roberto.jacinto@caixamagica.pt
* *

View File

@ -70,6 +70,8 @@
<string name="download_server">Getting application from</string> <string name="download_server">Getting application from</string>
<string name="repo_add_url">Repository address</string> <string name="repo_add_url">Repository address</string>
<string name="repo_add_fingerprint">fingerprint (optional)</string>
<string name="repo_exists">This repo already exists!</string>
<string name="repo_alrt">The list of used repositories has <string name="repo_alrt">The list of used repositories has
changed.\nDo you changed.\nDo you

View File

@ -10,6 +10,7 @@
<color name="black">#FF000000</color> <color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color> <color name="white">#FFFFFFFF</color>
<color name="red">#FFFF0000</color>
<style name="AboutDialogLight" parent="@android:style/Theme.Dialog"> <style name="AboutDialogLight" parent="@android:style/Theme.Dialog">
<item name="@android:windowBackground">@color/black</item> <item name="@android:windowBackground">@color/black</item>

View File

@ -48,6 +48,7 @@ import android.widget.ListView;
import android.widget.SimpleAdapter; import android.widget.SimpleAdapter;
import android.widget.TextView; import android.widget.TextView;
import org.fdroid.fdroid.DB.Repo;
import android.support.v4.app.NavUtils; import android.support.v4.app.NavUtils;
import android.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
@ -121,7 +122,7 @@ public class ManageRepo extends ListActivity {
|| scheme.equals("https") || scheme.equals("http")) { || scheme.equals("https") || scheme.equals("http")) {
String uriString = uri.toString().replace("fdroidrepo", "http"). String uriString = uri.toString().replace("fdroidrepo", "http").
replace(fingerprint + "@", ""); replace(fingerprint + "@", "");
showAddRepo(uriString); showAddRepo(uriString, fingerprint);
Log.i("ManageRepo", uriString + " fingerprint: " + fingerprint); Log.i("ManageRepo", uriString + " fingerprint: " + fingerprint);
} }
} }
@ -220,6 +221,25 @@ public class ManageRepo extends ListActivity {
} }
} }
protected List<Repo> getRepos() {
List<Repo> repos = null;
try {
DB db = DB.getDB();
repos = db.getRepos();
} finally {
DB.releaseDB();
}
return repos;
}
protected Repo getRepo(String repoUri, List<Repo> repos) {
if (repoUri != null)
for (Repo repo : repos)
if (repoUri.equals(repo.address))
return repo;
return null;
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
@ -230,16 +250,13 @@ public class ManageRepo extends ListActivity {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
private void showAddRepo(String uriString) { private void showAddRepo(String uriString, String fingerprint) {
LayoutInflater li = LayoutInflater.from(this); LayoutInflater li = LayoutInflater.from(this);
View view = li.inflate(R.layout.addrepo, null); View view = li.inflate(R.layout.addrepo, null);
Builder p = new AlertDialog.Builder(this).setView(view); Builder p = new AlertDialog.Builder(this).setView(view);
final AlertDialog alrt = p.create(); final AlertDialog alrt = p.create();
final EditText uriEditText = (EditText) view.findViewById(R.id.edit_uri);
if (uriString != null) { final EditText fingerprintEditText = (EditText) view.findViewById(R.id.edit_fingerprint);
EditText uriEditText = (EditText) view.findViewById(R.id.edit_uri);
uriEditText.setText(uriString);
}
alrt.setIcon(android.R.drawable.ic_menu_add); alrt.setIcon(android.R.drawable.ic_menu_add);
alrt.setTitle(getString(R.string.repo_add_title)); alrt.setTitle(getString(R.string.repo_add_title));
@ -248,9 +265,7 @@ public class ManageRepo extends ListActivity {
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
EditText uri = (EditText) alrt addRepo(uriEditText.getText().toString());
.findViewById(R.id.edit_uri);
addRepo(uri.getText().toString());
changed = true; changed = true;
redraw(); redraw();
} }
@ -265,6 +280,21 @@ public class ManageRepo extends ListActivity {
} }
}); });
alrt.show(); alrt.show();
List<Repo> repos = getRepos();
Repo repo = getRepo(uriString, repos);
if (repo != null) {
final TextView tv = (TextView) view.findViewById(R.id.repo_alert);
tv.setVisibility(0);
tv.setText(R.string.repo_exists);
// TODO if address and fingerprint match, then enable existing repo
// TODO if address matches but fingerprint doesn't, handle this with extra widgets
}
if (uriString != null)
uriEditText.setText(uriString);
if (fingerprint != null)
fingerprintEditText.setText(fingerprint);
} }
@Override @Override
@ -274,7 +304,7 @@ public class ManageRepo extends ListActivity {
switch (item.getItemId()) { switch (item.getItemId()) {
case ADD_REPO: case ADD_REPO:
showAddRepo(null); showAddRepo(null, null);
return true; return true;
case REM_REPO: case REM_REPO: