package com.czhj.devicehelper.oaId.helpers; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.content.pm.PackageInfo; import android.content.pm.Signature; import android.os.Build; import android.os.IBinder; import android.os.Looper; import com.czhj.devicehelper.oaId.helpers.DevicesIDsHelper; import com.czhj.devicehelper.oaId.interfaces.e; import com.czhj.sdk.logger.SigmobLog; import java.security.MessageDigest; import java.util.concurrent.LinkedBlockingQueue; import kotlin.UByte; public class g { public String a = "OUID"; e b; public final LinkedBlockingQueue<IBinder> c = new LinkedBlockingQueue<>(1); ServiceConnection d = new ServiceConnection() { /* class com.czhj.devicehelper.oaId.helpers.g.AnonymousClass1 */ public void onServiceConnected(ComponentName componentName, IBinder iBinder) { try { g.this.c.put(iBinder); } catch (Throwable unused) { } } public void onServiceDisconnected(ComponentName componentName) { g.this.b = null; } }; private Context e; private String f; public g(Context context) { this.e = context; } private String a(String str) { Signature[] signatureArr; String packageName = this.e.getPackageName(); if (this.f == null) { String str2 = null; try { signatureArr = this.e.getPackageManager().getPackageInfo(packageName, 64).signatures; } catch (Exception e2) { SigmobLog.e(e2.getMessage()); signatureArr = null; } if (signatureArr != null && signatureArr.length > 0) { byte[] byteArray = signatureArr[0].toByteArray(); try { MessageDigest instance = MessageDigest.getInstance("SHA1"); if (instance != null) { byte[] digest = instance.digest(byteArray); StringBuilder sb = new StringBuilder(); for (byte b2 : digest) { sb.append(Integer.toHexString((b2 & UByte.MAX_VALUE) | 256).substring(1, 3)); } str2 = sb.toString(); } } catch (Exception e3) { SigmobLog.e(e3.getMessage()); } } this.f = str2; } return ((e.a.C0036a) this.b).a(packageName, this.f, str); } private boolean a() { try { PackageInfo packageInfo = this.e.getPackageManager().getPackageInfo("com.heytap.openid", 0); if (packageInfo == null) { return false; } return (Build.VERSION.SDK_INT >= 28 ? packageInfo.getLongVersionCode() : (long) packageInfo.versionCode) >= 1; } catch (Exception e2) { SigmobLog.e(e2.getMessage()); return false; } } public void a(DevicesIDsHelper.AppIdsUpdater appIdsUpdater) { if (a() && Looper.myLooper() != Looper.getMainLooper()) { Intent intent = new Intent(); intent.setComponent(new ComponentName("com.heytap.openid", "com.heytap.openid.IdentifyService")); intent.setAction("action.com.heytap.openid.OPEN_ID_SERVICE"); if (this.e.bindService(intent, this.d, 1)) { try { e a2 = e.a.a(this.c.take()); this.b = a2; if (a2 != null) { String a3 = a("OUID"); if (appIdsUpdater != null) { appIdsUpdater.OnIdsAvalid(a3); } } } catch (Throwable th) { this.e.unbindService(this.d); throw th; } this.e.unbindService(this.d); } } } }