Files
rr3-apk/decompiled-community/sources/com/facebook/internal/BundleJSONConverter.java
Daniel Elliott c080f0d97f Add Discord community version (64-bit only)
- Added realracing3-community.apk (71.57 MB)
- Removed 32-bit support (armeabi-v7a)
- Only includes arm64-v8a libraries
- Decompiled source code included
- Added README-community.md with analysis
2026-02-18 15:48:36 -08:00

238 lines
11 KiB
Java

package com.facebook.internal;
import android.os.Bundle;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import kotlin.jvm.internal.Intrinsics;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/* loaded from: classes2.dex */
public final class BundleJSONConverter {
public static final BundleJSONConverter INSTANCE = new BundleJSONConverter();
private static final Map<Class<?>, Setter> SETTERS;
public interface Setter {
void setOnBundle(Bundle bundle, String str, Object obj) throws JSONException;
void setOnJSON(JSONObject jSONObject, String str, Object obj) throws JSONException;
}
private BundleJSONConverter() {
}
static {
HashMap hashMap = new HashMap();
SETTERS = hashMap;
hashMap.put(Boolean.class, new Setter() { // from class: com.facebook.internal.BundleJSONConverter.1
@Override // com.facebook.internal.BundleJSONConverter.Setter
public void setOnBundle(Bundle bundle, String key, Object value) throws JSONException {
Intrinsics.checkNotNullParameter(bundle, "bundle");
Intrinsics.checkNotNullParameter(key, "key");
Intrinsics.checkNotNullParameter(value, "value");
bundle.putBoolean(key, ((Boolean) value).booleanValue());
}
@Override // com.facebook.internal.BundleJSONConverter.Setter
public void setOnJSON(JSONObject json, String key, Object value) throws JSONException {
Intrinsics.checkNotNullParameter(json, "json");
Intrinsics.checkNotNullParameter(key, "key");
Intrinsics.checkNotNullParameter(value, "value");
json.put(key, value);
}
});
hashMap.put(Integer.class, new Setter() { // from class: com.facebook.internal.BundleJSONConverter.2
@Override // com.facebook.internal.BundleJSONConverter.Setter
public void setOnBundle(Bundle bundle, String key, Object value) throws JSONException {
Intrinsics.checkNotNullParameter(bundle, "bundle");
Intrinsics.checkNotNullParameter(key, "key");
Intrinsics.checkNotNullParameter(value, "value");
bundle.putInt(key, ((Integer) value).intValue());
}
@Override // com.facebook.internal.BundleJSONConverter.Setter
public void setOnJSON(JSONObject json, String key, Object value) throws JSONException {
Intrinsics.checkNotNullParameter(json, "json");
Intrinsics.checkNotNullParameter(key, "key");
Intrinsics.checkNotNullParameter(value, "value");
json.put(key, value);
}
});
hashMap.put(Long.class, new Setter() { // from class: com.facebook.internal.BundleJSONConverter.3
@Override // com.facebook.internal.BundleJSONConverter.Setter
public void setOnBundle(Bundle bundle, String key, Object value) throws JSONException {
Intrinsics.checkNotNullParameter(bundle, "bundle");
Intrinsics.checkNotNullParameter(key, "key");
Intrinsics.checkNotNullParameter(value, "value");
bundle.putLong(key, ((Long) value).longValue());
}
@Override // com.facebook.internal.BundleJSONConverter.Setter
public void setOnJSON(JSONObject json, String key, Object value) throws JSONException {
Intrinsics.checkNotNullParameter(json, "json");
Intrinsics.checkNotNullParameter(key, "key");
Intrinsics.checkNotNullParameter(value, "value");
json.put(key, value);
}
});
hashMap.put(Double.class, new Setter() { // from class: com.facebook.internal.BundleJSONConverter.4
@Override // com.facebook.internal.BundleJSONConverter.Setter
public void setOnBundle(Bundle bundle, String key, Object value) throws JSONException {
Intrinsics.checkNotNullParameter(bundle, "bundle");
Intrinsics.checkNotNullParameter(key, "key");
Intrinsics.checkNotNullParameter(value, "value");
bundle.putDouble(key, ((Double) value).doubleValue());
}
@Override // com.facebook.internal.BundleJSONConverter.Setter
public void setOnJSON(JSONObject json, String key, Object value) throws JSONException {
Intrinsics.checkNotNullParameter(json, "json");
Intrinsics.checkNotNullParameter(key, "key");
Intrinsics.checkNotNullParameter(value, "value");
json.put(key, value);
}
});
hashMap.put(String.class, new Setter() { // from class: com.facebook.internal.BundleJSONConverter.5
@Override // com.facebook.internal.BundleJSONConverter.Setter
public void setOnBundle(Bundle bundle, String key, Object value) throws JSONException {
Intrinsics.checkNotNullParameter(bundle, "bundle");
Intrinsics.checkNotNullParameter(key, "key");
Intrinsics.checkNotNullParameter(value, "value");
bundle.putString(key, (String) value);
}
@Override // com.facebook.internal.BundleJSONConverter.Setter
public void setOnJSON(JSONObject json, String key, Object value) throws JSONException {
Intrinsics.checkNotNullParameter(json, "json");
Intrinsics.checkNotNullParameter(key, "key");
Intrinsics.checkNotNullParameter(value, "value");
json.put(key, value);
}
});
hashMap.put(String[].class, new Setter() { // from class: com.facebook.internal.BundleJSONConverter.6
@Override // com.facebook.internal.BundleJSONConverter.Setter
public void setOnBundle(Bundle bundle, String key, Object value) throws JSONException {
Intrinsics.checkNotNullParameter(bundle, "bundle");
Intrinsics.checkNotNullParameter(key, "key");
Intrinsics.checkNotNullParameter(value, "value");
throw new IllegalArgumentException("Unexpected type from JSON");
}
@Override // com.facebook.internal.BundleJSONConverter.Setter
public void setOnJSON(JSONObject json, String key, Object value) throws JSONException {
Intrinsics.checkNotNullParameter(json, "json");
Intrinsics.checkNotNullParameter(key, "key");
Intrinsics.checkNotNullParameter(value, "value");
JSONArray jSONArray = new JSONArray();
String[] strArr = (String[]) value;
int length = strArr.length;
int i = 0;
while (i < length) {
String str = strArr[i];
i++;
jSONArray.put(str);
}
json.put(key, jSONArray);
}
});
hashMap.put(JSONArray.class, new Setter() { // from class: com.facebook.internal.BundleJSONConverter.7
/* JADX WARN: Multi-variable type inference failed */
@Override // com.facebook.internal.BundleJSONConverter.Setter
public void setOnBundle(Bundle bundle, String key, Object value) throws JSONException {
Intrinsics.checkNotNullParameter(bundle, "bundle");
Intrinsics.checkNotNullParameter(key, "key");
Intrinsics.checkNotNullParameter(value, "value");
JSONArray jSONArray = (JSONArray) value;
ArrayList arrayList = new ArrayList();
if (jSONArray.length() == 0) {
bundle.putStringArrayList(key, arrayList);
return;
}
int length = jSONArray.length();
if (length > 0) {
int i = 0;
while (true) {
int i2 = i + 1;
Object obj = jSONArray.get(i);
if (obj instanceof String) {
arrayList.add(obj);
if (i2 >= length) {
break;
} else {
i = i2;
}
} else {
throw new IllegalArgumentException(Intrinsics.stringPlus("Unexpected type in an array: ", obj.getClass()));
}
}
}
bundle.putStringArrayList(key, arrayList);
}
@Override // com.facebook.internal.BundleJSONConverter.Setter
public void setOnJSON(JSONObject json, String key, Object value) throws JSONException {
Intrinsics.checkNotNullParameter(json, "json");
Intrinsics.checkNotNullParameter(key, "key");
Intrinsics.checkNotNullParameter(value, "value");
throw new IllegalArgumentException("JSONArray's are not supported in bundles.");
}
});
}
public static final JSONObject convertToJSON(Bundle bundle) throws JSONException {
Intrinsics.checkNotNullParameter(bundle, "bundle");
JSONObject jSONObject = new JSONObject();
for (String key : bundle.keySet()) {
Object obj = bundle.get(key);
if (obj != null) {
if (obj instanceof List) {
JSONArray jSONArray = new JSONArray();
Iterator it = ((List) obj).iterator();
while (it.hasNext()) {
jSONArray.put((String) it.next());
}
jSONObject.put(key, jSONArray);
} else if (obj instanceof Bundle) {
jSONObject.put(key, convertToJSON((Bundle) obj));
} else {
Setter setter = SETTERS.get(obj.getClass());
if (setter == null) {
throw new IllegalArgumentException(Intrinsics.stringPlus("Unsupported type: ", obj.getClass()));
}
Intrinsics.checkNotNullExpressionValue(key, "key");
setter.setOnJSON(jSONObject, key, obj);
}
}
}
return jSONObject;
}
public static final Bundle convertToBundle(JSONObject jsonObject) throws JSONException {
Intrinsics.checkNotNullParameter(jsonObject, "jsonObject");
Bundle bundle = new Bundle();
Iterator<String> keys = jsonObject.keys();
while (keys.hasNext()) {
String key = keys.next();
Object value = jsonObject.get(key);
if (value != JSONObject.NULL) {
if (value instanceof JSONObject) {
bundle.putBundle(key, convertToBundle((JSONObject) value));
} else {
Setter setter = SETTERS.get(value.getClass());
if (setter == null) {
throw new IllegalArgumentException(Intrinsics.stringPlus("Unsupported type: ", value.getClass()));
}
Intrinsics.checkNotNullExpressionValue(key, "key");
Intrinsics.checkNotNullExpressionValue(value, "value");
setter.setOnBundle(bundle, key, value);
}
}
}
return bundle;
}
}