Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 4.19.1 #407

Merged
merged 15 commits into from
Dec 13, 2019
Merged
3 changes: 3 additions & 0 deletions Adjust/sdk-plugin-oaid/build.gradle
Original file line number Diff line number Diff line change
@@ -6,6 +6,9 @@ repositories {
maven {
url "https://oss.sonatype.org/content/repositories/staging/"
}
flatDir {
dirs 'libs'
}
}

android {
Binary file added Adjust/sdk-plugin-oaid/libs/miit_mdid_1.0.10.aar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
package com.adjust.sdk.oaid;

import android.content.Context;
import android.util.Log;

import com.bun.miitmdid.core.JLibrary;

public class AdjustOaid {
static boolean isOaidToBeRead = false;

public static void readOaid() {
AdjustOaid.isOaidToBeRead = true;
}

public static void readOaid(Context base) {
readOaid();

try {
JLibrary.InitEntry(base);
} catch (NoClassDefFoundError ex) {
Log.d("Adjust", "Couldn't find msa sdk " + ex.getMessage());
}
}

public static void doNotReadOaid() {
AdjustOaid.isOaidToBeRead = false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.adjust.sdk.oaid;

import android.content.Context;

import com.adjust.sdk.ILogger;
import com.bun.miitmdid.core.ErrorCode;
import com.bun.miitmdid.core.IIdentifierListener;
import com.bun.miitmdid.core.MdidSdkHelper;
import com.bun.miitmdid.supplier.IdSupplier;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

public class MsaSdkClient {

public static String getOaid(Context context, final ILogger logger, long maxWaitTimeInMilli) {
final BlockingQueue<String> oaidHolder = new LinkedBlockingQueue<String>(1);

try {
boolean msaInternalLogging = false;
int result = MdidSdkHelper.InitSdk(context, msaInternalLogging, new IIdentifierListener() {
@Override
public void OnSupport(boolean b, IdSupplier idSupplier) {
try {
if (idSupplier == null) {
// so to avoid waiting for timeout
oaidHolder.offer(null);
} else {
oaidHolder.offer(idSupplier.getOAID());
}
} catch (Exception e) {
logger.error("Fail to add %s", e.getMessage());
}
}
});

if (!isError(result, logger)) {
return oaidHolder.poll(maxWaitTimeInMilli, TimeUnit.MILLISECONDS);
}

} catch (NoClassDefFoundError ex) {
logger.error("Couldn't find msa sdk " + ex.getMessage());
} catch (InterruptedException e) {
logger.error("Waiting to read oaid from callback interrupted: %s",
e.getMessage());
} catch (Throwable t) {
logger.error("Oaid reading process failed %s", t.getMessage());
}

return null;
}

private static boolean isError(int result, ILogger logger) {
switch(result) {
case ErrorCode.INIT_ERROR_BEGIN:
logger.error("msa sdk error - INIT_ERROR_BEGIN");
return true;
case ErrorCode.INIT_ERROR_DEVICE_NOSUPPORT:
logger.error("msa sdk error - INIT_ERROR_DEVICE_NOSUPPORT");
return true;
case ErrorCode.INIT_ERROR_LOAD_CONFIGFILE:
logger.error("msa sdk error - INIT_ERROR_LOAD_CONFIGFILE");
return true;
case ErrorCode.INIT_ERROR_MANUFACTURER_NOSUPPORT:
logger.error("msa sdk error - INIT_ERROR_MANUFACTURER_NOSUPPORT");
return true;
case ErrorCode.INIT_HELPER_CALL_ERROR:
logger.error("msa sdk error - INIT_HELPER_CALL_ERROR");
return true;
default:
return false;
}
}


}
17 changes: 17 additions & 0 deletions Adjust/sdk-plugin-oaid/src/main/java/com/adjust/sdk/oaid/Util.java
Original file line number Diff line number Diff line change
@@ -13,13 +13,30 @@ public class Util {
public static Map<String, String> getOaidParameters(Context context, ILogger logger) {

if (AdjustOaid.isOaidToBeRead) {

// IMPORTANT: current logic is to first try reading the oaid with hms (huawei mobile service) approach
// which has the capability to return both oaid and limit tracking status
// And as a fallback, use the msa sdk approach, which currently only gives the oaid

Info oaidInfo = OpenDeviceIdentifierClient.getOaidInfo(context, logger, 1000);
if (oaidInfo != null) {
Map<String, String> parameters = new HashMap<String, String>();
PackageBuilder.addString(parameters, "oaid", oaidInfo.getOaid());
PackageBuilder.addBoolean(parameters, "oaid_tracking_enabled", !oaidInfo.isOaidTrackLimited());
return parameters;
}

logger.debug("Fail to read the OAID using hms, now try reading it using msa");

String oaid = MsaSdkClient.getOaid(context, logger, 1000);
if (oaid != null) {
Map<String, String> parameters = new HashMap<String, String>();
PackageBuilder.addString(parameters, "oaid", oaid);
return parameters;
}

logger.error("Fail to read the OAID completely");

}

return null;