SpeedCalculator.smali
.class public Lcom/liulishuo/okdownload/SpeedCalculator;
.super Ljava/lang/Object;
.source "SpeedCalculator.java"
# instance fields
.field public allIncreaseBytes:J
.field public beginTimestamp:J
.field public bytesPerSecond:J
.field public endTimestamp:J
.field public increaseBytes:J
.field public timestamp:J
# direct methods
.method static constructor <clinit>()V
.registers 1
return-void
.end method
.method public constructor <init>()V
.registers 1
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
return-void
.end method
.method public static humanReadableSpeed(JZ)Ljava/lang/String;
.registers 4
new-instance v0, Ljava/lang/StringBuilder;
invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V
invoke-static {p0, p1, p2}, Lcom/liulishuo/okdownload/core/Util;->humanReadableBytes(JZ)Ljava/lang/String;
move-result-object p0
invoke-virtual {v0, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
const-string p0, "/s"
invoke-virtual {v0, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
move-result-object p0
return-object p0
.end method
# virtual methods
.method public averageSpeed()Ljava/lang/String;
.registers 2
invoke-virtual {p0}, Lcom/liulishuo/okdownload/SpeedCalculator;->speedFromBegin()Ljava/lang/String;
move-result-object v0
return-object v0
.end method
.method public declared-synchronized downloading(J)V
.registers 8
monitor-enter p0
:try_start_1
iget-wide v0, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->timestamp:J
const-wide/16 v2, 0x0
cmp-long v4, v0, v2
if-nez v4, :cond_11
invoke-virtual {p0}, Lcom/liulishuo/okdownload/SpeedCalculator;->nowMillis()J
move-result-wide v0
iput-wide v0, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->timestamp:J
iput-wide v0, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->beginTimestamp:J
:cond_11
iget-wide v0, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->increaseBytes:J
add-long/2addr v0, p1
iput-wide v0, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->increaseBytes:J
iget-wide v0, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->allIncreaseBytes:J
add-long/2addr v0, p1
iput-wide v0, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->allIncreaseBytes:J
:try_end_1b
.catchall {:try_start_1 .. :try_end_1b} :catchall_1d
monitor-exit p0
return-void
:catchall_1d
move-exception p1
monitor-exit p0
throw p1
.end method
.method public declared-synchronized endTask()V
.registers 3
monitor-enter p0
:try_start_1
invoke-virtual {p0}, Lcom/liulishuo/okdownload/SpeedCalculator;->nowMillis()J
move-result-wide v0
iput-wide v0, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->endTimestamp:J
:try_end_7
.catchall {:try_start_1 .. :try_end_7} :catchall_9
monitor-exit p0
return-void
:catchall_9
move-exception v0
monitor-exit p0
throw v0
.end method
.method public declared-synchronized flush()V
.registers 9
monitor-enter p0
:try_start_1
invoke-virtual {p0}, Lcom/liulishuo/okdownload/SpeedCalculator;->nowMillis()J
move-result-wide v0
iget-wide v2, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->increaseBytes:J
const-wide/16 v4, 0x1
iget-wide v6, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->timestamp:J
sub-long v6, v0, v6
invoke-static {v4, v5, v6, v7}, Ljava/lang/Math;->max(JJ)J
move-result-wide v4
const-wide/16 v6, 0x0
iput-wide v6, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->increaseBytes:J
iput-wide v0, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->timestamp:J
long-to-float v0, v2
long-to-float v1, v4
div-float/2addr v0, v1
const/high16 v1, 0x447a0000 # 1000.0f
mul-float v0, v0, v1
float-to-long v0, v0
iput-wide v0, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->bytesPerSecond:J
:try_end_21
.catchall {:try_start_1 .. :try_end_21} :catchall_23
monitor-exit p0
return-void
:catchall_23
move-exception v0
monitor-exit p0
throw v0
.end method
.method public declared-synchronized getBytesPerSecondAndFlush()J
.registers 8
monitor-enter p0
:try_start_1
invoke-virtual {p0}, Lcom/liulishuo/okdownload/SpeedCalculator;->nowMillis()J
move-result-wide v0
iget-wide v2, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->timestamp:J
sub-long/2addr v0, v2
const-wide/16 v2, 0x3e8
const-wide/16 v4, 0x0
cmp-long v6, v0, v2
if-gez v6, :cond_1a
iget-wide v2, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->bytesPerSecond:J
cmp-long v6, v2, v4
if-eqz v6, :cond_1a
iget-wide v0, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->bytesPerSecond:J
:try_end_18
.catchall {:try_start_1 .. :try_end_18} :catchall_2e
monitor-exit p0
return-wide v0
:cond_1a
:try_start_1a
iget-wide v2, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->bytesPerSecond:J
:try_end_1c
.catchall {:try_start_1a .. :try_end_1c} :catchall_2e
cmp-long v6, v2, v4
if-nez v6, :cond_28
const-wide/16 v2, 0x1f4
cmp-long v6, v0, v2
if-gez v6, :cond_28
monitor-exit p0
return-wide v4
:cond_28
:try_start_28
invoke-virtual {p0}, Lcom/liulishuo/okdownload/SpeedCalculator;->getInstantBytesPerSecondAndFlush()J
move-result-wide v0
:try_end_2c
.catchall {:try_start_28 .. :try_end_2c} :catchall_2e
monitor-exit p0
return-wide v0
:catchall_2e
move-exception v0
monitor-exit p0
throw v0
.end method
.method public declared-synchronized getBytesPerSecondFromBegin()J
.registers 9
monitor-enter p0
:try_start_1
iget-wide v0, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->endTimestamp:J
const-wide/16 v2, 0x0
cmp-long v4, v0, v2
if-nez v4, :cond_e
invoke-virtual {p0}, Lcom/liulishuo/okdownload/SpeedCalculator;->nowMillis()J
move-result-wide v0
goto :goto_10
:cond_e
iget-wide v0, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->endTimestamp:J
:goto_10
iget-wide v2, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->allIncreaseBytes:J
const-wide/16 v4, 0x1
iget-wide v6, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->beginTimestamp:J
sub-long/2addr v0, v6
invoke-static {v4, v5, v0, v1}, Ljava/lang/Math;->max(JJ)J
move-result-wide v0
:try_end_1b
.catchall {:try_start_1 .. :try_end_1b} :catchall_25
long-to-float v2, v2
long-to-float v0, v0
div-float/2addr v2, v0
const/high16 v0, 0x447a0000 # 1000.0f
mul-float v2, v2, v0
float-to-long v0, v2
monitor-exit p0
return-wide v0
:catchall_25
move-exception v0
monitor-exit p0
throw v0
.end method
.method public getInstantBytesPerSecondAndFlush()J
.registers 3
invoke-virtual {p0}, Lcom/liulishuo/okdownload/SpeedCalculator;->flush()V
iget-wide v0, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->bytesPerSecond:J
return-wide v0
.end method
.method public declared-synchronized getInstantSpeedDurationMillis()J
.registers 5
monitor-enter p0
:try_start_1
invoke-virtual {p0}, Lcom/liulishuo/okdownload/SpeedCalculator;->nowMillis()J
move-result-wide v0
iget-wide v2, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->timestamp:J
:try_end_7
.catchall {:try_start_1 .. :try_end_7} :catchall_a
sub-long/2addr v0, v2
monitor-exit p0
return-wide v0
:catchall_a
move-exception v0
monitor-exit p0
throw v0
.end method
.method public getSpeedWithBinaryAndFlush()Ljava/lang/String;
.registers 4
invoke-virtual {p0}, Lcom/liulishuo/okdownload/SpeedCalculator;->getInstantBytesPerSecondAndFlush()J
move-result-wide v0
const/4 v2, 0x0
invoke-static {v0, v1, v2}, Lcom/liulishuo/okdownload/SpeedCalculator;->humanReadableSpeed(JZ)Ljava/lang/String;
move-result-object v0
return-object v0
.end method
.method public getSpeedWithSIAndFlush()Ljava/lang/String;
.registers 4
invoke-virtual {p0}, Lcom/liulishuo/okdownload/SpeedCalculator;->getInstantBytesPerSecondAndFlush()J
move-result-wide v0
const/4 v2, 0x1
invoke-static {v0, v1, v2}, Lcom/liulishuo/okdownload/SpeedCalculator;->humanReadableSpeed(JZ)Ljava/lang/String;
move-result-object v0
return-object v0
.end method
.method public instantSpeed()Ljava/lang/String;
.registers 2
invoke-virtual {p0}, Lcom/liulishuo/okdownload/SpeedCalculator;->getSpeedWithSIAndFlush()Ljava/lang/String;
move-result-object v0
return-object v0
.end method
.method public lastSpeed()Ljava/lang/String;
.registers 4
iget-wide v0, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->bytesPerSecond:J
const/4 v2, 0x1
invoke-static {v0, v1, v2}, Lcom/liulishuo/okdownload/SpeedCalculator;->humanReadableSpeed(JZ)Ljava/lang/String;
move-result-object v0
return-object v0
.end method
.method public nowMillis()J
.registers 3
invoke-static {}, Landroid/os/SystemClock;->uptimeMillis()J
move-result-wide v0
return-wide v0
.end method
.method public declared-synchronized reset()V
.registers 3
monitor-enter p0
const-wide/16 v0, 0x0
:try_start_3
iput-wide v0, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->timestamp:J
iput-wide v0, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->increaseBytes:J
iput-wide v0, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->bytesPerSecond:J
iput-wide v0, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->beginTimestamp:J
iput-wide v0, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->endTimestamp:J
iput-wide v0, p0, Lcom/liulishuo/okdownload/SpeedCalculator;->allIncreaseBytes:J
:try_end_f
.catchall {:try_start_3 .. :try_end_f} :catchall_11
monitor-exit p0
return-void
:catchall_11
move-exception v0
monitor-exit p0
throw v0
.end method
.method public speed()Ljava/lang/String;
.registers 4
invoke-virtual {p0}, Lcom/liulishuo/okdownload/SpeedCalculator;->getBytesPerSecondAndFlush()J
move-result-wide v0
const/4 v2, 0x1
invoke-static {v0, v1, v2}, Lcom/liulishuo/okdownload/SpeedCalculator;->humanReadableSpeed(JZ)Ljava/lang/String;
move-result-object v0
return-object v0
.end method
.method public speedFromBegin()Ljava/lang/String;
.registers 4
invoke-virtual {p0}, Lcom/liulishuo/okdownload/SpeedCalculator;->getBytesPerSecondFromBegin()J
move-result-wide v0
const/4 v2, 0x1
invoke-static {v0, v1, v2}, Lcom/liulishuo/okdownload/SpeedCalculator;->humanReadableSpeed(JZ)Ljava/lang/String;
move-result-object v0
return-object v0
.end method