Avoid NPE in getNotificationTitle

See the following crash reported via ACRA:

	java.lang.NullPointerException
	    at org.fdroid.fdroid.net.DownloaderService.getNotificationTitle(DownloaderService.java:188)
	    at org.fdroid.fdroid.net.DownloaderService.createNotification(DownloaderService.java:167)
	    at org.fdroid.fdroid.net.DownloaderService.handleIntent(DownloaderService.java:274)
	    at org.fdroid.fdroid.net.DownloaderService$ServiceHandler.handleMessage(DownloaderService.java:107)
	    at android.os.Handler.dispatchMessage(Handler.java:102)
	    at android.os.Looper.loop(Looper.java:136)
	    at android.os.HandlerThread.run(HandlerThread.java:61)

I'm not sure what the source of the null App was (could be that we
couldn't access the DB for some reason, or perhaps that somehow the app
wasn't in it anymore). In any case, it doesn't hurt to double check
here.

If the app is null, simply fall back to the title without the app name.
This commit is contained in:
Daniel Martí 2016-05-05 12:05:42 +01:00
parent 1192468015
commit a9c73dd278

View File

@ -181,15 +181,14 @@ public class DownloaderService extends Service {
* message.
*/
private String getNotificationTitle(@Nullable String packageName) {
String title;
if (packageName != null) {
App app = AppProvider.Helper.findByPackageName(
final App app = AppProvider.Helper.findByPackageName(
getContentResolver(), packageName, new String[]{AppProvider.DataColumns.NAME});
title = getString(R.string.downloading_apk, app.name);
} else {
title = getString(R.string.downloading);
if (app != null) {
return getString(R.string.downloading_apk, app.name);
}
return title;
}
return getString(R.string.downloading);
}
public static PendingIntent createAppDetailsIntent(@NonNull Context context, int requestCode, @Nullable String packageName) {