forked from organicmaps/organicmaps
[android] Fixed review notes https://github.com/mapsme/omim/pull/9514#discussion_r220187140
# Conflicts: # android/src/com/mapswithme/maps/ExternalLibrariesMediator.java
This commit is contained in:
parent
74ac5e9be7
commit
9f80cd64cf
16 changed files with 95 additions and 63 deletions
|
@ -16,6 +16,6 @@ extern "C"
|
|||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_ExternalLibrariesMediator_nativeInitCrashlytics(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
ASSERT(!g_crashlytics, ());
|
||||
g_crashlytics = crashlytics_init();
|
||||
ASSERT(!g_crashlytics, ());
|
||||
g_crashlytics = crashlytics_init();
|
||||
}
|
||||
|
|
|
@ -224,22 +224,22 @@ public class DownloadResourcesLegacyActivity extends BaseMwmFragmentActivity
|
|||
|
||||
private void initIntentProcessors()
|
||||
{
|
||||
mIntentProcessors = new IntentProcessor[]{
|
||||
Factory.createGeoIntentProcessor(),
|
||||
Factory.createHttpGe0IntentProcessor(),
|
||||
Factory.createGe0IntentProcessor(),
|
||||
Factory.createMapsWithMeIntentProcessor(getApplication()),
|
||||
Factory.createGoogleMapsIntentProcessor(),
|
||||
Factory.createOldLeadUrlProcessor(),
|
||||
Factory.createDlinkBookmarkCatalogueProcessor(),
|
||||
Factory.createMapsmeBookmarkCatalogueProcessor(),
|
||||
Factory.createOldCoreLinkAdapterProcessor(),
|
||||
Factory.createOpenCountryTaskProcessor(),
|
||||
Factory.createMapsmeProcessor(),
|
||||
Factory.createKmzKmlProcessor(this),
|
||||
Factory.createShowOnMapProcessor(),
|
||||
Factory.createBuildRouteProcessor()
|
||||
};
|
||||
mIntentProcessors = new IntentProcessor[] {
|
||||
Factory.createGeoIntentProcessor(),
|
||||
Factory.createHttpGe0IntentProcessor(),
|
||||
Factory.createGe0IntentProcessor(),
|
||||
Factory.createMapsWithMeIntentProcessor(getApplication()),
|
||||
Factory.createGoogleMapsIntentProcessor(),
|
||||
Factory.createOldLeadUrlProcessor(),
|
||||
Factory.createDlinkBookmarkCatalogueProcessor(),
|
||||
Factory.createMapsmeBookmarkCatalogueProcessor(),
|
||||
Factory.createOldCoreLinkAdapterProcessor(),
|
||||
Factory.createOpenCountryTaskProcessor(),
|
||||
Factory.createMapsmeProcessor(),
|
||||
Factory.createKmzKmlProcessor(this),
|
||||
Factory.createShowOnMapProcessor(),
|
||||
Factory.createBuildRouteProcessor()
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.mapswithme.maps;
|
||||
|
||||
import android.app.Application;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Looper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.UiThread;
|
||||
import android.text.TextUtils;
|
||||
|
@ -13,12 +13,13 @@ import com.crashlytics.android.ndk.CrashlyticsNdk;
|
|||
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
|
||||
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
|
||||
import com.google.android.gms.common.GooglePlayServicesRepairableException;
|
||||
import com.mapswithme.maps.bookmarks.OperationStatus;
|
||||
import com.mapswithme.maps.content.DefaultEventLogger;
|
||||
import com.mapswithme.maps.content.EventLogger;
|
||||
import com.mapswithme.maps.content.EventLoggerAggregator;
|
||||
import com.mapswithme.util.SharedPropertiesUtils;
|
||||
import com.mapswithme.util.Utils;
|
||||
import com.mapswithme.util.log.Logger;
|
||||
import com.mapswithme.util.log.LoggerFactory;
|
||||
import com.mopub.common.MoPub;
|
||||
import com.mopub.common.SdkConfiguration;
|
||||
import io.fabric.sdk.android.Fabric;
|
||||
|
@ -29,44 +30,46 @@ public class ExternalLibrariesMediator
|
|||
{
|
||||
private boolean mCrashlyticsInitialized;
|
||||
|
||||
private static final String TAG = ExternalLibrariesMediator.class.getSimpleName();
|
||||
private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
|
||||
|
||||
@NonNull
|
||||
private final MwmApplication mApplication;
|
||||
private final Application mApplication;
|
||||
|
||||
@NonNull
|
||||
private volatile EventLogger mEventLogger;
|
||||
|
||||
public ExternalLibrariesMediator(@NonNull MwmApplication application)
|
||||
public ExternalLibrariesMediator(@NonNull Application application)
|
||||
{
|
||||
mApplication = application;
|
||||
mEventLogger = new DefaultEventLogger(application);
|
||||
initSensitiveDataToleranceLibraries();
|
||||
initSensitiveDataStrictLibrariesAsync();
|
||||
}
|
||||
|
||||
private void initSensitiveDataToleranceLibraries()
|
||||
public void initSensitiveDataToleranceLibraries()
|
||||
{
|
||||
initMoPub();
|
||||
initCrashlytics();
|
||||
initAppsFlyer();
|
||||
}
|
||||
|
||||
private void initSensitiveDataStrictLibrariesAsync()
|
||||
public void initSensitiveDataStrictLibrariesAsync()
|
||||
{
|
||||
GetAdInfoTask getAdInfoTask = new GetAdInfoTask(this);
|
||||
getAdInfoTask.execute();
|
||||
}
|
||||
|
||||
private void initSensitiveDataStrictLibraries()
|
||||
private void initSensitiveEventLogger()
|
||||
{
|
||||
if (Looper.getMainLooper().getThread() != Thread.currentThread())
|
||||
if (com.mapswithme.util.concurrency.UiThread.isUiThreadNow())
|
||||
{
|
||||
throw new IllegalStateException("Must be call from Ui thread");
|
||||
mEventLogger = new EventLoggerAggregator(mApplication);
|
||||
mEventLogger.initialize();
|
||||
return;
|
||||
}
|
||||
|
||||
mEventLogger = new EventLoggerAggregator(mApplication);
|
||||
throw new IllegalStateException("Must be call from Ui thread");
|
||||
}
|
||||
|
||||
|
||||
private void initAppsFlyer()
|
||||
{
|
||||
// There is no necessary to use a conversion data listener for a while.
|
||||
|
@ -142,7 +145,7 @@ public class ExternalLibrariesMediator
|
|||
MoPub.initializeSdk(mApplication, sdkConfiguration, null);
|
||||
}
|
||||
|
||||
private static class GetAdInfoTask extends AsyncTask<Void, Void, OperationStatus<Boolean, Throwable>>
|
||||
private static class GetAdInfoTask extends AsyncTask<Void, Void, Boolean>
|
||||
{
|
||||
@NonNull
|
||||
private final ExternalLibrariesMediator mMediator;
|
||||
|
@ -153,16 +156,16 @@ public class ExternalLibrariesMediator
|
|||
}
|
||||
|
||||
@Override
|
||||
protected OperationStatus<Boolean, Throwable> doInBackground(Void... voids)
|
||||
protected Boolean doInBackground(Void... voids)
|
||||
{
|
||||
try
|
||||
{
|
||||
boolean trackingEnabled = isAdvertisingTrackingEnabled();
|
||||
return new OperationStatus<>(trackingEnabled, null);
|
||||
return isAdvertisingTrackingEnabled();
|
||||
}
|
||||
catch (GooglePlayServicesNotAvailableException | IOException | GooglePlayServicesRepairableException e)
|
||||
{
|
||||
return new OperationStatus<>(false, e);
|
||||
LOGGER.e(TAG, e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,11 +178,16 @@ public class ExternalLibrariesMediator
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(OperationStatus<Boolean, Throwable> status)
|
||||
protected void onPostExecute(Boolean status)
|
||||
{
|
||||
super.onPostExecute(status);
|
||||
if (status.isOk() && status.getResult() != null && status.getResult())
|
||||
mMediator.initSensitiveDataStrictLibraries();
|
||||
if (status != null && status)
|
||||
onEnabled();
|
||||
}
|
||||
|
||||
private void onEnabled()
|
||||
{
|
||||
mMediator.initSensitiveEventLogger();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -135,6 +135,8 @@ public class MwmApplication extends Application
|
|||
mLogger.d(TAG, "Application is created");
|
||||
mMainLoopHandler = new Handler(getMainLooper());
|
||||
mMediator = new ExternalLibrariesMediator(this);
|
||||
mMediator.initSensitiveDataToleranceLibraries();
|
||||
mMediator.initSensitiveDataStrictLibrariesAsync();
|
||||
mStatistics = new Statistics(mMediator);
|
||||
mVisibleAppLaunchListener = new VisibleAppLaunchListener(this);
|
||||
|
||||
|
@ -325,9 +327,9 @@ public class MwmApplication extends Application
|
|||
private static class VisibleAppLaunchListener implements AppBackgroundTracker.OnVisibleAppLaunchListener
|
||||
{
|
||||
@NonNull
|
||||
private final MwmApplication mApplication;
|
||||
private final Application mApplication;
|
||||
|
||||
VisibleAppLaunchListener(@NonNull MwmApplication application)
|
||||
VisibleAppLaunchListener(@NonNull Application application)
|
||||
{
|
||||
mApplication = application;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ public class OperationStatus<R, E>
|
|||
@Nullable
|
||||
private final E mError;
|
||||
|
||||
public OperationStatus(@Nullable R result, @Nullable E error)
|
||||
OperationStatus(@Nullable R result, @Nullable E error)
|
||||
{
|
||||
mResult = result;
|
||||
mError = error;
|
||||
|
|
|
@ -8,7 +8,7 @@ abstract class ContextDependentEventLogger implements EventLogger
|
|||
@NonNull
|
||||
private final Application mApplication;
|
||||
|
||||
protected ContextDependentEventLogger(@NonNull Application application)
|
||||
ContextDependentEventLogger(@NonNull Application application)
|
||||
{
|
||||
mApplication = application;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,12 @@ public class DefaultEventLogger extends ContextDependentEventLogger
|
|||
super(application);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize()
|
||||
{
|
||||
/* Do nothing */
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTags(@NonNull String tag, @Nullable String[] params)
|
||||
{
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.util.Map;
|
|||
|
||||
public interface EventLogger
|
||||
{
|
||||
void initialize();
|
||||
void sendTags(@NonNull String tag, @Nullable String[] params);
|
||||
void logEvent(@NonNull String event, @NonNull Map<String, String> params);
|
||||
void startActivity(@NonNull Activity context);
|
||||
|
|
|
@ -23,6 +23,15 @@ public class EventLoggerAggregator extends ContextDependentEventLogger
|
|||
mLoggers.put(FlurryEventLogger.class, new FlurryEventLogger(application));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize()
|
||||
{
|
||||
for (Map.Entry<Class<? extends EventLogger>, ? extends EventLogger> each : mLoggers.entrySet())
|
||||
{
|
||||
each.getValue().initialize();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTags(@NonNull String tag, @Nullable String[] params)
|
||||
{
|
||||
|
|
|
@ -16,10 +16,10 @@ public class FlurryEventLogger extends DefaultEventLogger
|
|||
FlurryEventLogger(@NonNull Application application)
|
||||
{
|
||||
super(application);
|
||||
initFlurry();
|
||||
}
|
||||
|
||||
private void initFlurry()
|
||||
@Override
|
||||
public void initialize()
|
||||
{
|
||||
//noinspection ConstantConditions
|
||||
FlurryAgent.setVersionName(BuildConfig.VERSION_NAME);
|
||||
|
@ -42,13 +42,13 @@ public class FlurryEventLogger extends DefaultEventLogger
|
|||
public void startActivity(@NonNull Activity context)
|
||||
{
|
||||
super.startActivity(context);
|
||||
FlurryAgent.onEndSession(context.getApplicationContext());
|
||||
FlurryAgent.onStartSession(context.getApplicationContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopActivity(@NonNull Activity context)
|
||||
{
|
||||
super.stopActivity(context);
|
||||
FlurryAgent.onStartSession(context.getApplicationContext());
|
||||
FlurryAgent.onEndSession(context.getApplicationContext());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,15 +17,17 @@ import java.util.Map;
|
|||
|
||||
public class LibnotifyEventLogger extends DefaultEventLogger
|
||||
{
|
||||
private final NotificationApi mApi;
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private NotificationApi mApi;
|
||||
|
||||
protected LibnotifyEventLogger(@NonNull Application application)
|
||||
LibnotifyEventLogger(@NonNull Application application)
|
||||
{
|
||||
super(application);
|
||||
mApi = initLibnotify();
|
||||
}
|
||||
|
||||
private NotificationApi initLibnotify()
|
||||
@Override
|
||||
public void initialize()
|
||||
{
|
||||
if (BuildConfig.DEBUG || BuildConfig.BUILD_TYPE.equals("beta"))
|
||||
{
|
||||
|
@ -39,7 +41,7 @@ public class LibnotifyEventLogger extends DefaultEventLogger
|
|||
NotificationFactory.setNetworkSyncMode(NetworkSyncMode.WIFI_ONLY);
|
||||
NotificationFactory.setBackgroundAwakeMode(BackgroundAwakeMode.DISABLED);
|
||||
NotificationFactory.initialize(getApplication());
|
||||
return NotificationFactory.get(getApplication());
|
||||
mApi = NotificationFactory.get(getApplication());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,6 +20,12 @@ public class MyTrackerEventLogger extends ContextDependentEventLogger
|
|||
initTracker();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTags(@NonNull String tag, @Nullable String[] params)
|
||||
{
|
||||
|
|
|
@ -22,10 +22,10 @@ public class PushWooshEventLogger extends DefaultEventLogger
|
|||
PushWooshEventLogger(@NonNull Application application)
|
||||
{
|
||||
super(application);
|
||||
initPushWoosh();
|
||||
}
|
||||
|
||||
private void initPushWoosh()
|
||||
@Override
|
||||
public void initialize()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -28,7 +28,7 @@ final class Locals
|
|||
@MainThread
|
||||
void onLocalsReceived(@NonNull LocalExpert[] experts)
|
||||
{
|
||||
if (!UiThread.currentThreadIsUi())
|
||||
if (!UiThread.isUiThreadNow())
|
||||
throw new AssertionError("Must be called from UI thread!");
|
||||
|
||||
if (mListener != null)
|
||||
|
@ -39,7 +39,7 @@ final class Locals
|
|||
@MainThread
|
||||
void onLocalsErrorReceived(@NonNull LocalsError error)
|
||||
{
|
||||
if (!UiThread.currentThreadIsUi())
|
||||
if (!UiThread.isUiThreadNow())
|
||||
throw new AssertionError("Must be called from UI thread!");
|
||||
|
||||
if (mListener != null)
|
||||
|
|
|
@ -40,7 +40,7 @@ public class TaxiManager
|
|||
@MainThread
|
||||
void onTaxiProvidersReceived(@NonNull TaxiInfo[] providers)
|
||||
{
|
||||
if (!UiThread.currentThreadIsUi())
|
||||
if (!UiThread.isUiThreadNow())
|
||||
throw new AssertionError("Must be called from UI thread!");
|
||||
|
||||
if (providers.length == 0)
|
||||
|
@ -64,7 +64,7 @@ public class TaxiManager
|
|||
@MainThread
|
||||
void onTaxiErrorsReceived(@NonNull TaxiInfoError[] errors)
|
||||
{
|
||||
if (!UiThread.currentThreadIsUi())
|
||||
if (!UiThread.isUiThreadNow())
|
||||
throw new AssertionError("Must be called from UI thread!");
|
||||
|
||||
if (errors.length == 0)
|
||||
|
|
|
@ -3,15 +3,13 @@ package com.mapswithme.util.concurrency;
|
|||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import com.mapswithme.util.Utils;
|
||||
|
||||
public class UiThread
|
||||
{
|
||||
private static final Handler sUiHandler = new Handler(Looper.getMainLooper());
|
||||
|
||||
public static boolean currentThreadIsUi()
|
||||
public static boolean isUiThreadNow()
|
||||
{
|
||||
return sUiHandler.getLooper().getThread() == Thread.currentThread();
|
||||
return Looper.getMainLooper().getThread() == Thread.currentThread();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -21,7 +19,7 @@ public class UiThread
|
|||
*/
|
||||
public static void run(Runnable task)
|
||||
{
|
||||
if (currentThreadIsUi())
|
||||
if (isUiThreadNow())
|
||||
task.run();
|
||||
else
|
||||
sUiHandler.post(task);
|
||||
|
|
Loading…
Add table
Reference in a new issue