package com.sina.weibo.sdk.utils; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.StatFs; import android.provider.Settings; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.DisplayMetrics; import android.view.WindowManager; import androidx.core.os.EnvironmentCompat; import com.health.doctor.networkhospital.order.detail.OrderDetail; import com.health.im.chat.domain.GroupChatMember; import com.sina.weibo.sdk.exception.WeiboException; import com.sina.weibo.sdk.net.HttpManager; import com.sina.weibo.sdk.net.WeiboParameters; import com.toogoo.appbase.bean.PrescriptionPatientInfo; import com.umeng.analytics.pro.c; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.lang.ref.WeakReference; import java.security.KeyFactory; import java.security.PublicKey; import java.security.spec.X509EncodedKeySpec; import java.util.ArrayList; import java.util.concurrent.locks.ReentrantLock; import javax.crypto.Cipher; import org.json.JSONException; import org.json.JSONObject; public class AidTask { private static final String AID_FILE_NAME = "weibo_sdk_aid"; public static final String AID_TAG = "weibo_aid_value"; private static final int MAX_RETRY_NUM = 3; private static final String TAG = "AidTask"; private static final int VERSION = 1; public static final int WHAT_LOAD_AID_ERR = 1002; public static final int WHAT_LOAD_AID_SUC = 1001; private static AidTask sInstance; private String hash; private AidInfo mAidInfo; private String mAppKey; private Context mContext; private CallbackHandler mHandler; private ArrayList<WeiboUtilListener> mListeners = new ArrayList<>(); private volatile ReentrantLock mTaskLock = new ReentrantLock(true); private String pkg; public static final class AidInfo { private String mAid; private String mSubCookie; public static AidInfo parseJson(String str) throws WeiboException { AidInfo aidInfo = new AidInfo(); try { JSONObject jSONObject = new JSONObject(str); if (jSONObject.has(c.O) || jSONObject.has("error_code")) { LogUtil.d(AidTask.TAG, "loadAidFromNet has error !!!"); throw new WeiboException("loadAidFromNet has error !!!"); } aidInfo.mAid = jSONObject.optString("aid", ""); aidInfo.mSubCookie = jSONObject.optString("sub", ""); return aidInfo; } catch (JSONException e2) { LogUtil.d(AidTask.TAG, "loadAidFromNet JSONException Msg : " + e2.getMessage()); throw new WeiboException("loadAidFromNet has error !!!"); } } /* access modifiers changed from: package-private */ public AidInfo cloneAidInfo() { AidInfo aidInfo = new AidInfo(); aidInfo.mAid = this.mAid; aidInfo.mSubCookie = this.mSubCookie; return aidInfo; } public String getAid() { return this.mAid; } public String getSubCookie() { return this.mSubCookie; } } public interface AidResultCallBack { void onAidGenFailed(Exception exc); void onAidGenSuccessed(AidInfo aidInfo); } /* access modifiers changed from: private */ public static class CallbackHandler extends Handler { private WeakReference<AidResultCallBack> callBackReference; public CallbackHandler(Looper looper) { super(looper); } public void handleMessage(Message message) { AidResultCallBack aidResultCallBack = this.callBackReference.get(); int i = message.what; if (i != 1001) { if (i == 1002 && aidResultCallBack != null) { aidResultCallBack.onAidGenFailed((WeiboException) message.obj); } } else if (aidResultCallBack != null) { aidResultCallBack.onAidGenSuccessed(((AidInfo) message.obj).cloneAidInfo()); } } public void setCallback(AidResultCallBack aidResultCallBack) { WeakReference<AidResultCallBack> weakReference; WeakReference<AidResultCallBack> weakReference2 = this.callBackReference; if (weakReference2 == null) { weakReference = new WeakReference<>(aidResultCallBack); } else if (weakReference2.get() != aidResultCallBack) { weakReference = new WeakReference<>(aidResultCallBack); } else { return; } this.callBackReference = weakReference; } } private AidTask(Context context) { if (context != null) { this.mContext = context.getApplicationContext(); this.mHandler = new CallbackHandler(this.mContext.getMainLooper()); new Thread(new Runnable() { /* class com.sina.weibo.sdk.utils.AidTask.AnonymousClass1 */ public void run() { for (int i = 0; i < 1; i++) { try { AidTask.this.getAidInfoFile(i).delete(); } catch (Exception unused) { } } } }).start(); } } private void aidTaskInit(String str, String str2, String str3) { if (!TextUtils.isEmpty(str)) { LogUtil.e(TAG, "aidTaskInit "); initAidInfo(str, str2, str3); } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ /* JADX WARNING: Removed duplicated region for block: B:19:0x0027 A[SYNTHETIC, Splitter:B:19:0x0027] */ /* JADX WARNING: Removed duplicated region for block: B:25:0x002e */ private synchronized void cacheAidInfo(String str) { Throwable th; if (!TextUtils.isEmpty(str)) { FileOutputStream fileOutputStream = null; try { FileOutputStream fileOutputStream2 = new FileOutputStream(getAidInfoFile(1)); try { fileOutputStream2.write(str.getBytes()); try { fileOutputStream2.close(); } catch (IOException unused) { } } catch (Exception unused2) { fileOutputStream = fileOutputStream2; if (fileOutputStream != null) { } } catch (Throwable th2) { th = th2; fileOutputStream = fileOutputStream2; if (fileOutputStream != null) { } throw th; } } catch (Exception unused3) { if (fileOutputStream != null) { fileOutputStream.close(); } } catch (Throwable th3) { th = th3; if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException unused4) { } } throw th; } } } /* JADX WARNING: Removed duplicated region for block: B:19:0x00bd A[SYNTHETIC, Splitter:B:19:0x00bd] */ private static String encryptRsa(String str, String str2) throws Exception { Throwable th; ByteArrayOutputStream byteArrayOutputStream; Cipher instance = Cipher.getInstance("RSA/ECB/PKCS1Padding"); instance.init(1, getPublicKey(str2)); byte[] bytes = str.getBytes("UTF-8"); try { byteArrayOutputStream = new ByteArrayOutputStream(); int i = 0; while (true) { try { int splite = splite(bytes, i, 117); if (splite == -1) { break; } byte[] doFinal = instance.doFinal(bytes, i, splite); byteArrayOutputStream.write(doFinal); LogUtil.d(TAG, "encryptRsa offset = " + i + " len = " + splite + " enBytes len = " + doFinal.length); i += splite; } catch (Throwable th2) { th = th2; if (byteArrayOutputStream != null) { try { byteArrayOutputStream.close(); } catch (IOException unused) { } } throw th; } } byteArrayOutputStream.flush(); byte[] byteArray = byteArrayOutputStream.toByteArray(); LogUtil.d(TAG, "encryptRsa total enBytes len = " + byteArray.length); byte[] encodebyte = Base64.encodebyte(byteArray); LogUtil.d(TAG, "encryptRsa total base64byte len = " + encodebyte.length); String str3 = "01" + new String(encodebyte, "UTF-8"); LogUtil.d(TAG, "encryptRsa total base64string : " + str3); try { byteArrayOutputStream.close(); } catch (IOException unused2) { } return str3; } catch (Throwable th3) { th = th3; byteArrayOutputStream = null; if (byteArrayOutputStream != null) { } throw th; } } private static String genMfpString(Context context) { String str; JSONObject jSONObject = new JSONObject(); try { String os = getOS(); if (!TextUtils.isEmpty(os)) { jSONObject.put("1", os); } String imei = getImei(context); if (!TextUtils.isEmpty(imei)) { jSONObject.put("2", imei); } String meid = getMeid(context); if (!TextUtils.isEmpty(meid)) { jSONObject.put("3", meid); } String imsi = getImsi(context); if (!TextUtils.isEmpty(imsi)) { jSONObject.put("4", imsi); } String mac = getMac(context); if (!TextUtils.isEmpty(mac)) { jSONObject.put("5", mac); } String iccid = getIccid(context); if (!TextUtils.isEmpty(iccid)) { jSONObject.put(OrderDetail.Item.TYPE_CHECK, iccid); } String serialNo = getSerialNo(); if (!TextUtils.isEmpty(serialNo)) { jSONObject.put("7", serialNo); } String androidId = getAndroidId(context); if (!TextUtils.isEmpty(androidId)) { jSONObject.put("10", androidId); } String cpu = getCpu(); if (!TextUtils.isEmpty(cpu)) { jSONObject.put("13", cpu); } String model = getModel(); if (!TextUtils.isEmpty(model)) { jSONObject.put("14", model); } String sdSize = getSdSize(); if (!TextUtils.isEmpty(sdSize)) { jSONObject.put("15", sdSize); } String resolution = getResolution(context); if (!TextUtils.isEmpty(resolution)) { jSONObject.put("16", resolution); } String ssid = getSsid(context); if (!TextUtils.isEmpty(ssid)) { jSONObject.put("17", ssid); } String deviceName = getDeviceName(); if (!TextUtils.isEmpty(deviceName)) { jSONObject.put("18", deviceName); } String connectType = getConnectType(context); if (!TextUtils.isEmpty(connectType)) { jSONObject.put("19", connectType); } try { str = Utility.generateUAAid(context); } catch (Exception e2) { e2.printStackTrace(); str = ""; } if (!TextUtils.isEmpty(str)) { jSONObject.put(GroupChatMember.GROUP_ROLE_MANAGER, str); } return jSONObject.toString(); } catch (JSONException unused) { return ""; } } private void generateAid(String str, AidResultCallBack aidResultCallBack) { generateAid(str, null, null, aidResultCallBack); } private void generateAid(String str, String str2, String str3, final AidResultCallBack aidResultCallBack) { if (!TextUtils.isEmpty(str)) { this.mAppKey = str; this.hash = str3; this.pkg = str2; new Thread(new Runnable() { /* class com.sina.weibo.sdk.utils.AidTask.AnonymousClass3 */ public void run() { AidTask.this.mTaskLock.lock(); AidInfo loadAidInfoFromCache = AidTask.this.loadAidInfoFromCache(); WeiboException e2 = null; if (loadAidInfoFromCache == null) { try { String loadAidFromNet = AidTask.this.loadAidFromNet(); loadAidInfoFromCache = AidInfo.parseJson(loadAidFromNet); AidTask.this.cacheAidInfo(loadAidFromNet); AidTask.this.mAidInfo = loadAidInfoFromCache; } catch (WeiboException e3) { e2 = e3; LogUtil.e(AidTask.TAG, "AidTaskInit WeiboException Msg : " + e2.getMessage()); } } AidTask.this.mTaskLock.unlock(); Message obtain = Message.obtain(); if (loadAidInfoFromCache != null) { obtain.what = 1001; obtain.obj = loadAidInfoFromCache; } else { obtain.what = 1002; obtain.obj = e2; } AidTask.this.mHandler.setCallback(aidResultCallBack); AidTask.this.mHandler.sendMessage(obtain); } }).start(); } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private File getAidInfoFile(int i) { File filesDir = this.mContext.getFilesDir(); return new File(filesDir, AID_FILE_NAME + i); } private static String getAndroidId(Context context) { try { return Settings.Secure.getString(context.getContentResolver(), "android_id"); } catch (Exception unused) { return ""; } } private static String getConnectType(Context context) { String str; try { NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo(); if (activeNetworkInfo == null) { return "none"; } if (activeNetworkInfo.getType() == 0) { switch (activeNetworkInfo.getSubtype()) { case 1: case 2: case 4: case 7: case 11: str = "2G"; break; case 3: case 5: case 6: case 8: case 9: case 10: case 12: case 14: case 15: str = "3G"; break; case 13: str = "4G"; break; default: return "none"; } } else if (activeNetworkInfo.getType() != 1) { return "none"; } else { str = "wifi"; } return str; } catch (Exception unused) { return "none"; } } private static String getCpu() { try { return Build.CPU_ABI; } catch (Exception unused) { return ""; } } private static String getDeviceName() { try { return Build.BRAND; } catch (Exception unused) { return ""; } } private static String getIccid(Context context) { try { return ((TelephonyManager) context.getSystemService("phone")).getSimSerialNumber(); } catch (Exception unused) { return ""; } } public static String getImei(Context context) { try { return ((TelephonyManager) context.getSystemService("phone")).getDeviceId(); } catch (Exception unused) { return ""; } } private static String getImsi(Context context) { try { return ((TelephonyManager) context.getSystemService("phone")).getSubscriberId(); } catch (Exception unused) { return ""; } } public static synchronized AidTask getInstance(Context context) { AidTask aidTask; synchronized (AidTask.class) { if (sInstance == null) { sInstance = new AidTask(context); } aidTask = sInstance; } return aidTask; } private static String getMac(Context context) { WifiInfo connectionInfo; try { WifiManager wifiManager = (WifiManager) context.getSystemService("wifi"); return (wifiManager == null || (connectionInfo = wifiManager.getConnectionInfo()) == null) ? "" : connectionInfo.getMacAddress(); } catch (Exception unused) { return ""; } } private static String getMeid(Context context) { try { return ((TelephonyManager) context.getSystemService("phone")).getDeviceId(); } catch (Exception unused) { return ""; } } private static String getMfp(Context context) { String str; try { str = new String(genMfpString(context).getBytes(), "UTF-8"); } catch (UnsupportedEncodingException unused) { str = ""; } LogUtil.d(TAG, "genMfpString() utf-8 string : " + str); try { String encryptRsa = encryptRsa(str, "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDHHM0Fi2Z6+QYKXqFUX2Cy6AaWq3cPi+GSn9oeAwQbPZR75JB7Netm0HtBVVbtPhzT7UO2p1JhFUKWqrqoYuAjkgMVPmA0sFrQohns5EE44Y86XQopD4ZO+dE5KjUZFE6vrPO3rWW3np2BqlgKpjnYZri6TJApmIpGcQg9/G/3zQIDAQAB"); LogUtil.d(TAG, "encryptRsa() string : " + encryptRsa); return encryptRsa; } catch (Exception e2) { LogUtil.e(TAG, e2.getMessage()); return ""; } } private static String getModel() { try { return Build.MODEL; } catch (Exception unused) { return ""; } } private static String getOS() { try { return "Android " + Build.VERSION.RELEASE; } catch (Exception unused) { return ""; } } private static PublicKey getPublicKey(String str) throws Exception { return KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(Base64.decode(str.getBytes()))); } private static String getResolution(Context context) { try { DisplayMetrics displayMetrics = new DisplayMetrics(); ((WindowManager) context.getSystemService("window")).getDefaultDisplay().getMetrics(displayMetrics); return String.valueOf(displayMetrics.widthPixels) + "*" + String.valueOf(displayMetrics.heightPixels); } catch (Exception unused) { return ""; } } private static String getSdSize() { try { StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getPath()); return Long.toString(((long) statFs.getBlockCount()) * ((long) statFs.getBlockSize())); } catch (Exception unused) { return ""; } } private static String getSerialNo() { try { Class<?> cls = Class.forName("android.os.SystemProperties"); return (String) cls.getMethod(PrescriptionPatientInfo.OPERATE_PRESCRIPTIONPATIENTINFO_GET, String.class, String.class).invoke(cls, "ro.serialno", EnvironmentCompat.MEDIA_UNKNOWN); } catch (Exception unused) { return ""; } } private static String getSsid(Context context) { try { WifiInfo connectionInfo = ((WifiManager) context.getSystemService("wifi")).getConnectionInfo(); return connectionInfo != null ? connectionInfo.getSSID() : ""; } catch (Exception unused) { return ""; } } private void initAidInfo(String str) { initAidInfo(str, null, null); } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private String loadAidFromNet() throws WeiboException { String str = this.pkg; if (str == null) { str = this.mContext.getPackageName(); } String str2 = this.hash; if (str2 == null) { str2 = Utility.getSign(this.mContext, str); } String mfp = getMfp(this.mContext); WeiboParameters weiboParameters = new WeiboParameters(this.mAppKey); weiboParameters.put("appkey", this.mAppKey); weiboParameters.put("mfp", mfp); weiboParameters.put("packagename", str); weiboParameters.put("key_hash", str2); try { String openUrl = HttpManager.openUrl(this.mContext, "https://api.weibo.com/oauth2/getaid.json", "GET", weiboParameters); LogUtil.d(TAG, "loadAidFromNet response : " + openUrl); return openUrl; } catch (WeiboException e2) { LogUtil.d(TAG, "loadAidFromNet WeiboException Msg : " + e2.getMessage()); throw e2; } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void notifyListener(AidInfo aidInfo) { Bundle bundle = new Bundle(); if (aidInfo != null) { bundle.putString(AID_TAG, aidInfo.getAid()); } try { if (this.mListeners != null && this.mListeners.size() > 0) { for (int i = 0; i < this.mListeners.size(); i++) { this.mListeners.get(i).onComplete(bundle); } } } catch (Exception e2) { e2.printStackTrace(); } } private static int splite(byte[] bArr, int i, int i2) { if (i >= bArr.length) { return -1; } return Math.min(bArr.length - i, i2); } public void addListener(WeiboUtilListener weiboUtilListener) { if (this.mListeners == null) { this.mListeners = new ArrayList<>(); } this.mListeners.add(weiboUtilListener); } public void aidTaskInit(String str) { if (!TextUtils.isEmpty(str)) { LogUtil.e(TAG, "aidTaskInit "); initAidInfo(str); } } public void getAidAsync(String str, AidResultCallBack aidResultCallBack) { if (!TextUtils.isEmpty(str)) { AidInfo aidInfo = this.mAidInfo; if (aidInfo == null || aidResultCallBack == null) { generateAid(str, aidResultCallBack); } else { aidResultCallBack.onAidGenSuccessed(aidInfo.cloneAidInfo()); } } } public AidInfo getAidSync(String str) throws WeiboException { if (TextUtils.isEmpty(str)) { return null; } LogUtil.e(TAG, "getAidSync "); if (this.mAidInfo == null) { aidTaskInit(str); } return this.mAidInfo; } public void initAidInfo(String str, String str2, String str3) { if (!TextUtils.isEmpty(str)) { this.mAppKey = str; this.pkg = str2; this.hash = str3; new Thread(new Runnable() { /* class com.sina.weibo.sdk.utils.AidTask.AnonymousClass2 */ public void run() { if (!AidTask.this.mTaskLock.tryLock()) { LogUtil.e(AidTask.TAG, "tryLock : false, return"); return; } AidInfo loadAidInfoFromCache = AidTask.this.loadAidInfoFromCache(); if (loadAidInfoFromCache == null) { int i = 1; do { i++; try { String loadAidFromNet = AidTask.this.loadAidFromNet(); AidInfo parseJson = AidInfo.parseJson(loadAidFromNet); AidTask.this.cacheAidInfo(loadAidFromNet); AidTask.this.mAidInfo = parseJson; AidTask.this.notifyListener(AidTask.this.mAidInfo); break; } catch (WeiboException e2) { LogUtil.e(AidTask.TAG, "AidTaskInit WeiboException Msg : " + e2.getMessage()); if (i >= 3) { } } } while (i >= 3); } else { AidTask.this.mAidInfo = loadAidInfoFromCache; } AidTask.this.mTaskLock.unlock(); } }).start(); } } public String loadAidFromCache() { AidInfo loadAidInfoFromCache = loadAidInfoFromCache(); return (loadAidInfoFromCache == null || loadAidInfoFromCache.getAid() == null) ? "" : loadAidInfoFromCache.getAid(); } /* access modifiers changed from: protected */ /* JADX WARNING: Exception block dominator not found, dom blocks: [] */ /* JADX WARNING: Missing exception handler attribute for start block: B:18:0x002e */ /* JADX WARNING: Removed duplicated region for block: B:16:0x002b A[SYNTHETIC, Splitter:B:16:0x002b] */ /* JADX WARNING: Removed duplicated region for block: B:23:0x0032 A[SYNTHETIC, Splitter:B:23:0x0032] */ public synchronized AidInfo loadAidInfoFromCache() { FileInputStream fileInputStream; Throwable th; try { fileInputStream = new FileInputStream(getAidInfoFile(1)); try { byte[] bArr = new byte[fileInputStream.available()]; fileInputStream.read(bArr); AidInfo parseJson = AidInfo.parseJson(new String(bArr)); try { fileInputStream.close(); } catch (IOException unused) { } return parseJson; } catch (Exception unused2) { if (fileInputStream != null) { } return null; } catch (Throwable th2) { th = th2; if (fileInputStream != null) { } throw th; } } catch (Exception unused3) { fileInputStream = null; if (fileInputStream != null) { try { fileInputStream.close(); } catch (IOException unused4) { } } return null; } catch (Throwable th3) { th = th3; fileInputStream = null; if (fileInputStream != null) { fileInputStream.close(); } throw th; } } public void removeListener(WeiboUtilListener weiboUtilListener) { ArrayList<WeiboUtilListener> arrayList = this.mListeners; if (arrayList != null && arrayList.size() > 0) { this.mListeners.remove(weiboUtilListener); } } public synchronized void setAppkey(String str) { this.mAppKey = str; } }