Expert mode - currently just displays md5 of signature for installed apps

This commit is contained in:
Ciaran Gultnieks 2011-01-04 23:52:04 +00:00
parent a5d4399e28
commit df6a37a705
4 changed files with 55 additions and 8 deletions

View File

@ -28,6 +28,10 @@
android:textSize="12sp" android:layout_height="wrap_content"
android:layout_width="fill_parent" />
<TextView android:id="@+id/signature" android:layout_below="@id/status"
android:layout_alignParentLeft="true" android:textSize="12sp"
android:layout_height="wrap_content" android:layout_width="fill_parent" />
</RelativeLayout>
</LinearLayout>

View File

@ -115,4 +115,7 @@
<string name="antinonfreenet">Network Services</string>
<string name="antinonfreenetlong">Show apps that promote non-free network services</string>
<string name="expert">Expert</string>
<string name="expert_mode">Enabled expert mode</string>
</resources>

View File

@ -7,9 +7,9 @@
</PreferenceCategory>
<PreferenceCategory android:title="@string/updates">
<ListPreference android:title="@string/automatic_repo_scan"
android:summary="@string/update_apps_list"
android:key="updateInterval" android:defaultValue="0"
android:entries="@array/updateIntervalNames" android:entryValues="@array/updateIntervalValues" />
android:summary="@string/update_apps_list" android:key="updateInterval"
android:defaultValue="0" android:entries="@array/updateIntervalNames"
android:entryValues="@array/updateIntervalValues" />
<CheckBoxPreference android:title="@string/notify"
android:defaultValue="false" android:summary="@string/notify_updates_available"
android:key="updateNotify" />
@ -29,9 +29,10 @@
android:key="cacheDownloaded" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/maintenance">
<Preference
android:title="@string/reset"
android:summary="@string/clear_all_cached_data"
android:key="reset" />
</PreferenceCategory>
<Preference android:title="@string/reset" android:summary="@string/clear_all_cached_data"
android:key="reset" />
<CheckBoxPreference android:title="@string/expert"
android:defaultValue="false" android:summary="@string/expert_mode"
android:key="expert" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -22,7 +22,10 @@ import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.math.BigInteger;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
@ -43,6 +46,7 @@ import android.widget.TextView;
import android.widget.Toast;
import android.content.pm.PackageManager;
import android.content.pm.PackageInfo;
import android.content.pm.Signature;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
@ -162,8 +166,12 @@ public class AppDetails extends ListActivity {
}
private boolean pref_cacheDownloaded;
private boolean pref_expert;
private boolean viewResetRequired;
// The signature of the installed version.
private Signature mInstalledSignature;
@Override
protected void onStart() {
super.onStart();
@ -174,6 +182,7 @@ public class AppDetails extends ListActivity {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
pref_cacheDownloaded = prefs.getBoolean("cacheDownloaded", true);
pref_expert = prefs.getBoolean("expert", false);
viewResetRequired = true;
}
@ -204,6 +213,19 @@ public class AppDetails extends ListActivity {
DB.Apk curver = app.getCurrentVersion();
app_currentvercode = curver == null ? 0 : curver.vercode;
// Get the signature of the installed package...
mInstalledSignature = null;
if (curver != null) {
PackageManager pm = getBaseContext().getPackageManager();
try {
PackageInfo pi = pm.getPackageInfo(appid,
PackageManager.GET_SIGNATURES);
mInstalledSignature = pi.signatures[0];
} catch (NameNotFoundException e) {
Log.d("FDroid", "Failed to get installed signature");
}
}
// Set the icon...
ImageView iv = (ImageView) findViewById(R.id.icon);
String icon_path = DB.getIconsPath() + app.icon;
@ -229,6 +251,23 @@ public class AppDetails extends ListActivity {
app.installedVersion));
tv = (TextView) findViewById(R.id.description);
tv.setText(app.description);
if (pref_expert && mInstalledSignature != null) {
try {
tv = (TextView) findViewById(R.id.signature);
byte[] sig = mInstalledSignature.toByteArray();
MessageDigest md;
md = MessageDigest.getInstance("MD5");
byte[] md5sum = new byte[32];
md.update(sig, 0, sig.length);
md5sum = md.digest();
BigInteger bigInt = new BigInteger(1, md5sum);
String md5hash = bigInt.toString(16);
while (md5hash.length() < 32)
md5hash = "0" + md5hash;
tv.setText("Signed: " + md5hash);
} catch (NoSuchAlgorithmException e) {
}
}
// Set up the list...
ApkListAdapter la = new ApkListAdapter(this);