fix crash when InstallManager is killed while actively downloading

This is very related to #660 but this time, I can't see any other way to
solve it but a null guard.  I don't think it is possible to guarantee that
the Downloader.ACTION_INTERRUPTED receiver will be unregistered since
onDestroy() might not even be called.

java.lang.NullPointerException
	at org.fdroid.fdroid.installer.InstallManagerService.removeFromActive(InstallManagerService.java:328)
	at org.fdroid.fdroid.installer.InstallManagerService.access$400(InstallManagerService.java:58)
	at org.fdroid.fdroid.installer.InstallManagerService$4.onReceive(InstallManagerService.java:212)
	at android.support.v4.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:297)
	at android.support.v4.content.LocalBroadcastManager.access$000(LocalBroadcastManager.java:46)
	at android.support.v4.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:116)
	at android.os.Handler.dispatchMessage(Handler.java:110)
	at android.os.Looper.loop(Looper.java:193)
	at android.app.ActivityThread.main(ActivityThread.java:5353)
	at java.lang.reflect.Method.invokeNative(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:515)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:830)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:646)
	at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
	at dalvik.system.NativeStart.main(Native Method)
This commit is contained in:
Hans-Christoph Steiner 2016-05-24 20:52:45 +02:00
parent fb3dcb293d
commit 2897dcb67e

View File

@ -357,9 +357,18 @@ public class InstallManagerService extends Service {
TEMP_HACK_APP_NAMES.put(urlString, app.name); // TODO delete me once InstallerService exists
}
/**
* Remove the {@link App} and {@Apk} instances that are associated with
* {@code urlString} from the {@link Map} of active apps. This can be
* called after this service has been destroyed and recreated based on the
* {@link BroadcastReceiver}s, in which case {@code urlString} would not
* find anything in the active maps.
*/
private static Apk removeFromActive(String urlString) {
Apk apk = ACTIVE_APKS.remove(urlString);
ACTIVE_APPS.remove(apk.packageName);
if (apk != null) {
ACTIVE_APPS.remove(apk.packageName);
}
return apk;
}