forked from organicmaps/organicmaps
[adnroid] remove MwmApplication.get method part 2
This commit is contained in:
parent
aa7ef4a189
commit
c5e12a5220
20 changed files with 58 additions and 37 deletions
|
@ -36,6 +36,7 @@ import com.mapswithme.maps.ugc.UGC;
|
|||
import com.mapswithme.util.Config;
|
||||
import com.mapswithme.util.ConnectionState;
|
||||
import com.mapswithme.util.Counters;
|
||||
import com.mapswithme.util.CrashlyticsUtils;
|
||||
import com.mapswithme.util.KeyValue;
|
||||
import com.mapswithme.util.SharedPropertiesUtils;
|
||||
import com.mapswithme.util.StorageUtils;
|
||||
|
@ -166,6 +167,7 @@ public class MwmApplication extends Application implements AppBackgroundTracker.
|
|||
mMediator.initSensitiveDataStrictLibrariesAsync();
|
||||
Statistics.INSTANCE.initialize(this);
|
||||
ConnectionState.INSTANCE.initialize(this);
|
||||
CrashlyticsUtils.INSTANCE.initialize(this);
|
||||
Statistics.INSTANCE.setMediator(mMediator);
|
||||
|
||||
initNotificationChannels();
|
||||
|
|
|
@ -318,7 +318,7 @@ public class ExternalLibrariesMediator
|
|||
| GooglePlayServicesRepairableException | TimeoutException e)
|
||||
{
|
||||
LOGGER.e(TAG, "Failed to obtain advertising id: ", e);
|
||||
CrashlyticsUtils.logException(e);
|
||||
CrashlyticsUtils.INSTANCE.logException(e);
|
||||
return new AdvertisingInfo(null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public abstract class AbstractLogBroadcastReceiver extends BroadcastReceiver
|
|||
String msg = "onReceive: " + intent + " app in background = "
|
||||
+ !backgroundTracker(context).isForeground();
|
||||
LOGGER.i(getTag(), msg);
|
||||
CrashlyticsUtils.log(Log.INFO, getTag(), msg);
|
||||
CrashlyticsUtils.INSTANCE.log(Log.INFO, getTag(), msg);
|
||||
onReceiveInternal(context, intent);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ public class UpgradeReceiver extends BroadcastReceiver
|
|||
String msg = "onReceive: " + intent + " app in background = "
|
||||
+ !backgroundTracker(context).isForeground();
|
||||
LOGGER.i(TAG, msg);
|
||||
CrashlyticsUtils.log(Log.INFO, TAG, msg);
|
||||
CrashlyticsUtils.INSTANCE.log(Log.INFO, TAG, msg);
|
||||
MwmApplication.onUpgrade(context);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ public class WorkerService extends JobIntentService
|
|||
String msg = "onHandleIntent: " + intent + " app in background = "
|
||||
+ !MwmApplication.backgroundTracker(getApplicationContext()).isForeground();
|
||||
LOGGER.i(TAG, msg);
|
||||
CrashlyticsUtils.log(Log.INFO, TAG, msg);
|
||||
CrashlyticsUtils.INSTANCE.log(Log.INFO, TAG, msg);
|
||||
final String action = intent.getAction();
|
||||
|
||||
if (TextUtils.isEmpty(action))
|
||||
|
|
|
@ -104,7 +104,7 @@ public class BaseActivityDelegate
|
|||
private void logLifecycleMethod(@NonNull String method)
|
||||
{
|
||||
String msg = mActivity.getClass().getSimpleName() + ": " + method + " activity: " + mActivity;
|
||||
CrashlyticsUtils.log(Log.INFO, TAG, msg);
|
||||
CrashlyticsUtils.INSTANCE.log(Log.INFO, TAG, msg);
|
||||
LOGGER.i(TAG, msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -409,7 +409,7 @@ public class BookmarksCatalogFragment extends BaseWebViewMwmFragment
|
|||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
CrashlyticsUtils.logException(e);
|
||||
CrashlyticsUtils.INSTANCE.logException(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -585,7 +585,7 @@ public class BookmarksCatalogFragment extends BaseWebViewMwmFragment
|
|||
{
|
||||
String msg = "Failed to encode details bundle '" + bundle + "': ";
|
||||
LOGGER.e(TAG, msg, e);
|
||||
CrashlyticsUtils.logException(new RuntimeException(msg, e));
|
||||
CrashlyticsUtils.INSTANCE.logException(new RuntimeException(msg, e));
|
||||
}
|
||||
|
||||
return encodedBundle;
|
||||
|
|
|
@ -109,7 +109,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<MergeAdapter>
|
|||
public void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
CrashlyticsUtils.log(Log.INFO, TAG, "onCreate");
|
||||
CrashlyticsUtils.INSTANCE.log(Log.INFO, TAG, "onCreate");
|
||||
BookmarkCategory category = getCategoryOrThrow();
|
||||
mCategoryDataSource = new CategoryDataSource(category);
|
||||
mCatalogListener = new CatalogListenerDecorator(this);
|
||||
|
@ -169,7 +169,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<MergeAdapter>
|
|||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
|
||||
{
|
||||
CrashlyticsUtils.log(Log.INFO, TAG, "onViewCreated");
|
||||
CrashlyticsUtils.INSTANCE.log(Log.INFO, TAG, "onViewCreated");
|
||||
|
||||
if (BookmarkManager.INSTANCE.isAsyncBookmarksLoadingInProgress())
|
||||
{
|
||||
|
@ -211,7 +211,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<MergeAdapter>
|
|||
public void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
CrashlyticsUtils.log(Log.INFO, TAG, "onStart");
|
||||
CrashlyticsUtils.INSTANCE.log(Log.INFO, TAG, "onStart");
|
||||
SearchEngine.INSTANCE.addBookmarkListener(this);
|
||||
BookmarkManager.INSTANCE.addLoadingListener(this);
|
||||
BookmarkManager.INSTANCE.addSortingListener(this);
|
||||
|
@ -223,7 +223,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<MergeAdapter>
|
|||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
CrashlyticsUtils.log(Log.INFO, TAG, "onResume");
|
||||
CrashlyticsUtils.INSTANCE.log(Log.INFO, TAG, "onResume");
|
||||
if (BookmarkManager.INSTANCE.isAsyncBookmarksLoadingInProgress())
|
||||
return;
|
||||
|
||||
|
@ -238,14 +238,14 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<MergeAdapter>
|
|||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
CrashlyticsUtils.log(Log.INFO, TAG,"onPause");
|
||||
CrashlyticsUtils.INSTANCE.log(Log.INFO, TAG,"onPause");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
super.onStop();
|
||||
CrashlyticsUtils.log(Log.INFO, TAG, "onStop");
|
||||
CrashlyticsUtils.INSTANCE.log(Log.INFO, TAG, "onStop");
|
||||
SearchEngine.INSTANCE.removeBookmarkListener(this);
|
||||
BookmarkManager.INSTANCE.removeLoadingListener(this);
|
||||
BookmarkManager.INSTANCE.removeSortingListener(this);
|
||||
|
|
|
@ -196,7 +196,7 @@ public class Factory
|
|||
String msg = this.getClass().getSimpleName() + ": incoming intent uri: " + uri;
|
||||
LOGGER.i(this.getClass().getSimpleName(), msg);
|
||||
org.alohalytics.Statistics.logEvent(msg);
|
||||
CrashlyticsUtils.log(Log.INFO, getClass().getSimpleName(), msg);
|
||||
CrashlyticsUtils.INSTANCE.log(Log.INFO, getClass().getSimpleName(), msg);
|
||||
return createMapTask(uri);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ public class TrackRecorderWakeReceiver extends BroadcastReceiver
|
|||
String msg = "onReceive: " + intent + " app in background = "
|
||||
+ !backgroundTracker(context).isForeground();
|
||||
LOGGER.i(TAG, msg);
|
||||
CrashlyticsUtils.log(Log.INFO, TAG, msg);
|
||||
CrashlyticsUtils.INSTANCE.log(Log.INFO, TAG, msg);
|
||||
TrackRecorder.INSTANCE.onWakeAlarm();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ public class TrackRecorderWakeService extends JobIntentService
|
|||
String msg = "onHandleIntent: " + intent + " app in background = "
|
||||
+ !MwmApplication.backgroundTracker(getApplicationContext()).isForeground();
|
||||
LOGGER.i(TAG, msg);
|
||||
CrashlyticsUtils.log(Log.INFO, TAG, msg);
|
||||
CrashlyticsUtils.INSTANCE.log(Log.INFO, TAG, msg);
|
||||
|
||||
synchronized (sLock)
|
||||
{
|
||||
|
@ -81,7 +81,7 @@ public class TrackRecorderWakeService extends JobIntentService
|
|||
{
|
||||
scheduler.cancel(each.getId());
|
||||
String logMsg = "Canceled job: " + each + ". All jobs: " + jobsRepresentation;
|
||||
CrashlyticsUtils.log(Log.INFO, TAG, logMsg);
|
||||
CrashlyticsUtils.INSTANCE.log(Log.INFO, TAG, logMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public class BookmarkPaymentDataParser implements PaymentDataParser
|
|||
String parameter = uri.getQueryParameter(name);
|
||||
if (TextUtils.isEmpty(parameter))
|
||||
{
|
||||
CrashlyticsUtils.logException(
|
||||
CrashlyticsUtils.INSTANCE.logException(
|
||||
new IllegalArgumentException("'" + name + "' parameter is required! URI: " + uri));
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ public class PurchaseUtils
|
|||
String tag = PurchaseUtils.class.getSimpleName();
|
||||
String msg = "Failed to form product details bundle for '" + details + "': ";
|
||||
logger.e(tag, msg, e);
|
||||
CrashlyticsUtils.logException(new RuntimeException(msg, e));
|
||||
CrashlyticsUtils.INSTANCE.logException(new RuntimeException(msg, e));
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ public class PurchaseUtils
|
|||
if (Period.getInstance(each.getSubscriptionPeriod()) == null)
|
||||
{
|
||||
String msg = "Unsupported subscription period: '" + each.getSubscriptionPeriod() + "'";
|
||||
CrashlyticsUtils.logException(new IllegalStateException(msg));
|
||||
CrashlyticsUtils.INSTANCE.logException(new IllegalStateException(msg));
|
||||
LOGGER.e(TAG, msg);
|
||||
return true;
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ public class PurchaseUtils
|
|||
List<String> uriGroups = uri.getQueryParameters(GROUPS);
|
||||
if (uriGroups == null || uriGroups.isEmpty())
|
||||
{
|
||||
CrashlyticsUtils.logException(
|
||||
CrashlyticsUtils.INSTANCE.logException(
|
||||
new IllegalArgumentException("'" + GROUPS
|
||||
+ "' parameter is required! URI: " + uri));
|
||||
return SubscriptionType.BOOKMARKS_ALL.getServerId();
|
||||
|
|
|
@ -127,7 +127,7 @@ public class ConnectivityJobScheduler implements ConnectivityListener
|
|||
{
|
||||
IllegalStateException exception = new IllegalStateException("Play services doesn't exist on" +
|
||||
" the device");
|
||||
CrashlyticsUtils.logException(exception);
|
||||
CrashlyticsUtils.INSTANCE.logException(exception);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,14 +1,23 @@
|
|||
package com.mapswithme.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.firebase.crashlytics.FirebaseCrashlytics;
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.base.Initializable;
|
||||
|
||||
public final class CrashlyticsUtils
|
||||
public enum CrashlyticsUtils implements Initializable<Context>
|
||||
{
|
||||
public static void logException(@NonNull Throwable exception)
|
||||
INSTANCE;
|
||||
|
||||
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||
@NonNull
|
||||
private Context mContext;
|
||||
|
||||
public void logException(@NonNull Throwable exception)
|
||||
{
|
||||
if (!checkCrashlytics())
|
||||
return;
|
||||
|
@ -16,7 +25,7 @@ public final class CrashlyticsUtils
|
|||
FirebaseCrashlytics.getInstance().recordException(exception);
|
||||
}
|
||||
|
||||
public static void log(int priority, @NonNull String tag, @NonNull String msg)
|
||||
public void log(int priority, @NonNull String tag, @NonNull String msg)
|
||||
{
|
||||
if (!checkCrashlytics())
|
||||
return;
|
||||
|
@ -24,9 +33,9 @@ public final class CrashlyticsUtils
|
|||
FirebaseCrashlytics.getInstance().log(toLevel(priority) + "/" + tag + ": " + msg);
|
||||
}
|
||||
|
||||
private static boolean checkCrashlytics()
|
||||
private boolean checkCrashlytics()
|
||||
{
|
||||
MwmApplication app = MwmApplication.get();
|
||||
MwmApplication app = MwmApplication.from(mContext);
|
||||
return app.getMediator().isCrashlyticsEnabled();
|
||||
}
|
||||
|
||||
|
@ -50,5 +59,15 @@ public final class CrashlyticsUtils
|
|||
}
|
||||
}
|
||||
|
||||
private CrashlyticsUtils() {}
|
||||
@Override
|
||||
public void initialize(@Nullable Context context)
|
||||
{
|
||||
mContext = MwmApplication.from(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
// No op
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public class MultipleTrackerReferrerReceiver extends BroadcastReceiver
|
|||
String msg = "onReceive: " + intent + " app in background = "
|
||||
+ !backgroundTracker(context).isForeground();
|
||||
LOGGER.i(TAG, msg);
|
||||
CrashlyticsUtils.log(Log.INFO, TAG, msg);
|
||||
CrashlyticsUtils.INSTANCE.log(Log.INFO, TAG, msg);
|
||||
Counters.initCounters(context);
|
||||
// parse & send referrer to Aloha
|
||||
try
|
||||
|
|
|
@ -173,7 +173,7 @@ public class StorageUtils
|
|||
LOGGER.e(TAG, "Can't create directories for: " + path
|
||||
+ " state = " + Environment.getExternalStorageState()
|
||||
+ " isPermissionGranted = " + isPermissionGranted);
|
||||
CrashlyticsUtils.logException(error);
|
||||
CrashlyticsUtils.INSTANCE.logException(error);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -249,11 +249,11 @@ public class Utils
|
|||
}
|
||||
catch (ActivityNotFoundException e)
|
||||
{
|
||||
CrashlyticsUtils.logException(e);
|
||||
CrashlyticsUtils.INSTANCE.logException(e);
|
||||
}
|
||||
catch (AndroidRuntimeException e)
|
||||
{
|
||||
CrashlyticsUtils.logException(e);
|
||||
CrashlyticsUtils.INSTANCE.logException(e);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
@ -270,12 +270,12 @@ public class Utils
|
|||
}
|
||||
catch (ActivityNotFoundException e)
|
||||
{
|
||||
CrashlyticsUtils.logException(e);
|
||||
CrashlyticsUtils.INSTANCE.logException(e);
|
||||
return false;
|
||||
}
|
||||
catch (AndroidRuntimeException e)
|
||||
{
|
||||
CrashlyticsUtils.logException(e);
|
||||
CrashlyticsUtils.INSTANCE.logException(e);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
return false;
|
||||
|
@ -875,7 +875,7 @@ public class Utils
|
|||
}
|
||||
catch (ActivityNotFoundException e)
|
||||
{
|
||||
CrashlyticsUtils.logException(e);
|
||||
CrashlyticsUtils.INSTANCE.logException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -180,7 +180,7 @@ public class LoggerFactory
|
|||
default:
|
||||
logger.v(CORE_TAG, msg);
|
||||
}
|
||||
CrashlyticsUtils.log(level, CORE_TAG, msg);
|
||||
CrashlyticsUtils.INSTANCE.log(level, CORE_TAG, msg);
|
||||
}
|
||||
|
||||
private static native void nativeToggleCoreDebugLogs(boolean enabled);
|
||||
|
|
|
@ -2047,7 +2047,7 @@ public enum Statistics implements Initializable<Context>
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
CrashlyticsUtils.logException(new RuntimeException("Failed to parse url: " + url, e));
|
||||
CrashlyticsUtils.INSTANCE.logException(new RuntimeException("Failed to parse url: " + url, e));
|
||||
}
|
||||
|
||||
result.add(TYPE, type);
|
||||
|
|
Loading…
Add table
Reference in a new issue