[android] Implemented obtaining the advertising id

This commit is contained in:
Александр Зацепин 2020-02-05 18:01:34 +03:00 committed by Daria Volvenkova
parent be5cf0bb83
commit 1db8ffe21b
3 changed files with 35 additions and 4 deletions

View file

@ -30,8 +30,18 @@ std::string Platform::UniqueClientId() const
std::string Platform::AdvertisingId() const
{
//TODO(@alexzatsepin): Implement me.
return {};
JNIEnv *env = jni::GetEnv();
static jmethodID const getAdvertisingId = jni::GetStaticMethodID(env, g_utilsClazz,
"getAdvertisingId",
"(Landroid/content/Context;)"
"Ljava/lang/String;");
jobject context = android::Platform::Instance().GetContext();
jni::TScopedLocalRef adIdRef(env, env->CallStaticObjectMethod(g_utilsClazz, getAdvertisingId,
context));
if (adIdRef.get() == nullptr)
return {};
return jni::ToNativeString(env, static_cast<jstring>(adIdRef.get()));
}
std::string Platform::MacAddress(bool md5Decoded) const

View file

@ -3,11 +3,11 @@ package com.mapswithme.maps.analytics;
import android.app.Application;
import android.os.AsyncTask;
import android.os.CountDownTimer;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import android.text.TextUtils;
import com.appsflyer.AppsFlyerConversionListener;
import com.appsflyer.AppsFlyerLib;
import com.crashlytics.android.Crashlytics;
@ -193,6 +193,12 @@ public class ExternalLibrariesMediator
return mAdvertisingInfo.isLimitAdTrackingEnabled();
}
@Nullable
public String getAdvertisingId()
{
return mAdvertisingInfo != null ? mAdvertisingInfo.getID() : null;
}
public void disableAdProvider(@NonNull Banner.Type type)
{
Framework.disableAdProvider(type);
@ -390,6 +396,12 @@ public class ExternalLibrariesMediator
"mInfo=" + mInfo +
'}';
}
@Nullable
String getID()
{
return mInfo != null ? mInfo.getId() : null;
}
}
@UiThread

View file

@ -35,6 +35,7 @@ import com.mapswithme.maps.BuildConfig;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
import com.mapswithme.maps.activity.CustomNavigateUpListener;
import com.mapswithme.maps.analytics.ExternalLibrariesMediator;
import com.mapswithme.util.concurrency.UiThread;
import com.mapswithme.util.log.Logger;
import com.mapswithme.util.log.LoggerFactory;
@ -380,6 +381,14 @@ public class Utils
return installationId;
}
@Nullable
public static String getAdvertisingId(@NonNull Context context)
{
MwmApplication application = MwmApplication.from(context);
ExternalLibrariesMediator mediator = application.getMediator();
return mediator.getAdvertisingId();
}
@NonNull
public static String getMacAddress(boolean md5Decoded)
{