fix(android): Add abaility to reinitialize CloudDownloadMgr

Fixes crashlytics [crash](https://console.firebase.google.com/u/0/project/kmapro-ee779/crashlytics/app/android:com.tavultesoft.kmapro/issues/ae59e122f0fac1eb6e082ddb21bb6fae?time=last-seven-days&sessionId=5E41A650017400013B04CE17115A1E88_DNE_0_v2)

There's an intermittent condition between the system notification bar showing a resource update available, the user closing the Keyman app, and the user later choosing  to update the resource.

By then, the CloudDownloadMgr may not be available to handle the download.

This makes the following change:
* When the Keyman app is closed, shutdown the CloudDownloadMgr (without destroying the InApp and System Keyboard).
* When preparing to download a resource update, re-initialize the CloudDownloadMgr as needed.
This commit is contained in:
Darcy Wong 2020-02-11 15:24:57 +07:00
parent c3cff2f24d
commit 71c32db6d3

View file

@ -7,6 +7,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;
import java.io.File;
import java.util.HashMap;
@ -56,7 +57,13 @@ public class CloudDownloadMgr{
{
if(isInitialized)
return;
aContext.registerReceiver(completeListener,new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
try {
aContext.registerReceiver(completeListener, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
} catch (Exception e) {
String message = "CloudDownloadMgr re-initializing";
Toast.makeText(aContext, message,
Toast.LENGTH_SHORT).show();
}
isInitialized = true;
}
@ -68,7 +75,13 @@ public class CloudDownloadMgr{
{
if(!isInitialized)
return;
aContext.unregisterReceiver(completeListener);
try {
aContext.unregisterReceiver(completeListener);
} catch (Exception e) {
String message = "CloudDownloadMgr shutting down.";
Toast.makeText(aContext, message,
Toast.LENGTH_SHORT).show();
}
isInitialized = false;
}
@ -184,8 +197,10 @@ public class CloudDownloadMgr{
ICloudDownloadCallback<ModelType,ResultType> aCallback,
CloudApiTypes.CloudApiParam... params)
{
if(!isInitialized)
throw new IllegalStateException("Downloadmanager is not initialize. Call KMManger.initialize before");
if(!isInitialized) {
Log.w(TAG, "Downloadmanager not initialized. Initializing CloudDownloadMgr.");
initialize(aContext);
}
synchronized (downloadSetByDownloadIdentifier) {