From bda9745d8baece9fa4892f37676abd7c6e9985f6 Mon Sep 17 00:00:00 2001 From: Thialfihar Date: Fri, 18 Jun 2010 15:14:41 +0000 Subject: [PATCH] much better version reading by directly looking for the APG package, rather than looping through all installed packages --- src/org/thialfihar/android/apg/Apg.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/org/thialfihar/android/apg/Apg.java b/src/org/thialfihar/android/apg/Apg.java index 8ccc3a2c0..6fd8794ff 100644 --- a/src/org/thialfihar/android/apg/Apg.java +++ b/src/org/thialfihar/android/apg/Apg.java @@ -37,7 +37,6 @@ import java.util.Date; import java.util.GregorianCalendar; import java.util.HashMap; import java.util.Iterator; -import java.util.List; import java.util.Map; import java.util.Vector; import java.util.regex.Pattern; @@ -90,6 +89,7 @@ import org.thialfihar.android.apg.utils.IterableIterator; import android.app.Activity; import android.content.Context; import android.content.pm.PackageInfo; +import android.content.pm.PackageManager.NameNotFoundException; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.net.Uri; @@ -1836,19 +1836,14 @@ public class Apg { if (VERSION != null) { return VERSION; } - List packs = context.getPackageManager().getInstalledPackages(0); - for (int i = 0; i < packs.size(); ++i) { - PackageInfo p = packs.get(i); - if (!p.packageName.equals(mApgPackageName)) { - continue; - } - - VERSION = p.versionName; + try { + PackageInfo pi = context.getPackageManager().getPackageInfo(mApgPackageName, 0); + VERSION = pi.versionName; return VERSION; + } catch (NameNotFoundException e) { + // unpossible! + return "0.0.0"; } - - // unpossible! - return "0.0.0"; } public static String getFullVersion(Context context) {