90 lines
3.3 KiB
Java
90 lines
3.3 KiB
Java
package com.facebook.devicerequests.internal;
|
|
|
|
import android.annotation.TargetApi;
|
|
import android.net.nsd.NsdManager;
|
|
import android.net.nsd.NsdServiceInfo;
|
|
import android.os.Build;
|
|
import com.facebook.FacebookSdk;
|
|
import com.facebook.internal.FetchedAppSettingsManager;
|
|
import com.facebook.internal.SmartLoginOption;
|
|
import java.util.HashMap;
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class DeviceRequestsHelper {
|
|
private static HashMap<String, NsdManager.RegistrationListener> a = new HashMap<>();
|
|
|
|
public static String a() {
|
|
JSONObject jSONObject = new JSONObject();
|
|
try {
|
|
jSONObject.put("device", Build.DEVICE);
|
|
jSONObject.put("model", Build.MODEL);
|
|
} catch (JSONException unused) {
|
|
}
|
|
return jSONObject.toString();
|
|
}
|
|
|
|
public static boolean b() {
|
|
return Build.VERSION.SDK_INT >= 16 && FetchedAppSettingsManager.c(FacebookSdk.c()).f().contains(SmartLoginOption.Enabled);
|
|
}
|
|
|
|
public static boolean c(String str) {
|
|
if (b()) {
|
|
return d(str);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@TargetApi(16)
|
|
private static boolean d(final String str) {
|
|
if (a.containsKey(str)) {
|
|
return true;
|
|
}
|
|
final String format = String.format("%s_%s_%s", "fbsdk", String.format("%s-%s", "android", FacebookSdk.l().replace('.', '|')), str);
|
|
NsdServiceInfo nsdServiceInfo = new NsdServiceInfo();
|
|
nsdServiceInfo.setServiceType("_fb._tcp.");
|
|
nsdServiceInfo.setServiceName(format);
|
|
nsdServiceInfo.setPort(80);
|
|
NsdManager nsdManager = (NsdManager) FacebookSdk.b().getSystemService("servicediscovery");
|
|
NsdManager.RegistrationListener registrationListener = new NsdManager.RegistrationListener() { // from class: com.facebook.devicerequests.internal.DeviceRequestsHelper.1
|
|
@Override // android.net.nsd.NsdManager.RegistrationListener
|
|
public void onRegistrationFailed(NsdServiceInfo nsdServiceInfo2, int i) {
|
|
DeviceRequestsHelper.a(str);
|
|
}
|
|
|
|
@Override // android.net.nsd.NsdManager.RegistrationListener
|
|
public void onServiceRegistered(NsdServiceInfo nsdServiceInfo2) {
|
|
if (format.equals(nsdServiceInfo2.getServiceName())) {
|
|
return;
|
|
}
|
|
DeviceRequestsHelper.a(str);
|
|
}
|
|
|
|
@Override // android.net.nsd.NsdManager.RegistrationListener
|
|
public void onServiceUnregistered(NsdServiceInfo nsdServiceInfo2) {
|
|
}
|
|
|
|
@Override // android.net.nsd.NsdManager.RegistrationListener
|
|
public void onUnregistrationFailed(NsdServiceInfo nsdServiceInfo2, int i) {
|
|
}
|
|
};
|
|
a.put(str, registrationListener);
|
|
nsdManager.registerService(nsdServiceInfo, 1, registrationListener);
|
|
return true;
|
|
}
|
|
|
|
@TargetApi(16)
|
|
private static void b(String str) {
|
|
NsdManager.RegistrationListener registrationListener = a.get(str);
|
|
if (registrationListener != null) {
|
|
((NsdManager) FacebookSdk.b().getSystemService("servicediscovery")).unregisterService(registrationListener);
|
|
a.remove(str);
|
|
}
|
|
}
|
|
|
|
public static void a(String str) {
|
|
b(str);
|
|
}
|
|
}
|