Skip to content

Commit

Permalink
Release 6.7.9
Browse files Browse the repository at this point in the history
  • Loading branch information
dengshiwei committed Mar 12, 2024
1 parent 1061498 commit b51dd00
Show file tree
Hide file tree
Showing 16 changed files with 163 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void registerListener() {
protected void delayExecution(Activity activity) {
if (mActivityLifecycleCallbacks != null) {
mActivityLifecycleCallbacks.onActivityCreated(activity, null); //延迟初始化监听 onActivityCreated 处理
mActivityLifecycleCallbacks.onActivityStarted(activity); //延迟初始化监听 onActivityCreated 处理
mActivityLifecycleCallbacks.onDelayInitStarted(activity); //延迟初始化监听 onActivityStarted 处理
}
if (SALog.isLogEnabled()) {
SALog.i(TAG, "SDK init success by:" + activity.getClass().getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@
import com.sensorsdata.analytics.android.sdk.core.mediator.Modules;
import com.sensorsdata.analytics.android.sdk.core.mediator.SAModuleManager;
import com.sensorsdata.analytics.android.sdk.data.adapter.DbAdapter;
import com.sensorsdata.analytics.android.sdk.data.adapter.DbParams;
import com.sensorsdata.analytics.android.sdk.data.persistent.PersistentLoader;
import com.sensorsdata.analytics.android.sdk.dialog.SensorsDataDialogUtils;
import com.sensorsdata.analytics.android.sdk.exceptions.SensorsDataExceptionHandler;
import com.sensorsdata.analytics.android.sdk.internal.beans.EventType;
import com.sensorsdata.analytics.android.sdk.monitor.SensorsDataActivityLifecycleCallbacks;
import com.sensorsdata.analytics.android.sdk.plugin.encrypt.SAStoreManager;
import com.sensorsdata.analytics.android.sdk.util.AppInfoUtils;
import com.sensorsdata.analytics.android.sdk.util.JSONUtils;
import com.sensorsdata.analytics.android.sdk.util.SADataHelper;
Expand Down Expand Up @@ -83,6 +85,7 @@ public class ActivityLifecycleCallbacks implements SensorsDataActivityLifecycleC
private long messageReceiveTime = 0L;
private final int MESSAGE_CODE_APP_END = 0;
private final int MESSAGE_CODE_START = 100;
private final int MESSAGE_CODE_START_DELAY = 101;
private final int MESSAGE_CODE_STOP = 200;
private final int MESSAGE_CODE_TIMER = 300;
/**
Expand Down Expand Up @@ -184,6 +187,17 @@ public void onNewIntent(Intent intent) {

}

public void onDelayInitStarted(Activity activity) {
if (!SensorsDataDialogUtils.isSchemeActivity(activity) && !hasActivity(activity)) {
if (mStartActivityCount == 0) {
// 第一个页面进行页面信息解析
buildScreenProperties(activity);
}
sendActivityHandleMessage(MESSAGE_CODE_START_DELAY);
addActivity(activity);
}
}


private void initHandler() {
try {
Expand All @@ -195,6 +209,7 @@ public void handleMessage(Message msg) {
int code = msg.what;
switch (code) {
case MESSAGE_CODE_START:
case MESSAGE_CODE_START_DELAY:
handleStartedMessage(msg);
break;
case MESSAGE_CODE_STOP:
Expand Down Expand Up @@ -274,15 +289,19 @@ private void handleStartedMessage(Message message) {
// 读取 Message 中的时间戳
long eventTime = bundle.getLong(TIME);
properties.put("event_time", eventTime > 0 ? eventTime : System.currentTimeMillis());
SACoreHelper.getInstance().trackQueueEvent(new Runnable() {
@Override
public void run() {
mContextManager.trackEvent(new InputData().setEventName("$AppStart").
setProperties(SADataHelper.appendLibMethodAutoTrack(properties)).setEventType(EventType.TRACK));
}
});

SensorsDataAPI.sharedInstance().flush();
if (message.what == MESSAGE_CODE_START_DELAY) {//延迟初始化需要延迟触发
SAStoreManager.getInstance().setString(DbParams.APP_START_DATA, properties.toString());
} else {
SACoreHelper.getInstance().trackQueueEvent(new Runnable() {
@Override
public void run() {
mContextManager.trackEvent(new InputData().setEventName("$AppStart").
setProperties(SADataHelper.appendLibMethodAutoTrack(properties)).setEventType(EventType.TRACK));
}
});

SensorsDataAPI.sharedInstance().flush();
}
}
} catch (Exception e) {
SALog.i(TAG, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,4 +721,11 @@ public interface ISensorsDataAPI extends IUserIdentityAPI, SAAdvertAPIProtocol,
* @param limitKeys 限制性属性 key
*/
void registerLimitKeys(Map<String, String> limitKeys);

/**
* 是否开启远程配置
*
* @param enable true 开启,false 不开启
*/
void enableRemoteConfig(boolean enable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,20 @@ public void registerLimitKeys(Map<String, String> limitKeys) {
SAPropertyManager.getInstance().registerLimitKeys(limitKeys);
}

@Override
public void enableRemoteConfig(boolean enable) {
try {
if (mSAContextManager != null) {
mInternalConfigs.isRemoteConfigEnabled = enable;
if (mSAContextManager.getRemoteManager() != null) {
mSAContextManager.getRemoteManager().pullSDKConfigFromServer();
}
}
} catch (Exception e) {
SALog.printStackTrace(e);
}
}


/**
* Debug 模式,用于检验数据导入是否正确。该模式下,事件会逐条实时发送到 Sensors Analytics,并根据返回值检查
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,11 @@ public void registerLimitKeys(Map<String, String> limitKeys) {

}

@Override
public void enableRemoteConfig(boolean enable) {

}

static class EmptySAContext extends SAContextManager {

public EmptySAContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,22 @@
import com.sensorsdata.analytics.android.sdk.core.event.TrackEventProcessor;
import com.sensorsdata.analytics.android.sdk.core.mediator.SAModuleManager;
import com.sensorsdata.analytics.android.sdk.data.adapter.DbAdapter;
import com.sensorsdata.analytics.android.sdk.data.adapter.DbParams;
import com.sensorsdata.analytics.android.sdk.data.persistent.PersistentFirstDay;
import com.sensorsdata.analytics.android.sdk.data.persistent.PersistentLoader;
import com.sensorsdata.analytics.android.sdk.internal.beans.EventType;
import com.sensorsdata.analytics.android.sdk.internal.beans.InternalConfigOptions;
import com.sensorsdata.analytics.android.sdk.listener.SAEventListener;
import com.sensorsdata.analytics.android.sdk.plugin.encrypt.SAStoreManager;
import com.sensorsdata.analytics.android.sdk.plugin.property.PropertyPluginManager;
import com.sensorsdata.analytics.android.sdk.remote.BaseSensorsDataSDKRemoteManager;
import com.sensorsdata.analytics.android.sdk.remote.SensorsDataRemoteManager;
import com.sensorsdata.analytics.android.sdk.useridentity.UserIdentityAPI;
import com.sensorsdata.analytics.android.sdk.util.SADataHelper;
import com.sensorsdata.analytics.android.sdk.util.TimeUtils;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -89,7 +94,7 @@ public SAContextManager(SensorsDataAPI sensorsDataAPI, InternalConfigOptions int
}

/**
* execute delay task,before init module and track event
* execute delay task,before init module and track event
*/
private void executeDelayTask() {
SACoreHelper.getInstance().trackQueueEvent(new Runnable() {
Expand Down Expand Up @@ -183,12 +188,34 @@ public PropertyPluginManager getPluginManager() {

public void trackEvent(InputData inputData) {
try {
checkAppStart();
mTrackEventProcessor.trackEvent(inputData);
} catch (Exception e) {
SALog.printStackTrace(e);
}
}

private void checkAppStart() {
if (SAStoreManager.getInstance().isExists(DbParams.APP_START_DATA)) {
SACoreHelper.getInstance().trackQueueEvent(new Runnable() {
@Override
public void run() {
try {
String startData = SAStoreManager.getInstance().getString(DbParams.APP_START_DATA, "");
if (!TextUtils.isEmpty(startData)) {
JSONObject properties = new JSONObject(startData);
trackEvent(new InputData().setEventName("$AppStart").
setProperties(SADataHelper.appendLibMethodAutoTrack(properties)).setEventType(EventType.TRACK));
SAStoreManager.getInstance().remove(DbParams.APP_START_DATA);
}
} catch (Exception e) {
SALog.printStackTrace(e);
}
}
});
}
}

public Context getContext() {
return mContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class DbParams {
mEnableSDKUri, mDisableSDKUri, mRemoteConfigUri, mUserIdentities, mLoginIdKeyUri, mPushIdUri;
/* 替换 APP_END_DATA 数据,使用新的 SP 文件保存 */
public static final String APP_EXIT_DATA = "app_exit_data";
public static final String APP_START_DATA = "app_start_data";

public interface PersistentName {
String APP_END_DATA = "app_end_data";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,29 @@ protected void onCreate(Bundle savedInstanceState) {
}
//未初始化 SDK 时,直接拉起 LaunchActivity
if (SensorsDataAPI.sharedInstance() instanceof SensorsDataAPIEmptyImplementation) {
SALog.i(TAG, "onCreate SensorsDataAPIEmptyImplementation");
SensorsDataDialogUtils.startLaunchActivity(this);
} else {
SALog.i(TAG, "onCreate handleSchemeUrl");
SensorsDataUtils.handleSchemeUrl(this, this.getIntent());
}
}

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
//未初始化 SDK 时,直接拉起 LaunchActivity
if (SensorsDataAPI.sharedInstance() instanceof SensorsDataAPIEmptyImplementation) {
SensorsDataDialogUtils.startLaunchActivity(this);
} else {
SensorsDataUtils.handleSchemeUrl(this, this.getIntent());
try {
SALog.i(TAG, "onNewIntent intent = " + intent);
//未初始化 SDK 时,直接拉起 LaunchActivity
if (SensorsDataAPI.sharedInstance() instanceof SensorsDataAPIEmptyImplementation) {
SALog.i(TAG, "onNewIntent SensorsDataAPIEmptyImplementation");
SensorsDataDialogUtils.startLaunchActivity(this);
} else {
SALog.i(TAG, "onNewIntent handleSchemeUrl");
SensorsDataUtils.handleSchemeUrl(this, this.getIntent());
}
} catch (Exception e) {
SALog.printStackTrace(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ public class InternalConfigOptions {
public SensorsDataAPI.DebugMode debugMode = SensorsDataAPI.DebugMode.DEBUG_OFF;
// EventCallBack
public SensorsDataTrackEventCallBack sensorsDataTrackEventCallBack;
public boolean isRemoteConfigEnabled = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,22 @@ public void sensorsdata_track(String event) {
H5Helper.trackEventFromH5(event, enableVerify);
} catch (Exception e) {
SALog.printStackTrace(e);
SALog.i(TAG, "sensorsdata_track event = exception = " + event);
}
}

@JavascriptInterface
public boolean sensorsdata_verify(String event) {
try {
SALog.i(TAG, "sensorsdata_verify event = " + event);
SALog.i(TAG, "sensorsdata_verify event = " + event + ", enableVerify = " + enableVerify);
if (!enableVerify) {
sensorsdata_track(event);
return true;
}
return H5Helper.verifyEventFromH5(event);
} catch (Exception e) {
SALog.printStackTrace(e);
SALog.i(TAG, "sensorsdata_verify return false,exception = " + e.getMessage());
return false;
}
}
Expand All @@ -122,7 +124,6 @@ public String sensorsdata_get_server_url() {
@JavascriptInterface
public boolean sensorsdata_visual_verify(String event) {
try {
SALog.i(TAG, "sensorsdata_visual_verify event = " + event);
if (!enableVerify) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ public static void addJavascriptInterface(View webView, Object obj, String inter

public static boolean verifyEventFromH5(String eventInfo) {
try {
SALog.i("SA.AppWebViewInterface", "verifyEventFromH5 h5 eventInfo = " + eventInfo);
if (TextUtils.isEmpty(eventInfo)) {
return false;
}
JSONObject eventObject = new JSONObject(eventInfo);

String serverUrl = eventObject.optString("server_url");
SALog.i("SA.AppWebViewInterface", "verifyEventFromH5 h5 serverUrl = " + serverUrl);
if (!TextUtils.isEmpty(serverUrl)) {
if (!(new ServerUrl(serverUrl).check(new ServerUrl(SensorsDataAPI.getConfigOptions().getServerUrl())))) {
return false;
Expand All @@ -85,10 +87,12 @@ public static void trackEventFromH5(String eventInfo, boolean enableVerify) {
}

JSONObject eventObject = new JSONObject(eventInfo);
SALog.i("SA.AppWebViewInterface", "trackEventFromH5 h5 enableVerify = " + enableVerify);
if (enableVerify) {
String serverUrl = eventObject.optString("server_url");
SALog.i("SA.AppWebViewInterface", "trackEventFromH5 h5 serverUrl = " + serverUrl);
if (!TextUtils.isEmpty(serverUrl)) {
if (!(new ServerUrl(serverUrl).check(new ServerUrl(SensorsDataAPI.sharedInstance().getServerUrl())))) {
if (!(new ServerUrl(serverUrl).check(new ServerUrl(SensorsDataAPI.getConfigOptions().getServerUrl())))) {
return;
}
} else {
Expand Down Expand Up @@ -146,6 +150,7 @@ public static void handleJsMessage(WeakReference<View> view, final String messag

private static void trackEvent(final String eventInfo) {
if (SensorsDataAPI.sharedInstance() instanceof SensorsDataAPIEmptyImplementation) {
SALog.i("SA.AppWebViewInterface", "trackEvent SensorsDataAPIEmptyImplementation");
return;
}
SACoreHelper.getInstance().trackQueueEvent(new Runnable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private boolean isRequestValid() {
*/
private void writeRemoteRequestRandomTime() {
SAConfigOptions configOptions = mContextManager.getInternalConfigs().saConfigOptions;
if (configOptions == null) {
if (configOptions == null || !mContextManager.getInternalConfigs().isRemoteConfigEnabled) {// 此时就不保存随机时间
return;
}
//默认情况下,随机请求时间为最小时间间隔
Expand All @@ -112,7 +112,8 @@ private void cleanRemoteRequestRandomTime() {
@Override
public void pullSDKConfigFromServer() {
SAConfigOptions configOptions = mContextManager.getInternalConfigs().saConfigOptions;
if (configOptions == null || configOptions.isDisableSDK()) {
if (configOptions == null || configOptions.isDisableSDK()
|| !mContextManager.getInternalConfigs().isRemoteConfigEnabled && !mContextManager.getInternalConfigs().saConfigOptions.isEnableEncrypt()) {
return;
}

Expand Down Expand Up @@ -177,7 +178,9 @@ private void pullSDKConfigCount(final boolean enableConfigV) {
mPullSDKConfigCountDownTimer = new CountDownTimer(90 * 1000, 30 * 1000) {
@Override
public void onTick(long l) {
if (mSensorsDataAPI != null && !mSensorsDataAPI.isNetworkRequestEnable() || mContextManager.getInternalConfigs().saConfigOptions.isDisableSDK()) {
if (mSensorsDataAPI != null && !mSensorsDataAPI.isNetworkRequestEnable()
|| mContextManager.getInternalConfigs().saConfigOptions.isDisableSDK()
|| !mContextManager.getInternalConfigs().isRemoteConfigEnabled && !mContextManager.getInternalConfigs().saConfigOptions.isEnableEncrypt()) {
SALog.i(TAG, "Close network request or sdk is disable");
return;
}
Expand All @@ -200,7 +203,9 @@ public void onResponse(String response) {
if (!TextUtils.isEmpty(response)) {
SensorsDataSDKRemoteConfig sdkRemoteConfig = toSDKRemoteConfig(response);
SAModuleManager.getInstance().invokeModuleFunction(Modules.Encrypt.MODULE_NAME, Modules.Encrypt.METHOD_STORE_SECRET_KEY, response);
setSDKRemoteConfig(sdkRemoteConfig);
if (mContextManager.getInternalConfigs().isRemoteConfigEnabled) {//开启时才保存远程配置信息
setSDKRemoteConfig(sdkRemoteConfig);
}
}
SALog.i(TAG, "Remote request was successful,response data is " + response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static void handleSchemeUrl(Activity activity, Intent intent) {
if (activity != null && intent != null) {
uri = intent.getData();
}
SALog.i(TAG, "handleSchemeUrl uri = " + uri + ", intent = " + intent);
if (uri != null) {
SensorsDataAPI sensorsDataAPI = SensorsDataAPI.sharedInstance();
String host = uri.getHost();
Expand Down
Loading

0 comments on commit b51dd00

Please sign in to comment.