forked from organicmaps/organicmaps
[android] Removed AbstractLogBroadcastReceiver.
Signed-off-by: vng <viktor.govako@gmail.com>
This commit is contained in:
parent
ffd39d1378
commit
4d7d1d4307
3 changed files with 8 additions and 77 deletions
|
@ -1,55 +0,0 @@
|
|||
package com.mapswithme.maps.background;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mapswithme.util.CrashlyticsUtils;
|
||||
import com.mapswithme.util.log.Logger;
|
||||
import com.mapswithme.util.log.LoggerFactory;
|
||||
|
||||
import static com.mapswithme.maps.MwmApplication.backgroundTracker;
|
||||
|
||||
public abstract class AbstractLogBroadcastReceiver extends BroadcastReceiver
|
||||
{
|
||||
private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
|
||||
|
||||
@Override
|
||||
public final void onReceive(Context context, Intent intent)
|
||||
{
|
||||
if (intent == null)
|
||||
{
|
||||
LOGGER.w(getTag(), "A null intent detected");
|
||||
return;
|
||||
}
|
||||
|
||||
String action = intent.getAction();
|
||||
if (!TextUtils.equals(getAssertAction(), action))
|
||||
{
|
||||
LOGGER.w(getTag(), "An intent with wrong action detected: " + action);
|
||||
return;
|
||||
}
|
||||
|
||||
String msg = "onReceive: " + intent + " app in background = "
|
||||
+ !backgroundTracker(context).isForeground();
|
||||
LOGGER.i(getTag(), msg);
|
||||
CrashlyticsUtils.INSTANCE.log(Log.INFO, getTag(), msg);
|
||||
onReceiveInternal(context, intent);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
protected String getTag()
|
||||
{
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
protected abstract String getAssertAction();
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public abstract void onReceiveInternal(@NonNull Context context, @NonNull Intent intent);
|
||||
}
|
|
@ -6,23 +6,18 @@ import android.content.Intent;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.JobIntentService;
|
||||
|
||||
import com.mapswithme.maps.MwmBroadcastReceiver;
|
||||
import com.mapswithme.maps.scheduling.JobIdMap;
|
||||
|
||||
public class SystemDownloadCompletedReceiver extends AbstractLogBroadcastReceiver
|
||||
public class SystemDownloadCompletedReceiver extends MwmBroadcastReceiver
|
||||
{
|
||||
@NonNull
|
||||
@Override
|
||||
protected String getAssertAction()
|
||||
{
|
||||
return DownloadManager.ACTION_DOWNLOAD_COMPLETE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceiveInternal(@NonNull Context context, @NonNull Intent intent)
|
||||
public void onReceiveInitialized(@NonNull Context context, @NonNull Intent intent)
|
||||
{
|
||||
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
if (manager == null)
|
||||
return;
|
||||
throw new IllegalStateException("Failed to get a download manager");
|
||||
|
||||
intent.setClass(context, SystemDownloadCompletedService.class);
|
||||
int jobId = JobIdMap.getId(SystemDownloadCompletedService.class);
|
||||
JobIntentService.enqueueWork(context, SystemDownloadCompletedService.class, jobId, intent);
|
||||
|
|
|
@ -8,10 +8,11 @@ import android.database.Cursor;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.JobIntentService;
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.MwmJobIntentService;
|
||||
import com.mapswithme.maps.downloader.MapDownloadCompletedProcessor;
|
||||
import com.mapswithme.util.Utils;
|
||||
|
||||
public class SystemDownloadCompletedService extends JobIntentService
|
||||
public class SystemDownloadCompletedService extends MwmJobIntentService
|
||||
{
|
||||
private interface DownloadProcessor
|
||||
{
|
||||
|
@ -19,17 +20,7 @@ public class SystemDownloadCompletedService extends JobIntentService
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCreate()
|
||||
{
|
||||
super.onCreate();
|
||||
MwmApplication app = (MwmApplication) getApplication();
|
||||
if (app.arePlatformAndCoreInitialized())
|
||||
return;
|
||||
app.initCore();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHandleWork(@NonNull Intent intent)
|
||||
protected void onHandleWorkInitialized(@NonNull Intent intent)
|
||||
{
|
||||
DownloadManager manager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
|
||||
if (manager == null)
|
||||
|
|
Loading…
Add table
Reference in a new issue