Skip to content

Commit

Permalink
Release 6.6.5
Browse files Browse the repository at this point in the history
  • Loading branch information
weiqiangliu committed Mar 24, 2023
1 parent 231f227 commit 5daf981
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 21 deletions.
8 changes: 6 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
buildscript {
apply from: "script_config/config.gradle"
repositories {
jcenter()
mavenCentral()
google()
maven {
url 'https://maven.google.com'
}
maven{
url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'
}
maven {
url './repo'
}
Expand All @@ -27,12 +29,14 @@ buildscript {

allprojects {
repositories {
jcenter()
mavenCentral()
google()
maven {
url 'https://maven.google.com'
}
maven{
url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'
}
maven {
url '../repo'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public abstract class Event {
public abstract JSONObject toJSONObject();

public long getTime() {
return mTime;
return mTime == 0 ? System.currentTimeMillis() : mTime;
}

public void setTime(long time) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private void appendNativeProperty(EventType eventType, TrackEvent trackEvent, SA
SADataHelper.addCarrier(contextManager.getContext(), trackEvent.getProperties());
if (eventType.isTrack()) {
//是否首日访问
trackEvent.getProperties().put("$is_first_day", contextManager.isFirstDay(trackEvent.getTime()));
trackEvent.getProperties().put("$is_first_day", contextManager.isFirstDay(trackEvent.getExtras().optLong("time")));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ int queryDataCount(Uri uri, int select) {
break;
}
if (selectionArgs != null) {
return queryDataCount(uri, null, DbParams.KEY_IS_INSTANT_EVENT + "=?", selectionArgs, null);
return queryDataCount(uri, new String[]{"_id"}, DbParams.KEY_IS_INSTANT_EVENT + "=?", selectionArgs, null);
}
return queryDataCount(uri, null, null, null, null);
return queryDataCount(uri, new String[]{"_id"}, null, null, null);
}

/**
Expand All @@ -111,12 +111,30 @@ int queryDataCount(Uri uri, String[] projection, String selection,
return 0;
}

String getFirstRowId(Uri uri, String instant_event) {
Cursor cursor = null;
try {
cursor = contentResolver.query(uri, new String[]{"_id"}, DbParams.KEY_IS_INSTANT_EVENT + "=?", new String[]{instant_event}, DbParams.KEY_CREATED_AT + " ASC LIMIT " + 1);
if (cursor != null) {
return cursor.getString(cursor.getColumnIndexOrThrow("_id"));
}
} catch (Exception ex) {
SALog.printStackTrace(ex);
} finally {
if (cursor != null) {
cursor.close();
}
}
return "";
}

/**
* delete data
*/
void deleteData(Uri uri, String id) {
try {
if (DbParams.DB_DELETE_ALL.equals(id)) {
SALog.i(TAG, "deleteData DB_DELETE_ALL");
contentResolver.delete(uri, null, null);
} else {
contentResolver.delete(uri, "_id <= ?", new String[]{id});
Expand All @@ -131,10 +149,10 @@ void deleteData(Uri uri, String id) {
*
* @param uri Uri
* @param ids 指定的 id 集合
* @return 数据库中遗留数据条数
*/
public void deleteData(Uri uri, JSONArray ids) {
try {
SALog.i(TAG, "deleteData ids = " + ids);
mContext.getContentResolver().delete(uri, "_id in " + buildIds(ids), null);
} catch (Exception e) {
SALog.printStackTrace(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteBlobTooBigException;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.text.TextUtils;
Expand Down Expand Up @@ -77,6 +78,23 @@ String[] queryData(Uri uri, int limit) {

@Override
String[] queryData(Uri uri, boolean is_instant_event, int limit) {
try {
return queryDataInner(uri, is_instant_event, limit);
} catch (SQLiteBlobTooBigException bigException) {
SALog.i(TAG, "Could not pull records for SensorsData out of database events. SQLiteBlobTooBigException ", bigException);
return handleBigException(uri, is_instant_event);
} catch (final SQLiteException e) {
SALog.i(TAG, "Could not pull records for SensorsData out of database events. Waiting to send.", e);
}
return null;
}

@Override
void deleteData(Uri uri, String id) {
super.deleteData(uri, id);
}

private String[] queryDataInner(Uri uri, boolean is_instant_event, int limit) {
Cursor cursor = null;
String data = null;
String eventIds = null;
Expand Down Expand Up @@ -117,10 +135,6 @@ String[] queryData(Uri uri, boolean is_instant_event, int limit) {
eventIds = idArray.toString();
}
}
} catch (final SQLiteException e) {
SALog.i(TAG, "Could not pull records for SensorsData out of database events. Waiting to send.", e);
eventIds = null;
data = null;
} finally {
if (cursor != null) {
cursor.close();
Expand All @@ -133,8 +147,18 @@ String[] queryData(Uri uri, boolean is_instant_event, int limit) {
return null;
}

@Override
void deleteData(Uri uri, String id) {
super.deleteData(uri, id);
/*
用于处理 SQLiteBlobTooBigException 的场景,出现此类情况时,只读取一条数据上报
*/
private String[] handleBigException(Uri uri, boolean is_instant_event) {
try {
return queryDataInner(uri, is_instant_event, 1);
} catch (SQLiteBlobTooBigException bigException) {//说明第一条数据就是 SQLiteBlobTooBigException,该条数据一直无法上报,所以删除处理
deleteData(uri, getFirstRowId(uri, is_instant_event ? "1" : "0"));
SALog.printStackTrace(bigException);
} catch (Exception e) {
SALog.printStackTrace(e);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void assertPropertyTypes(JSONObject properties) throws InvalidData
String key = iterator.next();
try {
// Check Keys
if (!assertPropertyKey(key)){
if (!assertPropertyKey(key)) {
iterator.remove();
continue;
}
Expand Down Expand Up @@ -93,8 +93,15 @@ public static void assertPropertyTypes(JSONObject properties) throws InvalidData
continue;
}

if (value instanceof String && ((String) value).length() > MAX_LENGTH_1024) {
SALog.i(TAG, value + " length is longer than " + MAX_LENGTH_1024);
if ("app_crashed_reason".equals(key) && value instanceof String && ((String) value).length() > 8191 * 2) {
SALog.d(TAG, "The property value is too long. [key='" + key
+ "', value='" + value + "']");
value = ((String) value).substring(0, 8191 * 2) + "$";
properties.put(key, value);
} else if (value instanceof String && ((String) value).length() > 8191) {
properties.put(key, ((String) value).substring(0, 8191) + "$");
SALog.d(TAG, "The property value is too long. [key='" + key
+ "', value='" + value + "']");
}
} catch (JSONException e) {
throw new InvalidDataException("Unexpected property key. [key='" + key + "']");
Expand All @@ -106,7 +113,7 @@ public static void assertPropertyTypes(JSONObject properties) throws InvalidData

public static void assertEventName(String key) {
if (TextUtils.isEmpty(key)) {
SALog.i(TAG,"EventName is empty or null");
SALog.i(TAG, "EventName is empty or null");
return;
}
int length = key.length();
Expand All @@ -121,6 +128,7 @@ public static void assertEventName(String key) {

/**
* 校验属性 key、item_type
*
* @param key key、item_type
* @return true 为不删除该属性,false 需要移除属性
*/
Expand All @@ -143,6 +151,7 @@ public static boolean assertPropertyKey(String key) {

/**
* 校验 item_id
*
* @param key key、item_type
*/
public static void assertItemId(String key) {
Expand All @@ -167,6 +176,7 @@ public static void assertDistinctId(String value) throws InvalidDataException {

/**
* 校验属性
*
* @param property 属性
* @return String
*/
Expand Down Expand Up @@ -203,6 +213,7 @@ public static void addTimeProperty(JSONObject jsonObject) {
}
}
}

public static void addCarrier(Context context, JSONObject property) {
try {
if (TextUtils.isEmpty(property.optString("$carrier"))) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sensorsdata.analytics.android.sdk.exposure;

import android.os.Build;
import android.view.View;

import com.sensorsdata.analytics.android.sdk.core.SAContextManager;
Expand All @@ -14,6 +15,10 @@ public class SAExposureProtocolImpl implements SAModuleProtocol {

@Override
public void install(SAContextManager contextManager) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
setModuleState(false);
return;
}
if (!contextManager.getInternalConfigs().saConfigOptions.isDisableSDK()) {
setModuleState(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class PushUtils {
public static String getJPushSDKName(byte whichPushSDK) {
String name;
switch (whichPushSDK) {
case 0:
name = "Jpush";
break;
case 1:
name = "Xiaomi";
break;
Expand All @@ -43,8 +46,14 @@ public static String getJPushSDKName(byte whichPushSDK) {
case 5:
name = "vivo";
break;
case 6:
name = "Asus";
break;
case 8:
name = "fcm";
break;
default:
name = null;
name = "Jpush";
}
return name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ public class PushUtilsTest {

@Test
public void getJPushSDKName() {
Assert.assertEquals("Jpush", PushUtils.getJPushSDKName((byte) 0));
Assert.assertEquals("Xiaomi", PushUtils.getJPushSDKName((byte) 1));
Assert.assertEquals("HUAWEI", PushUtils.getJPushSDKName((byte) 2));
Assert.assertEquals("Meizu", PushUtils.getJPushSDKName((byte) 3));
Assert.assertEquals("OPPO", PushUtils.getJPushSDKName((byte) 4));
Assert.assertEquals("vivo", PushUtils.getJPushSDKName((byte) 5));
Assert.assertEquals("Asus", PushUtils.getJPushSDKName((byte) 6));
Assert.assertEquals("fcm", PushUtils.getJPushSDKName((byte) 8));
Assert.assertEquals("Jpush", PushUtils.getJPushSDKName((byte) 100));
}
}
4 changes: 2 additions & 2 deletions script_config/config.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
ext {
versions = [
// 全量 SDK 版本号
sdk_version : "6.6.4",
sdk_version : "6.6.5",
// 最小插件版本号依赖
min_plugin_version: "3.5.2",
// 子模块版本号
module_version : "0.1.7"
module_version : "0.1.8"
]

publish = [
Expand Down

0 comments on commit 5daf981

Please sign in to comment.