package com.google.android.play.core.assetpacks;

import X.0HH;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.ParcelFileDescriptor;
import com.bytedance.covode.number.Covode;
import com.google.android.play.core.b.b;
import com.google.android.play.core.b.bg;
import com.google.android.play.core.b.r;
import com.google.android.play.core.tasks.e;
import com.google.android.play.core.tasks.g;
import com.google.android.play.core.tasks.p;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;

public final class bu implements dk {
    public static final b LIZ = new b("FakeAssetPackService");
    public static final AtomicInteger LJIIIIZZ = new AtomicInteger(1);
    public final w LIZIZ;
    public final Context LIZJ;
    public final ch LIZLLL;
    public final Handler LJ = new Handler(Looper.getMainLooper());
    public final String LJFF;
    public final ay LJI;
    public final bg<Executor> LJII;

    static {
        Covode.recordClassIndex(44154);
    }

    public bu(File file, w wVar, ay ayVar, Context context, ch chVar, bg<Executor> bgVar) {
        this.LJFF = file.getAbsolutePath();
        this.LIZIZ = wVar;
        this.LJI = ayVar;
        this.LIZJ = context;
        this.LIZLLL = chVar;
        this.LJII = bgVar;
    }

    public static String LIZ(File file) {
        try {
            return bw.LIZ((List<File>) Arrays.asList(new File[]{file}));
        } catch (NoSuchAlgorithmException e) {
            throw new com.google.android.play.core.common.b("SHA256 algorithm not supported.", e);
        } catch (IOException e2) {
            throw new com.google.android.play.core.common.b(0HH.LIZ("Could not digest file: %s.", new Object[]{file}), e2);
        }
    }

    public final e<List<String>> LIZ(Map<String, Long> map) {
        LIZ.LIZJ("syncPacks()", new Object[0]);
        return g.LIZ(new ArrayList());
    }

    public final void LIZ() {
        LIZ.LIZJ("keepAlive", new Object[0]);
    }

    public final void LIZ(int i) {
        LIZ.LIZJ("notifySessionFailed", new Object[0]);
    }

    public final void LIZ(int i, String str) {
        LIZ.LIZJ("notifyModuleCompleted", new Object[0]);
        this.LJII.LIZ().execute(new br(this, i, str));
    }

    public final void LIZ(int i, String str, String str2, int i2) {
        LIZ.LIZJ("notifyChunkTransferred", new Object[0]);
    }

    public final void LIZ(List<String> list) {
        LIZ.LIZJ("cancelDownload(%s)", list);
    }

    public final File[] LIZ(String str) {
        File file = new File(this.LJFF);
        if (file.isDirectory()) {
            File[] listFiles = file.listFiles(new bs(str));
            if (listFiles != null) {
                int length = listFiles.length;
                if (length != 0) {
                    int i = 0;
                    while (!r.LIZ(listFiles[i]).equals(str)) {
                        i++;
                        if (i >= length) {
                            throw new com.google.android.play.core.common.b(0HH.LIZ("No master slice available for pack '%s'.", new Object[]{str}));
                        }
                    }
                    return listFiles;
                }
                throw new com.google.android.play.core.common.b(0HH.LIZ("No APKs available for pack '%s'.", new Object[]{str}));
            }
            throw new com.google.android.play.core.common.b(0HH.LIZ("Failed fetching APKs for pack '%s'.", new Object[]{str}));
        }
        throw new com.google.android.play.core.common.b(0HH.LIZ("Local testing directory '%s' not found.", new Object[]{file}));
    }

    public final e<ParcelFileDescriptor> LIZIZ(int i, String str, String str2, int i2) {
        LIZ.LIZJ("getChunkFileDescriptor(session=%d, %s, %s, %d)", Integer.valueOf(i), str, str2, Integer.valueOf(i2));
        p pVar = new p();
        try {
            for (File file : LIZ(str)) {
                if (r.LIZ(file).equals(str2)) {
                    pVar.LIZ.LIZ(ParcelFileDescriptor.open(file, 268435456));
                    return pVar.LIZ;
                }
            }
            throw new com.google.android.play.core.common.b(0HH.LIZ("Local testing slice for '%s' not found.", new Object[]{str2}));
        } catch (FileNotFoundException e) {
            LIZ.LIZLLL("getChunkFileDescriptor failed", e);
            pVar.LIZ((Exception) new com.google.android.play.core.common.b("Asset Slice file not found.", e));
        } catch (com.google.android.play.core.common.b e2) {
            LIZ.LIZLLL("getChunkFileDescriptor failed", e2);
            pVar.LIZ((Exception) e2);
        }
    }
}
