Skip to content

Commit

Permalink
Release 0.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
weiqiangliu committed May 27, 2022
1 parent 6957f2f commit d507c6e
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 11 deletions.
4 changes: 2 additions & 2 deletions SensorsABTestSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'signing'
apply plugin: 'maven-publish'

version = "0.2.2"
version = "0.2.3"
android {
compileSdkVersion 29

Expand Down Expand Up @@ -47,7 +47,7 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
compileOnly 'com.sensorsdata.analytics.android:SensorsAnalyticsSDK:6.3.3'
compileOnly 'com.sensorsdata.analytics.android:SensorsAnalyticsSDK:6.3.4'
// compileOnly files('libs/SensorsAnalyticsSDK-6.2.0.aar')
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.sensorsdata.abtest;

public class SensorsDataVersionConfig {
/**
* 当前 SDK 的版本
*/
public static final String SDK_VERSION = "0.2.3";

/**
* 当前 SDK 所要依赖的版本,可以为 JSONArray
*/
public static final String DEPENDENT_SDK_VERSIONS = "[\n" +
" {\n" +
" \"DEPENDENT_MIN_SDK_VERSIONS\":\"6.3.4\",\n" +
" \"SDK_VERSION_PATH\":\"com.sensorsdata.analytics.android.sdk.SensorsDataAPI\",\n" +
" \"ERROR_MESSAGE\":\"当前 SA SDK 版本 %s 过低,请升级至 %s 及其以上版本后进行使用\"\n" +
" }\n" +
"]";
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.sensorsdata.abtest.entity.RequestingExperimentInfo;
import com.sensorsdata.abtest.entity.SABErrorEnum;
import com.sensorsdata.abtest.exception.DataInvalidException;
import com.sensorsdata.abtest.util.AppInfoUtils;
import com.sensorsdata.abtest.util.CommonUtils;
import com.sensorsdata.abtest.util.SensorsDataHelper;
import com.sensorsdata.abtest.util.TaskRunner;
Expand All @@ -56,10 +57,14 @@ public class SensorsABTestApiRequestHelper<T> {
private static final String TAG = "SAB.SensorsABTestApiRequestHelper";
private boolean mHasCallback = false;
private String mUserIdentifier;
public final static int DEFAULT_TIMEOUT = 30 * 1000;
private int timeoutMillSeconds = DEFAULT_TIMEOUT;
private TimeoutRunnable runnable;

public void requestExperimentByParamName(final String distinctId, final String loginId, final String anonymousId, final String customIDs,
final String paramName, final T defaultValue, Map<String, Object> properties,
final int timeoutMillSeconds, final OnABTestReceivedData<T> callBack, boolean mergeRequest) {
setTimeoutMillSeconds(timeoutMillSeconds);
// callback 为 null
if (callBack == null) {
SALog.i(TAG, "试验 callback 不正确,试验 callback 不能为空!");
Expand Down Expand Up @@ -126,16 +131,20 @@ public void requestExperimentByParamName(final String distinctId, final String l
}

// 启动定时器
final TimeoutRunnable runnable = new TimeoutRunnable(currentTask);
TaskRunner.getBackHandler().postDelayed(runnable, timeoutMillSeconds);
if (!AppInfoUtils.checkSASDKVersionIsValid(AppInfoUtils.SA_TIMEOUT_VALID_VERSION)) {
runnable = new TimeoutRunnable(currentTask);
TaskRunner.getBackHandler().postDelayed(runnable, timeoutMillSeconds);
}

mUserIdentifier = CommonUtils.getCurrentUserIdentifier();
requestExperimentsAndUpdateCache(propertiesString, paramName, new IApiCallback<Map<String, Experiment>>() {
@Override
public void onSuccess(Map<String, Experiment> experimentMap) {
RequestExperimentTaskRecorderManager.getInstance().removeTask(currentTask);
List<RequestingExperimentInfo> taskExperimentInfoList = currentTask.getRequestingExperimentList();
TaskRunner.getBackHandler().removeCallbacks(runnable);
if (!AppInfoUtils.checkSASDKVersionIsValid(AppInfoUtils.SA_TIMEOUT_VALID_VERSION)) {
TaskRunner.getBackHandler().removeCallbacks(runnable);
}
if (mHasCallback) {
SALog.i(TAG, "Request success! but all callbacks has been returned with default value!");
return;
Expand Down Expand Up @@ -188,7 +197,9 @@ public void onSuccess(Map<String, Experiment> experimentMap) {

@Override
public void onFailure(int errorCode, String message) {
TaskRunner.getBackHandler().removeCallbacks(runnable);
if (!AppInfoUtils.checkSASDKVersionIsValid(AppInfoUtils.SA_TIMEOUT_VALID_VERSION)) {
TaskRunner.getBackHandler().removeCallbacks(runnable);
}
RequestExperimentTaskRecorderManager.getInstance().removeTask(currentTask);
if (!mHasCallback) {
List<RequestingExperimentInfo> taskExperimentInfoList = currentTask.getRequestingExperimentList();
Expand Down Expand Up @@ -232,8 +243,16 @@ void requestExperiments(Map<String, String> properties, String paramName, JSONOb
}
Map<String, String> headers = new HashMap<>();
headers.put("project-key", key);
new RequestHelper.Builder(HttpMethod.POST, url)
.header(headers)
RequestHelper.Builder builder = new RequestHelper.Builder(HttpMethod.POST, url);
if (AppInfoUtils.checkSASDKVersionIsValid(AppInfoUtils.SA_TIMEOUT_VALID_VERSION)) {
try {
builder.connectionTimeout(timeoutMillSeconds);
builder.readTimeout(timeoutMillSeconds);
} catch (NoSuchMethodError e) {
SALog.i(TAG, e.getMessage());
}
}
builder.header(headers)
.jsonData(requestBody)
.callback(new HttpCallback.StringCallback() {
@Override
Expand Down Expand Up @@ -355,4 +374,9 @@ public void run() {
}
}
}

public SensorsABTestApiRequestHelper setTimeoutMillSeconds(int timeoutMillSeconds) {
this.timeoutMillSeconds = timeoutMillSeconds;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ public void handlerJSMessage() {
JSONObject data = jsonObject.optJSONObject("data");
if (data != null) {
request.messageId = data.optString("message_id");
int timeout = data.optInt("timeout");
if (timeout <= 0) {
timeout = SensorsABTestApiRequestHelper.DEFAULT_TIMEOUT;
}
final String distinctId = SensorsDataAPI.sharedInstance().getDistinctId();
new SensorsABTestApiRequestHelper<>().requestExperiments(null, null, data.optJSONObject("request_body"), new IApiCallback<String>() {
new SensorsABTestApiRequestHelper<>().setTimeoutMillSeconds(timeout).requestExperiments(null, null, data.optJSONObject("request_body"), new IApiCallback<String>() {
@Override
public void onSuccess(String s) {
if (TextUtils.isEmpty(s)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public class AppInfoUtils {
private static final String TAG = "AppInfoUtils";
public static final String MIN_SA_SDK_VERSION = "4.3.6";
public static final String MIN_SA_SECRET_SDK_VERSION = "6.2.0";
/**
* 网络超时可用版本
*/
public static final String SA_TIMEOUT_VALID_VERSION = "6.3.4";

public static boolean checkSASDKVersionIsValid() {
return checkSASDKVersionIsValid(MIN_SA_SDK_VERSION);
Expand All @@ -40,7 +44,7 @@ public static boolean checkSASecretVersionIsValid() {
return checkSASDKVersionIsValid(MIN_SA_SECRET_SDK_VERSION);
}

private static boolean checkSASDKVersionIsValid(String saVersion) {
public static boolean checkSASDKVersionIsValid(String saVersion) {
SensorsDataAPI sensorsDataAPI = SensorsDataAPI.sharedInstance();
if (sensorsDataAPI instanceof SensorsDataAPIEmptyImplementation) {
Log.e(TAG, "神策 Android 埋点 SDK 未集成或未初始化");
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation project(path: ':SensorsABTestSDK')
implementation 'com.tencent.tbs.tbssdk:sdk:43903'
implementation 'com.sensorsdata.analytics.android:SensorsAnalyticsSDK:6.3.3'
implementation 'com.sensorsdata.analytics.android:SensorsAnalyticsSDK:6.3.4'
// implementation files('libs/SensorsAnalyticsSDK-6.2.0.aar')
}

0 comments on commit d507c6e

Please sign in to comment.