Skip to content

Commit

Permalink
Release 3.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzhzh committed Mar 25, 2019
1 parent d3670ea commit 51b15c9
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 83 deletions.
2 changes: 1 addition & 1 deletion SensorsAnalyticsSDK/build.gradle
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

version = "3.0.4"
version = "3.0.5"

android {
compileSdkVersion 23
Expand Down
@@ -0,0 +1,57 @@
/**Created by dengshiwei on 2019/03/11.
* Copyright © 2015-2019 Sensors Data Inc. All rights reserved. */

package com.sensorsdata.analytics.android.sdk;

public final class SAConfigOptions {
/**
* 请求配置地址,默认从 ServerUrl 解析
*/
private String remoteConfigUrl;

/**
* 数据上报服务器地址
*/
private String serverUrl;

/**
* 私有构造函数
*/
private SAConfigOptions(){}

/**
* 获取 SAOptionsConfig 实例
* @param serverUrl,数据上报服务器地址
*/
public SAConfigOptions(String serverUrl) {
this.serverUrl = serverUrl;
}

/**
* 设置远程配置请求地址
* @param remoteConfigUrl,远程配置请求地址
* @return SAOptionsConfig
*/
public SAConfigOptions setRemoteConfigUrl(String remoteConfigUrl) {
this.remoteConfigUrl = remoteConfigUrl;
return this;
}

/**
* 设置数据上报地址
* @param serverUrl,数据上报地址
* @return SAOptionsConfig
*/
public SAConfigOptions setServerUrl(String serverUrl) {
this.serverUrl = serverUrl;
return this;
}

String getRemoteConfigUrl() {
return remoteConfigUrl;
}

String getServerUrl() {
return serverUrl;
}
}
Expand Up @@ -430,7 +430,7 @@ public static SensorsDataAPI sharedInstance(Context context) {
*/
@Deprecated
public static SensorsDataAPI sharedInstance(Context context, String serverURL, DebugMode debugMode) {
return getInstance(context,serverURL,debugMode);
return getInstance(context, serverURL, debugMode);
}

/**
Expand All @@ -441,10 +441,21 @@ public static SensorsDataAPI sharedInstance(Context context, String serverURL, D
* @return SensorsDataAPI单例
*/
public static SensorsDataAPI sharedInstance(Context context, String serverURL) {
return getInstance(context,serverURL,DebugMode.DEBUG_OFF);
return getInstance(context, serverURL, DebugMode.DEBUG_OFF);
}

private static SensorsDataAPI getInstance(Context context, String serverURL, DebugMode debugMode){
/**
* 初始化并获取 SensorsDataAPI 单例
* @param context App 的 Context
* @param saConfigOptions SDK 的配置项
* @return SensorsDataAPI 单例
*/
public static SensorsDataAPI sharedInstance(Context context, SAConfigOptions saConfigOptions) {
mSAConfigOptions = saConfigOptions;
return getInstance(context, saConfigOptions.getServerUrl(), DebugMode.DEBUG_OFF);
}

private static SensorsDataAPI getInstance(Context context, String serverURL, DebugMode debugMode) {
if (null == context) {
return new SensorsDataAPIEmptyImplementation();
}
Expand Down Expand Up @@ -535,21 +546,32 @@ public void run() {
return;
}

URL url = null;
URL url;
String configUrl = null;
int pathPrefix = mServerUrl.lastIndexOf("/");
if (pathPrefix != -1) {
configUrl = mServerUrl.substring(0, pathPrefix);
if (mSAConfigOptions != null && !TextUtils.isEmpty(mSAConfigOptions.getRemoteConfigUrl())) {
configUrl = mSAConfigOptions.getRemoteConfigUrl();
} else {
int pathPrefix = mServerUrl.lastIndexOf("/");
if (pathPrefix != -1) {
configUrl = mServerUrl.substring(0, pathPrefix);
configUrl = configUrl + "/config/Android.conf";
}
}

if (!TextUtils.isEmpty(configUrl)) {
String configVersion = null;
if (mSDKRemoteConfig != null) {
configVersion = mSDKRemoteConfig.getV();
}

configUrl = configUrl + "/config/Android.conf";

if (configVersion != null) {
configUrl = configUrl + "?v=" + configVersion;
if (!TextUtils.isEmpty(configVersion)) {
if (configUrl.contains("?")) {
configUrl = configUrl + "&v=" + configVersion;
} else {
configUrl = configUrl + "?v=" + configVersion;
}
}
SALog.d(TAG, "Android remote config url:" + configUrl);
}

url = new URL(configUrl);
Expand All @@ -575,8 +597,11 @@ public void run() {
while ((data = bufferedReader.readLine()) != null) {
result.append(data);
}
SensorsDataSDKRemoteConfig sdkRemoteConfig = SensorsDataUtils.toSDKRemoteConfig(result.toString());
setSDKRemoteConfig(sdkRemoteConfig, false);
data = result.toString();
if (!TextUtils.isEmpty(data)) {
SensorsDataSDKRemoteConfig sdkRemoteConfig = SensorsDataUtils.toSDKRemoteConfig(data);
setSDKRemoteConfig(sdkRemoteConfig, false);
}
}
} catch (Exception e) {
com.sensorsdata.analytics.android.sdk.SALog.printStackTrace(e);
Expand Down Expand Up @@ -835,7 +860,7 @@ public void setFlushBulkSize(int flushBulkSize) {
*/
@Override
public void setSessionIntervalTime(int sessionIntervalTime) {
if(DbAdapter.getInstance() == null){
if (DbAdapter.getInstance() == null) {
SALog.i(TAG, "The static method sharedInstance(context, serverURL, debugMode) should be called before calling sharedInstance()");
return;
}
Expand All @@ -859,7 +884,7 @@ public void setSessionIntervalTime(int sessionIntervalTime) {
*/
@Override
public int getSessionIntervalTime() {
if(DbAdapter.getInstance() == null){
if (DbAdapter.getInstance() == null) {
SALog.i(TAG, "The static method sharedInstance(context, serverURL, debugMode) should be called before calling sharedInstance()");
return 30 * 1000;
}
Expand All @@ -879,8 +904,8 @@ public void setGPSLocation(double latitude, double longitude) {
mGPSLocation = new SensorsDataGPSLocation();
}

mGPSLocation.setLatitude((long)(latitude * Math.pow(10, 6)));
mGPSLocation.setLongitude((long)(longitude * Math.pow(10, 6)));
mGPSLocation.setLatitude((long) (latitude * Math.pow(10, 6)));
mGPSLocation.setLongitude((long) (longitude * Math.pow(10, 6)));
} catch (Exception e) {
com.sensorsdata.analytics.android.sdk.SALog.printStackTrace(e);
}
Expand Down Expand Up @@ -1083,7 +1108,8 @@ public void trackAppCrash() {
public void process(SensorsDataAPI m);
}

/* package */ static void allInstances(InstanceProcessor processor) {
/* package */
static void allInstances(InstanceProcessor processor) {
synchronized (sInstanceMap) {
for (final SensorsDataAPI instance : sInstanceMap.values()) {
processor.process(instance);
Expand Down Expand Up @@ -1291,7 +1317,7 @@ public void resumeAutoTrackActivities(List<Class<?>> activitiesList) {
return;
}

if (mAutoTrackIgnoredActivities == null){
if (mAutoTrackIgnoredActivities == null) {
mAutoTrackIgnoredActivities = new ArrayList<>();
}

Expand Down Expand Up @@ -1475,7 +1501,7 @@ public boolean isFragmentAutoTrackAppViewScreen(Class<?> fragment) {
if (fragment.getClass().getAnnotation(SensorsDataIgnoreTrackAppViewScreen.class) != null) {
return false;
}
} catch (Exception e){
} catch (Exception e) {
com.sensorsdata.analytics.android.sdk.SALog.printStackTrace(e);
}

Expand Down Expand Up @@ -1538,7 +1564,7 @@ public void ignoreAutoTrackEventType(List<AutoTrackEventType> eventTypeList) {
return;
}

for (AutoTrackEventType eventType: eventTypeList) {
for (AutoTrackEventType eventType : eventTypeList) {
if (eventType != null && mAutoTrackEventTypeList.contains(eventType)) {
mAutoTrackEventTypeList.remove(eventType);
}
Expand All @@ -1560,7 +1586,7 @@ public boolean isAutoTrackEventTypeIgnored(AutoTrackEventType eventType) {
return mSDKRemoteConfig.isAutoTrackEventTypeIgnored(eventType);
}
}
if (eventType != null && !mAutoTrackEventTypeList.contains(eventType)) {
if (eventType != null && !mAutoTrackEventTypeList.contains(eventType)) {
return true;
}
return false;
Expand Down Expand Up @@ -1647,7 +1673,7 @@ public void setViewID(Object alertDialog, String viewID) {
return;
}

Window window = (Window)getWindowMethod.invoke(alertDialog);
Window window = (Window) getWindowMethod.invoke(alertDialog);
if (window != null) {
window.getDecorView().setTag(R.id.sensors_analytics_tag_view_id, viewID);
}
Expand Down Expand Up @@ -1708,7 +1734,7 @@ public void ignoreView(View view) {
@Override
public void ignoreView(View view, boolean ignore) {
if (view != null) {
view.setTag(R.id.sensors_analytics_tag_view_ignored, ignore ? "1": "0");
view.setTag(R.id.sensors_analytics_tag_view_ignored, ignore ? "1" : "0");
}
}

Expand Down Expand Up @@ -1803,7 +1829,7 @@ public void addHeatMapActivities(List<Class<?>> activitiesList) {
return;
}

for (Class<?> activity: activitiesList) {
for (Class<?> activity : activitiesList) {
if (activity != null) {
if (!mHeatMapActivities.contains(activity.hashCode())) {
mHeatMapActivities.add(activity.hashCode());
Expand Down Expand Up @@ -1957,7 +1983,7 @@ public void login(final String loginId) {
* @param properties 用户登录属性
*/
@Override
public void login(final String loginId , final JSONObject properties) {
public void login(final String loginId, final JSONObject properties) {
try {
assertDistinctId(loginId);
} catch (Exception e) {
Expand Down Expand Up @@ -2561,9 +2587,9 @@ public void trackViewScreen(final Object fragment) {
//ignored
}

if (!(supportFragmentClass !=null && supportFragmentClass.isInstance(fragment)) &&
!(appFragmentClass !=null && appFragmentClass.isInstance(fragment)) &&
!(androidXFragmentClass !=null && androidXFragmentClass.isInstance(fragment))) {
if (!(supportFragmentClass != null && supportFragmentClass.isInstance(fragment)) &&
!(appFragmentClass != null && appFragmentClass.isInstance(fragment)) &&
!(androidXFragmentClass != null && androidXFragmentClass.isInstance(fragment))) {
return;
}

Expand All @@ -2588,7 +2614,7 @@ public void run() {
try {
Method getActivityMethod = fragment.getClass().getMethod("getActivity");
if (getActivityMethod != null) {
activity = (Activity)getActivityMethod.invoke(fragment);
activity = (Activity) getActivityMethod.invoke(fragment);
}
} catch (Exception e) {
//ignored
Expand All @@ -2602,7 +2628,7 @@ public void run() {
}

if (!TextUtils.isEmpty(title)) {
properties.put(AopConstants.TITLE,title);
properties.put(AopConstants.TITLE, title);
}

properties.put("$screen_name", screenName);
Expand Down Expand Up @@ -2840,7 +2866,7 @@ public void run() {
* @param properties 属性列表
*/
@Override
public void profileSetOnce(final JSONObject properties) {
public void profileSetOnce(final JSONObject properties) {
mTrackTaskManager.addTrackEventTask(new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -3527,7 +3553,7 @@ private void trackEvent(final EventType eventType, final String eventName, final
libProperties.put("$lib_detail", libDetail);

//防止用户自定义事件以及公共属性可能会加$device_id属性,导致覆盖sdk原始的$device_id属性值
if (sendProperties.has("$device_id")){//由于profileSet等类型事件没有$device_id属性,故加此判断
if (sendProperties.has("$device_id")) {//由于profileSet等类型事件没有$device_id属性,故加此判断
if (mDeviceInfo.containsKey("$device_id")) {
sendProperties.put("$device_id", mDeviceInfo.get("$device_id"));
}
Expand Down Expand Up @@ -3569,7 +3595,7 @@ public void resumeTrackTaskThread() {
/**
* 点击图是否进行检查 SSL
* @return boolean 是否进行检查 */
protected boolean isSSLCertificateChecking(){
protected boolean isSSLCertificateChecking() {
return mIsSSLCertificateChecking;
}

Expand Down Expand Up @@ -3661,7 +3687,7 @@ public void profilePushId(String propertyKey, String pushId) {
try {
assertKey(propertyKey);
if (TextUtils.isEmpty(pushId)) {
SALog.d(TAG,"pushId is empty");
SALog.d(TAG, "pushId is empty");
return;
}
String distinctId = getLoginId();
Expand All @@ -3680,12 +3706,11 @@ public void profilePushId(String propertyKey, String pushId) {
}
}


// 可视化埋点功能最低API版本
static final int VTRACK_SUPPORTED_MIN_API = 16;

// SDK版本
static final String VERSION = "3.0.4";
static final String VERSION = "3.0.5";
// 此属性插件会进行访问,谨慎删除。当前 SDK 版本所需插件最低版本号,设为空,意为没有任何限制
static final String MIN_PLUGIN_VERSION = "3.0.0";

Expand All @@ -3704,9 +3729,11 @@ public void profilePushId(String propertyKey, String pushId) {
private static SensorsDataGPSLocation mGPSLocation;

// Configures
/* SensorsAnalytics 地址 */
/* SensorsAnalytics 地址 */
private String mServerUrl;
private String mOriginServerUrl;
/* 远程配置 */
private static SAConfigOptions mSAConfigOptions;
/* Debug模式选项 */
private DebugMode mDebugMode = DebugMode.DEBUG_OFF;
/* Flush时间间隔 */
Expand Down

0 comments on commit 51b15c9

Please sign in to comment.