ProcessUtil.smali

.class public Lcom/facebook/stetho/common/ProcessUtil;
.super Ljava/lang/Object;
.source "SourceFile"


# static fields
.field private static final CMDLINE_BUFFER_SIZE:I = 0x40

.field private static sProcessName:Ljava/lang/String;

.field private static sProcessNameRead:Z


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

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

    return-void
.end method

.method public static declared-synchronized getProcessName()Ljava/lang/String;
    .registers 2

    const-class v0, Lcom/facebook/stetho/common/ProcessUtil;

    monitor-enter v0

    .line 1
    :try_start_3
    sget-boolean v1, Lcom/facebook/stetho/common/ProcessUtil;->sProcessNameRead:Z

    if-nez v1, :cond_10

    const/4 v1, 0x1

    .line 2
    sput-boolean v1, Lcom/facebook/stetho/common/ProcessUtil;->sProcessNameRead:Z
    :try_end_a
    .catchall {:try_start_3 .. :try_end_a} :catchall_14

    .line 3
    :try_start_a
    invoke-static {}, Lcom/facebook/stetho/common/ProcessUtil;->readProcessName()Ljava/lang/String;

    move-result-object v1

    sput-object v1, Lcom/facebook/stetho/common/ProcessUtil;->sProcessName:Ljava/lang/String;
    :try_end_10
    .catch Ljava/io/IOException; {:try_start_a .. :try_end_10} :catch_10
    .catchall {:try_start_a .. :try_end_10} :catchall_14

    .line 4
    :catch_10
    :cond_10
    :try_start_10
    sget-object v1, Lcom/facebook/stetho/common/ProcessUtil;->sProcessName:Ljava/lang/String;
    :try_end_12
    .catchall {:try_start_10 .. :try_end_12} :catchall_14

    monitor-exit v0

    return-object v1

    :catchall_14
    move-exception v1

    monitor-exit v0

    throw v1
.end method

.method private static indexOf([BIIB)I
    .registers 4

    const/4 p1, 0x0

    .line 1
    :goto_1
    array-length p2, p0

    if-ge p1, p2, :cond_c

    .line 2
    aget-byte p2, p0, p1

    if-ne p2, p3, :cond_9

    return p1

    :cond_9
    add-int/lit8 p1, p1, 0x1

    goto :goto_1

    :cond_c
    const/4 p0, -0x1

    return p0
.end method

.method private static readProcessName()Ljava/lang/String;
    .registers 7
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    const/16 v0, 0x40

    new-array v0, v0, [B

    .line 1
    new-instance v1, Ljava/io/FileInputStream;

    const-string v2, "/proc/self/cmdline"

    invoke-direct {v1, v2}, Ljava/io/FileInputStream;-><init>(Ljava/lang/String;)V

    const/4 v2, 0x1

    const/4 v3, 0x0

    .line 2
    :try_start_d
    invoke-virtual {v1, v0}, Ljava/io/FileInputStream;->read([B)I

    move-result v4
    :try_end_11
    .catchall {:try_start_d .. :try_end_11} :catchall_24

    .line 3
    :try_start_11
    invoke-static {v0, v3, v4, v3}, Lcom/facebook/stetho/common/ProcessUtil;->indexOf([BIIB)I

    move-result v5

    .line 4
    new-instance v6, Ljava/lang/String;

    if-lez v5, :cond_1a

    move v4, v5

    :cond_1a
    invoke-direct {v6, v0, v3, v4}, Ljava/lang/String;-><init>([BII)V
    :try_end_1d
    .catchall {:try_start_11 .. :try_end_1d} :catchall_21

    .line 5
    invoke-static {v1, v3}, Lcom/facebook/stetho/common/Util;->close(Ljava/io/Closeable;Z)V

    return-object v6

    :catchall_21
    move-exception v0

    const/4 v3, 0x1

    goto :goto_25

    :catchall_24
    move-exception v0

    :goto_25
    xor-int/2addr v2, v3

    invoke-static {v1, v2}, Lcom/facebook/stetho/common/Util;->close(Ljava/io/Closeable;Z)V

    throw v0
.end method