package K.K.ʬ;

import android.content.Context;
import android.os.Build;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import com.facebook.appevents.AppEventsConstants;
import com.facebook.devicerequests.internal.DeviceRequestsHelper;
import com.facebook.internal.ServerProtocol;
import com.facebook.places.model.PlaceFields;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.security.MessageDigest;
import org.json.JSONObject;
import K.K.K.ʬ.C2369;

/* renamed from: K.K.ʬ.ʬ  reason: contains not printable characters */
public class C2355 extends C2359 {
    /* JADX WARNING: Code restructure failed: missing block: B:16:0x0053, code lost:
        if (r4 != null) goto L_0x0056;
     */
    /* renamed from: K  reason: contains not printable characters */
    public static String m6174(Context context) {
        String str;
        String str2;
        StringBuilder sb;
        try {
            FileInputStream openFileInput = context.openFileInput("advt.tk");
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(Math.max(8192, openFileInput.available()));
            byte[] bArr = new byte[8192];
            while (true) {
                int read = openFileInput.read(bArr);
                if (read < 0) {
                    break;
                }
                byteArrayOutputStream.write(bArr, 0, read);
            }
            str = new String(byteArrayOutputStream.toByteArray());
        } catch (Exception unused) {
            str = null;
        }
        if (!TextUtils.isEmpty(str)) {
            return str;
        }
        String string = Settings.Secure.getString(context.getContentResolver(), "android_id");
        try {
            if (C2369.m6270(context, "android.permission.READ_PHONE_STATE")) {
                str2 = ((TelephonyManager) context.getSystemService(PlaceFields.PHONE)).getDeviceId();
            }
        } catch (Exception unused2) {
        }
        str2 = "unknown";
        String r5 = C2360.m6195(context);
        try {
            if (TextUtils.isEmpty(string) && "unknown".equals(str2) && "02:00:00:00:00:00".equals(r5)) {
                sb = new StringBuilder();
                sb.append(m6175().toString());
                sb.append(System.currentTimeMillis());
            } else {
                sb = new StringBuilder();
                sb.append(string);
                sb.append(str2);
                sb.append(r5);
            }
            byte[] digest = MessageDigest.getInstance("MD5").digest(sb.toString().getBytes());
            StringBuilder sb2 = new StringBuilder();
            for (byte b : digest) {
                String hexString = Integer.toHexString(b & 255);
                if (hexString.length() == 1) {
                    hexString = AppEventsConstants.EVENT_PARAM_VALUE_NO + hexString;
                }
                sb2.append(hexString);
            }
            context.deleteFile("advt.tk");
            context.openFileOutput("advt.tk", 0).write(sb2.toString().getBytes());
        } catch (Exception unused3) {
        }
        return "";
    }

    /* renamed from: K  reason: contains not printable characters */
    public static JSONObject m6175() {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("brand", Build.BRAND);
            jSONObject.put("ABI", Build.CPU_ABI);
            jSONObject.put("CPU", Build.HARDWARE);
            jSONObject.put(ServerProtocol.DIALOG_PARAM_DISPLAY, Build.DISPLAY);
            jSONObject.put("manufacturer", Build.MANUFACTURER);
            jSONObject.put(DeviceRequestsHelper.DEVICE_INFO_MODEL, Build.MODEL);
            jSONObject.put("androidVersion", Build.VERSION.SDK_INT);
        } catch (Exception unused) {
        }
        return jSONObject;
    }
}
