177 lines
5.6 KiB
Java
177 lines
5.6 KiB
Java
package com.facebook.appevents;
|
|
|
|
import android.os.Bundle;
|
|
import com.facebook.FacebookException;
|
|
import com.facebook.LoggingBehavior;
|
|
import com.facebook.internal.Logger;
|
|
import com.facebook.internal.Utility;
|
|
import java.io.Serializable;
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.security.MessageDigest;
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.util.HashSet;
|
|
import java.util.Locale;
|
|
import java.util.UUID;
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
/* loaded from: classes.dex */
|
|
class AppEvent implements Serializable {
|
|
private static final HashSet<String> e = new HashSet<>();
|
|
private final JSONObject a;
|
|
private final boolean b;
|
|
private final String c;
|
|
private final String d;
|
|
|
|
static class SerializationProxyV1 implements Serializable {
|
|
private final String a;
|
|
private final boolean b;
|
|
|
|
private Object readResolve() throws JSONException {
|
|
return new AppEvent(this.a, this.b, null);
|
|
}
|
|
}
|
|
|
|
static class SerializationProxyV2 implements Serializable {
|
|
private final String a;
|
|
private final boolean b;
|
|
private final String c;
|
|
|
|
private Object readResolve() throws JSONException {
|
|
return new AppEvent(this.a, this.b, this.c);
|
|
}
|
|
|
|
private SerializationProxyV2(String str, boolean z, String str2) {
|
|
this.a = str;
|
|
this.b = z;
|
|
this.c = str2;
|
|
}
|
|
}
|
|
|
|
private String e() {
|
|
return a(this.a.toString());
|
|
}
|
|
|
|
private Object writeReplace() {
|
|
return new SerializationProxyV2(this.a.toString(), this.b, this.d);
|
|
}
|
|
|
|
public boolean a() {
|
|
return this.b;
|
|
}
|
|
|
|
public JSONObject b() {
|
|
return this.a;
|
|
}
|
|
|
|
public String c() {
|
|
return this.c;
|
|
}
|
|
|
|
public boolean d() {
|
|
if (this.d == null) {
|
|
return true;
|
|
}
|
|
return e().equals(this.d);
|
|
}
|
|
|
|
public String toString() {
|
|
return String.format("\"%s\", implicit: %b, json: %s", this.a.optString("_eventName"), Boolean.valueOf(this.b), this.a.toString());
|
|
}
|
|
|
|
public AppEvent(String str, String str2, Double d, Bundle bundle, boolean z, UUID uuid) throws JSONException, FacebookException {
|
|
this.a = a(str, str2, d, bundle, z, uuid);
|
|
this.b = z;
|
|
this.c = str2;
|
|
this.d = e();
|
|
}
|
|
|
|
private static JSONObject a(String str, String str2, Double d, Bundle bundle, boolean z, UUID uuid) throws FacebookException, JSONException {
|
|
b(str2);
|
|
JSONObject jSONObject = new JSONObject();
|
|
jSONObject.put("_eventName", str2);
|
|
jSONObject.put("_eventName_md5", a(str2));
|
|
jSONObject.put("_logTime", System.currentTimeMillis() / 1000);
|
|
jSONObject.put("_ui", str);
|
|
if (uuid != null) {
|
|
jSONObject.put("_session_id", uuid);
|
|
}
|
|
if (d != null) {
|
|
jSONObject.put("_valueToSum", d.doubleValue());
|
|
}
|
|
if (z) {
|
|
jSONObject.put("_implicitlyLogged", "1");
|
|
}
|
|
String e2 = AppEventsLogger.e();
|
|
if (e2 != null) {
|
|
jSONObject.put("_app_user_id", e2);
|
|
}
|
|
if (bundle != null) {
|
|
for (String str3 : bundle.keySet()) {
|
|
b(str3);
|
|
Object obj = bundle.get(str3);
|
|
if (!(obj instanceof String) && !(obj instanceof Number)) {
|
|
throw new FacebookException(String.format("Parameter value '%s' for key '%s' should be a string or a numeric type.", obj, str3));
|
|
}
|
|
jSONObject.put(str3, obj.toString());
|
|
}
|
|
}
|
|
if (!z) {
|
|
Logger.a(LoggingBehavior.APP_EVENTS, "AppEvents", "Created app event '%s'", jSONObject.toString());
|
|
}
|
|
return jSONObject;
|
|
}
|
|
|
|
private static void b(String str) throws FacebookException {
|
|
boolean contains;
|
|
if (str == null || str.length() == 0 || str.length() > 40) {
|
|
if (str == null) {
|
|
str = "<None Provided>";
|
|
}
|
|
throw new FacebookException(String.format(Locale.ROOT, "Identifier '%s' must be less than %d characters", str, 40));
|
|
}
|
|
synchronized (e) {
|
|
contains = e.contains(str);
|
|
}
|
|
if (contains) {
|
|
return;
|
|
}
|
|
if (!str.matches("^[0-9a-zA-Z_]+[0-9a-zA-Z _-]*$")) {
|
|
throw new FacebookException(String.format("Skipping event named '%s' due to illegal name - must be under 40 chars and alphanumeric, _, - or space, and not start with a space or hyphen.", str));
|
|
}
|
|
synchronized (e) {
|
|
e.add(str);
|
|
}
|
|
}
|
|
|
|
private AppEvent(String str, boolean z, String str2) throws JSONException {
|
|
this.a = new JSONObject(str);
|
|
this.b = z;
|
|
this.c = this.a.optString("_eventName");
|
|
this.d = str2;
|
|
}
|
|
|
|
private static String a(String str) {
|
|
try {
|
|
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
|
|
byte[] bytes = str.getBytes("UTF-8");
|
|
messageDigest.update(bytes, 0, bytes.length);
|
|
return a(messageDigest.digest());
|
|
} catch (UnsupportedEncodingException e2) {
|
|
Utility.a("Failed to generate checksum: ", (Exception) e2);
|
|
return "1";
|
|
} catch (NoSuchAlgorithmException e3) {
|
|
Utility.a("Failed to generate checksum: ", (Exception) e3);
|
|
return "0";
|
|
}
|
|
}
|
|
|
|
private static String a(byte[] bArr) {
|
|
StringBuffer stringBuffer = new StringBuffer();
|
|
for (byte b : bArr) {
|
|
stringBuffer.append(String.format("%02x", Byte.valueOf(b)));
|
|
}
|
|
return stringBuffer.toString();
|
|
}
|
|
}
|