package wg;

import android.content.Context;
import java.io.File;
import java.util.HashMap;
import java.util.Map;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes4.dex */
public class f implements g {

    /* renamed from: a, reason: collision with root package name */
    private final Map f49384a = new HashMap();

    private File b(String str) {
        Context a10 = i0.f().a().a();
        if (a10 == null) {
            t.a("Services", "DataQueueService", "Failed to create DataQueue for database (%s), the ApplicationContext is null", str);
            return null;
        }
        String i10 = com.adobe.marketing.mobile.internal.util.c.i(str);
        File databasePath = a10.getDatabasePath(i10);
        if (databasePath.exists()) {
            return databasePath;
        }
        try {
            File c10 = i0.f().e().c();
            if (c10 != null) {
                File file = new File(c10, i10);
                if (file.exists()) {
                    com.adobe.marketing.mobile.internal.util.c.f(file, databasePath);
                    t.a("Services", "DataQueueService", "Successfully moved DataQueue for database (%s) from cache directory to database directory", str);
                }
            }
        } catch (Exception unused) {
            t.a("Services", "DataQueueService", "Failed to move DataQueue for database (%s) from cache directory to database directory", str);
        }
        return databasePath;
    }

    @Override // wg.g
    public e a(String str) {
        if (ch.j.a(str)) {
            t.f("Services", "DataQueueService", "Failed to create DataQueue, database name is null", new Object[0]);
            return null;
        }
        e eVar = (e) this.f49384a.get(str);
        if (eVar == null) {
            synchronized (this) {
                eVar = (e) this.f49384a.get(str);
                if (eVar == null) {
                    File b10 = b(str);
                    if (b10 == null) {
                        t.f("Services", "DataQueueService", "Failed to create DataQueue for database (%s).", str);
                        return null;
                    }
                    h0 h0Var = new h0(b10.getPath());
                    this.f49384a.put(str, h0Var);
                    eVar = h0Var;
                }
            }
        }
        return eVar;
    }
}
