Skip to content

Commit

Permalink
Release 0.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
weiqiangliu committed Jul 9, 2021
1 parent eb3780b commit 7f9458f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion 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.0.5"
version = "0.0.6"
android {
compileSdkVersion 29

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.sensorsdata.abtest.core.SensorsABTestCacheManager;
import com.sensorsdata.abtest.entity.SABErrorEnum;
import com.sensorsdata.abtest.util.AppInfoUtils;
import com.sensorsdata.abtest.util.TaskRunner;
import com.sensorsdata.abtest.util.UrlUtil;
import com.sensorsdata.analytics.android.sdk.SALog;
import com.sensorsdata.analytics.android.sdk.SensorsDataAPI;
Expand Down Expand Up @@ -194,9 +195,14 @@ public <T> void fastFetchABTest(final String paramName, final T defaultValue, fi
@Override
public void run() {
try {
T t = SensorsABTestCacheManager.getInstance().getExperimentVariableValue(paramName, defaultValue);
final T t = SensorsABTestCacheManager.getInstance().getExperimentVariableValue(paramName, defaultValue);
if (t != null && callBack != null) {
callBack.onResult(t);
TaskRunner.getUiThreadHandler().post(new Runnable() {
@Override
public void run() {
callBack.onResult(t);
}
});
} else {
asyncFetchABTestInner(paramName, defaultValue, timeoutMillSeconds, callBack);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ public void requestExperimentByParamName(final String distinctId, final String l
SALog.i(TAG, String.format("experiment param name:%s,试验参数名不正确,试验参数名必须为非空字符串!", paramName));
if (!mHasCallback) {
SABErrorDispatcher.dispatchSABException(SABErrorEnum.ASYNC_REQUEST_NULL_EXPERIMENT_PARAMETER_NAME, defaultValue);
callBack.onResult(defaultValue);
mHasCallback = true;
TaskRunner.getUiThreadHandler().post(new Runnable() {
@Override
public void run() {
callBack.onResult(defaultValue);
}
});
}
return;
}
Expand All @@ -73,8 +78,13 @@ public void requestExperimentByParamName(final String distinctId, final String l
if (context != null && !NetworkUtils.isNetworkAvailable(context)) {
if (!mHasCallback) {
SABErrorDispatcher.dispatchSABException(SABErrorEnum.ASYNC_REQUEST_NETWORK_UNAVAILABLE, defaultValue);
callBack.onResult(defaultValue);
mHasCallback = true;
TaskRunner.getUiThreadHandler().post(new Runnable() {
@Override
public void run() {
callBack.onResult(defaultValue);
}
});
}
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@

import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;


public class TaskRunner {
private static final String TAG = "SAB.TaskRunner";

private Handler mBackHandler;
private Handler mUiThreadHandler;

private static class SingletonHolder {
static TaskRunner sRunner = new TaskRunner();
Expand All @@ -40,5 +42,14 @@ public static synchronized Handler getBackHandler() {
}
return backHandler;
}

public static synchronized Handler getUiThreadHandler() {
Handler uiHandler = SingletonHolder.sRunner.mUiThreadHandler;
if (uiHandler == null) {
uiHandler = new Handler(Looper.getMainLooper());
SingletonHolder.sRunner.mUiThreadHandler = uiHandler;
}
return uiHandler;
}
}

0 comments on commit 7f9458f

Please sign in to comment.