Skip to content

Commit

Permalink
Release 6.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
weiqiangliu committed Dec 10, 2021
1 parent d8787fd commit bdcfafc
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 31 deletions.
2 changes: 1 addition & 1 deletion SensorsAnalyticsSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'com.android.library'
apply plugin: 'signing'
apply plugin: 'maven-publish'

version = "6.1.0"
version = "6.1.1"
def min_plugin_version = "3.4.0"

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
Expand All @@ -36,13 +37,15 @@
import com.sensorsdata.analytics.android.sdk.ScreenAutoTracker;
import com.sensorsdata.analytics.android.sdk.SensorsDataAPI;
import com.sensorsdata.analytics.android.sdk.util.AopUtil;
import com.sensorsdata.analytics.android.sdk.util.FragmentCacheUtil;
import com.sensorsdata.analytics.android.sdk.util.SADataHelper;
import com.sensorsdata.analytics.android.sdk.util.SAFragmentUtils;
import com.sensorsdata.analytics.android.sdk.util.SensorsDataUtils;
import com.sensorsdata.analytics.android.sdk.util.WeakSet;

import org.json.JSONObject;

import java.lang.ref.WeakReference;
import java.util.Set;

/**
Expand Down Expand Up @@ -79,6 +82,8 @@ public void onViewCreated(Object object, View rootView, Bundle bundle) {
window.getDecorView().getRootView().setTag(R.id.sensors_analytics_tag_view_fragment_name, "");
}
}
//缓存 fragment
FragmentCacheUtil.setFragmentToCache(fragmentName, object);
} catch (Exception e) {
SALog.printStackTrace(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public PersistentFirstTrackInstallation(Future<SharedPreferences> loadStoredPref
super(loadStoredPreferences, PersistentLoader.PersistentName.FIRST_INSTALL, new PersistentSerializer<Boolean>() {
@Override
public Boolean load(String value) {
return Boolean.valueOf(value);
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public PersistentFirstTrackInstallationWithCallback(Future<SharedPreferences> lo
super(loadStoredPreferences, PersistentLoader.PersistentName.FIRST_INSTALL_CALLBACK, new PersistentSerializer<Boolean>() {
@Override
public Boolean load(String value) {
return Boolean.valueOf(value);
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@

package com.sensorsdata.analytics.android.sdk.util;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.text.TextUtils;
import android.util.LruCache;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
Expand All @@ -52,7 +50,6 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
Expand All @@ -61,10 +58,7 @@
import java.util.Locale;

public class AopUtil {

private static final String TAG = "SA.AopUtil";
@SuppressLint("NewApi")
private static LruCache<String, WeakReference<Object>> sLruCache = new LruCache<>(10);

// 采集 viewType 忽略以下包内 view 直接返回对应的基础控件 viewType
private static ArrayList<String> sOSViewPackage = new ArrayList<String>() {{
Expand Down Expand Up @@ -396,16 +390,20 @@ public static String getViewId(View view) {
try {
idString = (String) view.getTag(R.id.sensors_analytics_tag_view_id);
if (TextUtils.isEmpty(idString)) {
if (view.getId() != View.NO_ID) {
if (isValid(view.getId())) {
idString = view.getContext().getResources().getResourceEntryName(view.getId());
}
}
} catch (Exception e) {
//ignore
SALog.printStackTrace(e);
}
return idString;
}

private static boolean isValid(int id) {
return id != -1 && (id & 0xff000000) != 0 && (id & 0x00ff0000) != 0;
}

/**
* 采集 View 的 $element_type 主要区分继承系统 View 和继承系统 View 的自定义 View
*
Expand Down Expand Up @@ -738,26 +736,7 @@ public static Object getFragmentFromView(View view, Activity activity) {
}
}
}
if (!TextUtils.isEmpty(fragmentName)) {
WeakReference<Object> weakReference = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR1) {
weakReference = sLruCache.get(fragmentName);
}
Object object;
if (weakReference != null) {
object = weakReference.get();
if (object != null) {
return object;
}
}

object = Class.forName(fragmentName).newInstance();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
sLruCache.put(fragmentName, new WeakReference<>(object));
}

return object;
}
return FragmentCacheUtil.getFragmentFromCache(fragmentName);
}
} catch (Exception e) {
SALog.printStackTrace(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.sensorsdata.analytics.android.sdk.util;

import android.annotation.SuppressLint;
import android.os.Build;
import android.text.TextUtils;
import android.util.LruCache;

import com.sensorsdata.analytics.android.sdk.SALog;

import java.lang.ref.WeakReference;

public class FragmentCacheUtil {

@SuppressLint("NewApi")
private static LruCache<String, WeakReference<Object>> sFragmentLruCache = new LruCache<>(Integer.MAX_VALUE);

public static void setFragmentToCache(String fragmentName, Object object) {
if (!TextUtils.isEmpty(fragmentName) && null != object && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
sFragmentLruCache.put(fragmentName, new WeakReference<>(object));
}
}

public static Object getFragmentFromCache(String fragmentName) {
try {
if (!TextUtils.isEmpty(fragmentName)) {
WeakReference<Object> weakReference = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR1) {
weakReference = sFragmentLruCache.get(fragmentName);
}
Object object;
if (null != weakReference) {
object = weakReference.get();
if (null != object) {
return object;
}
}
object = Class.forName(fragmentName).newInstance();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
sFragmentLruCache.put(fragmentName, new WeakReference<>(object));
}
return object;
}
} catch (Exception e) {
SALog.printStackTrace(e);
}
return null;
}
}

0 comments on commit bdcfafc

Please sign in to comment.