fix crash if an APK has a short embedded description

caught java.lang.StringIndexOutOfBoundsException:
  at java.lang.String.substring(String.java:1651)
  at java.lang.String.subSequence(String.java:2040)
  at org.fdroid.fdroid.data.App.setFromPackageInfo(App.java:298)
  at org.fdroid.fdroid.data.App.<init>(App.java:268)
  at org.fdroid.fdroid.localrepo.CacheSwapAppsService.onHandleIntent(CacheSwapAppsService.java:78)
  at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:130)
  at android.os.HandlerThread.run(HandlerThread.java:60)
This commit is contained in:
Hans-Christoph Steiner 2016-06-01 22:44:03 +02:00
parent 748352e5a1
commit cf4fedbe13

View File

@ -294,8 +294,10 @@ public class App extends ValueObject implements Comparable<App> {
final CharSequence appDescription = appInfo.loadDescription(pm); final CharSequence appDescription = appInfo.loadDescription(pm);
if (TextUtils.isEmpty(appDescription)) { if (TextUtils.isEmpty(appDescription)) {
this.summary = "(installed by " + installerPackageLabel + ")"; this.summary = "(installed by " + installerPackageLabel + ")";
} else { } else if (appDescription.length() > 40) {
this.summary = (String) appDescription.subSequence(0, 40); this.summary = (String) appDescription.subSequence(0, 40);
} else {
this.summary = (String) appDescription;
} }
this.added = new Date(packageInfo.firstInstallTime); this.added = new Date(packageInfo.firstInstallTime);
this.lastUpdated = new Date(packageInfo.lastUpdateTime); this.lastUpdated = new Date(packageInfo.lastUpdateTime);