ExecutionDelegator.smali

.class public Lcom/firebase/jobdispatcher/ExecutionDelegator;
.super Ljava/lang/Object;
.source "ExecutionDelegator.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/firebase/jobdispatcher/ExecutionDelegator$JobFinishedCallback;
    }
.end annotation


# static fields
.field public static final TAG:Ljava/lang/String; = "FJD.ExternalReceiver"

.field public static final serviceConnections:Landroidx/collection/SimpleArrayMap;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Landroidx/collection/SimpleArrayMap<",
            "Ljava/lang/String;",
            "Lcom/firebase/jobdispatcher/JobServiceConnection;",
            ">;"
        }
    .end annotation
.end field


# instance fields
.field public final context:Landroid/content/Context;

.field public final execCallback:Lcom/firebase/jobdispatcher/IJobCallback;

.field public final jobFinishedCallback:Lcom/firebase/jobdispatcher/ExecutionDelegator$JobFinishedCallback;


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

    new-instance v0, Landroidx/collection/SimpleArrayMap;

    invoke-direct {v0}, Landroidx/collection/SimpleArrayMap;-><init>()V

    sput-object v0, Lcom/firebase/jobdispatcher/ExecutionDelegator;->serviceConnections:Landroidx/collection/SimpleArrayMap;

    return-void
.end method

.method public constructor <init>(Landroid/content/Context;Lcom/firebase/jobdispatcher/ExecutionDelegator$JobFinishedCallback;)V
    .registers 4

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

    new-instance v0, Lcom/firebase/jobdispatcher/ExecutionDelegator$1;

    invoke-direct {v0, p0}, Lcom/firebase/jobdispatcher/ExecutionDelegator$1;-><init>(Lcom/firebase/jobdispatcher/ExecutionDelegator;)V

    iput-object v0, p0, Lcom/firebase/jobdispatcher/ExecutionDelegator;->execCallback:Lcom/firebase/jobdispatcher/IJobCallback;

    iput-object p1, p0, Lcom/firebase/jobdispatcher/ExecutionDelegator;->context:Landroid/content/Context;

    iput-object p2, p0, Lcom/firebase/jobdispatcher/ExecutionDelegator;->jobFinishedCallback:Lcom/firebase/jobdispatcher/ExecutionDelegator$JobFinishedCallback;

    return-void
.end method

.method public static synthetic access$000(Lcom/firebase/jobdispatcher/ExecutionDelegator;Lcom/firebase/jobdispatcher/JobInvocation;I)V
    .registers 3

    invoke-direct {p0, p1, p2}, Lcom/firebase/jobdispatcher/ExecutionDelegator;->onJobFinishedMessage(Lcom/firebase/jobdispatcher/JobInvocation;I)V

    return-void
.end method

.method public static cleanServiceConnections()V
    .registers 2
    .annotation build Landroidx/annotation/VisibleForTesting;
    .end annotation

    sget-object v0, Lcom/firebase/jobdispatcher/ExecutionDelegator;->serviceConnections:Landroidx/collection/SimpleArrayMap;

    monitor-enter v0

    :try_start_3
    sget-object v1, Lcom/firebase/jobdispatcher/ExecutionDelegator;->serviceConnections:Landroidx/collection/SimpleArrayMap;

    invoke-virtual {v1}, Landroidx/collection/SimpleArrayMap;->clear()V

    monitor-exit v0

    return-void

    :catchall_a
    move-exception v1

    monitor-exit v0
    :try_end_c
    .catchall {:try_start_3 .. :try_end_c} :catchall_a

    throw v1
.end method

.method private createBindIntent(Lcom/firebase/jobdispatcher/JobParameters;)Landroid/content/Intent;
    .registers 4
    .annotation build Landroidx/annotation/NonNull;
    .end annotation

    new-instance v0, Landroid/content/Intent;

    const-string v1, "com.firebase.jobdispatcher.ACTION_EXECUTE"

    invoke-direct {v0, v1}, Landroid/content/Intent;-><init>(Ljava/lang/String;)V

    iget-object v1, p0, Lcom/firebase/jobdispatcher/ExecutionDelegator;->context:Landroid/content/Context;

    invoke-interface {p1}, Lcom/firebase/jobdispatcher/JobParameters;->getService()Ljava/lang/String;

    move-result-object p1

    invoke-virtual {v0, v1, p1}, Landroid/content/Intent;->setClassName(Landroid/content/Context;Ljava/lang/String;)Landroid/content/Intent;

    return-object v0
.end method

.method public static getJobServiceConnection(Ljava/lang/String;)Lcom/firebase/jobdispatcher/JobServiceConnection;
    .registers 3
    .annotation build Landroidx/annotation/VisibleForTesting;
    .end annotation

    sget-object v0, Lcom/firebase/jobdispatcher/ExecutionDelegator;->serviceConnections:Landroidx/collection/SimpleArrayMap;

    monitor-enter v0

    :try_start_3
    sget-object v1, Lcom/firebase/jobdispatcher/ExecutionDelegator;->serviceConnections:Landroidx/collection/SimpleArrayMap;

    invoke-virtual {v1, p0}, Landroidx/collection/SimpleArrayMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object p0

    check-cast p0, Lcom/firebase/jobdispatcher/JobServiceConnection;

    monitor-exit v0

    return-object p0

    :catchall_d
    move-exception p0

    monitor-exit v0
    :try_end_f
    .catchall {:try_start_3 .. :try_end_f} :catchall_d

    throw p0
.end method

.method private onJobFinishedMessage(Lcom/firebase/jobdispatcher/JobInvocation;I)V
    .registers 6

    sget-object v0, Lcom/firebase/jobdispatcher/ExecutionDelegator;->serviceConnections:Landroidx/collection/SimpleArrayMap;

    monitor-enter v0

    :try_start_3
    sget-object v1, Lcom/firebase/jobdispatcher/ExecutionDelegator;->serviceConnections:Landroidx/collection/SimpleArrayMap;

    invoke-virtual {p1}, Lcom/firebase/jobdispatcher/JobInvocation;->getService()Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v1, v2}, Landroidx/collection/SimpleArrayMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Lcom/firebase/jobdispatcher/JobServiceConnection;

    if-eqz v1, :cond_23

    invoke-virtual {v1, p1}, Lcom/firebase/jobdispatcher/JobServiceConnection;->onJobFinished(Lcom/firebase/jobdispatcher/JobInvocation;)V

    invoke-virtual {v1}, Lcom/firebase/jobdispatcher/JobServiceConnection;->wasUnbound()Z

    move-result v1

    if-eqz v1, :cond_23

    sget-object v1, Lcom/firebase/jobdispatcher/ExecutionDelegator;->serviceConnections:Landroidx/collection/SimpleArrayMap;

    invoke-virtual {p1}, Lcom/firebase/jobdispatcher/JobInvocation;->getService()Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v1, v2}, Landroidx/collection/SimpleArrayMap;->remove(Ljava/lang/Object;)Ljava/lang/Object;

    :cond_23
    monitor-exit v0
    :try_end_24
    .catchall {:try_start_3 .. :try_end_24} :catchall_2a

    iget-object v0, p0, Lcom/firebase/jobdispatcher/ExecutionDelegator;->jobFinishedCallback:Lcom/firebase/jobdispatcher/ExecutionDelegator$JobFinishedCallback;

    invoke-interface {v0, p1, p2}, Lcom/firebase/jobdispatcher/ExecutionDelegator$JobFinishedCallback;->onJobFinished(Lcom/firebase/jobdispatcher/JobInvocation;I)V

    return-void

    :catchall_2a
    move-exception p1

    :try_start_2b
    monitor-exit v0
    :try_end_2c
    .catchall {:try_start_2b .. :try_end_2c} :catchall_2a

    throw p1
.end method

.method public static stopJob(Lcom/firebase/jobdispatcher/JobInvocation;Z)V
    .registers 5

    sget-object v0, Lcom/firebase/jobdispatcher/ExecutionDelegator;->serviceConnections:Landroidx/collection/SimpleArrayMap;

    monitor-enter v0

    :try_start_3
    sget-object v1, Lcom/firebase/jobdispatcher/ExecutionDelegator;->serviceConnections:Landroidx/collection/SimpleArrayMap;

    invoke-virtual {p0}, Lcom/firebase/jobdispatcher/JobInvocation;->getService()Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v1, v2}, Landroidx/collection/SimpleArrayMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Lcom/firebase/jobdispatcher/JobServiceConnection;

    if-eqz v1, :cond_23

    invoke-virtual {v1, p0, p1}, Lcom/firebase/jobdispatcher/JobServiceConnection;->onStop(Lcom/firebase/jobdispatcher/JobInvocation;Z)V

    invoke-virtual {v1}, Lcom/firebase/jobdispatcher/JobServiceConnection;->wasUnbound()Z

    move-result p1

    if-eqz p1, :cond_23

    sget-object p1, Lcom/firebase/jobdispatcher/ExecutionDelegator;->serviceConnections:Landroidx/collection/SimpleArrayMap;

    invoke-virtual {p0}, Lcom/firebase/jobdispatcher/JobInvocation;->getService()Ljava/lang/String;

    move-result-object p0

    invoke-virtual {p1, p0}, Landroidx/collection/SimpleArrayMap;->remove(Ljava/lang/Object;)Ljava/lang/Object;

    :cond_23
    monitor-exit v0

    return-void

    :catchall_25
    move-exception p0

    monitor-exit v0
    :try_end_27
    .catchall {:try_start_3 .. :try_end_27} :catchall_25

    throw p0
.end method


# virtual methods
.method public executeJob(Lcom/firebase/jobdispatcher/JobInvocation;)V
    .registers 7

    if-nez p1, :cond_3

    return-void

    :cond_3
    sget-object v0, Lcom/firebase/jobdispatcher/ExecutionDelegator;->serviceConnections:Landroidx/collection/SimpleArrayMap;

    monitor-enter v0

    :try_start_6
    sget-object v1, Lcom/firebase/jobdispatcher/ExecutionDelegator;->serviceConnections:Landroidx/collection/SimpleArrayMap;

    invoke-virtual {p1}, Lcom/firebase/jobdispatcher/JobInvocation;->getService()Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v1, v2}, Landroidx/collection/SimpleArrayMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Lcom/firebase/jobdispatcher/JobServiceConnection;

    if-eqz v1, :cond_28

    invoke-virtual {v1}, Lcom/firebase/jobdispatcher/JobServiceConnection;->wasUnbound()Z

    move-result v2

    if-nez v2, :cond_28

    invoke-virtual {v1, p1}, Lcom/firebase/jobdispatcher/JobServiceConnection;->hasJobInvocation(Lcom/firebase/jobdispatcher/JobInvocation;)Z

    move-result v2

    if-eqz v2, :cond_3a

    invoke-virtual {v1}, Lcom/firebase/jobdispatcher/JobServiceConnection;->isConnected()Z

    move-result v2

    if-nez v2, :cond_3a

    monitor-exit v0

    return-void

    :cond_28
    new-instance v1, Lcom/firebase/jobdispatcher/JobServiceConnection;

    iget-object v2, p0, Lcom/firebase/jobdispatcher/ExecutionDelegator;->execCallback:Lcom/firebase/jobdispatcher/IJobCallback;

    iget-object v3, p0, Lcom/firebase/jobdispatcher/ExecutionDelegator;->context:Landroid/content/Context;

    invoke-direct {v1, v2, v3}, Lcom/firebase/jobdispatcher/JobServiceConnection;-><init>(Lcom/firebase/jobdispatcher/IJobCallback;Landroid/content/Context;)V

    sget-object v2, Lcom/firebase/jobdispatcher/ExecutionDelegator;->serviceConnections:Landroidx/collection/SimpleArrayMap;

    invoke-virtual {p1}, Lcom/firebase/jobdispatcher/JobInvocation;->getService()Ljava/lang/String;

    move-result-object v3

    invoke-virtual {v2, v3, v1}, Landroidx/collection/SimpleArrayMap;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    :cond_3a
    invoke-virtual {v1, p1}, Lcom/firebase/jobdispatcher/JobServiceConnection;->startJob(Lcom/firebase/jobdispatcher/JobInvocation;)Z

    move-result v2

    if-nez v2, :cond_6a

    iget-object v2, p0, Lcom/firebase/jobdispatcher/ExecutionDelegator;->context:Landroid/content/Context;

    invoke-direct {p0, p1}, Lcom/firebase/jobdispatcher/ExecutionDelegator;->createBindIntent(Lcom/firebase/jobdispatcher/JobParameters;)Landroid/content/Intent;

    move-result-object v3

    const/4 v4, 0x1

    invoke-virtual {v2, v3, v1, v4}, Landroid/content/Context;->bindService(Landroid/content/Intent;Landroid/content/ServiceConnection;I)Z

    move-result v2

    if-nez v2, :cond_6a

    const-string v2, "FJD.ExternalReceiver"

    new-instance v3, Ljava/lang/StringBuilder;

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

    const-string v4, "Unable to bind to "

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

    invoke-virtual {p1}, Lcom/firebase/jobdispatcher/JobInvocation;->getService()Ljava/lang/String;

    move-result-object p1

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

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

    move-result-object p1

    invoke-static {v2, p1}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    invoke-virtual {v1}, Lcom/firebase/jobdispatcher/JobServiceConnection;->unbind()V

    :cond_6a
    monitor-exit v0

    return-void

    :catchall_6c
    move-exception p1

    monitor-exit v0
    :try_end_6e
    .catchall {:try_start_6 .. :try_end_6e} :catchall_6c

    throw p1
.end method