348 lines
8.4 KiB
Smali
348 lines
8.4 KiB
Smali
.class public Lcom/squareup/picasso/UrlConnectionDownloader;
|
|
.super Ljava/lang/Object;
|
|
.source "UrlConnectionDownloader.java"
|
|
|
|
# interfaces
|
|
.implements Lcom/squareup/picasso/Downloader;
|
|
|
|
|
|
# annotations
|
|
.annotation system Ldalvik/annotation/MemberClasses;
|
|
value = {
|
|
Lcom/squareup/picasso/UrlConnectionDownloader$ResponseCacheIcs;
|
|
}
|
|
.end annotation
|
|
|
|
|
|
# static fields
|
|
.field static volatile a:Ljava/lang/Object;
|
|
|
|
.field private static final b:Ljava/lang/Object;
|
|
|
|
.field private static final c:Ljava/lang/ThreadLocal;
|
|
.annotation system Ldalvik/annotation/Signature;
|
|
value = {
|
|
"Ljava/lang/ThreadLocal<",
|
|
"Ljava/lang/StringBuilder;",
|
|
">;"
|
|
}
|
|
.end annotation
|
|
.end field
|
|
|
|
|
|
# instance fields
|
|
.field private final d:Landroid/content/Context;
|
|
|
|
|
|
# direct methods
|
|
.method static constructor <clinit>()V
|
|
.locals 1
|
|
|
|
.line 38
|
|
new-instance v0, Ljava/lang/Object;
|
|
|
|
invoke-direct {v0}, Ljava/lang/Object;-><init>()V
|
|
|
|
sput-object v0, Lcom/squareup/picasso/UrlConnectionDownloader;->b:Ljava/lang/Object;
|
|
|
|
.line 40
|
|
new-instance v0, Lcom/squareup/picasso/UrlConnectionDownloader$1;
|
|
|
|
invoke-direct {v0}, Lcom/squareup/picasso/UrlConnectionDownloader$1;-><init>()V
|
|
|
|
sput-object v0, Lcom/squareup/picasso/UrlConnectionDownloader;->c:Ljava/lang/ThreadLocal;
|
|
|
|
return-void
|
|
.end method
|
|
|
|
.method public constructor <init>(Landroid/content/Context;)V
|
|
.locals 0
|
|
|
|
.line 49
|
|
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
|
|
|
|
.line 50
|
|
invoke-virtual {p1}, Landroid/content/Context;->getApplicationContext()Landroid/content/Context;
|
|
|
|
move-result-object p1
|
|
|
|
iput-object p1, p0, Lcom/squareup/picasso/UrlConnectionDownloader;->d:Landroid/content/Context;
|
|
|
|
return-void
|
|
.end method
|
|
|
|
.method private static a(Landroid/content/Context;)V
|
|
.locals 2
|
|
|
|
.line 114
|
|
sget-object v0, Lcom/squareup/picasso/UrlConnectionDownloader;->a:Ljava/lang/Object;
|
|
|
|
if-nez v0, :cond_1
|
|
|
|
.line 116
|
|
:try_start_0
|
|
sget-object v0, Lcom/squareup/picasso/UrlConnectionDownloader;->b:Ljava/lang/Object;
|
|
|
|
monitor-enter v0
|
|
:try_end_0
|
|
.catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0
|
|
|
|
.line 117
|
|
:try_start_1
|
|
sget-object v1, Lcom/squareup/picasso/UrlConnectionDownloader;->a:Ljava/lang/Object;
|
|
|
|
if-nez v1, :cond_0
|
|
|
|
.line 118
|
|
invoke-static {p0}, Lcom/squareup/picasso/UrlConnectionDownloader$ResponseCacheIcs;->a(Landroid/content/Context;)Ljava/lang/Object;
|
|
|
|
move-result-object p0
|
|
|
|
sput-object p0, Lcom/squareup/picasso/UrlConnectionDownloader;->a:Ljava/lang/Object;
|
|
|
|
.line 120
|
|
:cond_0
|
|
monitor-exit v0
|
|
|
|
goto :goto_0
|
|
|
|
:catchall_0
|
|
move-exception p0
|
|
|
|
monitor-exit v0
|
|
:try_end_1
|
|
.catchall {:try_start_1 .. :try_end_1} :catchall_0
|
|
|
|
:try_start_2
|
|
throw p0
|
|
:try_end_2
|
|
.catch Ljava/io/IOException; {:try_start_2 .. :try_end_2} :catch_0
|
|
|
|
:catch_0
|
|
:cond_1
|
|
:goto_0
|
|
return-void
|
|
.end method
|
|
|
|
|
|
# virtual methods
|
|
.method public a(Landroid/net/Uri;I)Lcom/squareup/picasso/Downloader$Response;
|
|
.locals 4
|
|
.annotation system Ldalvik/annotation/Throws;
|
|
value = {
|
|
Ljava/io/IOException;
|
|
}
|
|
.end annotation
|
|
|
|
.line 61
|
|
sget v0, Landroid/os/Build$VERSION;->SDK_INT:I
|
|
|
|
const/16 v1, 0xe
|
|
|
|
if-lt v0, v1, :cond_0
|
|
|
|
.line 62
|
|
iget-object v0, p0, Lcom/squareup/picasso/UrlConnectionDownloader;->d:Landroid/content/Context;
|
|
|
|
invoke-static {v0}, Lcom/squareup/picasso/UrlConnectionDownloader;->a(Landroid/content/Context;)V
|
|
|
|
.line 65
|
|
:cond_0
|
|
invoke-virtual {p0, p1}, Lcom/squareup/picasso/UrlConnectionDownloader;->a(Landroid/net/Uri;)Ljava/net/HttpURLConnection;
|
|
|
|
move-result-object p1
|
|
|
|
const/4 v0, 0x1
|
|
|
|
.line 66
|
|
invoke-virtual {p1, v0}, Ljava/net/HttpURLConnection;->setUseCaches(Z)V
|
|
|
|
if-eqz p2, :cond_5
|
|
|
|
.line 71
|
|
invoke-static {p2}, Lcom/squareup/picasso/NetworkPolicy;->isOfflineOnly(I)Z
|
|
|
|
move-result v0
|
|
|
|
if-eqz v0, :cond_1
|
|
|
|
const-string v0, "only-if-cached,max-age=2147483647"
|
|
|
|
goto :goto_0
|
|
|
|
.line 74
|
|
:cond_1
|
|
sget-object v0, Lcom/squareup/picasso/UrlConnectionDownloader;->c:Ljava/lang/ThreadLocal;
|
|
|
|
invoke-virtual {v0}, Ljava/lang/ThreadLocal;->get()Ljava/lang/Object;
|
|
|
|
move-result-object v0
|
|
|
|
check-cast v0, Ljava/lang/StringBuilder;
|
|
|
|
const/4 v1, 0x0
|
|
|
|
.line 75
|
|
invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->setLength(I)V
|
|
|
|
.line 77
|
|
invoke-static {p2}, Lcom/squareup/picasso/NetworkPolicy;->shouldReadFromDiskCache(I)Z
|
|
|
|
move-result v1
|
|
|
|
if-nez v1, :cond_2
|
|
|
|
const-string v1, "no-cache"
|
|
|
|
.line 78
|
|
invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
|
|
|
|
.line 80
|
|
:cond_2
|
|
invoke-static {p2}, Lcom/squareup/picasso/NetworkPolicy;->shouldWriteToDiskCache(I)Z
|
|
|
|
move-result v1
|
|
|
|
if-nez v1, :cond_4
|
|
|
|
.line 81
|
|
invoke-virtual {v0}, Ljava/lang/StringBuilder;->length()I
|
|
|
|
move-result v1
|
|
|
|
if-lez v1, :cond_3
|
|
|
|
const/16 v1, 0x2c
|
|
|
|
.line 82
|
|
invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(C)Ljava/lang/StringBuilder;
|
|
|
|
:cond_3
|
|
const-string v1, "no-store"
|
|
|
|
.line 84
|
|
invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
|
|
|
|
.line 87
|
|
:cond_4
|
|
invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
|
|
|
|
move-result-object v0
|
|
|
|
:goto_0
|
|
const-string v1, "Cache-Control"
|
|
|
|
.line 90
|
|
invoke-virtual {p1, v1, v0}, Ljava/net/HttpURLConnection;->setRequestProperty(Ljava/lang/String;Ljava/lang/String;)V
|
|
|
|
.line 93
|
|
:cond_5
|
|
invoke-virtual {p1}, Ljava/net/HttpURLConnection;->getResponseCode()I
|
|
|
|
move-result v0
|
|
|
|
const/16 v1, 0x12c
|
|
|
|
if-ge v0, v1, :cond_6
|
|
|
|
const-string p2, "Content-Length"
|
|
|
|
const/4 v0, -0x1
|
|
|
|
.line 100
|
|
invoke-virtual {p1, p2, v0}, Ljava/net/HttpURLConnection;->getHeaderFieldInt(Ljava/lang/String;I)I
|
|
|
|
move-result p2
|
|
|
|
int-to-long v0, p2
|
|
|
|
const-string p2, "X-Android-Response-Source"
|
|
|
|
.line 101
|
|
invoke-virtual {p1, p2}, Ljava/net/HttpURLConnection;->getHeaderField(Ljava/lang/String;)Ljava/lang/String;
|
|
|
|
move-result-object p2
|
|
|
|
invoke-static {p2}, Lcom/squareup/picasso/Utils;->a(Ljava/lang/String;)Z
|
|
|
|
move-result p2
|
|
|
|
.line 103
|
|
new-instance v2, Lcom/squareup/picasso/Downloader$Response;
|
|
|
|
invoke-virtual {p1}, Ljava/net/HttpURLConnection;->getInputStream()Ljava/io/InputStream;
|
|
|
|
move-result-object p1
|
|
|
|
invoke-direct {v2, p1, p2, v0, v1}, Lcom/squareup/picasso/Downloader$Response;-><init>(Ljava/io/InputStream;ZJ)V
|
|
|
|
return-object v2
|
|
|
|
.line 95
|
|
:cond_6
|
|
invoke-virtual {p1}, Ljava/net/HttpURLConnection;->disconnect()V
|
|
|
|
.line 96
|
|
new-instance v1, Lcom/squareup/picasso/Downloader$ResponseException;
|
|
|
|
new-instance v2, Ljava/lang/StringBuilder;
|
|
|
|
invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V
|
|
|
|
invoke-virtual {v2, v0}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;
|
|
|
|
const-string v3, " "
|
|
|
|
invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
|
|
|
|
invoke-virtual {p1}, Ljava/net/HttpURLConnection;->getResponseMessage()Ljava/lang/String;
|
|
|
|
move-result-object p1
|
|
|
|
invoke-virtual {v2, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
|
|
|
|
invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
|
|
|
|
move-result-object p1
|
|
|
|
invoke-direct {v1, p1, p2, v0}, Lcom/squareup/picasso/Downloader$ResponseException;-><init>(Ljava/lang/String;II)V
|
|
|
|
throw v1
|
|
.end method
|
|
|
|
.method protected a(Landroid/net/Uri;)Ljava/net/HttpURLConnection;
|
|
.locals 1
|
|
.annotation system Ldalvik/annotation/Throws;
|
|
value = {
|
|
Ljava/io/IOException;
|
|
}
|
|
.end annotation
|
|
|
|
.line 54
|
|
new-instance v0, Ljava/net/URL;
|
|
|
|
invoke-virtual {p1}, Landroid/net/Uri;->toString()Ljava/lang/String;
|
|
|
|
move-result-object p1
|
|
|
|
invoke-direct {v0, p1}, Ljava/net/URL;-><init>(Ljava/lang/String;)V
|
|
|
|
invoke-virtual {v0}, Ljava/net/URL;->openConnection()Ljava/net/URLConnection;
|
|
|
|
move-result-object p1
|
|
|
|
check-cast p1, Ljava/net/HttpURLConnection;
|
|
|
|
const/16 v0, 0x3a98
|
|
|
|
.line 55
|
|
invoke-virtual {p1, v0}, Ljava/net/HttpURLConnection;->setConnectTimeout(I)V
|
|
|
|
const/16 v0, 0x4e20
|
|
|
|
.line 56
|
|
invoke-virtual {p1, v0}, Ljava/net/HttpURLConnection;->setReadTimeout(I)V
|
|
|
|
return-object p1
|
|
.end method
|