forked from organicmaps/organicmaps
[android] Delayed core initialization depending on advertising id obtainting
This commit is contained in:
parent
67f075e37f
commit
e4fb97c32e
3 changed files with 116 additions and 30 deletions
android/src/com/mapswithme/maps
|
@ -132,6 +132,7 @@ public class MwmApplication extends Application
|
|||
mMainLoopHandler = new Handler(getMainLooper());
|
||||
mMediator = new ExternalLibrariesMediator(this);
|
||||
mMediator.initSensitiveDataToleranceLibraries();
|
||||
mMediator.initSensitiveDataStrictLibrariesAsync();
|
||||
Statistics.INSTANCE.setMediator(mMediator);
|
||||
|
||||
mPrefs = getSharedPreferences(getString(R.string.pref_file_name), MODE_PRIVATE);
|
||||
|
@ -236,7 +237,6 @@ public class MwmApplication extends Application
|
|||
TrafficManager.INSTANCE.initialize();
|
||||
SubwayManager.from(this).initialize();
|
||||
mFrameworkInitialized = true;
|
||||
mMediator.initSensitiveDataStrictLibrariesAsync();
|
||||
}
|
||||
|
||||
private void initNativeStrings()
|
||||
|
|
|
@ -12,6 +12,9 @@ import android.support.v4.app.FragmentManager;
|
|||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapswithme.maps.ads.Banner;
|
||||
import com.mapswithme.maps.analytics.ExternalLibrariesMediator;
|
||||
import com.mapswithme.maps.base.BaseActivity;
|
||||
import com.mapswithme.maps.base.BaseActivityDelegate;
|
||||
import com.mapswithme.maps.downloader.UpdaterDialogFragment;
|
||||
|
@ -27,11 +30,16 @@ import com.mapswithme.util.PermissionsUtils;
|
|||
import com.mapswithme.util.ThemeUtils;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.concurrency.UiThread;
|
||||
import com.mapswithme.util.log.Logger;
|
||||
import com.mapswithme.util.log.LoggerFactory;
|
||||
import com.mapswithme.util.statistics.PushwooshHelper;
|
||||
|
||||
public class SplashActivity extends AppCompatActivity
|
||||
implements BaseNewsFragment.NewsDialogListener, BaseActivity
|
||||
{
|
||||
private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
|
||||
private static final String TAG = SplashActivity.class.getSimpleName();
|
||||
private static final String EXTRA_CORE_INITIALIZED = "extra_core_initialized";
|
||||
private static final String EXTRA_ACTIVITY_TO_START = "extra_activity_to_start";
|
||||
public static final String EXTRA_INITIAL_INTENT = "extra_initial_intent";
|
||||
private static final int REQUEST_PERMISSIONS = 1;
|
||||
|
@ -65,13 +73,47 @@ public class SplashActivity extends AppCompatActivity
|
|||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (mCoreInitialized)
|
||||
{
|
||||
UiThread.runLater(mFinalDelayedTask);
|
||||
return;
|
||||
}
|
||||
|
||||
ExternalLibrariesMediator mediator = ((MwmApplication) getApplicationContext()).getMediator();
|
||||
if (!mediator.isAdvertisingInfoObtained())
|
||||
{
|
||||
UiThread.runLater(mInitCoreDelayedTask, DELAY);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mediator.isLimitAdTrackingEnabled())
|
||||
{
|
||||
LOGGER.i(TAG, "Limit ad tracking disabled, sensitive tracking initialized");
|
||||
mediator.initSensitiveEventLogger();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.i(TAG, "Limit ad tracking enabled, sensitive tracking not initialized");
|
||||
}
|
||||
|
||||
init();
|
||||
LOGGER.i(TAG, "Core initialized: " + mCoreInitialized);
|
||||
if (mCoreInitialized)
|
||||
{
|
||||
if (mediator.isLimitAdTrackingEnabled())
|
||||
{
|
||||
LOGGER.i(TAG, "Limit ad tracking enabled, rb banners disabled.");
|
||||
mediator.disableAdProvider(Banner.Type.TYPE_RB);
|
||||
}
|
||||
}
|
||||
|
||||
// Run delayed task because resumeDialogs() must see the actual value of mCanceled flag,
|
||||
// since onPause() callback can be blocked because of UI thread is busy with framework
|
||||
// initialization.
|
||||
UiThread.runLater(mFinalDelayedTask);
|
||||
}
|
||||
};
|
||||
|
||||
@NonNull
|
||||
private final Runnable mFinalDelayedTask = new Runnable()
|
||||
{
|
||||
|
@ -109,6 +151,8 @@ public class SplashActivity extends AppCompatActivity
|
|||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
mBaseDelegate.onCreate();
|
||||
if (savedInstanceState != null)
|
||||
mCoreInitialized = savedInstanceState.getBoolean(EXTRA_CORE_INITIALIZED);
|
||||
handleUpdateMapsFragmentCorrectly(savedInstanceState);
|
||||
UiThread.cancelDelayedTasks(mPermissionsDelayedTask);
|
||||
UiThread.cancelDelayedTasks(mInitCoreDelayedTask);
|
||||
|
@ -117,6 +161,13 @@ public class SplashActivity extends AppCompatActivity
|
|||
initView();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState)
|
||||
{
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBoolean(EXTRA_CORE_INITIALIZED, mCoreInitialized);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent)
|
||||
{
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.mapswithme.maps.analytics;
|
|||
import android.app.Application;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
import android.text.TextUtils;
|
||||
|
||||
|
@ -13,7 +14,11 @@ 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.*;
|
||||
import com.mapswithme.maps.BuildConfig;
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.PrivateVariables;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.ads.Banner;
|
||||
import com.mapswithme.util.CrashlyticsUtils;
|
||||
import com.mapswithme.util.Utils;
|
||||
|
@ -21,7 +26,6 @@ import com.mapswithme.util.log.Logger;
|
|||
import com.mapswithme.util.log.LoggerFactory;
|
||||
import com.mopub.common.MoPub;
|
||||
import com.mopub.common.SdkConfiguration;
|
||||
import com.my.target.common.MyTargetPrivacy;
|
||||
import io.fabric.sdk.android.Fabric;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -37,6 +41,8 @@ public class ExternalLibrariesMediator
|
|||
private final Application mApplication;
|
||||
@NonNull
|
||||
private volatile EventLogger mEventLogger;
|
||||
@Nullable
|
||||
private AdvertisingInfo mAdvertisingInfo;
|
||||
|
||||
public ExternalLibrariesMediator(@NonNull Application application)
|
||||
{
|
||||
|
@ -57,7 +63,7 @@ public class ExternalLibrariesMediator
|
|||
getAdInfoTask.execute();
|
||||
}
|
||||
|
||||
private void initSensitiveEventLogger()
|
||||
public void initSensitiveEventLogger()
|
||||
{
|
||||
if (com.mapswithme.util.concurrency.UiThread.isUiThread())
|
||||
{
|
||||
|
@ -144,7 +150,39 @@ public class ExternalLibrariesMediator
|
|||
MoPub.initializeSdk(mApplication, sdkConfiguration, null);
|
||||
}
|
||||
|
||||
private static class GetAdInfoTask extends AsyncTask<Void, Void, Boolean>
|
||||
@UiThread
|
||||
void setAdvertisingInfo(@NonNull AdvertisingInfo info)
|
||||
{
|
||||
mAdvertisingInfo = info;
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public boolean isAdvertisingInfoObtained()
|
||||
{
|
||||
return mAdvertisingInfo != null;
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public boolean isLimitAdTrackingEnabled()
|
||||
{
|
||||
if (mAdvertisingInfo == null)
|
||||
throw new IllegalStateException("Advertising info must be obtained first!");
|
||||
|
||||
return mAdvertisingInfo.isLimitAdTrackingEnabled();
|
||||
}
|
||||
|
||||
public void disableAdProvider(@NonNull Banner.Type type)
|
||||
{
|
||||
Framework.disableAdProvider(type);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
Application getApplication()
|
||||
{
|
||||
return mApplication;
|
||||
}
|
||||
|
||||
private static class GetAdInfoTask extends AsyncTask<Void, Void, AdvertisingInfo>
|
||||
{
|
||||
@NonNull
|
||||
private final ExternalLibrariesMediator mMediator;
|
||||
|
@ -155,47 +193,44 @@ public class ExternalLibrariesMediator
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... voids)
|
||||
protected AdvertisingInfo doInBackground(Void... voids)
|
||||
{
|
||||
try
|
||||
{
|
||||
return isAdvertisingTrackingEnabled();
|
||||
Application application = mMediator.getApplication();
|
||||
AdvertisingIdClient.Info info = AdvertisingIdClient.getAdvertisingIdInfo(application);
|
||||
return new AdvertisingInfo(info);
|
||||
}
|
||||
catch (GooglePlayServicesNotAvailableException | IOException | GooglePlayServicesRepairableException e)
|
||||
{
|
||||
LOGGER.e(TAG, "Failed to obtain advertising id: ", e);
|
||||
CrashlyticsUtils.logException(e);
|
||||
return false;
|
||||
return new AdvertisingInfo(null);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAdvertisingTrackingEnabled() throws GooglePlayServicesNotAvailableException,
|
||||
IOException,
|
||||
GooglePlayServicesRepairableException
|
||||
{
|
||||
AdvertisingIdClient.Info info = AdvertisingIdClient.getAdvertisingIdInfo(mMediator.mApplication);
|
||||
return info.isLimitAdTrackingEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean status)
|
||||
protected void onPostExecute(@NonNull AdvertisingInfo info)
|
||||
{
|
||||
super.onPostExecute(status);
|
||||
if (status != null && status)
|
||||
onEnabled();
|
||||
else
|
||||
onDisabled();
|
||||
super.onPostExecute(info);
|
||||
mMediator.setAdvertisingInfo(info);
|
||||
}
|
||||
}
|
||||
|
||||
private static class AdvertisingInfo
|
||||
{
|
||||
@Nullable
|
||||
private final AdvertisingIdClient.Info mInfo;
|
||||
|
||||
private AdvertisingInfo(@Nullable AdvertisingIdClient.Info info)
|
||||
{
|
||||
mInfo = info;
|
||||
}
|
||||
|
||||
private void onDisabled()
|
||||
@UiThread
|
||||
boolean isLimitAdTrackingEnabled()
|
||||
{
|
||||
Framework.disableAdProvider(Banner.Type.TYPE_RB);
|
||||
MyTargetPrivacy.setUserConsent(false);
|
||||
}
|
||||
|
||||
private void onEnabled()
|
||||
{
|
||||
mMediator.initSensitiveEventLogger();
|
||||
return mInfo != null && mInfo.isLimitAdTrackingEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue