CacheService.smali

.class public Lcom/tradplus/ads/common/CacheService;
.super Ljava/lang/Object;


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/tradplus/ads/common/CacheService$b;,
        Lcom/tradplus/ads/common/CacheService$a;,
        Lcom/tradplus/ads/common/CacheService$DiskLruCacheGetListener;
    }
.end annotation


# static fields
.field private static a:Lcom/tradplus/ads/common/DiskLruCache;


# direct methods
.method public constructor <init>()V
    .registers 1

    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method

.method public static clearAndNullCaches()V
    .registers 2
    .annotation build Lcom/tradplus/ads/common/VisibleForTesting;
    .end annotation

    .annotation runtime Ljava/lang/Deprecated;
    .end annotation

    sget-object v0, Lcom/tradplus/ads/common/CacheService;->a:Lcom/tradplus/ads/common/DiskLruCache;

    if-eqz v0, :cond_d

    const/4 v1, 0x0

    :try_start_5
    invoke-virtual {v0}, Lcom/tradplus/ads/common/DiskLruCache;->delete()V

    sput-object v1, Lcom/tradplus/ads/common/CacheService;->a:Lcom/tradplus/ads/common/DiskLruCache;
    :try_end_a
    .catch Ljava/io/IOException; {:try_start_5 .. :try_end_a} :catch_b

    goto :goto_d

    :catch_b
    sput-object v1, Lcom/tradplus/ads/common/CacheService;->a:Lcom/tradplus/ads/common/DiskLruCache;

    :cond_d
    :goto_d
    return-void
.end method

.method public static containsKeyDiskCache(Ljava/lang/String;)Z
    .registers 3

    sget-object v0, Lcom/tradplus/ads/common/CacheService;->a:Lcom/tradplus/ads/common/DiskLruCache;

    const/4 v1, 0x0

    if-nez v0, :cond_6

    return v1

    :cond_6
    :try_start_6
    invoke-static {p0}, Lcom/tradplus/ads/common/CacheService;->createValidDiskCacheKey(Ljava/lang/String;)Ljava/lang/String;

    move-result-object p0

    invoke-virtual {v0, p0}, Lcom/tradplus/ads/common/DiskLruCache;->get(Ljava/lang/String;)Lcom/tradplus/ads/common/DiskLruCache$Snapshot;

    move-result-object p0
    :try_end_e
    .catch Ljava/lang/Exception; {:try_start_6 .. :try_end_e} :catch_11

    if-eqz p0, :cond_11

    const/4 v1, 0x1

    :catch_11
    :cond_11
    return v1
.end method

.method public static createValidDiskCacheKey(Ljava/lang/String;)Ljava/lang/String;
    .registers 1

    invoke-static {p0}, Lcom/tradplus/ads/common/util/Utils;->sha1(Ljava/lang/String;)Ljava/lang/String;

    move-result-object p0

    return-object p0
.end method

.method public static getDiskCacheDirectory(Landroid/content/Context;)Ljava/io/File;
    .registers 3

    invoke-virtual {p0}, Landroid/content/Context;->getCacheDir()Ljava/io/File;

    move-result-object p0

    if-nez p0, :cond_8

    const/4 p0, 0x0

    return-object p0

    :cond_8
    invoke-virtual {p0}, Ljava/io/File;->getPath()Ljava/lang/String;

    move-result-object p0

    new-instance v0, Ljava/io/File;

    new-instance v1, Ljava/lang/StringBuilder;

    invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v1, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    sget-object p0, Ljava/io/File;->separator:Ljava/lang/String;

    invoke-virtual {v1, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    const-string p0, "flute-cache"

    invoke-virtual {v1, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object p0

    invoke-direct {v0, p0}, Ljava/io/File;-><init>(Ljava/lang/String;)V

    return-object v0
.end method

.method public static getDiskLruCache()Lcom/tradplus/ads/common/DiskLruCache;
    .registers 1
    .annotation build Lcom/tradplus/ads/common/VisibleForTesting;
    .end annotation

    .annotation runtime Ljava/lang/Deprecated;
    .end annotation

    sget-object v0, Lcom/tradplus/ads/common/CacheService;->a:Lcom/tradplus/ads/common/DiskLruCache;

    return-object v0
.end method

.method public static getFilePathDiskCache(Ljava/lang/String;)Ljava/lang/String;
    .registers 3

    sget-object v0, Lcom/tradplus/ads/common/CacheService;->a:Lcom/tradplus/ads/common/DiskLruCache;

    if-nez v0, :cond_6

    const/4 p0, 0x0

    return-object p0

    :cond_6
    new-instance v0, Ljava/lang/StringBuilder;

    invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V

    sget-object v1, Lcom/tradplus/ads/common/CacheService;->a:Lcom/tradplus/ads/common/DiskLruCache;

    invoke-virtual {v1}, Lcom/tradplus/ads/common/DiskLruCache;->getDirectory()Ljava/io/File;

    move-result-object v1

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;

    sget-object v1, Ljava/io/File;->separator:Ljava/lang/String;

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    invoke-static {p0}, Lcom/tradplus/ads/common/CacheService;->createValidDiskCacheKey(Ljava/lang/String;)Ljava/lang/String;

    move-result-object p0

    invoke-virtual {v0, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    const-string p0, "."

    invoke-virtual {v0, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    const/4 p0, 0x0

    invoke-virtual {v0, p0}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object p0

    return-object p0
.end method

.method public static getFromDiskCache(Ljava/lang/String;)[B
    .registers 7

    sget-object v0, Lcom/tradplus/ads/common/CacheService;->a:Lcom/tradplus/ads/common/DiskLruCache;

    const/4 v1, 0x0

    if-nez v0, :cond_6

    return-object v1

    :cond_6
    :try_start_6
    invoke-static {p0}, Lcom/tradplus/ads/common/CacheService;->createValidDiskCacheKey(Ljava/lang/String;)Ljava/lang/String;

    move-result-object p0

    invoke-virtual {v0, p0}, Lcom/tradplus/ads/common/DiskLruCache;->get(Ljava/lang/String;)Lcom/tradplus/ads/common/DiskLruCache$Snapshot;

    move-result-object p0
    :try_end_e
    .catch Ljava/lang/Exception; {:try_start_6 .. :try_end_e} :catch_46
    .catchall {:try_start_6 .. :try_end_e} :catchall_43

    if-nez p0, :cond_16

    if-eqz p0, :cond_15

    invoke-virtual {p0}, Lcom/tradplus/ads/common/DiskLruCache$Snapshot;->close()V

    :cond_15
    return-object v1

    :cond_16
    const/4 v0, 0x0

    :try_start_17
    invoke-virtual {p0, v0}, Lcom/tradplus/ads/common/DiskLruCache$Snapshot;->getInputStream(I)Ljava/io/InputStream;

    move-result-object v2

    if-eqz v2, :cond_35

    invoke-virtual {p0, v0}, Lcom/tradplus/ads/common/DiskLruCache$Snapshot;->getLength(I)J

    move-result-wide v3

    long-to-int v0, v3

    new-array v1, v0, [B

    new-instance v0, Ljava/io/BufferedInputStream;

    invoke-direct {v0, v2}, Ljava/io/BufferedInputStream;-><init>(Ljava/io/InputStream;)V
    :try_end_29
    .catch Ljava/lang/Exception; {:try_start_17 .. :try_end_29} :catch_3e
    .catchall {:try_start_17 .. :try_end_29} :catchall_3c

    :try_start_29
    invoke-static {v0, v1}, Lcom/tradplus/ads/common/util/Streams;->readStream(Ljava/io/InputStream;[B)V
    :try_end_2c
    .catchall {:try_start_29 .. :try_end_2c} :catchall_30

    :try_start_2c
    invoke-static {v0}, Lcom/tradplus/ads/common/util/Streams;->closeStream(Ljava/io/Closeable;)V

    goto :goto_35

    :catchall_30
    move-exception v2

    invoke-static {v0}, Lcom/tradplus/ads/common/util/Streams;->closeStream(Ljava/io/Closeable;)V

    throw v2
    :try_end_35
    .catch Ljava/lang/Exception; {:try_start_2c .. :try_end_35} :catch_3e
    .catchall {:try_start_2c .. :try_end_35} :catchall_3c

    :cond_35
    :goto_35
    if-eqz p0, :cond_3a

    invoke-virtual {p0}, Lcom/tradplus/ads/common/DiskLruCache$Snapshot;->close()V

    :cond_3a
    move-object p0, v1

    goto :goto_52

    :catchall_3c
    move-exception v0

    goto :goto_53

    :catch_3e
    move-exception v0

    move-object v5, v1

    move-object v1, p0

    move-object p0, v5

    goto :goto_48

    :catchall_43
    move-exception v0

    move-object p0, v1

    goto :goto_53

    :catch_46
    move-exception v0

    move-object p0, v1

    :goto_48
    :try_start_48
    const-string v2, "Unable to get from DiskLruCache"

    invoke-static {v2, v0}, Lcom/tradplus/ads/common/util/LogUtil;->show(Ljava/lang/String;Ljava/lang/Object;)V
    :try_end_4d
    .catchall {:try_start_48 .. :try_end_4d} :catchall_43

    if-eqz v1, :cond_52

    invoke-virtual {v1}, Lcom/tradplus/ads/common/DiskLruCache$Snapshot;->close()V

    :cond_52
    :goto_52
    return-object p0

    :goto_53
    if-eqz p0, :cond_58

    invoke-virtual {p0}, Lcom/tradplus/ads/common/DiskLruCache$Snapshot;->close()V

    :cond_58
    throw v0
.end method

.method public static getFromDiskCacheAsync(Ljava/lang/String;Lcom/tradplus/ads/common/CacheService$DiskLruCacheGetListener;)V
    .registers 3

    new-instance v0, Lcom/tradplus/ads/common/CacheService$a;

    invoke-direct {v0, p0, p1}, Lcom/tradplus/ads/common/CacheService$a;-><init>(Ljava/lang/String;Lcom/tradplus/ads/common/CacheService$DiskLruCacheGetListener;)V

    const/4 p0, 0x0

    new-array p0, p0, [Ljava/lang/Void;

    invoke-virtual {v0, p0}, Landroid/os/AsyncTask;->execute([Ljava/lang/Object;)Landroid/os/AsyncTask;

    return-void
.end method

.method public static initialize(Landroid/content/Context;)V
    .registers 1

    invoke-static {p0}, Lcom/tradplus/ads/common/CacheService;->initializeDiskCache(Landroid/content/Context;)Z

    return-void
.end method

.method public static initializeDiskCache(Landroid/content/Context;)Z
    .registers 6

    const/4 v0, 0x0

    if-nez p0, :cond_4

    return v0

    :cond_4
    sget-object v1, Lcom/tradplus/ads/common/CacheService;->a:Lcom/tradplus/ads/common/DiskLruCache;

    const/4 v2, 0x1

    if-nez v1, :cond_22

    invoke-static {p0}, Lcom/tradplus/ads/common/CacheService;->getDiskCacheDirectory(Landroid/content/Context;)Ljava/io/File;

    move-result-object p0

    if-nez p0, :cond_10

    return v0

    :cond_10
    invoke-static {p0}, Lcom/tradplus/ads/common/util/DeviceUtils;->diskCacheSizeBytes(Ljava/io/File;)J

    move-result-wide v3

    :try_start_14
    invoke-static {p0, v2, v2, v3, v4}, Lcom/tradplus/ads/common/DiskLruCache;->open(Ljava/io/File;IIJ)Lcom/tradplus/ads/common/DiskLruCache;

    move-result-object p0

    sput-object p0, Lcom/tradplus/ads/common/CacheService;->a:Lcom/tradplus/ads/common/DiskLruCache;
    :try_end_1a
    .catch Ljava/io/IOException; {:try_start_14 .. :try_end_1a} :catch_1b

    goto :goto_22

    :catch_1b
    move-exception p0

    const-string v1, "Unable to create DiskLruCache"

    invoke-static {v1, p0}, Lcom/tradplus/ads/common/util/LogUtil;->show(Ljava/lang/String;Ljava/lang/Object;)V

    return v0

    :cond_22
    :goto_22
    return v2
.end method

.method public static putToDiskCache(Ljava/lang/String;Ljava/io/InputStream;)Z
    .registers 5

    sget-object v0, Lcom/tradplus/ads/common/CacheService;->a:Lcom/tradplus/ads/common/DiskLruCache;

    const/4 v1, 0x0

    if-nez v0, :cond_6

    return v1

    :cond_6
    const/4 v2, 0x0

    :try_start_7
    invoke-static {p0}, Lcom/tradplus/ads/common/CacheService;->createValidDiskCacheKey(Ljava/lang/String;)Ljava/lang/String;

    move-result-object p0

    invoke-virtual {v0, p0}, Lcom/tradplus/ads/common/DiskLruCache;->edit(Ljava/lang/String;)Lcom/tradplus/ads/common/DiskLruCache$Editor;

    move-result-object v2

    if-nez v2, :cond_12

    return v1

    :cond_12
    new-instance p0, Ljava/io/BufferedOutputStream;

    invoke-virtual {v2, v1}, Lcom/tradplus/ads/common/DiskLruCache$Editor;->newOutputStream(I)Ljava/io/OutputStream;

    move-result-object v0

    invoke-direct {p0, v0}, Ljava/io/BufferedOutputStream;-><init>(Ljava/io/OutputStream;)V

    invoke-static {p1, p0}, Lcom/tradplus/ads/common/util/Streams;->copyContent(Ljava/io/InputStream;Ljava/io/OutputStream;)V

    invoke-virtual {p0}, Ljava/io/BufferedOutputStream;->flush()V

    invoke-virtual {p0}, Ljava/io/FilterOutputStream;->close()V

    sget-object p0, Lcom/tradplus/ads/common/CacheService;->a:Lcom/tradplus/ads/common/DiskLruCache;

    invoke-virtual {p0}, Lcom/tradplus/ads/common/DiskLruCache;->flush()V

    invoke-virtual {v2}, Lcom/tradplus/ads/common/DiskLruCache$Editor;->commit()V
    :try_end_2c
    .catch Ljava/lang/Exception; {:try_start_7 .. :try_end_2c} :catch_2e

    const/4 p0, 0x1

    return p0

    :catch_2e
    move-exception p0

    const-string p1, "Unable to put to DiskLruCache"

    invoke-static {p1, p0}, Lcom/tradplus/ads/common/util/LogUtil;->show(Ljava/lang/String;Ljava/lang/Object;)V

    if-eqz v2, :cond_39

    :try_start_36
    invoke-virtual {v2}, Lcom/tradplus/ads/common/DiskLruCache$Editor;->abort()V
    :try_end_39
    .catch Ljava/io/IOException; {:try_start_36 .. :try_end_39} :catch_39

    :catch_39
    :cond_39
    return v1
.end method

.method public static putToDiskCache(Ljava/lang/String;[B)Z
    .registers 3

    new-instance v0, Ljava/io/ByteArrayInputStream;

    invoke-direct {v0, p1}, Ljava/io/ByteArrayInputStream;-><init>([B)V

    invoke-static {p0, v0}, Lcom/tradplus/ads/common/CacheService;->putToDiskCache(Ljava/lang/String;Ljava/io/InputStream;)Z

    move-result p0

    return p0
.end method

.method public static putToDiskCacheAsync(Ljava/lang/String;[B)V
    .registers 3

    new-instance v0, Lcom/tradplus/ads/common/CacheService$b;

    invoke-direct {v0, p0, p1}, Lcom/tradplus/ads/common/CacheService$b;-><init>(Ljava/lang/String;[B)V

    const/4 p0, 0x0

    new-array p0, p0, [Ljava/lang/Void;

    invoke-virtual {v0, p0}, Landroid/os/AsyncTask;->execute([Ljava/lang/Object;)Landroid/os/AsyncTask;

    return-void
.end method