ApkLibraryInstaller.smali

.class public Lio/rong/imlib/relinker/ApkLibraryInstaller;
.super Ljava/lang/Object;
.source "ApkLibraryInstaller.java"

# interfaces
.implements Lio/rong/imlib/relinker/ReLinker$LibraryInstaller;


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;
    }
.end annotation


# static fields
.field private static final COPY_BUFFER_SIZE:I = 0x1000

.field private static final MAX_TRIES:I = 0x5


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

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

    return-void
.end method

.method private closeSilently(Ljava/io/Closeable;)V
    .registers 2

    if-eqz p1, :cond_5

    .line 1
    :try_start_2
    invoke-interface {p1}, Ljava/io/Closeable;->close()V
    :try_end_5
    .catch Ljava/io/IOException; {:try_start_2 .. :try_end_5} :catch_5

    :catch_5
    :cond_5
    return-void
.end method

.method private copy(Ljava/io/InputStream;Ljava/io/OutputStream;)J
    .registers 8
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    const/16 v0, 0x1000

    .line 1
    new-array v0, v0, [B

    const-wide/16 v1, 0x0

    .line 2
    :goto_6
    invoke-virtual {p1, v0}, Ljava/io/InputStream;->read([B)I

    move-result v3

    const/4 v4, -0x1

    if-ne v3, v4, :cond_11

    .line 3
    invoke-virtual {p2}, Ljava/io/OutputStream;->flush()V

    return-wide v1

    :cond_11
    const/4 v4, 0x0

    .line 4
    invoke-virtual {p2, v0, v4, v3}, Ljava/io/OutputStream;->write([BII)V

    int-to-long v3, v3

    add-long/2addr v1, v3

    goto :goto_6
.end method

.method private findAPKWithLibrary(Landroid/content/Context;[Ljava/lang/String;Ljava/lang/String;Lio/rong/imlib/relinker/ReLinkerInstance;)Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;
    .registers 21

    move-object/from16 v0, p2

    .line 1
    invoke-direct/range {p0 .. p1}, Lio/rong/imlib/relinker/ApkLibraryInstaller;->sourceDirectories(Landroid/content/Context;)[Ljava/lang/String;

    move-result-object v1

    array-length v2, v1

    const/4 v3, 0x0

    const/4 v4, 0x0

    move-object v6, v3

    const/4 v5, 0x0

    :goto_b
    if-ge v5, v2, :cond_87

    aget-object v7, v1, v5

    const/4 v8, 0x0

    :goto_10
    add-int/lit8 v9, v8, 0x1

    const/4 v10, 0x5

    const/4 v11, 0x1

    if-ge v8, v10, :cond_24

    .line 2
    :try_start_16
    new-instance v8, Ljava/util/zip/ZipFile;

    new-instance v12, Ljava/io/File;

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

    invoke-direct {v8, v12, v11}, Ljava/util/zip/ZipFile;-><init>(Ljava/io/File;I)V
    :try_end_20
    .catch Ljava/io/IOException; {:try_start_16 .. :try_end_20} :catch_22

    move-object v6, v8

    goto :goto_24

    :catch_22
    move v8, v9

    goto :goto_10

    :cond_24
    :goto_24
    if-nez v6, :cond_2b

    move-object/from16 v13, p3

    move-object/from16 v10, p4

    goto :goto_83

    :cond_2b
    const/4 v8, 0x0

    :goto_2c
    add-int/lit8 v9, v8, 0x1

    if-ge v8, v10, :cond_7c

    .line 3
    array-length v8, v0

    const/4 v12, 0x0

    :goto_32
    if-ge v12, v8, :cond_75

    aget-object v13, v0, v12

    .line 4
    new-instance v14, Ljava/lang/StringBuilder;

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

    const-string v15, "lib"

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

    sget-char v15, Ljava/io/File;->separatorChar:C

    invoke-virtual {v14, v15}, Ljava/lang/StringBuilder;->append(C)Ljava/lang/StringBuilder;

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

    sget-char v13, Ljava/io/File;->separatorChar:C

    invoke-virtual {v14, v13}, Ljava/lang/StringBuilder;->append(C)Ljava/lang/StringBuilder;

    move-object/from16 v13, p3

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

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

    move-result-object v14

    const/4 v15, 0x2

    .line 5
    new-array v15, v15, [Ljava/lang/Object;

    aput-object v14, v15, v4

    aput-object v7, v15, v11

    const-string v4, "Looking for %s in APK %s..."

    move-object/from16 v10, p4

    invoke-virtual {v10, v4, v15}, Lio/rong/imlib/relinker/ReLinkerInstance;->log(Ljava/lang/String;[Ljava/lang/Object;)V

    .line 6
    invoke-virtual {v6, v14}, Ljava/util/zip/ZipFile;->getEntry(Ljava/lang/String;)Ljava/util/zip/ZipEntry;

    move-result-object v4

    if-eqz v4, :cond_70

    .line 7
    new-instance v0, Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;

    invoke-direct {v0, v6, v4, v3}, Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;-><init>(Ljava/util/zip/ZipFile;Ljava/util/zip/ZipEntry;Lio/rong/imlib/relinker/ApkLibraryInstaller$1;)V

    return-object v0

    :cond_70
    add-int/lit8 v12, v12, 0x1

    const/4 v4, 0x0

    const/4 v10, 0x5

    goto :goto_32

    :cond_75
    move-object/from16 v13, p3

    move-object/from16 v10, p4

    move v8, v9

    const/4 v10, 0x5

    goto :goto_2c

    :cond_7c
    move-object/from16 v13, p3

    move-object/from16 v10, p4

    .line 8
    :try_start_80
    invoke-virtual {v6}, Ljava/util/zip/ZipFile;->close()V
    :try_end_83
    .catch Ljava/io/IOException; {:try_start_80 .. :try_end_83} :catch_83

    :catch_83
    :goto_83
    add-int/lit8 v5, v5, 0x1

    const/4 v4, 0x0

    goto :goto_b

    :cond_87
    return-object v3
.end method

.method private sourceDirectories(Landroid/content/Context;)[Ljava/lang/String;
    .registers 6

    .line 1
    invoke-virtual {p1}, Landroid/content/Context;->getApplicationInfo()Landroid/content/pm/ApplicationInfo;

    move-result-object p1

    .line 2
    sget v0, Landroid/os/Build$VERSION;->SDK_INT:I

    const/4 v1, 0x0

    const/4 v2, 0x1

    const/16 v3, 0x15

    if-lt v0, v3, :cond_20

    iget-object v0, p1, Landroid/content/pm/ApplicationInfo;->splitSourceDirs:[Ljava/lang/String;

    if-eqz v0, :cond_20

    array-length v3, v0

    if-eqz v3, :cond_20

    .line 3
    array-length v3, v0

    add-int/2addr v3, v2

    new-array v3, v3, [Ljava/lang/String;

    .line 4
    iget-object p1, p1, Landroid/content/pm/ApplicationInfo;->sourceDir:Ljava/lang/String;

    aput-object p1, v3, v1

    .line 5
    array-length p1, v0

    invoke-static {v0, v1, v3, v2, p1}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V

    return-object v3

    .line 6
    :cond_20
    new-array v0, v2, [Ljava/lang/String;

    iget-object p1, p1, Landroid/content/pm/ApplicationInfo;->sourceDir:Ljava/lang/String;

    aput-object p1, v0, v1

    return-object v0
.end method


# virtual methods
.method public installLibrary(Landroid/content/Context;[Ljava/lang/String;Ljava/lang/String;Ljava/io/File;Lio/rong/imlib/relinker/ReLinkerInstance;)V
    .registers 16

    const/4 v0, 0x0

    .line 1
    :try_start_1
    invoke-direct {p0, p1, p2, p3, p5}, Lio/rong/imlib/relinker/ApkLibraryInstaller;->findAPKWithLibrary(Landroid/content/Context;[Ljava/lang/String;Ljava/lang/String;Lio/rong/imlib/relinker/ReLinkerInstance;)Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;

    move-result-object p1
    :try_end_5
    .catchall {:try_start_1 .. :try_end_5} :catchall_ae

    if-eqz p1, :cond_a6

    const/4 p2, 0x0

    const/4 v1, 0x0

    :goto_9
    add-int/lit8 v2, v1, 0x1

    const/4 v3, 0x5

    if-ge v1, v3, :cond_91

    :try_start_e
    const-string v1, "Found %s! Extracting..."

    const/4 v3, 0x1

    .line 2
    new-array v4, v3, [Ljava/lang/Object;

    aput-object p3, v4, p2

    invoke-virtual {p5, v1, v4}, Lio/rong/imlib/relinker/ReLinkerInstance;->log(Ljava/lang/String;[Ljava/lang/Object;)V
    :try_end_18
    .catchall {:try_start_e .. :try_end_18} :catchall_ac

    .line 3
    :try_start_18
    invoke-virtual {p4}, Ljava/io/File;->exists()Z

    move-result v1

    if-nez v1, :cond_26

    invoke-virtual {p4}, Ljava/io/File;->createNewFile()Z

    move-result v1
    :try_end_22
    .catch Ljava/io/IOException; {:try_start_18 .. :try_end_22} :catch_8e
    .catchall {:try_start_18 .. :try_end_22} :catchall_ac

    if-nez v1, :cond_26

    goto/16 :goto_8e

    .line 4
    :cond_26
    :try_start_26
    # getter for: Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;->zipFile:Ljava/util/zip/ZipFile;
    invoke-static {p1}, Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;->access$200(Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;)Ljava/util/zip/ZipFile;

    move-result-object v1

    # getter for: Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;->zipEntry:Ljava/util/zip/ZipEntry;
    invoke-static {p1}, Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;->access$100(Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;)Ljava/util/zip/ZipEntry;

    move-result-object v4

    invoke-virtual {v1, v4}, Ljava/util/zip/ZipFile;->getInputStream(Ljava/util/zip/ZipEntry;)Ljava/io/InputStream;

    move-result-object v1
    :try_end_32
    .catch Ljava/io/FileNotFoundException; {:try_start_26 .. :try_end_32} :catch_88
    .catch Ljava/io/IOException; {:try_start_26 .. :try_end_32} :catch_82
    .catchall {:try_start_26 .. :try_end_32} :catchall_79

    .line 5
    :try_start_32
    new-instance v4, Ljava/io/FileOutputStream;

    invoke-direct {v4, p4}, Ljava/io/FileOutputStream;-><init>(Ljava/io/File;)V
    :try_end_37
    .catch Ljava/io/FileNotFoundException; {:try_start_32 .. :try_end_37} :catch_77
    .catch Ljava/io/IOException; {:try_start_32 .. :try_end_37} :catch_75
    .catchall {:try_start_32 .. :try_end_37} :catchall_73

    .line 6
    :try_start_37
    invoke-direct {p0, v1, v4}, Lio/rong/imlib/relinker/ApkLibraryInstaller;->copy(Ljava/io/InputStream;Ljava/io/OutputStream;)J

    move-result-wide v5

    .line 7
    invoke-virtual {v4}, Ljava/io/FileOutputStream;->getFD()Ljava/io/FileDescriptor;

    move-result-object v7

    invoke-virtual {v7}, Ljava/io/FileDescriptor;->sync()V

    .line 8
    invoke-virtual {p4}, Ljava/io/File;->length()J

    move-result-wide v7
    :try_end_46
    .catch Ljava/io/FileNotFoundException; {:try_start_37 .. :try_end_46} :catch_8a
    .catch Ljava/io/IOException; {:try_start_37 .. :try_end_46} :catch_84
    .catchall {:try_start_37 .. :try_end_46} :catchall_70

    cmp-long v9, v5, v7

    if-eqz v9, :cond_51

    .line 9
    :try_start_4a
    invoke-direct {p0, v1}, Lio/rong/imlib/relinker/ApkLibraryInstaller;->closeSilently(Ljava/io/Closeable;)V

    .line 10
    :goto_4d
    invoke-direct {p0, v4}, Lio/rong/imlib/relinker/ApkLibraryInstaller;->closeSilently(Ljava/io/Closeable;)V

    goto :goto_8e

    .line 11
    :cond_51
    invoke-direct {p0, v1}, Lio/rong/imlib/relinker/ApkLibraryInstaller;->closeSilently(Ljava/io/Closeable;)V

    .line 12
    invoke-direct {p0, v4}, Lio/rong/imlib/relinker/ApkLibraryInstaller;->closeSilently(Ljava/io/Closeable;)V

    .line 13
    invoke-virtual {p4, v3, p2}, Ljava/io/File;->setReadable(ZZ)Z

    .line 14
    invoke-virtual {p4, v3, p2}, Ljava/io/File;->setExecutable(ZZ)Z

    .line 15
    invoke-virtual {p4, v3}, Ljava/io/File;->setWritable(Z)Z
    :try_end_60
    .catchall {:try_start_4a .. :try_end_60} :catchall_ac

    if-eqz p1, :cond_6f

    .line 16
    :try_start_62
    # getter for: Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;->zipFile:Ljava/util/zip/ZipFile;
    invoke-static {p1}, Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;->access$200(Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;)Ljava/util/zip/ZipFile;

    move-result-object p2

    if-eqz p2, :cond_6f

    .line 17
    # getter for: Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;->zipFile:Ljava/util/zip/ZipFile;
    invoke-static {p1}, Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;->access$200(Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;)Ljava/util/zip/ZipFile;

    move-result-object p1

    invoke-virtual {p1}, Ljava/util/zip/ZipFile;->close()V
    :try_end_6f
    .catch Ljava/io/IOException; {:try_start_62 .. :try_end_6f} :catch_6f

    :catch_6f
    :cond_6f
    return-void

    :catchall_70
    move-exception p2

    move-object v0, v4

    goto :goto_7b

    :catchall_73
    move-exception p2

    goto :goto_7b

    :catch_75
    move-object v4, v0

    goto :goto_84

    :catch_77
    move-object v4, v0

    goto :goto_8a

    :catchall_79
    move-exception p2

    move-object v1, v0

    .line 18
    :goto_7b
    :try_start_7b
    invoke-direct {p0, v1}, Lio/rong/imlib/relinker/ApkLibraryInstaller;->closeSilently(Ljava/io/Closeable;)V

    .line 19
    invoke-direct {p0, v0}, Lio/rong/imlib/relinker/ApkLibraryInstaller;->closeSilently(Ljava/io/Closeable;)V

    throw p2

    :catch_82
    move-object v1, v0

    move-object v4, v1

    .line 20
    :catch_84
    :goto_84
    invoke-direct {p0, v1}, Lio/rong/imlib/relinker/ApkLibraryInstaller;->closeSilently(Ljava/io/Closeable;)V

    goto :goto_4d

    :catch_88
    move-object v1, v0

    move-object v4, v1

    :catch_8a
    :goto_8a
    invoke-direct {p0, v1}, Lio/rong/imlib/relinker/ApkLibraryInstaller;->closeSilently(Ljava/io/Closeable;)V

    goto :goto_4d

    :catch_8e
    :goto_8e
    move v1, v2

    goto/16 :goto_9

    :cond_91
    const-string p2, "FATAL! Couldn\'t extract the library from the APK!"

    .line 21
    invoke-virtual {p5, p2}, Lio/rong/imlib/relinker/ReLinkerInstance;->log(Ljava/lang/String;)V
    :try_end_96
    .catchall {:try_start_7b .. :try_end_96} :catchall_ac

    if-eqz p1, :cond_a5

    .line 22
    :try_start_98
    # getter for: Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;->zipFile:Ljava/util/zip/ZipFile;
    invoke-static {p1}, Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;->access$200(Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;)Ljava/util/zip/ZipFile;

    move-result-object p2

    if-eqz p2, :cond_a5

    .line 23
    # getter for: Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;->zipFile:Ljava/util/zip/ZipFile;
    invoke-static {p1}, Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;->access$200(Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;)Ljava/util/zip/ZipFile;

    move-result-object p1

    invoke-virtual {p1}, Ljava/util/zip/ZipFile;->close()V
    :try_end_a5
    .catch Ljava/io/IOException; {:try_start_98 .. :try_end_a5} :catch_a5

    :catch_a5
    :cond_a5
    return-void

    .line 24
    :cond_a6
    :try_start_a6
    new-instance p2, Lio/rong/imlib/relinker/MissingLibraryException;

    invoke-direct {p2, p3}, Lio/rong/imlib/relinker/MissingLibraryException;-><init>(Ljava/lang/String;)V

    throw p2
    :try_end_ac
    .catchall {:try_start_a6 .. :try_end_ac} :catchall_ac

    :catchall_ac
    move-exception p2

    goto :goto_b0

    :catchall_ae
    move-exception p2

    move-object p1, v0

    :goto_b0
    if-eqz p1, :cond_bf

    .line 25
    :try_start_b2
    # getter for: Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;->zipFile:Ljava/util/zip/ZipFile;
    invoke-static {p1}, Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;->access$200(Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;)Ljava/util/zip/ZipFile;

    move-result-object p3

    if-eqz p3, :cond_bf

    .line 26
    # getter for: Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;->zipFile:Ljava/util/zip/ZipFile;
    invoke-static {p1}, Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;->access$200(Lio/rong/imlib/relinker/ApkLibraryInstaller$ZipFileInZipEntry;)Ljava/util/zip/ZipFile;

    move-result-object p1

    invoke-virtual {p1}, Ljava/util/zip/ZipFile;->close()V
    :try_end_bf
    .catch Ljava/io/IOException; {:try_start_b2 .. :try_end_bf} :catch_bf

    .line 27
    :catch_bf
    :cond_bf
    goto :goto_c1

    :goto_c0
    throw p2

    :goto_c1
    goto :goto_c0
.end method