granularity level: instruction

		.class public Lcom/google/firebase/installations/local/PersistedInstallation;
.super Ljava/lang/Object;
.source "PersistedInstallation.java"

.annotation system Ldalvik/annotation/MemberClasses;
value = {
Lcom/google/firebase/installations/local/PersistedInstallation$RegistrationStatus;
}
.end annotation

.field private static final AUTH_TOKEN_KEY:Ljava/lang/String; = "AuthToken"
.field private static final EXPIRES_IN_SECONDS_KEY:Ljava/lang/String; = "ExpiresInSecs"
.field private static final FIREBASE_INSTALLATION_ID_KEY:Ljava/lang/String; = "Fid"
.field private static final FIS_ERROR_KEY:Ljava/lang/String; = "FisError"
.field private static final PERSISTED_STATUS_KEY:Ljava/lang/String; = "Status"
.field private static final REFRESH_TOKEN_KEY:Ljava/lang/String; = "RefreshToken"
.field private static final SETTINGS_FILE_NAME_PREFIX:Ljava/lang/String; = "PersistedInstallation"
.field private static final TOKEN_CREATION_TIME_IN_SECONDS_KEY:Ljava/lang/String; = "TokenCreationEpochInSecs"
.field private dataFile:Ljava/io/File;
.field private final firebaseApp:Lcom/google/firebase/FirebaseApp;


.method public constructor <init>(Lcom/google/firebase/FirebaseApp;)V
	.locals 0

	invoke-direct {p0}, Ljava/lang/Object;-><init>()V
	iput-object p1, p0, Lcom/google/firebase/installations/local/PersistedInstallation;->firebaseApp:Lcom/google/firebase/FirebaseApp;
	return-void
.end method

.method private getDataFile()Ljava/io/File;
	.locals 4

	iget-object v0, p0, Lcom/google/firebase/installations/local/PersistedInstallation;->dataFile:Ljava/io/File;
	if-nez v0, :cond_1
	monitor-enter p0
	:try_start_0
	iget-object v0, p0, Lcom/google/firebase/installations/local/PersistedInstallation;->dataFile:Ljava/io/File;
	if-nez v0, :cond_0
	new-instance v0, Ljava/io/File;
	iget-object v1, p0, Lcom/google/firebase/installations/local/PersistedInstallation;->firebaseApp:Lcom/google/firebase/FirebaseApp;
	invoke-virtual {v1}, Lcom/google/firebase/FirebaseApp;->getApplicationContext()Landroid/content/Context;
	move-result-object v1
	invoke-virtual {v1}, Landroid/content/Context;->getFilesDir()Ljava/io/File;
	move-result-object v1
	new-instance v2, Ljava/lang/StringBuilder;
	invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V
	const-string v3, "PersistedInstallation."
	invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
	iget-object v3, p0, Lcom/google/firebase/installations/local/PersistedInstallation;->firebaseApp:Lcom/google/firebase/FirebaseApp;
	invoke-virtual {v3}, Lcom/google/firebase/FirebaseApp;->getPersistenceKey()Ljava/lang/String;
	move-result-object v3
	invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
	const-string v3, ".json"
	invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
	invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
	move-result-object v2
	invoke-direct {v0, v1, v2}, Ljava/io/File;-><init>(Ljava/io/File;Ljava/lang/String;)V
	iput-object v0, p0, Lcom/google/firebase/installations/local/PersistedInstallation;->dataFile:Ljava/io/File;
	:cond_0
	monitor-exit p0
	goto :goto_0
	:catchall_0
	move-exception v0
	monitor-exit p0
	:try_end_0
	.catchall {:try_start_0 .. :try_end_0} :catchall_0
	throw v0
	:goto_0
	:cond_1
	iget-object v0, p0, Lcom/google/firebase/installations/local/PersistedInstallation;->dataFile:Ljava/io/File;
	return-object v0
.end method

.method private readJSONFromFile()Lorg/json/JSONObject;
	.locals 6

	new-instance v0, Ljava/io/ByteArrayOutputStream;
	invoke-direct {v0}, Ljava/io/ByteArrayOutputStream;-><init>()V
	const/16 v1, 0x4000
	new-array v2, v1, [B
	:try_start_0
	new-instance v3, Ljava/io/FileInputStream;
	invoke-direct {p0}, Lcom/google/firebase/installations/local/PersistedInstallation;->getDataFile()Ljava/io/File;
	move-result-object v4
	invoke-direct {v3, v4}, Ljava/io/FileInputStream;-><init>(Ljava/io/File;)V
	:try_end_0
	.catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0
	.catch Lorg/json/JSONException; {:try_start_0 .. :try_end_0} :catch_0
	:goto_0
	const/4 v4, 0x0
	:try_start_1
	invoke-virtual {v3, v2, v4, v1}, Ljava/io/FileInputStream;->read([BII)I
	move-result v5
	if-gez v5, :cond_0
	new-instance v1, Lorg/json/JSONObject;
	invoke-virtual {v0}, Ljava/io/ByteArrayOutputStream;->toString()Ljava/lang/String;
	move-result-object v0
	invoke-direct {v1, v0}, Lorg/json/JSONObject;-><init>(Ljava/lang/String;)V
	:try_end_1
	.catchall {:try_start_1 .. :try_end_1} :catchall_0
	:try_start_2
	invoke-virtual {v3}, Ljava/io/FileInputStream;->close()V
	:try_end_2
	.catch Ljava/io/IOException; {:try_start_2 .. :try_end_2} :catch_0
	.catch Lorg/json/JSONException; {:try_start_2 .. :try_end_2} :catch_0
	return-object v1
	:try_start_3
	:cond_0
	invoke-virtual {v0, v2, v4, v5}, Ljava/io/ByteArrayOutputStream;->write([BII)V
	:try_end_3
	.catchall {:try_start_3 .. :try_end_3} :catchall_0
	goto :goto_0
	:catchall_0
	move-exception v0
	:try_start_4
	invoke-virtual {v3}, Ljava/io/FileInputStream;->close()V
	:try_end_4
	.catchall {:try_start_4 .. :try_end_4} :catchall_1
	goto :goto_1
	:catchall_1
	move-exception v1
	:try_start_5
	invoke-virtual {v0, v1}, Ljava/lang/Throwable;->addSuppressed(Ljava/lang/Throwable;)V
	:goto_1
	throw v0
	:try_end_5
	.catch Ljava/io/IOException; {:try_start_5 .. :try_end_5} :catch_0
	.catch Lorg/json/JSONException; {:try_start_5 .. :try_end_5} :catch_0
	:catch_0
	new-instance v0, Lorg/json/JSONObject;
	invoke-direct {v0}, Lorg/json/JSONObject;-><init>()V
	return-object v0
.end method

.method public clearForTesting()V
	.locals 1

	invoke-direct {p0}, Lcom/google/firebase/installations/local/PersistedInstallation;->getDataFile()Ljava/io/File;
	move-result-object v0
	invoke-virtual {v0}, Ljava/io/File;->delete()Z
	return-void
.end method

.method public insertOrUpdatePersistedInstallationEntry(Lcom/google/firebase/installations/local/PersistedInstallationEntry;)Lcom/google/firebase/installations/local/PersistedInstallationEntry;
	.locals 4

	:try_start_0
	new-instance v0, Lorg/json/JSONObject;
	invoke-direct {v0}, Lorg/json/JSONObject;-><init>()V
	const-string v1, "Fid"
	invoke-virtual {p1}, Lcom/google/firebase/installations/local/PersistedInstallationEntry;->getFirebaseInstallationId()Ljava/lang/String;
	move-result-object v2
	invoke-virtual {v0, v1, v2}, Lorg/json/JSONObject;->put(Ljava/lang/String;Ljava/lang/Object;)Lorg/json/JSONObject;
	const-string v1, "Status"
	invoke-virtual {p1}, Lcom/google/firebase/installations/local/PersistedInstallationEntry;->getRegistrationStatus()Lcom/google/firebase/installations/local/PersistedInstallation$RegistrationStatus;
	move-result-object v2
	invoke-virtual {v2}, Lcom/google/firebase/installations/local/PersistedInstallation$RegistrationStatus;->ordinal()I
	move-result v2
	invoke-virtual {v0, v1, v2}, Lorg/json/JSONObject;->put(Ljava/lang/String;I)Lorg/json/JSONObject;
	const-string v1, "AuthToken"
	invoke-virtual {p1}, Lcom/google/firebase/installations/local/PersistedInstallationEntry;->getAuthToken()Ljava/lang/String;
	move-result-object v2
	invoke-virtual {v0, v1, v2}, Lorg/json/JSONObject;->put(Ljava/lang/String;Ljava/lang/Object;)Lorg/json/JSONObject;
	const-string v1, "RefreshToken"
	invoke-virtual {p1}, Lcom/google/firebase/installations/local/PersistedInstallationEntry;->getRefreshToken()Ljava/lang/String;
	move-result-object v2
	invoke-virtual {v0, v1, v2}, Lorg/json/JSONObject;->put(Ljava/lang/String;Ljava/lang/Object;)Lorg/json/JSONObject;
	const-string v1, "TokenCreationEpochInSecs"
	invoke-virtual {p1}, Lcom/google/firebase/installations/local/PersistedInstallationEntry;->getTokenCreationEpochInSecs()J
	move-result-wide v2
	invoke-virtual {v0, v1, v2, v3}, Lorg/json/JSONObject;->put(Ljava/lang/String;J)Lorg/json/JSONObject;
	const-string v1, "ExpiresInSecs"
	invoke-virtual {p1}, Lcom/google/firebase/installations/local/PersistedInstallationEntry;->getExpiresInSecs()J
	move-result-wide v2
	invoke-virtual {v0, v1, v2, v3}, Lorg/json/JSONObject;->put(Ljava/lang/String;J)Lorg/json/JSONObject;
	const-string v1, "FisError"
	invoke-virtual {p1}, Lcom/google/firebase/installations/local/PersistedInstallationEntry;->getFisError()Ljava/lang/String;
	move-result-object v2
	invoke-virtual {v0, v1, v2}, Lorg/json/JSONObject;->put(Ljava/lang/String;Ljava/lang/Object;)Lorg/json/JSONObject;
	const-string v1, "PersistedInstallation"
	const-string v2, "tmp"
	iget-object v3, p0, Lcom/google/firebase/installations/local/PersistedInstallation;->firebaseApp:Lcom/google/firebase/FirebaseApp;
	invoke-virtual {v3}, Lcom/google/firebase/FirebaseApp;->getApplicationContext()Landroid/content/Context;
	move-result-object v3
	invoke-virtual {v3}, Landroid/content/Context;->getFilesDir()Ljava/io/File;
	move-result-object v3
	invoke-static {v1, v2, v3}, Ljava/io/File;->createTempFile(Ljava/lang/String;Ljava/lang/String;Ljava/io/File;)Ljava/io/File;
	move-result-object v1
	new-instance v2, Ljava/io/FileOutputStream;
	invoke-direct {v2, v1}, Ljava/io/FileOutputStream;-><init>(Ljava/io/File;)V
	invoke-virtual {v0}, Lorg/json/JSONObject;->toString()Ljava/lang/String;
	move-result-object v0
	const-string v3, "UTF-8"
	invoke-virtual {v0, v3}, Ljava/lang/String;->getBytes(Ljava/lang/String;)[B
	move-result-object v0
	invoke-virtual {v2, v0}, Ljava/io/FileOutputStream;->write([B)V
	invoke-virtual {v2}, Ljava/io/FileOutputStream;->close()V
	invoke-direct {p0}, Lcom/google/firebase/installations/local/PersistedInstallation;->getDataFile()Ljava/io/File;
	move-result-object v0
	invoke-virtual {v1, v0}, Ljava/io/File;->renameTo(Ljava/io/File;)Z
	move-result v0
	if-eqz v0, :cond_0
	goto :goto_0
	:cond_0
	new-instance v0, Ljava/io/IOException;
	const-string v1, "unable to rename the tmpfile to PersistedInstallation"
	invoke-direct {v0, v1}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V
	throw v0
	:try_end_0
	.catch Lorg/json/JSONException; {:try_start_0 .. :try_end_0} :catch_0
	.catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0
	:goto_0
	:catch_0
	return-object p1
.end method

.method public readPersistedInstallationEntryValue()Lcom/google/firebase/installations/local/PersistedInstallationEntry;
	.locals 11

	invoke-direct {p0}, Lcom/google/firebase/installations/local/PersistedInstallation;->readJSONFromFile()Lorg/json/JSONObject;
	move-result-object v0
	const-string v1, "Fid"
	const/4 v2, 0x0
	invoke-virtual {v0, v1, v2}, Lorg/json/JSONObject;->optString(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
	move-result-object v1
	sget-object v3, Lcom/google/firebase/installations/local/PersistedInstallation$RegistrationStatus;->ATTEMPT_MIGRATION:Lcom/google/firebase/installations/local/PersistedInstallation$RegistrationStatus;
	invoke-virtual {v3}, Lcom/google/firebase/installations/local/PersistedInstallation$RegistrationStatus;->ordinal()I
	move-result v3
	const-string v4, "Status"
	invoke-virtual {v0, v4, v3}, Lorg/json/JSONObject;->optInt(Ljava/lang/String;I)I
	move-result v3
	const-string v4, "AuthToken"
	invoke-virtual {v0, v4, v2}, Lorg/json/JSONObject;->optString(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
	move-result-object v4
	const-string v5, "RefreshToken"
	invoke-virtual {v0, v5, v2}, Lorg/json/JSONObject;->optString(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
	move-result-object v5
	const-string v6, "TokenCreationEpochInSecs"
	const-wide/16 v7, 0x0
	invoke-virtual {v0, v6, v7, v8}, Lorg/json/JSONObject;->optLong(Ljava/lang/String;J)J
	move-result-wide v9
	const-string v6, "ExpiresInSecs"
	invoke-virtual {v0, v6, v7, v8}, Lorg/json/JSONObject;->optLong(Ljava/lang/String;J)J
	move-result-wide v6
	const-string v8, "FisError"
	invoke-virtual {v0, v8, v2}, Lorg/json/JSONObject;->optString(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
	move-result-object v0
	invoke-static {}, Lcom/google/firebase/installations/local/PersistedInstallationEntry;->builder()Lcom/google/firebase/installations/local/PersistedInstallationEntry$Builder;
	move-result-object v2
	invoke-virtual {v2, v1}, Lcom/google/firebase/installations/local/PersistedInstallationEntry$Builder;->setFirebaseInstallationId(Ljava/lang/String;)Lcom/google/firebase/installations/local/PersistedInstallationEntry$Builder;
	move-result-object v1
	invoke-static {}, Lcom/google/firebase/installations/local/PersistedInstallation$RegistrationStatus;->values()[Lcom/google/firebase/installations/local/PersistedInstallation$RegistrationStatus;
	move-result-object v2
	aget-object v2, v2, v3
	invoke-virtual {v1, v2}, Lcom/google/firebase/installations/local/PersistedInstallationEntry$Builder;->setRegistrationStatus(Lcom/google/firebase/installations/local/PersistedInstallation$RegistrationStatus;)Lcom/google/firebase/installations/local/PersistedInstallationEntry$Builder;
	move-result-object v1
	invoke-virtual {v1, v4}, Lcom/google/firebase/installations/local/PersistedInstallationEntry$Builder;->setAuthToken(Ljava/lang/String;)Lcom/google/firebase/installations/local/PersistedInstallationEntry$Builder;
	move-result-object v1
	invoke-virtual {v1, v5}, Lcom/google/firebase/installations/local/PersistedInstallationEntry$Builder;->setRefreshToken(Ljava/lang/String;)Lcom/google/firebase/installations/local/PersistedInstallationEntry$Builder;
	move-result-object v1
	invoke-virtual {v1, v9, v10}, Lcom/google/firebase/installations/local/PersistedInstallationEntry$Builder;->setTokenCreationEpochInSecs(J)Lcom/google/firebase/installations/local/PersistedInstallationEntry$Builder;
	move-result-object v1
	invoke-virtual {v1, v6, v7}, Lcom/google/firebase/installations/local/PersistedInstallationEntry$Builder;->setExpiresInSecs(J)Lcom/google/firebase/installations/local/PersistedInstallationEntry$Builder;
	move-result-object v1
	invoke-virtual {v1, v0}, Lcom/google/firebase/installations/local/PersistedInstallationEntry$Builder;->setFisError(Ljava/lang/String;)Lcom/google/firebase/installations/local/PersistedInstallationEntry$Builder;
	move-result-object v0
	invoke-virtual {v0}, Lcom/google/firebase/installations/local/PersistedInstallationEntry$Builder;->build()Lcom/google/firebase/installations/local/PersistedInstallationEntry;
	move-result-object v0
	return-object v0
.end method