正在查看: Vi App v10.18.0 应用的 AnalyticsMessages.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Vi App v10.18.0 应用的 AnalyticsMessages.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.mixpanel.android.mpmetrics;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.DisplayMetrics;
import com.mixpanel.android.mpmetrics.MPDbAdapter;
import com.mixpanel.android.util.HttpService;
import com.mixpanel.android.util.LegacyVersionUtils;
import com.mixpanel.android.util.MPLog;
import com.mixpanel.android.util.RemoteService;
import com.onmobile.rbtsdkui.analytics.AnalyticsConstants;
import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
class AnalyticsMessages {
private static final Map<Context, AnalyticsMessages> sInstances = new HashMap();
public final MPConfig mConfig;
public final Context mContext;
private final Worker mWorker;
public static class EventDescription extends MixpanelMessageDescription {
private final String mEventName;
private final boolean mIsAutomatic;
private final JSONObject mSessionMetadata;
public EventDescription(String str, JSONObject jSONObject, String str2, boolean z, JSONObject jSONObject2) {
super(str2, jSONObject);
this.mEventName = str;
this.mIsAutomatic = z;
this.mSessionMetadata = jSONObject2;
}
public String getEventName() {
return this.mEventName;
}
public JSONObject getProperties() {
return getMessage();
}
public JSONObject getSessionMetadata() {
return this.mSessionMetadata;
}
}
public static class GroupDescription extends MixpanelMessageDescription {
public String toString() {
return getMessage().toString();
}
}
public static class MixpanelDescription {
private final String mToken;
public MixpanelDescription(String str) {
this.mToken = str;
}
public String getToken() {
return this.mToken;
}
}
public static class MixpanelMessageDescription extends MixpanelDescription {
private final JSONObject mMessage;
public MixpanelMessageDescription(String str, JSONObject jSONObject) {
super(str);
if (jSONObject != null && jSONObject.length() > 0) {
Iterator<String> keys = jSONObject.keys();
while (keys.hasNext()) {
String next = keys.next();
try {
jSONObject.get(next).toString();
} catch (AssertionError e) {
jSONObject.remove(next);
MPLog.e("MixpanelAPI.Messages", "Removing people profile property from update (see https://github.com/mixpanel/mixpanel-android/issues/567)", e);
} catch (JSONException unused) {
}
}
}
this.mMessage = jSONObject;
}
public JSONObject getMessage() {
return this.mMessage;
}
}
public static class PeopleDescription extends MixpanelMessageDescription {
public PeopleDescription(JSONObject jSONObject, String str) {
super(str, jSONObject);
}
public boolean isAnonymous() {
return !getMessage().has("$distinct_id");
}
public String toString() {
return getMessage().toString();
}
}
public static class PushAnonymousPeopleDescription extends MixpanelDescription {
private final String mDistinctId;
public PushAnonymousPeopleDescription(String str, String str2) {
super(str2);
this.mDistinctId = str;
}
public String getDistinctId() {
return this.mDistinctId;
}
public String toString() {
return this.mDistinctId;
}
}
public static class UpdateEventsPropertiesDescription extends MixpanelDescription {
private final Map<String, String> mProps;
public Map<String, String> getProperties() {
return this.mProps;
}
}
public class Worker {
private long mAveFlushFrequency;
private long mFlushCount;
private Handler mHandler;
private final Object mHandlerLock;
private long mLastFlushTime;
private SystemInformation mSystemInformation;
public final AnalyticsMessages this$0;
public class AnalyticsMessageHandler extends Handler {
private MPDbAdapter mDbAdapter;
private int mFailedRetries;
private final long mFlushInterval;
private long mTrackEngageRetryAfter;
public final Worker this$1;
private JSONObject getDefaultEventProperties() throws JSONException {
JSONObject jSONObject = new JSONObject();
jSONObject.put("mp_lib", AnalyticsConstants.EVENT_PV_OS_ANDROID);
jSONObject.put("$lib_version", "7.3.1");
jSONObject.put("$os", "Android");
String str = Build.VERSION.RELEASE;
if (str == null) {
str = "UNKNOWN";
}
jSONObject.put("$os_version", str);
String str2 = Build.MANUFACTURER;
if (str2 == null) {
str2 = "UNKNOWN";
}
jSONObject.put("$manufacturer", str2);
String str3 = Build.BRAND;
if (str3 == null) {
str3 = "UNKNOWN";
}
jSONObject.put("$brand", str3);
String str4 = Build.MODEL;
jSONObject.put("$model", str4 != null ? str4 : "UNKNOWN");
DisplayMetrics displayMetrics = this.this$1.mSystemInformation.getDisplayMetrics();
jSONObject.put("$screen_dpi", displayMetrics.densityDpi);
jSONObject.put("$screen_height", displayMetrics.heightPixels);
jSONObject.put("$screen_width", displayMetrics.widthPixels);
String appVersionName = this.this$1.mSystemInformation.getAppVersionName();
if (appVersionName != null) {
jSONObject.put("$app_version", appVersionName);
jSONObject.put("$app_version_string", appVersionName);
}
Integer appVersionCode = this.this$1.mSystemInformation.getAppVersionCode();
if (appVersionCode != null) {
String valueOf = String.valueOf(appVersionCode);
jSONObject.put("$app_release", valueOf);
jSONObject.put("$app_build_number", valueOf);
}
Boolean valueOf2 = Boolean.valueOf(this.this$1.mSystemInformation.hasNFC());
if (valueOf2 != null) {
jSONObject.put("$has_nfc", valueOf2.booleanValue());
}
Boolean valueOf3 = Boolean.valueOf(this.this$1.mSystemInformation.hasTelephony());
if (valueOf3 != null) {
jSONObject.put("$has_telephone", valueOf3.booleanValue());
}
String currentNetworkOperator = this.this$1.mSystemInformation.getCurrentNetworkOperator();
if (currentNetworkOperator != null && !currentNetworkOperator.trim().isEmpty()) {
jSONObject.put("$carrier", currentNetworkOperator);
}
Boolean isWifiConnected = this.this$1.mSystemInformation.isWifiConnected();
if (isWifiConnected != null) {
jSONObject.put("$wifi", isWifiConnected.booleanValue());
}
Boolean isBluetoothEnabled = this.this$1.mSystemInformation.isBluetoothEnabled();
if (isBluetoothEnabled != null) {
jSONObject.put("$bluetooth_enabled", isBluetoothEnabled);
}
String bluetoothVersion = this.this$1.mSystemInformation.getBluetoothVersion();
if (bluetoothVersion != null) {
jSONObject.put("$bluetooth_version", bluetoothVersion);
}
return jSONObject;
}
private JSONObject prepareEventObject(EventDescription eventDescription) throws JSONException {
JSONObject jSONObject = new JSONObject();
JSONObject properties = eventDescription.getProperties();
JSONObject defaultEventProperties = getDefaultEventProperties();
defaultEventProperties.put("token", eventDescription.getToken());
if (properties != null) {
Iterator<String> keys = properties.keys();
while (keys.hasNext()) {
String next = keys.next();
defaultEventProperties.put(next, properties.get(next));
}
}
jSONObject.put("event", eventDescription.getEventName());
jSONObject.put("properties", defaultEventProperties);
jSONObject.put("$mp_metadata", eventDescription.getSessionMetadata());
return jSONObject;
}
private void sendAllData(MPDbAdapter mPDbAdapter, String str) {
RemoteService poster = this.this$1.this$0.getPoster();
AnalyticsMessages analyticsMessages = this.this$1.this$0;
if (!poster.isOnline(analyticsMessages.mContext, analyticsMessages.mConfig.getOfflineMode())) {
this.this$1.this$0.logAboutMessageToMixpanel("Not flushing data to Mixpanel because the device is not connected to the internet.");
return;
}
sendData(mPDbAdapter, str, MPDbAdapter.Table.EVENTS, this.this$1.this$0.mConfig.getEventsEndpoint());
sendData(mPDbAdapter, str, MPDbAdapter.Table.PEOPLE, this.this$1.this$0.mConfig.getPeopleEndpoint());
sendData(mPDbAdapter, str, MPDbAdapter.Table.GROUPS, this.this$1.this$0.mConfig.getGroupsEndpoint());
}
private void sendData(com.mixpanel.android.mpmetrics.MPDbAdapter r17, java.lang.String r18, com.mixpanel.android.mpmetrics.MPDbAdapter.Table r19, java.lang.String r20) {
throw new UnsupportedOperationException("Method not decompiled: com.mixpanel.android.mpmetrics.AnalyticsMessages.Worker.AnalyticsMessageHandler.sendData(com.mixpanel.android.mpmetrics.MPDbAdapter, java.lang.String, com.mixpanel.android.mpmetrics.MPDbAdapter$Table, java.lang.String):void");
}
@Override
public void handleMessage(Message message) {
String token;
String str;
if (this.mDbAdapter == null) {
AnalyticsMessages analyticsMessages = this.this$1.this$0;
MPDbAdapter makeDbAdapter = analyticsMessages.makeDbAdapter(analyticsMessages.mContext);
this.mDbAdapter = makeDbAdapter;
makeDbAdapter.cleanupEvents(System.currentTimeMillis() - this.this$1.this$0.mConfig.getDataExpiration(), MPDbAdapter.Table.EVENTS);
this.mDbAdapter.cleanupEvents(System.currentTimeMillis() - this.this$1.this$0.mConfig.getDataExpiration(), MPDbAdapter.Table.PEOPLE);
}
int i = -3;
try {
int i2 = message.what;
if (i2 == 0) {
PeopleDescription peopleDescription = (PeopleDescription) message.obj;
MPDbAdapter.Table table = peopleDescription.isAnonymous() ? MPDbAdapter.Table.ANONYMOUS_PEOPLE : MPDbAdapter.Table.PEOPLE;
this.this$1.this$0.logAboutMessageToMixpanel("Queuing people record for sending later");
this.this$1.this$0.logAboutMessageToMixpanel(" " + peopleDescription.toString());
token = peopleDescription.getToken();
i = this.mDbAdapter.addJSON(peopleDescription.getMessage(), token, table);
if (peopleDescription.isAnonymous()) {
i = 0;
}
} else if (i2 == 3) {
GroupDescription groupDescription = (GroupDescription) message.obj;
this.this$1.this$0.logAboutMessageToMixpanel("Queuing group record for sending later");
this.this$1.this$0.logAboutMessageToMixpanel(" " + groupDescription.toString());
token = groupDescription.getToken();
i = this.mDbAdapter.addJSON(groupDescription.getMessage(), token, MPDbAdapter.Table.GROUPS);
} else if (i2 == 1) {
EventDescription eventDescription = (EventDescription) message.obj;
try {
JSONObject prepareEventObject = prepareEventObject(eventDescription);
this.this$1.this$0.logAboutMessageToMixpanel("Queuing event for sending later");
this.this$1.this$0.logAboutMessageToMixpanel(" " + prepareEventObject.toString());
str = eventDescription.getToken();
try {
i = this.mDbAdapter.addJSON(prepareEventObject, str, MPDbAdapter.Table.EVENTS);
} catch (JSONException e) {
e = e;
MPLog.e("MixpanelAPI.Messages", "Exception tracking event " + eventDescription.getEventName(), e);
token = str;
if (i < this.this$1.this$0.mConfig.getBulkUploadLimit()) {
}
this.this$1.this$0.logAboutMessageToMixpanel("Flushing queue due to bulk upload limit (" + i + ") for project " + token);
this.this$1.updateFlushFrequency();
sendAllData(this.mDbAdapter, token);
return;
}
} catch (JSONException e2) {
e = e2;
str = null;
}
token = str;
} else if (i2 == 4) {
PushAnonymousPeopleDescription pushAnonymousPeopleDescription = (PushAnonymousPeopleDescription) message.obj;
String distinctId = pushAnonymousPeopleDescription.getDistinctId();
token = pushAnonymousPeopleDescription.getToken();
i = this.mDbAdapter.pushAnonymousUpdatesToPeopleDb(token, distinctId);
} else if (i2 == 7) {
token = ((MixpanelDescription) message.obj).getToken();
this.mDbAdapter.cleanupAllEvents(MPDbAdapter.Table.ANONYMOUS_PEOPLE, token);
} else {
if (i2 == 8) {
UpdateEventsPropertiesDescription updateEventsPropertiesDescription = (UpdateEventsPropertiesDescription) message.obj;
MPLog.d("MixpanelAPI.Messages", this.mDbAdapter.rewriteEventDataWithProperties(updateEventsPropertiesDescription.getProperties(), updateEventsPropertiesDescription.getToken()) + " stored events were updated with new properties.");
} else if (i2 == 2) {
this.this$1.this$0.logAboutMessageToMixpanel("Flushing queue due to scheduled or forced flush");
this.this$1.updateFlushFrequency();
token = (String) message.obj;
sendAllData(this.mDbAdapter, token);
} else if (i2 == 6) {
token = ((MixpanelDescription) message.obj).getToken();
this.mDbAdapter.cleanupAllEvents(MPDbAdapter.Table.EVENTS, token);
this.mDbAdapter.cleanupAllEvents(MPDbAdapter.Table.PEOPLE, token);
this.mDbAdapter.cleanupAllEvents(MPDbAdapter.Table.GROUPS, token);
this.mDbAdapter.cleanupAllEvents(MPDbAdapter.Table.ANONYMOUS_PEOPLE, token);
} else if (i2 == 5) {
MPLog.w("MixpanelAPI.Messages", "Worker received a hard kill. Dumping all events and force-killing. Thread id " + Thread.currentThread().getId());
synchronized (this.this$1.mHandlerLock) {
this.mDbAdapter.deleteDB();
this.this$1.mHandler = null;
Looper.myLooper().quit();
}
} else if (i2 == 9) {
LegacyVersionUtils.removeLegacyResidualImageFiles((File) message.obj);
} else {
MPLog.e("MixpanelAPI.Messages", "Unexpected message received by Mixpanel worker: " + message);
}
token = null;
}
if ((i < this.this$1.this$0.mConfig.getBulkUploadLimit() || i == -2) && this.mFailedRetries <= 0 && token != null) {
this.this$1.this$0.logAboutMessageToMixpanel("Flushing queue due to bulk upload limit (" + i + ") for project " + token);
this.this$1.updateFlushFrequency();
sendAllData(this.mDbAdapter, token);
return;
}
if (i <= 0 || hasMessages(2, token)) {
return;
}
this.this$1.this$0.logAboutMessageToMixpanel("Queue depth " + i + " - Adding flush in " + this.mFlushInterval);
if (this.mFlushInterval >= 0) {
Message obtain = Message.obtain();
obtain.what = 2;
obtain.obj = token;
obtain.arg1 = 1;
sendMessageDelayed(obtain, this.mFlushInterval);
}
} catch (RuntimeException e3) {
MPLog.e("MixpanelAPI.Messages", "Worker threw an unhandled exception", e3);
synchronized (this.this$1.mHandlerLock) {
this.this$1.mHandler = null;
try {
Looper.myLooper().quit();
MPLog.e("MixpanelAPI.Messages", "Mixpanel will not process any more analytics messages", e3);
} catch (Exception e4) {
MPLog.e("MixpanelAPI.Messages", "Could not halt looper", e4);
}
}
}
}
}
public void updateFlushFrequency() {
long currentTimeMillis = System.currentTimeMillis();
long j = this.mFlushCount;
long j2 = 1 + j;
long j3 = this.mLastFlushTime;
if (j3 > 0) {
long j4 = ((currentTimeMillis - j3) + (this.mAveFlushFrequency * j)) / j2;
this.mAveFlushFrequency = j4;
this.this$0.logAboutMessageToMixpanel("Average send frequency approximately " + (j4 / 1000) + " seconds.");
}
this.mLastFlushTime = currentTimeMillis;
this.mFlushCount = j2;
}
public void runMessage(Message message) {
synchronized (this.mHandlerLock) {
Handler handler = this.mHandler;
if (handler == null) {
this.this$0.logAboutMessageToMixpanel("Dead mixpanel worker dropping a message: " + message.what);
} else {
handler.sendMessage(message);
}
}
}
}
public void logAboutMessageToMixpanel(String str) {
MPLog.v("MixpanelAPI.Messages", str + " (Thread " + Thread.currentThread().getId() + ")");
}
public void eventsMessage(EventDescription eventDescription) {
Message obtain = Message.obtain();
obtain.what = 1;
obtain.obj = eventDescription;
this.mWorker.runMessage(obtain);
}
public RemoteService getPoster() {
return new HttpService();
}
public MPDbAdapter makeDbAdapter(Context context) {
return MPDbAdapter.getInstance(context);
}
public void peopleMessage(PeopleDescription peopleDescription) {
Message obtain = Message.obtain();
obtain.what = 0;
obtain.obj = peopleDescription;
this.mWorker.runMessage(obtain);
}
public void postToServer(MixpanelDescription mixpanelDescription) {
Message obtain = Message.obtain();
obtain.what = 2;
obtain.obj = mixpanelDescription.getToken();
obtain.arg1 = 0;
this.mWorker.runMessage(obtain);
}
public void pushAnonymousPeopleMessage(PushAnonymousPeopleDescription pushAnonymousPeopleDescription) {
Message obtain = Message.obtain();
obtain.what = 4;
obtain.obj = pushAnonymousPeopleDescription;
this.mWorker.runMessage(obtain);
}
public void logAboutMessageToMixpanel(String str, Throwable th) {
MPLog.v("MixpanelAPI.Messages", str + " (Thread " + Thread.currentThread().getId() + ")", th);
}
}