add summary/description to installed apps based on installed info

First try to get the description from APK, which is seems that no one sets
so it is usually null. Then get info about how it was installed, like
which app store, when it was installed and upgraded.
This commit is contained in:
Hans-Christoph Steiner 2014-05-06 17:09:19 -04:00
parent e35a6e05c7
commit b11232b607
2 changed files with 23 additions and 17 deletions

View File

@ -187,8 +187,18 @@ public class App extends ValueObject implements Comparable<App> {
packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES
| PackageManager.GET_PERMISSIONS);
this.name = (String) appInfo.loadLabel(pm);
this.summary = (String) appInfo.loadDescription(pm);
String installerPackageName = pm.getInstallerPackageName(packageName);
ApplicationInfo installerAppInfo = pm.getApplicationInfo(installerPackageName,
PackageManager.GET_META_DATA);
CharSequence installerPackageLabel = installerAppInfo.loadLabel(pm);
if (TextUtils.isEmpty(installerPackageLabel))
installerPackageLabel = installerPackageName;
CharSequence appDescription = appInfo.loadDescription(pm);
if (TextUtils.isEmpty(appDescription))
this.summary = "(installed by " + installerPackageLabel + ")";
else
this.summary = (String) appDescription.subSequence(0, 40);
this.id = appInfo.packageName;
if (Build.VERSION.SDK_INT > 8) {
this.added = new Date(packageInfo.firstInstallTime);
@ -197,10 +207,17 @@ public class App extends ValueObject implements Comparable<App> {
this.added = new Date(System.currentTimeMillis());
this.lastUpdated = this.added;
}
this.description = "<p>";
if (!TextUtils.isEmpty(appDescription))
this.description += appDescription + "\n";
this.description += "(installed by " + installerPackageLabel
+ ", first installed on " + this.added
+ ", last updated on " + this.lastUpdated + ")</p>";
this.name = (String) appInfo.loadLabel(pm);
this.appInfo = appInfo;
this.apks = new ArrayList<Apk>();
// TODO: use pm.getInstallerPackageName(packageName) for something
File apkFile = new File(appInfo.publicSourceDir);
Apk apk = new Apk();
apk.version = packageInfo.versionName;

View File

@ -7,13 +7,11 @@ import android.content.SharedPreferences;
import android.content.pm.*;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.AssetManager;
import android.content.res.XmlResourceParser;
import android.graphics.*;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Bitmap.Config;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.Log;
@ -23,17 +21,12 @@ import org.fdroid.fdroid.data.Apk;
import org.fdroid.fdroid.data.App;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.*;
import java.security.cert.Certificate;
import java.security.cert.CertificateEncodingException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map.Entry;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@ -283,7 +276,7 @@ public class LocalRepoManager {
rootElement.appendChild(repo);
Element repoDesc = doc.createElement("description");
repoDesc.setTextContent("A repo generated from apps installed on " + repoName);
repoDesc.setTextContent("A local FDroid repo generated from apps installed on " + repoName);
repo.appendChild(repoDesc);
SimpleDateFormat dateToStr = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
@ -312,15 +305,11 @@ public class LocalRepoManager {
application.appendChild(name);
Element summary = doc.createElement("summary");
summary.setTextContent(app.name);
summary.setTextContent(app.summary);
application.appendChild(summary);
Element description = doc.createElement("description");
description.setTextContent(app.name);
application.appendChild(description);
Element desc = doc.createElement("desc");
desc.setTextContent(app.name);
desc.setTextContent(app.description);
application.appendChild(desc);
Element icon = doc.createElement("icon");