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:
parent
1192468015
commit
a9c73dd278
@ -181,15 +181,14 @@ public class DownloaderService extends Service {
|
|||||||
* message.
|
* message.
|
||||||
*/
|
*/
|
||||||
private String getNotificationTitle(@Nullable String packageName) {
|
private String getNotificationTitle(@Nullable String packageName) {
|
||||||
String title;
|
|
||||||
if (packageName != null) {
|
if (packageName != null) {
|
||||||
App app = AppProvider.Helper.findByPackageName(
|
final App app = AppProvider.Helper.findByPackageName(
|
||||||
getContentResolver(), packageName, new String[]{AppProvider.DataColumns.NAME});
|
getContentResolver(), packageName, new String[]{AppProvider.DataColumns.NAME});
|
||||||
title = getString(R.string.downloading_apk, app.name);
|
if (app != null) {
|
||||||
} else {
|
return getString(R.string.downloading_apk, app.name);
|
||||||
title = getString(R.string.downloading);
|
}
|
||||||
}
|
}
|
||||||
return title;
|
return getString(R.string.downloading);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PendingIntent createAppDetailsIntent(@NonNull Context context, int requestCode, @Nullable String packageName) {
|
public static PendingIntent createAppDetailsIntent(@NonNull Context context, int requestCode, @Nullable String packageName) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user