package cn.jiguang.x; import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.Looper; import android.text.TextUtils; import cn.jiguang.o.d; import java.util.concurrent.Callable; import java.util.concurrent.FutureTask; import java.util.concurrent.TimeUnit; import org.json.JSONObject; public class a { /* access modifiers changed from: package-private */ /* renamed from: cn.jiguang.x.a$a reason: collision with other inner class name */ public static class CallableC0009a implements Callable<String> { private Context a; public CallableC0009a(Context context) { this.a = context; } /* renamed from: a */ public String call() { try { return a.h(this.a); } catch (Throwable th) { cn.jiguang.af.a.d("IdHelper", "[GoogleIdCall] failed:" + th.getMessage()); return ""; } } } /* access modifiers changed from: package-private */ public static class b implements Callable<String> { private Context a; public b(Context context) { this.a = context; } /* renamed from: a */ public String call() { try { String str = Build.MANUFACTURER; if (TextUtils.isEmpty(str)) { return ""; } if ("huawei".equals(str.toLowerCase())) { return a.i(this.a); } cn.jiguang.af.a.d("IdHelper", "not supported this device:" + str); return ""; } catch (Throwable th) { cn.jiguang.af.a.d("IdHelper", "[LocalIdCall] failed:" + th.getMessage()); return ""; } } } public static JSONObject a(Context context) { try { JSONObject jSONObject = new JSONObject(); String b2 = b(context); cn.jiguang.af.a.a("IdHelper", "[getAllIds] miit id is: " + b2); if (!TextUtils.isEmpty(b2)) { jSONObject = new JSONObject(b2); } else { String str = Build.MANUFACTURER; if (!TextUtils.isEmpty(str)) { if (str.toLowerCase().equals("xiaomi")) { String a = cn.jiguang.ac.a.a(context); if (!TextUtils.isEmpty(a)) { jSONObject = new JSONObject(a); } } else { String c = c(context); if (TextUtils.isEmpty(c)) { c = ""; } jSONObject.put("oaid", c); } } } String d = d(context); if (TextUtils.isEmpty(d)) { d = ""; } jSONObject.put("gadid", d); return jSONObject; } catch (Throwable th) { cn.jiguang.af.a.d("IdHelper", "[getAllIds] failed:" + th.getMessage()); return null; } } private static boolean a() { try { Class<?> cls = Class.forName("com.bun.miitmdid.core.MdidSdkHelper"); cn.jiguang.af.a.a("IdHelper", "MdidSdkHelper name:" + cls.getName()); return true; } catch (Throwable th) { cn.jiguang.af.a.d("IdHelper", "not found mitt class" + th); return false; } } public static String b(Context context) { if (b()) { cn.jiguang.af.a.f("IdHelper", "not get id in main thread"); return ""; } else if (!a()) { return ""; } else { String g = g(context); if (!TextUtils.isEmpty(g)) { return g; } cn.jiguang.af.a.d("IdHelper", "not get ids by mitts"); return ""; } } private static boolean b() { try { return Looper.getMainLooper().getThread().getId() == Thread.currentThread().getId(); } catch (Throwable th) { cn.jiguang.af.a.d("IdHelper", "[isMainThread] failed:" + th.getMessage()); return true; } } public static String c(Context context) { try { if (b()) { cn.jiguang.af.a.d("IdHelper", "not get id in main thread"); return ""; } FutureTask futureTask = new FutureTask(new b(context)); d.b(futureTask); return (String) futureTask.get(1, TimeUnit.SECONDS); } catch (Throwable th) { cn.jiguang.af.a.d("IdHelper", "getOaidByLocal failed:" + th.getMessage()); return ""; } } public static String d(Context context) { try { if (b()) { cn.jiguang.af.a.d("IdHelper", "not get id in main thread"); return ""; } FutureTask futureTask = new FutureTask(new CallableC0009a(context)); d.b(futureTask); return (String) futureTask.get(1, TimeUnit.SECONDS); } catch (Throwable th) { cn.jiguang.af.a.d("IdHelper", "getGoogleAdid failed:" + th.getMessage()); return ""; } } private static String g(Context context) { try { Class.forName("com.bun.miitmdid.core.IIdentifierListener"); FutureTask futureTask = new FutureTask(new cn.jiguang.aa.a(context)); d.b(futureTask); return (String) futureTask.get(2, TimeUnit.SECONDS); } catch (Throwable th) { cn.jiguang.af.a.d("IdHelper", "getMittIds by version 13 failed:" + th); return ""; } } /* access modifiers changed from: private */ public static String h(Context context) { if (b()) { cn.jiguang.af.a.f("IdHelper", "not get id in main thread"); return ""; } try { context.getPackageManager().getPackageInfo("com.android.vending", 0); try { Intent intent = new Intent("com.google.android.gms.ads.identifier.service.START"); intent.setPackage("com.google.android.gms"); cn.jiguang.y.b bVar = new cn.jiguang.y.b(); if (context.bindService(intent, bVar, 1)) { try { if (bVar.a) { cn.jiguang.af.a.f("IdHelper", "repeat bind"); return ""; } cn.jiguang.y.a aVar = new cn.jiguang.y.a(bVar.b.take()); cn.jiguang.af.a.a("IdHelper", "google ad id:" + aVar.a()); String a = aVar.a(); context.unbindService(bVar); return a; } catch (Throwable unused) { return ""; } finally { context.unbindService(bVar); } } else { cn.jiguang.af.a.d("IdHelper", "bind failed"); return ""; } } catch (Throwable th) { cn.jiguang.af.a.d("IdHelper", "getAdvertisingIdInfo Exception: " + th.toString()); return ""; } } catch (Throwable unused2) { cn.jiguang.af.a.a("IdHelper", "not supported google"); return ""; } } /* access modifiers changed from: private */ public static String i(Context context) { try { context.getPackageManager().getPackageInfo("com.huawei.hwid", 0); try { Intent intent = new Intent("com.uodis.opendevice.OPENIDS_SERVICE"); intent.setPackage("com.huawei.hwid"); cn.jiguang.z.b bVar = new cn.jiguang.z.b(); if (context.bindService(intent, bVar, 1)) { try { if (bVar.a) { cn.jiguang.af.a.f("IdHelper", "repeat bind"); return ""; } cn.jiguang.z.a aVar = new cn.jiguang.z.a(bVar.b.take()); cn.jiguang.af.a.a("IdHelper", "oaid:" + aVar.a()); String a = aVar.a(); context.unbindService(bVar); return a; } catch (Throwable unused) { return ""; } finally { context.unbindService(bVar); } } else { cn.jiguang.af.a.d("IdHelper", "bind failed"); return ""; } } catch (Throwable th) { cn.jiguang.af.a.d("IdHelper", "getAdvertisingIdInfo Exception: " + th.toString()); return ""; } } catch (Throwable unused2) { return ""; } } }