package com.appsflyer.internal;

import android.content.Context;
import android.content.SharedPreferences;
import com.appsflyer.AFLogger;
import com.appsflyer.AppsFlyerLibCore;
import com.appsflyer.AppsFlyerProperties;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.lang.ref.WeakReference;
import java.security.SecureRandom;

public final class af {

    /* renamed from: ˎ  reason: contains not printable characters */
    public static String f2012;

    /* JADX WARNING: Removed duplicated region for block: B:20:0x0033 A[SYNTHETIC, Splitter:B:20:0x0033] */
    /* JADX WARNING: Removed duplicated region for block: B:27:0x0041  */
    /* JADX WARNING: Removed duplicated region for block: B:31:0x004a A[SYNTHETIC, Splitter:B:31:0x004a] */
    /* renamed from: ˎ  reason: contains not printable characters */
    public static String m1185(File file) {
        Throwable th;
        IOException e;
        byte[] bArr;
        RandomAccessFile randomAccessFile = null;
        byte[] bArr2 = null;
        try {
            RandomAccessFile randomAccessFile2 = new RandomAccessFile(file, "r");
            try {
                bArr2 = new byte[((int) randomAccessFile2.length())];
                randomAccessFile2.readFully(bArr2);
                randomAccessFile2.close();
                try {
                    randomAccessFile2.close();
                } catch (IOException e2) {
                    AFLogger.afErrorLog("Exception while trying to close the InstallationFile", e2);
                }
            } catch (IOException e3) {
                e = e3;
                bArr = bArr2;
                randomAccessFile = randomAccessFile2;
                try {
                    AFLogger.afErrorLog("Exception while reading InstallationFile: ", e);
                    if (randomAccessFile != null) {
                    }
                    bArr2 = bArr;
                    if (bArr2 == null) {
                    }
                    return new String(bArr2);
                } catch (Throwable th2) {
                    th = th2;
                    if (randomAccessFile != null) {
                        try {
                            randomAccessFile.close();
                        } catch (IOException e4) {
                            AFLogger.afErrorLog("Exception while trying to close the InstallationFile", e4);
                        }
                    }
                    throw th;
                }
            } catch (Throwable th3) {
                th = th3;
                randomAccessFile = randomAccessFile2;
                if (randomAccessFile != null) {
                }
                throw th;
            }
        } catch (IOException e5) {
            e = e5;
            bArr = null;
            AFLogger.afErrorLog("Exception while reading InstallationFile: ", e);
            if (randomAccessFile != null) {
                try {
                    randomAccessFile.close();
                } catch (IOException e6) {
                    AFLogger.afErrorLog("Exception while trying to close the InstallationFile", e6);
                }
            }
            bArr2 = bArr;
            if (bArr2 == null) {
            }
            return new String(bArr2);
        }
        if (bArr2 == null) {
            bArr2 = new byte[0];
        }
        return new String(bArr2);
    }

    /* renamed from: ॱ  reason: contains not printable characters */
    public static synchronized String m1186(WeakReference<Context> weakReference) {
        synchronized (af.class) {
            if (weakReference.get() == null) {
                return f2012;
            }
            if (f2012 == null) {
                String str = null;
                if (weakReference.get() != null) {
                    str = AppsFlyerLibCore.m1100(weakReference.get()).getString("AF_INSTALLATION", null);
                }
                if (str != null) {
                    f2012 = str;
                } else {
                    try {
                        File file = new File(weakReference.get().getFilesDir(), "AF_INSTALLATION");
                        if (!file.exists()) {
                            long currentTimeMillis = System.currentTimeMillis();
                            StringBuilder sb = new StringBuilder();
                            sb.append(currentTimeMillis);
                            sb.append("-");
                            sb.append(Math.abs(new SecureRandom().nextLong()));
                            f2012 = sb.toString();
                        } else {
                            f2012 = m1185(file);
                            file.delete();
                        }
                        String str2 = f2012;
                        SharedPreferences.Editor edit = AppsFlyerLibCore.m1100(weakReference.get()).edit();
                        edit.putString("AF_INSTALLATION", str2);
                        edit.apply();
                    } catch (Exception e) {
                        AFLogger.afErrorLog("Error getting AF unique ID", e);
                    }
                }
                if (f2012 != null) {
                    AppsFlyerProperties.getInstance().set("uid", f2012);
                }
            }
            return f2012;
        }
    }
}
