From 4d7d1d4307ede96cad408b1d3db360a1dfaa5654 Mon Sep 17 00:00:00 2001 From: vng Date: Mon, 26 Apr 2021 10:36:46 +0300 Subject: [PATCH] [android] Removed AbstractLogBroadcastReceiver. Signed-off-by: vng --- .../AbstractLogBroadcastReceiver.java | 55 ------------------- .../SystemDownloadCompletedReceiver.java | 15 ++--- .../SystemDownloadCompletedService.java | 15 +---- 3 files changed, 8 insertions(+), 77 deletions(-) delete mode 100644 android/src/com/mapswithme/maps/background/AbstractLogBroadcastReceiver.java diff --git a/android/src/com/mapswithme/maps/background/AbstractLogBroadcastReceiver.java b/android/src/com/mapswithme/maps/background/AbstractLogBroadcastReceiver.java deleted file mode 100644 index 06ac0b7c2a..0000000000 --- a/android/src/com/mapswithme/maps/background/AbstractLogBroadcastReceiver.java +++ /dev/null @@ -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); -} diff --git a/android/src/com/mapswithme/maps/background/SystemDownloadCompletedReceiver.java b/android/src/com/mapswithme/maps/background/SystemDownloadCompletedReceiver.java index 3d55e6b06e..3a61192047 100644 --- a/android/src/com/mapswithme/maps/background/SystemDownloadCompletedReceiver.java +++ b/android/src/com/mapswithme/maps/background/SystemDownloadCompletedReceiver.java @@ -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); diff --git a/android/src/com/mapswithme/maps/background/SystemDownloadCompletedService.java b/android/src/com/mapswithme/maps/background/SystemDownloadCompletedService.java index 5330c1c808..dbe305c2b6 100644 --- a/android/src/com/mapswithme/maps/background/SystemDownloadCompletedService.java +++ b/android/src/com/mapswithme/maps/background/SystemDownloadCompletedService.java @@ -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)