package com.parse;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.UUID;
import p138.p176.p177.p242.p246.p251.C4303;

/* JADX INFO: loaded from: classes.dex */
public class InstallationId {
    public final File file;
    public String installationId;
    public final Object lock = new Object();

    public InstallationId(File file) {
        this.file = file;
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x0029 A[Catch: all -> 0x0038, TryCatch #0 {, blocks: (B:4:0x0003, B:6:0x0007, B:11:0x0025, B:13:0x0029, B:14:0x0034, B:9:0x0013, B:10:0x001c), top: B:20:0x0003, inners: #1, #2 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public String get() {
        synchronized (this.lock) {
            if (this.installationId == null) {
                try {
                    try {
                        this.installationId = C4303.readFileToString(this.file, "UTF-8");
                    } catch (IOException e) {
                        PLog.log(6, "InstallationId", "Unexpected exception reading installation id from disk", e);
                    }
                } catch (FileNotFoundException unused) {
                    PLog.log(4, "InstallationId", "Couldn't find existing installationId file. Creating one instead.", null);
                }
                if (this.installationId == null) {
                    setInternal(UUID.randomUUID().toString());
                }
            } else if (this.installationId == null) {
            }
        }
        return this.installationId;
    }

    public void set(String str) {
        synchronized (this.lock) {
            if (!C4303.isEmpty(str) && !str.equals(get())) {
                setInternal(str);
            }
        }
    }

    public final void setInternal(String str) {
        synchronized (this.lock) {
            try {
                C4303.writeByteArrayToFile(this.file, str.getBytes(Charset.forName("UTF-8")));
            } catch (IOException e) {
                PLog.log(6, "InstallationId", "Unexpected exception writing installation id to disk", e);
            }
            this.installationId = str;
        }
    }
}
