.class public Lcom/alipay/sdk/authjs/JsBridge;
.super Ljava/lang/Object;
.source "SourceFile"


# instance fields
.field private callback:Lcom/alipay/sdk/authjs/IJsCallback;

.field private context:Landroid/content/Context;


# direct methods
.method public constructor <init>(Landroid/content/Context;Lcom/alipay/sdk/authjs/IJsCallback;)V
    .locals 0

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

    .line 24
    iput-object p1, p0, Lcom/alipay/sdk/authjs/JsBridge;->context:Landroid/content/Context;

    .line 25
    iput-object p2, p0, Lcom/alipay/sdk/authjs/JsBridge;->callback:Lcom/alipay/sdk/authjs/IJsCallback;

    return-void
.end method

.method static synthetic access$000(Lcom/alipay/sdk/authjs/JsBridge;Lcom/alipay/sdk/authjs/CallInfo;)Lcom/alipay/sdk/authjs/CallInfo$CallError;
    .locals 0

    .line 18
    invoke-direct {p0, p1}, Lcom/alipay/sdk/authjs/JsBridge;->callNative(Lcom/alipay/sdk/authjs/CallInfo;)Lcom/alipay/sdk/authjs/CallInfo$CallError;

    move-result-object p0

    return-object p0
.end method

.method static synthetic access$100(Lcom/alipay/sdk/authjs/JsBridge;Ljava/lang/String;Lcom/alipay/sdk/authjs/CallInfo$CallError;Z)V
    .locals 0
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Lorg/json/JSONException;
        }
    .end annotation

    .line 18
    invoke-direct {p0, p1, p2, p3}, Lcom/alipay/sdk/authjs/JsBridge;->onCallError(Ljava/lang/String;Lcom/alipay/sdk/authjs/CallInfo$CallError;Z)V

    return-void
.end method

.method static synthetic access$200(Lcom/alipay/sdk/authjs/JsBridge;)Lcom/alipay/sdk/authjs/IJsCallback;
    .locals 0

    .line 18
    iget-object p0, p0, Lcom/alipay/sdk/authjs/JsBridge;->callback:Lcom/alipay/sdk/authjs/IJsCallback;

    return-object p0
.end method

.method private callNative(Lcom/alipay/sdk/authjs/CallInfo;)Lcom/alipay/sdk/authjs/CallInfo$CallError;
    .locals 2

    if-eqz p1, :cond_0

    const-string v0, "toast"

    .line 132
    invoke-virtual {p1}, Lcom/alipay/sdk/authjs/CallInfo;->getFunc()Ljava/lang/String;

    move-result-object v1

    invoke-virtual {v0, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v0

    if-eqz v0, :cond_0

    .line 133
    invoke-direct {p0, p1}, Lcom/alipay/sdk/authjs/JsBridge;->toast(Lcom/alipay/sdk/authjs/CallInfo;)V

    .line 135
    :cond_0
    sget-object p1, Lcom/alipay/sdk/authjs/CallInfo$CallError;->NONE_ERROR:Lcom/alipay/sdk/authjs/CallInfo$CallError;

    return-object p1
.end method

.method private onCallError(Ljava/lang/String;Lcom/alipay/sdk/authjs/CallInfo$CallError;Z)V
    .locals 2
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Lorg/json/JSONException;
        }
    .end annotation

    .line 103
    invoke-static {p1}, Landroid/text/TextUtils;->isEmpty(Ljava/lang/CharSequence;)Z

    move-result v0

    if-eqz v0, :cond_0

    return-void

    .line 106
    :cond_0
    new-instance v0, Lorg/json/JSONObject;

    invoke-direct {v0}, Lorg/json/JSONObject;-><init>()V

    const-string v1, "error"

    .line 107
    invoke-virtual {p2}, Lcom/alipay/sdk/authjs/CallInfo$CallError;->ordinal()I

    move-result p2

    invoke-virtual {v0, v1, p2}, Lorg/json/JSONObject;->put(Ljava/lang/String;I)Lorg/json/JSONObject;

    .line 108
    new-instance p2, Lcom/alipay/sdk/authjs/CallInfo;

    const-string v1, "callback"

    invoke-direct {p2, v1}, Lcom/alipay/sdk/authjs/CallInfo;-><init>(Ljava/lang/String;)V

    .line 109
    invoke-virtual {p2, v0}, Lcom/alipay/sdk/authjs/CallInfo;->setParam(Lorg/json/JSONObject;)V

    .line 110
    invoke-virtual {p2, p1}, Lcom/alipay/sdk/authjs/CallInfo;->setClientId(Ljava/lang/String;)V

    if-eqz p3, :cond_1

    .line 112
    iget-object p1, p0, Lcom/alipay/sdk/authjs/JsBridge;->callback:Lcom/alipay/sdk/authjs/IJsCallback;

    invoke-interface {p1, p2}, Lcom/alipay/sdk/authjs/IJsCallback;->callJS(Lcom/alipay/sdk/authjs/CallInfo;)V

    return-void

    .line 114
    :cond_1
    invoke-virtual {p0, p2}, Lcom/alipay/sdk/authjs/JsBridge;->callJava(Lcom/alipay/sdk/authjs/CallInfo;)V

    return-void
.end method

.method private static runOnMain(Ljava/lang/Runnable;)V
    .locals 2

    if-nez p0, :cond_0

    return-void

    .line 122
    :cond_0
    invoke-static {}, Landroid/os/Looper;->getMainLooper()Landroid/os/Looper;

    move-result-object v0

    invoke-static {}, Landroid/os/Looper;->myLooper()Landroid/os/Looper;

    move-result-object v1

    if-ne v0, v1, :cond_1

    const/4 v0, 0x1

    goto :goto_0

    :cond_1
    const/4 v0, 0x0

    :goto_0
    if-eqz v0, :cond_2

    .line 124
    invoke-interface {p0}, Ljava/lang/Runnable;->run()V

    return-void

    .line 126
    :cond_2
    new-instance v0, Landroid/os/Handler;

    invoke-static {}, Landroid/os/Looper;->getMainLooper()Landroid/os/Looper;

    move-result-object v1

    invoke-direct {v0, v1}, Landroid/os/Handler;-><init>(Landroid/os/Looper;)V

    .line 127
    invoke-virtual {v0, p0}, Landroid/os/Handler;->post(Ljava/lang/Runnable;)Z

    return-void
.end method

.method private toast(Lcom/alipay/sdk/authjs/CallInfo;)V
    .locals 5

    .line 139
    invoke-virtual {p1}, Lcom/alipay/sdk/authjs/CallInfo;->getParam()Lorg/json/JSONObject;

    move-result-object v0

    const-string v1, "content"

    .line 140
    invoke-virtual {v0, v1}, Lorg/json/JSONObject;->optString(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v1

    const-string v2, "duration"

    .line 142
    invoke-virtual {v0, v2}, Lorg/json/JSONObject;->optInt(Ljava/lang/String;)I

    move-result v0

    const/16 v2, 0x9c4

    if-ge v0, v2, :cond_0

    const/4 v0, 0x0

    goto :goto_0

    :cond_0
    const/4 v0, 0x1

    .line 150
    :goto_0
    iget-object v2, p0, Lcom/alipay/sdk/authjs/JsBridge;->context:Landroid/content/Context;

    invoke-static {v2, v1, v0}, Landroid/widget/Toast;->makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;

    move-result-object v1

    invoke-virtual {v1}, Landroid/widget/Toast;->show()V

    .line 152
    new-instance v1, Ljava/util/Timer;

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

    .line 153
    new-instance v2, Lcom/alipay/sdk/authjs/JsBridge$2;

    invoke-direct {v2, p0, p1}, Lcom/alipay/sdk/authjs/JsBridge$2;-><init>(Lcom/alipay/sdk/authjs/JsBridge;Lcom/alipay/sdk/authjs/CallInfo;)V

    int-to-long v3, v0

    invoke-virtual {v1, v2, v3, v4}, Ljava/util/Timer;->schedule(Ljava/util/TimerTask;J)V

    return-void
.end method


# virtual methods
.method public callJava(Lcom/alipay/sdk/authjs/CallInfo;)V
    .locals 2
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Lorg/json/JSONException;
        }
    .end annotation

    if-nez p1, :cond_0

    return-void

    .line 79
    :cond_0
    invoke-virtual {p1}, Lcom/alipay/sdk/authjs/CallInfo;->getFunc()Ljava/lang/String;

    move-result-object v0

    .line 80
    invoke-static {v0}, Landroid/text/TextUtils;->isEmpty(Ljava/lang/CharSequence;)Z

    move-result v0

    if-eqz v0, :cond_1

    .line 81
    invoke-virtual {p1}, Lcom/alipay/sdk/authjs/CallInfo;->getClientId()Ljava/lang/String;

    move-result-object p1

    sget-object v0, Lcom/alipay/sdk/authjs/CallInfo$CallError;->INVALID_PARAMETER:Lcom/alipay/sdk/authjs/CallInfo$CallError;

    const/4 v1, 0x1

    invoke-direct {p0, p1, v0, v1}, Lcom/alipay/sdk/authjs/JsBridge;->onCallError(Ljava/lang/String;Lcom/alipay/sdk/authjs/CallInfo$CallError;Z)V

    return-void

    .line 86
    :cond_1
    new-instance v0, Lcom/alipay/sdk/authjs/JsBridge$1;

    invoke-direct {v0, p0, p1}, Lcom/alipay/sdk/authjs/JsBridge$1;-><init>(Lcom/alipay/sdk/authjs/JsBridge;Lcom/alipay/sdk/authjs/CallInfo;)V

    .line 98
    invoke-static {v0}, Lcom/alipay/sdk/authjs/JsBridge;->runOnMain(Ljava/lang/Runnable;)V

    return-void
.end method

.method public callJava(Ljava/lang/String;)V
    .locals 5

    const/4 v0, 0x0

    .line 32
    :try_start_0
    new-instance v1, Lorg/json/JSONObject;

    invoke-direct {v1, p1}, Lorg/json/JSONObject;-><init>(Ljava/lang/String;)V

    const-string p1, "clientId"

    .line 33
    invoke-virtual {v1, p1}, Lorg/json/JSONObject;->getString(Ljava/lang/String;)Ljava/lang/String;

    move-result-object p1
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 34
    :try_start_1
    invoke-static {p1}, Landroid/text/TextUtils;->isEmpty(Ljava/lang/CharSequence;)Z

    move-result v2

    if-eqz v2, :cond_0

    return-void

    :cond_0
    const-string v2, "param"

    .line 38
    invoke-virtual {v1, v2}, Lorg/json/JSONObject;->getJSONObject(Ljava/lang/String;)Lorg/json/JSONObject;

    move-result-object v2

    .line 39
    instance-of v3, v2, Lorg/json/JSONObject;

    if-eqz v3, :cond_1

    .line 40
    move-object v0, v2

    check-cast v0, Lorg/json/JSONObject;

    :cond_1
    const-string v2, "func"

    .line 54
    invoke-virtual {v1, v2}, Lorg/json/JSONObject;->getString(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v2

    const-string v3, "bundleName"

    .line 55
    invoke-virtual {v1, v3}, Lorg/json/JSONObject;->getString(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v1

    .line 56
    new-instance v3, Lcom/alipay/sdk/authjs/CallInfo;

    const-string v4, "call"

    invoke-direct {v3, v4}, Lcom/alipay/sdk/authjs/CallInfo;-><init>(Ljava/lang/String;)V

    .line 57
    invoke-virtual {v3, v1}, Lcom/alipay/sdk/authjs/CallInfo;->setBundleName(Ljava/lang/String;)V

    .line 58
    invoke-virtual {v3, v2}, Lcom/alipay/sdk/authjs/CallInfo;->setFunc(Ljava/lang/String;)V

    .line 59
    invoke-virtual {v3, v0}, Lcom/alipay/sdk/authjs/CallInfo;->setParam(Lorg/json/JSONObject;)V

    .line 60
    invoke-virtual {v3, p1}, Lcom/alipay/sdk/authjs/CallInfo;->setClientId(Ljava/lang/String;)V

    .line 61
    invoke-virtual {p0, v3}, Lcom/alipay/sdk/authjs/JsBridge;->callJava(Lcom/alipay/sdk/authjs/CallInfo;)V
    :try_end_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_1

    return-void

    :catch_0
    move-object p1, v0

    .line 64
    :catch_1
    invoke-static {p1}, Landroid/text/TextUtils;->isEmpty(Ljava/lang/CharSequence;)Z

    move-result v0

    if-nez v0, :cond_2

    .line 66
    :try_start_2
    sget-object v0, Lcom/alipay/sdk/authjs/CallInfo$CallError;->RUNTIME_ERROR:Lcom/alipay/sdk/authjs/CallInfo$CallError;

    const/4 v1, 0x1

    invoke-direct {p0, p1, v0, v1}, Lcom/alipay/sdk/authjs/JsBridge;->onCallError(Ljava/lang/String;Lcom/alipay/sdk/authjs/CallInfo$CallError;Z)V
    :try_end_2
    .catch Lorg/json/JSONException; {:try_start_2 .. :try_end_2} :catch_2

    return-void

    :catch_2
    :cond_2
    return-void
.end method
