1166 lines
43 KiB
Java
1166 lines
43 KiB
Java
package com.facebook;
|
|
|
|
import android.graphics.Bitmap;
|
|
import android.net.Uri;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.os.Parcel;
|
|
import android.os.ParcelFileDescriptor;
|
|
import android.os.Parcelable;
|
|
import android.text.TextUtils;
|
|
import android.util.Log;
|
|
import android.util.Pair;
|
|
import com.facebook.GraphRequestBatch;
|
|
import com.facebook.internal.InternalSettings;
|
|
import com.facebook.internal.Logger;
|
|
import com.facebook.internal.ServerProtocol;
|
|
import com.facebook.internal.Utility;
|
|
import com.facebook.internal.Validate;
|
|
import com.ubt.jimu.base.entities.Constant;
|
|
import com.ubt.jimu.controller.data.widget.JockstickDataConverter;
|
|
import com.unity3d.ads.metadata.MediationMetaData;
|
|
import java.io.Closeable;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.OutputStream;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.MalformedURLException;
|
|
import java.net.URL;
|
|
import java.net.URLConnection;
|
|
import java.net.URLEncoder;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Collection;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import java.util.Map;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class GraphRequest {
|
|
public static final String n = "GraphRequest";
|
|
private static String o;
|
|
private static Pattern p = Pattern.compile("^/?v\\d+\\.\\d+/(.*)");
|
|
private static volatile String q;
|
|
private AccessToken a;
|
|
private HttpMethod b;
|
|
private String c;
|
|
private JSONObject d;
|
|
private String e;
|
|
private String f;
|
|
private boolean g;
|
|
private Bundle h;
|
|
private Callback i;
|
|
private String j;
|
|
private Object k;
|
|
private String l;
|
|
private boolean m;
|
|
|
|
private static class Attachment {
|
|
private final GraphRequest a;
|
|
private final Object b;
|
|
|
|
public Attachment(GraphRequest graphRequest, Object obj) {
|
|
this.a = graphRequest;
|
|
this.b = obj;
|
|
}
|
|
|
|
public GraphRequest a() {
|
|
return this.a;
|
|
}
|
|
|
|
public Object b() {
|
|
return this.b;
|
|
}
|
|
}
|
|
|
|
public interface Callback {
|
|
void a(GraphResponse graphResponse);
|
|
}
|
|
|
|
public interface GraphJSONObjectCallback {
|
|
void a(JSONObject jSONObject, GraphResponse graphResponse);
|
|
}
|
|
|
|
private interface KeyValueSerializer {
|
|
void a(String str, String str2) throws IOException;
|
|
}
|
|
|
|
public interface OnProgressCallback extends Callback {
|
|
void a(long j, long j2);
|
|
}
|
|
|
|
public static class ParcelableResourceWithMimeType<RESOURCE extends Parcelable> implements Parcelable {
|
|
public static final Parcelable.Creator<ParcelableResourceWithMimeType> CREATOR = new Parcelable.Creator<ParcelableResourceWithMimeType>() { // from class: com.facebook.GraphRequest.ParcelableResourceWithMimeType.1
|
|
/* JADX WARN: Can't rename method to resolve collision */
|
|
@Override // android.os.Parcelable.Creator
|
|
public ParcelableResourceWithMimeType createFromParcel(Parcel parcel) {
|
|
return new ParcelableResourceWithMimeType(parcel);
|
|
}
|
|
|
|
/* JADX WARN: Can't rename method to resolve collision */
|
|
@Override // android.os.Parcelable.Creator
|
|
public ParcelableResourceWithMimeType[] newArray(int i) {
|
|
return new ParcelableResourceWithMimeType[i];
|
|
}
|
|
};
|
|
private final String mimeType;
|
|
private final RESOURCE resource;
|
|
|
|
@Override // android.os.Parcelable
|
|
public int describeContents() {
|
|
return 1;
|
|
}
|
|
|
|
public String getMimeType() {
|
|
return this.mimeType;
|
|
}
|
|
|
|
public RESOURCE getResource() {
|
|
return this.resource;
|
|
}
|
|
|
|
@Override // android.os.Parcelable
|
|
public void writeToParcel(Parcel parcel, int i) {
|
|
parcel.writeString(this.mimeType);
|
|
parcel.writeParcelable(this.resource, i);
|
|
}
|
|
|
|
public ParcelableResourceWithMimeType(RESOURCE resource, String str) {
|
|
this.mimeType = str;
|
|
this.resource = resource;
|
|
}
|
|
|
|
private ParcelableResourceWithMimeType(Parcel parcel) {
|
|
this.mimeType = parcel.readString();
|
|
this.resource = (RESOURCE) parcel.readParcelable(FacebookSdk.b().getClassLoader());
|
|
}
|
|
}
|
|
|
|
private static class Serializer implements KeyValueSerializer {
|
|
private final OutputStream a;
|
|
private final Logger b;
|
|
private boolean c = true;
|
|
private boolean d;
|
|
|
|
public Serializer(OutputStream outputStream, Logger logger, boolean z) {
|
|
this.d = false;
|
|
this.a = outputStream;
|
|
this.b = logger;
|
|
this.d = z;
|
|
}
|
|
|
|
private RuntimeException b() {
|
|
return new IllegalArgumentException("value is not a supported type.");
|
|
}
|
|
|
|
public void a(String str, Object obj, GraphRequest graphRequest) throws IOException {
|
|
Closeable closeable = this.a;
|
|
if (closeable instanceof RequestOutputStream) {
|
|
((RequestOutputStream) closeable).a(graphRequest);
|
|
}
|
|
if (GraphRequest.e(obj)) {
|
|
a(str, GraphRequest.f(obj));
|
|
return;
|
|
}
|
|
if (obj instanceof Bitmap) {
|
|
a(str, (Bitmap) obj);
|
|
return;
|
|
}
|
|
if (obj instanceof byte[]) {
|
|
a(str, (byte[]) obj);
|
|
return;
|
|
}
|
|
if (obj instanceof Uri) {
|
|
a(str, (Uri) obj, (String) null);
|
|
return;
|
|
}
|
|
if (obj instanceof ParcelFileDescriptor) {
|
|
a(str, (ParcelFileDescriptor) obj, (String) null);
|
|
return;
|
|
}
|
|
if (!(obj instanceof ParcelableResourceWithMimeType)) {
|
|
throw b();
|
|
}
|
|
ParcelableResourceWithMimeType parcelableResourceWithMimeType = (ParcelableResourceWithMimeType) obj;
|
|
Parcelable resource = parcelableResourceWithMimeType.getResource();
|
|
String mimeType = parcelableResourceWithMimeType.getMimeType();
|
|
if (resource instanceof ParcelFileDescriptor) {
|
|
a(str, (ParcelFileDescriptor) resource, mimeType);
|
|
} else {
|
|
if (!(resource instanceof Uri)) {
|
|
throw b();
|
|
}
|
|
a(str, (Uri) resource, mimeType);
|
|
}
|
|
}
|
|
|
|
public void b(String str, Object... objArr) throws IOException {
|
|
a(str, objArr);
|
|
if (this.d) {
|
|
return;
|
|
}
|
|
a("\r\n", new Object[0]);
|
|
}
|
|
|
|
public void a(String str, JSONArray jSONArray, Collection<GraphRequest> collection) throws IOException, JSONException {
|
|
Closeable closeable = this.a;
|
|
if (!(closeable instanceof RequestOutputStream)) {
|
|
a(str, jSONArray.toString());
|
|
return;
|
|
}
|
|
RequestOutputStream requestOutputStream = (RequestOutputStream) closeable;
|
|
a(str, (String) null, (String) null);
|
|
a("[", new Object[0]);
|
|
int i = 0;
|
|
for (GraphRequest graphRequest : collection) {
|
|
JSONObject jSONObject = jSONArray.getJSONObject(i);
|
|
requestOutputStream.a(graphRequest);
|
|
if (i > 0) {
|
|
a(",%s", jSONObject.toString());
|
|
} else {
|
|
a("%s", jSONObject.toString());
|
|
}
|
|
i++;
|
|
}
|
|
a("]", new Object[0]);
|
|
Logger logger = this.b;
|
|
if (logger != null) {
|
|
logger.a(" " + str, (Object) jSONArray.toString());
|
|
}
|
|
}
|
|
|
|
@Override // com.facebook.GraphRequest.KeyValueSerializer
|
|
public void a(String str, String str2) throws IOException {
|
|
a(str, (String) null, (String) null);
|
|
b("%s", str2);
|
|
a();
|
|
Logger logger = this.b;
|
|
if (logger != null) {
|
|
logger.a(" " + str, (Object) str2);
|
|
}
|
|
}
|
|
|
|
public void a(String str, Bitmap bitmap) throws IOException {
|
|
a(str, str, "image/png");
|
|
bitmap.compress(Bitmap.CompressFormat.PNG, 100, this.a);
|
|
b("", new Object[0]);
|
|
a();
|
|
Logger logger = this.b;
|
|
if (logger != null) {
|
|
logger.a(" " + str, (Object) "<Image>");
|
|
}
|
|
}
|
|
|
|
public void a(String str, byte[] bArr) throws IOException {
|
|
a(str, str, "content/unknown");
|
|
this.a.write(bArr);
|
|
b("", new Object[0]);
|
|
a();
|
|
Logger logger = this.b;
|
|
if (logger != null) {
|
|
logger.a(" " + str, (Object) String.format(Locale.ROOT, "<Data: %d>", Integer.valueOf(bArr.length)));
|
|
}
|
|
}
|
|
|
|
public void a(String str, Uri uri, String str2) throws IOException {
|
|
int a;
|
|
if (str2 == null) {
|
|
str2 = "content/unknown";
|
|
}
|
|
a(str, str, str2);
|
|
if (this.a instanceof ProgressNoopOutputStream) {
|
|
((ProgressNoopOutputStream) this.a).a(Utility.a(uri));
|
|
a = 0;
|
|
} else {
|
|
a = Utility.a(FacebookSdk.b().getContentResolver().openInputStream(uri), this.a) + 0;
|
|
}
|
|
b("", new Object[0]);
|
|
a();
|
|
Logger logger = this.b;
|
|
if (logger != null) {
|
|
logger.a(" " + str, (Object) String.format(Locale.ROOT, "<Data: %d>", Integer.valueOf(a)));
|
|
}
|
|
}
|
|
|
|
public void a(String str, ParcelFileDescriptor parcelFileDescriptor, String str2) throws IOException {
|
|
int a;
|
|
if (str2 == null) {
|
|
str2 = "content/unknown";
|
|
}
|
|
a(str, str, str2);
|
|
OutputStream outputStream = this.a;
|
|
if (outputStream instanceof ProgressNoopOutputStream) {
|
|
((ProgressNoopOutputStream) outputStream).a(parcelFileDescriptor.getStatSize());
|
|
a = 0;
|
|
} else {
|
|
a = Utility.a((InputStream) new ParcelFileDescriptor.AutoCloseInputStream(parcelFileDescriptor), this.a) + 0;
|
|
}
|
|
b("", new Object[0]);
|
|
a();
|
|
Logger logger = this.b;
|
|
if (logger != null) {
|
|
logger.a(" " + str, (Object) String.format(Locale.ROOT, "<Data: %d>", Integer.valueOf(a)));
|
|
}
|
|
}
|
|
|
|
public void a() throws IOException {
|
|
if (!this.d) {
|
|
b("--%s", "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f");
|
|
} else {
|
|
this.a.write("&".getBytes());
|
|
}
|
|
}
|
|
|
|
public void a(String str, String str2, String str3) throws IOException {
|
|
if (!this.d) {
|
|
a("Content-Disposition: form-data; name=\"%s\"", str);
|
|
if (str2 != null) {
|
|
a("; filename=\"%s\"", str2);
|
|
}
|
|
b("", new Object[0]);
|
|
if (str3 != null) {
|
|
b("%s: %s", "Content-Type", str3);
|
|
}
|
|
b("", new Object[0]);
|
|
return;
|
|
}
|
|
this.a.write(String.format("%s=", str).getBytes());
|
|
}
|
|
|
|
public void a(String str, Object... objArr) throws IOException {
|
|
if (!this.d) {
|
|
if (this.c) {
|
|
this.a.write("--".getBytes());
|
|
this.a.write("3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f".getBytes());
|
|
this.a.write("\r\n".getBytes());
|
|
this.c = false;
|
|
}
|
|
this.a.write(String.format(str, objArr).getBytes());
|
|
return;
|
|
}
|
|
this.a.write(URLEncoder.encode(String.format(Locale.US, str, objArr), "UTF-8").getBytes());
|
|
}
|
|
}
|
|
|
|
public GraphRequest() {
|
|
this(null, null, null, null, null);
|
|
}
|
|
|
|
public static GraphRequest a(AccessToken accessToken, final GraphJSONObjectCallback graphJSONObjectCallback) {
|
|
return new GraphRequest(accessToken, "me", null, null, new Callback() { // from class: com.facebook.GraphRequest.1
|
|
@Override // com.facebook.GraphRequest.Callback
|
|
public void a(GraphResponse graphResponse) {
|
|
GraphJSONObjectCallback graphJSONObjectCallback2 = GraphJSONObjectCallback.this;
|
|
if (graphJSONObjectCallback2 != null) {
|
|
graphJSONObjectCallback2.a(graphResponse.b(), graphResponse);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
private void m() {
|
|
if (this.a != null) {
|
|
if (!this.h.containsKey(AccessToken.ACCESS_TOKEN_KEY)) {
|
|
String token = this.a.getToken();
|
|
Logger.c(token);
|
|
this.h.putString(AccessToken.ACCESS_TOKEN_KEY, token);
|
|
}
|
|
} else if (!this.m && !this.h.containsKey(AccessToken.ACCESS_TOKEN_KEY)) {
|
|
String c = FacebookSdk.c();
|
|
String g = FacebookSdk.g();
|
|
if (Utility.c(c) || Utility.c(g)) {
|
|
Log.d(n, "Warning: Request without access token missing application ID or client token.");
|
|
} else {
|
|
this.h.putString(AccessToken.ACCESS_TOKEN_KEY, c + "|" + g);
|
|
}
|
|
}
|
|
this.h.putString("sdk", "android");
|
|
this.h.putString("format", "json");
|
|
if (FacebookSdk.a(LoggingBehavior.GRAPH_API_DEBUG_INFO)) {
|
|
this.h.putString("debug", "info");
|
|
} else if (FacebookSdk.a(LoggingBehavior.GRAPH_API_DEBUG_WARNING)) {
|
|
this.h.putString("debug", "warning");
|
|
}
|
|
}
|
|
|
|
private String n() {
|
|
return p.matcher(this.c).matches() ? this.c : String.format("%s/%s", this.l, this.c);
|
|
}
|
|
|
|
private static String o() {
|
|
return String.format("multipart/form-data; boundary=%s", "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f");
|
|
}
|
|
|
|
private static String p() {
|
|
if (q == null) {
|
|
q = String.format("%s.%s", "FBAndroidSDK", "4.24.0");
|
|
String a = InternalSettings.a();
|
|
if (!Utility.c(a)) {
|
|
q = String.format(Locale.ROOT, "%s/%s", q, a);
|
|
}
|
|
}
|
|
return q;
|
|
}
|
|
|
|
public final Callback d() {
|
|
return this.i;
|
|
}
|
|
|
|
public final JSONObject e() {
|
|
return this.d;
|
|
}
|
|
|
|
public final String f() {
|
|
return this.c;
|
|
}
|
|
|
|
public final HttpMethod g() {
|
|
return this.b;
|
|
}
|
|
|
|
public final Bundle h() {
|
|
return this.h;
|
|
}
|
|
|
|
final String i() {
|
|
if (this.j != null) {
|
|
throw new FacebookException("Can't override URL for a batch request");
|
|
}
|
|
String format = String.format("%s/%s", ServerProtocol.c(), n());
|
|
m();
|
|
Uri parse = Uri.parse(a(format));
|
|
return String.format("%s?%s", parse.getPath(), parse.getQuery());
|
|
}
|
|
|
|
public final Object j() {
|
|
return this.k;
|
|
}
|
|
|
|
final String k() {
|
|
String str;
|
|
String str2 = this.j;
|
|
if (str2 != null) {
|
|
return str2.toString();
|
|
}
|
|
String format = String.format("%s/%s", (g() == HttpMethod.POST && (str = this.c) != null && str.endsWith("/videos")) ? ServerProtocol.d() : ServerProtocol.c(), n());
|
|
m();
|
|
return a(format);
|
|
}
|
|
|
|
public final String l() {
|
|
return this.l;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("{Request: ");
|
|
sb.append(" accessToken: ");
|
|
Object obj = this.a;
|
|
if (obj == null) {
|
|
obj = "null";
|
|
}
|
|
sb.append(obj);
|
|
sb.append(", graphPath: ");
|
|
sb.append(this.c);
|
|
sb.append(", graphObject: ");
|
|
sb.append(this.d);
|
|
sb.append(", httpMethod: ");
|
|
sb.append(this.b);
|
|
sb.append(", parameters: ");
|
|
sb.append(this.h);
|
|
sb.append("}");
|
|
return sb.toString();
|
|
}
|
|
|
|
public GraphRequest(AccessToken accessToken, String str, Bundle bundle, HttpMethod httpMethod, Callback callback) {
|
|
this(accessToken, str, bundle, httpMethod, callback, null);
|
|
}
|
|
|
|
private static boolean d(GraphRequestBatch graphRequestBatch) {
|
|
Iterator<GraphRequestBatch.Callback> it = graphRequestBatch.g().iterator();
|
|
while (it.hasNext()) {
|
|
if (it.next() instanceof GraphRequestBatch.OnProgressCallback) {
|
|
return true;
|
|
}
|
|
}
|
|
Iterator<GraphRequest> it2 = graphRequestBatch.iterator();
|
|
while (it2.hasNext()) {
|
|
if (it2.next().d() instanceof OnProgressCallback) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private static boolean e(GraphRequestBatch graphRequestBatch) {
|
|
Iterator<GraphRequest> it = graphRequestBatch.iterator();
|
|
while (it.hasNext()) {
|
|
GraphRequest next = it.next();
|
|
Iterator<String> it2 = next.h.keySet().iterator();
|
|
while (it2.hasNext()) {
|
|
if (d(next.h.get(it2.next()))) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static HttpURLConnection f(GraphRequestBatch graphRequestBatch) {
|
|
g(graphRequestBatch);
|
|
try {
|
|
HttpURLConnection httpURLConnection = null;
|
|
try {
|
|
httpURLConnection = a(graphRequestBatch.size() == 1 ? new URL(graphRequestBatch.get(0).k()) : new URL(ServerProtocol.c()));
|
|
a(graphRequestBatch, httpURLConnection);
|
|
return httpURLConnection;
|
|
} catch (IOException | JSONException e) {
|
|
Utility.a(httpURLConnection);
|
|
throw new FacebookException("could not construct request body", e);
|
|
}
|
|
} catch (MalformedURLException e2) {
|
|
throw new FacebookException("could not construct URL for request", e2);
|
|
}
|
|
}
|
|
|
|
static final void g(GraphRequestBatch graphRequestBatch) {
|
|
Iterator<GraphRequest> it = graphRequestBatch.iterator();
|
|
while (it.hasNext()) {
|
|
GraphRequest next = it.next();
|
|
if (HttpMethod.GET.equals(next.g()) && b(next)) {
|
|
Bundle h = next.h();
|
|
if (!h.containsKey("fields") || Utility.c(h.getString("fields"))) {
|
|
Logger.a(LoggingBehavior.DEVELOPER_ERRORS, 5, "Request", "starting with Graph API v2.4, GET requests for /%s should contain an explicit \"fields\" parameter.", next.f());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public final GraphRequestAsyncTask b() {
|
|
return b(this);
|
|
}
|
|
|
|
public final AccessToken c() {
|
|
return this.a;
|
|
}
|
|
|
|
public GraphRequest(AccessToken accessToken, String str, Bundle bundle, HttpMethod httpMethod, Callback callback, String str2) {
|
|
this.g = true;
|
|
this.m = false;
|
|
this.a = accessToken;
|
|
this.c = str;
|
|
this.l = str2;
|
|
a(callback);
|
|
a(httpMethod);
|
|
if (bundle != null) {
|
|
this.h = new Bundle(bundle);
|
|
} else {
|
|
this.h = new Bundle();
|
|
}
|
|
if (this.l == null) {
|
|
this.l = FacebookSdk.j();
|
|
}
|
|
}
|
|
|
|
public static GraphRequest a(AccessToken accessToken, String str, JSONObject jSONObject, Callback callback) {
|
|
GraphRequest graphRequest = new GraphRequest(accessToken, str, null, HttpMethod.POST, callback);
|
|
graphRequest.a(jSONObject);
|
|
return graphRequest;
|
|
}
|
|
|
|
public static GraphRequestAsyncTask b(GraphRequest... graphRequestArr) {
|
|
Validate.a(graphRequestArr, "requests");
|
|
return b((Collection<GraphRequest>) Arrays.asList(graphRequestArr));
|
|
}
|
|
|
|
private static String c(GraphRequestBatch graphRequestBatch) {
|
|
String applicationId;
|
|
if (!Utility.c(graphRequestBatch.e())) {
|
|
return graphRequestBatch.e();
|
|
}
|
|
Iterator<GraphRequest> it = graphRequestBatch.iterator();
|
|
while (it.hasNext()) {
|
|
AccessToken accessToken = it.next().a;
|
|
if (accessToken != null && (applicationId = accessToken.getApplicationId()) != null) {
|
|
return applicationId;
|
|
}
|
|
}
|
|
if (!Utility.c(o)) {
|
|
return o;
|
|
}
|
|
return FacebookSdk.c();
|
|
}
|
|
|
|
public static GraphRequest a(AccessToken accessToken, String str, Callback callback) {
|
|
return new GraphRequest(accessToken, str, null, null, callback);
|
|
}
|
|
|
|
public static GraphRequestAsyncTask b(Collection<GraphRequest> collection) {
|
|
return b(new GraphRequestBatch(collection));
|
|
}
|
|
|
|
public static GraphRequestAsyncTask b(GraphRequestBatch graphRequestBatch) {
|
|
Validate.c(graphRequestBatch, "requests");
|
|
GraphRequestAsyncTask graphRequestAsyncTask = new GraphRequestAsyncTask(graphRequestBatch);
|
|
graphRequestAsyncTask.executeOnExecutor(FacebookSdk.h(), new Void[0]);
|
|
return graphRequestAsyncTask;
|
|
}
|
|
|
|
private static boolean d(Object obj) {
|
|
return (obj instanceof Bitmap) || (obj instanceof byte[]) || (obj instanceof Uri) || (obj instanceof ParcelFileDescriptor) || (obj instanceof ParcelableResourceWithMimeType);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public static boolean e(Object obj) {
|
|
return (obj instanceof String) || (obj instanceof Boolean) || (obj instanceof Number) || (obj instanceof Date);
|
|
}
|
|
|
|
public final void a(JSONObject jSONObject) {
|
|
this.d = jSONObject;
|
|
}
|
|
|
|
public final void a(HttpMethod httpMethod) {
|
|
if (this.j != null && httpMethod != HttpMethod.GET) {
|
|
throw new FacebookException("Can't change HTTP method on request with overridden URL.");
|
|
}
|
|
if (httpMethod == null) {
|
|
httpMethod = HttpMethod.GET;
|
|
}
|
|
this.b = httpMethod;
|
|
}
|
|
|
|
static final boolean b(GraphRequest graphRequest) {
|
|
String l = graphRequest.l();
|
|
if (Utility.c(l)) {
|
|
return true;
|
|
}
|
|
if (l.startsWith("v")) {
|
|
l = l.substring(1);
|
|
}
|
|
String[] split = l.split("\\.");
|
|
if (split.length < 2 || Integer.parseInt(split[0]) <= 2) {
|
|
return Integer.parseInt(split[0]) >= 2 && Integer.parseInt(split[1]) >= 4;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public final void a(boolean z) {
|
|
this.m = z;
|
|
}
|
|
|
|
public final void a(Bundle bundle) {
|
|
this.h = bundle;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public static String f(Object obj) {
|
|
if (obj instanceof String) {
|
|
return (String) obj;
|
|
}
|
|
if (!(obj instanceof Boolean) && !(obj instanceof Number)) {
|
|
if (obj instanceof Date) {
|
|
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US).format(obj);
|
|
}
|
|
throw new IllegalArgumentException("Unsupported parameter type.");
|
|
}
|
|
return obj.toString();
|
|
}
|
|
|
|
public final void a(final Callback callback) {
|
|
if (!FacebookSdk.a(LoggingBehavior.GRAPH_API_DEBUG_INFO) && !FacebookSdk.a(LoggingBehavior.GRAPH_API_DEBUG_WARNING)) {
|
|
this.i = callback;
|
|
} else {
|
|
this.i = new Callback(this) { // from class: com.facebook.GraphRequest.4
|
|
@Override // com.facebook.GraphRequest.Callback
|
|
public void a(GraphResponse graphResponse) {
|
|
JSONObject b = graphResponse.b();
|
|
JSONObject optJSONObject = b != null ? b.optJSONObject("__debug__") : null;
|
|
JSONArray optJSONArray = optJSONObject != null ? optJSONObject.optJSONArray("messages") : null;
|
|
if (optJSONArray != null) {
|
|
for (int i = 0; i < optJSONArray.length(); i++) {
|
|
JSONObject optJSONObject2 = optJSONArray.optJSONObject(i);
|
|
String optString = optJSONObject2 != null ? optJSONObject2.optString("message") : null;
|
|
String optString2 = optJSONObject2 != null ? optJSONObject2.optString("type") : null;
|
|
String optString3 = optJSONObject2 != null ? optJSONObject2.optString(Constant.Community.SOURCE_LINK_TYPE) : null;
|
|
if (optString != null && optString2 != null) {
|
|
LoggingBehavior loggingBehavior = LoggingBehavior.GRAPH_API_DEBUG_INFO;
|
|
if (optString2.equals("warning")) {
|
|
loggingBehavior = LoggingBehavior.GRAPH_API_DEBUG_WARNING;
|
|
}
|
|
if (!Utility.c(optString3)) {
|
|
optString = optString + " Link: " + optString3;
|
|
}
|
|
Logger.a(loggingBehavior, GraphRequest.n, optString);
|
|
}
|
|
}
|
|
}
|
|
Callback callback2 = callback;
|
|
if (callback2 != null) {
|
|
callback2.a(graphResponse);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
public final void a(Object obj) {
|
|
this.k = obj;
|
|
}
|
|
|
|
private static boolean b(String str) {
|
|
Matcher matcher = p.matcher(str);
|
|
if (matcher.matches()) {
|
|
str = matcher.group(1);
|
|
}
|
|
return str.startsWith("me/") || str.startsWith("/me/");
|
|
}
|
|
|
|
public final GraphResponse a() {
|
|
return a(this);
|
|
}
|
|
|
|
public static GraphResponse a(GraphRequest graphRequest) {
|
|
List<GraphResponse> a = a(graphRequest);
|
|
if (a != null && a.size() == 1) {
|
|
return a.get(0);
|
|
}
|
|
throw new FacebookException("invalid state: expected a single response");
|
|
}
|
|
|
|
public static List<GraphResponse> a(GraphRequest... graphRequestArr) {
|
|
Validate.a(graphRequestArr, "requests");
|
|
return a((Collection<GraphRequest>) Arrays.asList(graphRequestArr));
|
|
}
|
|
|
|
public static List<GraphResponse> a(Collection<GraphRequest> collection) {
|
|
return a(new GraphRequestBatch(collection));
|
|
}
|
|
|
|
public static List<GraphResponse> a(GraphRequestBatch graphRequestBatch) {
|
|
Validate.c(graphRequestBatch, "requests");
|
|
try {
|
|
try {
|
|
HttpURLConnection f = f(graphRequestBatch);
|
|
List<GraphResponse> a = a(f, graphRequestBatch);
|
|
Utility.a(f);
|
|
return a;
|
|
} catch (Exception e) {
|
|
List<GraphResponse> a2 = GraphResponse.a(graphRequestBatch.k(), (HttpURLConnection) null, new FacebookException(e));
|
|
a(graphRequestBatch, a2);
|
|
Utility.a((URLConnection) null);
|
|
return a2;
|
|
}
|
|
} catch (Throwable th) {
|
|
Utility.a((URLConnection) null);
|
|
throw th;
|
|
}
|
|
}
|
|
|
|
public static List<GraphResponse> a(HttpURLConnection httpURLConnection, GraphRequestBatch graphRequestBatch) {
|
|
List<GraphResponse> a = GraphResponse.a(httpURLConnection, graphRequestBatch);
|
|
Utility.a(httpURLConnection);
|
|
int size = graphRequestBatch.size();
|
|
if (size == a.size()) {
|
|
a(graphRequestBatch, a);
|
|
AccessTokenManager.d().a();
|
|
return a;
|
|
}
|
|
throw new FacebookException(String.format(Locale.US, "Received %d responses while expecting %d", Integer.valueOf(a.size()), Integer.valueOf(size)));
|
|
}
|
|
|
|
static void a(final GraphRequestBatch graphRequestBatch, List<GraphResponse> list) {
|
|
int size = graphRequestBatch.size();
|
|
final ArrayList arrayList = new ArrayList();
|
|
for (int i = 0; i < size; i++) {
|
|
Callback callback = graphRequestBatch.get(i).i;
|
|
if (callback != null) {
|
|
arrayList.add(new Pair(callback, list.get(i)));
|
|
}
|
|
}
|
|
if (arrayList.size() > 0) {
|
|
Runnable runnable = new Runnable() { // from class: com.facebook.GraphRequest.5
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
Iterator it = arrayList.iterator();
|
|
while (it.hasNext()) {
|
|
Pair pair = (Pair) it.next();
|
|
((Callback) pair.first).a((GraphResponse) pair.second);
|
|
}
|
|
Iterator<GraphRequestBatch.Callback> it2 = graphRequestBatch.g().iterator();
|
|
while (it2.hasNext()) {
|
|
it2.next().a(graphRequestBatch);
|
|
}
|
|
}
|
|
};
|
|
Handler f = graphRequestBatch.f();
|
|
if (f == null) {
|
|
runnable.run();
|
|
} else {
|
|
f.post(runnable);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static HttpURLConnection a(URL url) throws IOException {
|
|
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
|
|
httpURLConnection.setRequestProperty("User-Agent", p());
|
|
httpURLConnection.setRequestProperty("Accept-Language", Locale.getDefault().toString());
|
|
httpURLConnection.setChunkedStreamingMode(0);
|
|
return httpURLConnection;
|
|
}
|
|
|
|
private String a(String str) {
|
|
Uri.Builder buildUpon = Uri.parse(str).buildUpon();
|
|
for (String str2 : this.h.keySet()) {
|
|
Object obj = this.h.get(str2);
|
|
if (obj == null) {
|
|
obj = "";
|
|
}
|
|
if (e(obj)) {
|
|
buildUpon.appendQueryParameter(str2, f(obj).toString());
|
|
} else if (this.b == HttpMethod.GET) {
|
|
throw new IllegalArgumentException(String.format(Locale.US, "Unsupported parameter type for GET request: %s", obj.getClass().getSimpleName()));
|
|
}
|
|
}
|
|
return buildUpon.toString();
|
|
}
|
|
|
|
private void a(JSONArray jSONArray, Map<String, Attachment> map) throws JSONException, IOException {
|
|
JSONObject jSONObject = new JSONObject();
|
|
String str = this.e;
|
|
if (str != null) {
|
|
jSONObject.put(MediationMetaData.KEY_NAME, str);
|
|
jSONObject.put("omit_response_on_success", this.g);
|
|
}
|
|
String str2 = this.f;
|
|
if (str2 != null) {
|
|
jSONObject.put("depends_on", str2);
|
|
}
|
|
String i = i();
|
|
jSONObject.put("relative_url", i);
|
|
jSONObject.put("method", this.b);
|
|
AccessToken accessToken = this.a;
|
|
if (accessToken != null) {
|
|
Logger.c(accessToken.getToken());
|
|
}
|
|
ArrayList arrayList = new ArrayList();
|
|
Iterator<String> it = this.h.keySet().iterator();
|
|
while (it.hasNext()) {
|
|
Object obj = this.h.get(it.next());
|
|
if (d(obj)) {
|
|
String format = String.format(Locale.ROOT, "%s%d", "file", Integer.valueOf(map.size()));
|
|
arrayList.add(format);
|
|
map.put(format, new Attachment(this, obj));
|
|
}
|
|
}
|
|
if (!arrayList.isEmpty()) {
|
|
jSONObject.put("attached_files", TextUtils.join(",", arrayList));
|
|
}
|
|
if (this.d != null) {
|
|
final ArrayList arrayList2 = new ArrayList();
|
|
a(this.d, i, new KeyValueSerializer(this) { // from class: com.facebook.GraphRequest.6
|
|
@Override // com.facebook.GraphRequest.KeyValueSerializer
|
|
public void a(String str3, String str4) throws IOException {
|
|
arrayList2.add(String.format(Locale.US, "%s=%s", str3, URLEncoder.encode(str4, "UTF-8")));
|
|
}
|
|
});
|
|
jSONObject.put("body", TextUtils.join("&", arrayList2));
|
|
}
|
|
jSONArray.put(jSONObject);
|
|
}
|
|
|
|
private static void a(HttpURLConnection httpURLConnection, boolean z) {
|
|
if (z) {
|
|
httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
|
httpURLConnection.setRequestProperty("Content-Encoding", "gzip");
|
|
} else {
|
|
httpURLConnection.setRequestProperty("Content-Type", o());
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Removed duplicated region for block: B:26:0x00ca */
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct code enable 'Show inconsistent code' option in preferences
|
|
*/
|
|
static final void a(com.facebook.GraphRequestBatch r13, java.net.HttpURLConnection r14) throws java.io.IOException, org.json.JSONException {
|
|
/*
|
|
com.facebook.internal.Logger r6 = new com.facebook.internal.Logger
|
|
com.facebook.LoggingBehavior r0 = com.facebook.LoggingBehavior.REQUESTS
|
|
java.lang.String r1 = "Request"
|
|
r6.<init>(r0, r1)
|
|
int r2 = r13.size()
|
|
boolean r5 = e(r13)
|
|
r0 = 0
|
|
r1 = 1
|
|
if (r2 != r1) goto L1c
|
|
com.facebook.GraphRequest r3 = r13.get(r0)
|
|
com.facebook.HttpMethod r3 = r3.b
|
|
goto L1e
|
|
L1c:
|
|
com.facebook.HttpMethod r3 = com.facebook.HttpMethod.POST
|
|
L1e:
|
|
java.lang.String r4 = r3.name()
|
|
r14.setRequestMethod(r4)
|
|
a(r14, r5)
|
|
java.net.URL r4 = r14.getURL()
|
|
java.lang.String r7 = "Request:\n"
|
|
r6.a(r7)
|
|
java.lang.String r7 = r13.j()
|
|
java.lang.String r8 = "Id"
|
|
r6.a(r8, r7)
|
|
java.lang.String r7 = "URL"
|
|
r6.a(r7, r4)
|
|
java.lang.String r7 = r14.getRequestMethod()
|
|
java.lang.String r8 = "Method"
|
|
r6.a(r8, r7)
|
|
java.lang.String r7 = "User-Agent"
|
|
java.lang.String r8 = r14.getRequestProperty(r7)
|
|
r6.a(r7, r8)
|
|
java.lang.String r7 = "Content-Type"
|
|
java.lang.String r8 = r14.getRequestProperty(r7)
|
|
r6.a(r7, r8)
|
|
int r7 = r13.l()
|
|
r14.setConnectTimeout(r7)
|
|
int r7 = r13.l()
|
|
r14.setReadTimeout(r7)
|
|
com.facebook.HttpMethod r7 = com.facebook.HttpMethod.POST
|
|
if (r3 != r7) goto L6d
|
|
r0 = 1
|
|
L6d:
|
|
if (r0 != 0) goto L73
|
|
r6.a()
|
|
return
|
|
L73:
|
|
r14.setDoOutput(r1)
|
|
r0 = 0
|
|
java.io.BufferedOutputStream r1 = new java.io.BufferedOutputStream // Catch: java.lang.Throwable -> Lc6
|
|
java.io.OutputStream r14 = r14.getOutputStream() // Catch: java.lang.Throwable -> Lc6
|
|
r1.<init>(r14) // Catch: java.lang.Throwable -> Lc6
|
|
if (r5 == 0) goto L8b
|
|
java.util.zip.GZIPOutputStream r14 = new java.util.zip.GZIPOutputStream // Catch: java.lang.Throwable -> L88
|
|
r14.<init>(r1) // Catch: java.lang.Throwable -> L88
|
|
goto L8c
|
|
L88:
|
|
r13 = move-exception
|
|
r14 = r1
|
|
goto Lc8
|
|
L8b:
|
|
r14 = r1
|
|
L8c:
|
|
boolean r0 = d(r13) // Catch: java.lang.Throwable -> Lc4
|
|
if (r0 == 0) goto Lb6
|
|
com.facebook.ProgressNoopOutputStream r0 = new com.facebook.ProgressNoopOutputStream // Catch: java.lang.Throwable -> Lc4
|
|
android.os.Handler r1 = r13.f() // Catch: java.lang.Throwable -> Lc4
|
|
r0.<init>(r1) // Catch: java.lang.Throwable -> Lc4
|
|
r8 = 0
|
|
r7 = r13
|
|
r9 = r2
|
|
r10 = r4
|
|
r11 = r0
|
|
r12 = r5
|
|
a(r7, r8, r9, r10, r11, r12) // Catch: java.lang.Throwable -> Lc4
|
|
int r1 = r0.a() // Catch: java.lang.Throwable -> Lc4
|
|
java.util.Map r10 = r0.b() // Catch: java.lang.Throwable -> Lc4
|
|
com.facebook.ProgressOutputStream r0 = new com.facebook.ProgressOutputStream // Catch: java.lang.Throwable -> Lc4
|
|
long r11 = (long) r1 // Catch: java.lang.Throwable -> Lc4
|
|
r7 = r0
|
|
r8 = r14
|
|
r9 = r13
|
|
r7.<init>(r8, r9, r10, r11) // Catch: java.lang.Throwable -> Lc4
|
|
r14 = r0
|
|
Lb6:
|
|
r0 = r13
|
|
r1 = r6
|
|
r3 = r4
|
|
r4 = r14
|
|
a(r0, r1, r2, r3, r4, r5) // Catch: java.lang.Throwable -> Lc4
|
|
r14.close()
|
|
r6.a()
|
|
return
|
|
Lc4:
|
|
r13 = move-exception
|
|
goto Lc8
|
|
Lc6:
|
|
r13 = move-exception
|
|
r14 = r0
|
|
Lc8:
|
|
if (r14 == 0) goto Lcd
|
|
r14.close()
|
|
Lcd:
|
|
throw r13
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.facebook.GraphRequest.a(com.facebook.GraphRequestBatch, java.net.HttpURLConnection):void");
|
|
}
|
|
|
|
private static void a(GraphRequestBatch graphRequestBatch, Logger logger, int i, URL url, OutputStream outputStream, boolean z) throws IOException, JSONException {
|
|
Serializer serializer = new Serializer(outputStream, logger, z);
|
|
if (i == 1) {
|
|
GraphRequest graphRequest = graphRequestBatch.get(0);
|
|
HashMap hashMap = new HashMap();
|
|
for (String str : graphRequest.h.keySet()) {
|
|
Object obj = graphRequest.h.get(str);
|
|
if (d(obj)) {
|
|
hashMap.put(str, new Attachment(graphRequest, obj));
|
|
}
|
|
}
|
|
if (logger != null) {
|
|
logger.a(" Parameters:\n");
|
|
}
|
|
a(graphRequest.h, serializer, graphRequest);
|
|
if (logger != null) {
|
|
logger.a(" Attachments:\n");
|
|
}
|
|
a(hashMap, serializer);
|
|
JSONObject jSONObject = graphRequest.d;
|
|
if (jSONObject != null) {
|
|
a(jSONObject, url.getPath(), serializer);
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
String c = c(graphRequestBatch);
|
|
if (!Utility.c(c)) {
|
|
serializer.a("batch_app_id", c);
|
|
HashMap hashMap2 = new HashMap();
|
|
a(serializer, graphRequestBatch, hashMap2);
|
|
if (logger != null) {
|
|
logger.a(" Attachments:\n");
|
|
}
|
|
a(hashMap2, serializer);
|
|
return;
|
|
}
|
|
throw new FacebookException("App ID was not specified at the request or Settings.");
|
|
}
|
|
|
|
/* JADX WARN: Removed duplicated region for block: B:12:0x0029 */
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct code enable 'Show inconsistent code' option in preferences
|
|
*/
|
|
private static void a(org.json.JSONObject r6, java.lang.String r7, com.facebook.GraphRequest.KeyValueSerializer r8) throws java.io.IOException {
|
|
/*
|
|
boolean r0 = b(r7)
|
|
r1 = 1
|
|
r2 = 0
|
|
if (r0 == 0) goto L1e
|
|
java.lang.String r0 = ":"
|
|
int r0 = r7.indexOf(r0)
|
|
java.lang.String r3 = "?"
|
|
int r7 = r7.indexOf(r3)
|
|
r3 = 3
|
|
if (r0 <= r3) goto L1e
|
|
r3 = -1
|
|
if (r7 == r3) goto L1c
|
|
if (r0 >= r7) goto L1e
|
|
L1c:
|
|
r7 = 1
|
|
goto L1f
|
|
L1e:
|
|
r7 = 0
|
|
L1f:
|
|
java.util.Iterator r0 = r6.keys()
|
|
L23:
|
|
boolean r3 = r0.hasNext()
|
|
if (r3 == 0) goto L44
|
|
java.lang.Object r3 = r0.next()
|
|
java.lang.String r3 = (java.lang.String) r3
|
|
java.lang.Object r4 = r6.opt(r3)
|
|
if (r7 == 0) goto L3f
|
|
java.lang.String r5 = "image"
|
|
boolean r5 = r3.equalsIgnoreCase(r5)
|
|
if (r5 == 0) goto L3f
|
|
r5 = 1
|
|
goto L40
|
|
L3f:
|
|
r5 = 0
|
|
L40:
|
|
a(r3, r4, r8, r5)
|
|
goto L23
|
|
L44:
|
|
return
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.facebook.GraphRequest.a(org.json.JSONObject, java.lang.String, com.facebook.GraphRequest$KeyValueSerializer):void");
|
|
}
|
|
|
|
private static void a(String str, Object obj, KeyValueSerializer keyValueSerializer, boolean z) throws IOException {
|
|
Class<?> cls = obj.getClass();
|
|
if (JSONObject.class.isAssignableFrom(cls)) {
|
|
JSONObject jSONObject = (JSONObject) obj;
|
|
if (z) {
|
|
Iterator<String> keys = jSONObject.keys();
|
|
while (keys.hasNext()) {
|
|
String next = keys.next();
|
|
a(String.format("%s[%s]", str, next), jSONObject.opt(next), keyValueSerializer, z);
|
|
}
|
|
return;
|
|
}
|
|
if (jSONObject.has(JockstickDataConverter.ID)) {
|
|
a(str, jSONObject.optString(JockstickDataConverter.ID), keyValueSerializer, z);
|
|
return;
|
|
} else if (jSONObject.has("url")) {
|
|
a(str, jSONObject.optString("url"), keyValueSerializer, z);
|
|
return;
|
|
} else {
|
|
if (jSONObject.has("fbsdk:create_object")) {
|
|
a(str, jSONObject.toString(), keyValueSerializer, z);
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
if (JSONArray.class.isAssignableFrom(cls)) {
|
|
JSONArray jSONArray = (JSONArray) obj;
|
|
int length = jSONArray.length();
|
|
for (int i = 0; i < length; i++) {
|
|
a(String.format(Locale.ROOT, "%s[%d]", str, Integer.valueOf(i)), jSONArray.opt(i), keyValueSerializer, z);
|
|
}
|
|
return;
|
|
}
|
|
if (!String.class.isAssignableFrom(cls) && !Number.class.isAssignableFrom(cls) && !Boolean.class.isAssignableFrom(cls)) {
|
|
if (Date.class.isAssignableFrom(cls)) {
|
|
keyValueSerializer.a(str, new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US).format((Date) obj));
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
keyValueSerializer.a(str, obj.toString());
|
|
}
|
|
|
|
private static void a(Bundle bundle, Serializer serializer, GraphRequest graphRequest) throws IOException {
|
|
for (String str : bundle.keySet()) {
|
|
Object obj = bundle.get(str);
|
|
if (e(obj)) {
|
|
serializer.a(str, obj, graphRequest);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void a(Map<String, Attachment> map, Serializer serializer) throws IOException {
|
|
for (String str : map.keySet()) {
|
|
Attachment attachment = map.get(str);
|
|
if (d(attachment.b())) {
|
|
serializer.a(str, attachment.b(), attachment.a());
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void a(Serializer serializer, Collection<GraphRequest> collection, Map<String, Attachment> map) throws JSONException, IOException {
|
|
JSONArray jSONArray = new JSONArray();
|
|
Iterator<GraphRequest> it = collection.iterator();
|
|
while (it.hasNext()) {
|
|
it.next().a(jSONArray, map);
|
|
}
|
|
serializer.a("batch", jSONArray, collection);
|
|
}
|
|
}
|