granularity level: instruction

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


.field private static final ALLOWABLE_SCOPES:[Ljava/lang/String;
.field private static final IID_SHARED_PREFS_NAME:Ljava/lang/String; = "com.google.android.gms.appid"
.field private static final JSON_ENCODED_PREFIX:Ljava/lang/String; = "{"
.field private static final JSON_TOKEN_KEY:Ljava/lang/String; = "token"
.field private static final STORE_KEY_ID:Ljava/lang/String; = "|S|id"
.field private static final STORE_KEY_PUB:Ljava/lang/String; = "|S||P|"
.field private static final STORE_KEY_SEPARATOR:Ljava/lang/String; = "|"
.field private static final STORE_KEY_TOKEN:Ljava/lang/String; = "|T|"
.field private final defaultSenderId:Ljava/lang/String;
.field private final iidPrefs:Landroid/content/SharedPreferences;


.method static constructor <clinit>()V
	.locals 4

	const-string v0, "*"
	const-string v1, "FCM"
	const-string v2, "GCM"
	const-string v3, ""
	filled-new-array {v0, v1, v2, v3}, [Ljava/lang/String;
	move-result-object v0
	sput-object v0, Lcom/google/firebase/installations/local/IidStore;->ALLOWABLE_SCOPES:[Ljava/lang/String;
	return-void
.end method

.method public constructor <init>(Landroid/content/SharedPreferences;Ljava/lang/String;)V
	.locals 0

	invoke-direct {p0}, Ljava/lang/Object;-><init>()V
	iput-object p1, p0, Lcom/google/firebase/installations/local/IidStore;->iidPrefs:Landroid/content/SharedPreferences;
	iput-object p2, p0, Lcom/google/firebase/installations/local/IidStore;->defaultSenderId:Ljava/lang/String;
	return-void
.end method

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

	invoke-direct {p0}, Ljava/lang/Object;-><init>()V
	invoke-virtual {p1}, Lcom/google/firebase/FirebaseApp;->getApplicationContext()Landroid/content/Context;
	move-result-object v0
	const-string v1, "com.google.android.gms.appid"
	const/4 v2, 0x0
	invoke-virtual {v0, v1, v2}, Landroid/content/Context;->getSharedPreferences(Ljava/lang/String;I)Landroid/content/SharedPreferences;
	move-result-object v0
	iput-object v0, p0, Lcom/google/firebase/installations/local/IidStore;->iidPrefs:Landroid/content/SharedPreferences;
	invoke-static {p1}, Lcom/google/firebase/installations/local/IidStore;->getDefaultSenderId(Lcom/google/firebase/FirebaseApp;)Ljava/lang/String;
	move-result-object p1
	iput-object p1, p0, Lcom/google/firebase/installations/local/IidStore;->defaultSenderId:Ljava/lang/String;
	return-void
.end method

.method private createTokenKey(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
	.locals 2

	new-instance v0, Ljava/lang/StringBuilder;
	invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V
	const-string v1, "|T|"
	invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
	invoke-virtual {v0, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
	const-string p1, "|"
	invoke-virtual {v0, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
	invoke-virtual {v0, p2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
	invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
	move-result-object p1
	return-object p1
.end method

.method private static getDefaultSenderId(Lcom/google/firebase/FirebaseApp;)Ljava/lang/String;
	.locals 3

	invoke-virtual {p0}, Lcom/google/firebase/FirebaseApp;->getOptions()Lcom/google/firebase/FirebaseOptions;
	move-result-object v0
	invoke-virtual {v0}, Lcom/google/firebase/FirebaseOptions;->getGcmSenderId()Ljava/lang/String;
	move-result-object v0
	if-eqz v0, :cond_0
	return-object v0
	:cond_0
	invoke-virtual {p0}, Lcom/google/firebase/FirebaseApp;->getOptions()Lcom/google/firebase/FirebaseOptions;
	move-result-object p0
	invoke-virtual {p0}, Lcom/google/firebase/FirebaseOptions;->getApplicationId()Ljava/lang/String;
	move-result-object p0
	const-string v0, "1:"
	invoke-virtual {p0, v0}, Ljava/lang/String;->startsWith(Ljava/lang/String;)Z
	move-result v0
	if-nez v0, :cond_1
	const-string v0, "2:"
	invoke-virtual {p0, v0}, Ljava/lang/String;->startsWith(Ljava/lang/String;)Z
	move-result v0
	if-nez v0, :cond_1
	return-object p0
	:cond_1
	const-string v0, ":"
	invoke-virtual {p0, v0}, Ljava/lang/String;->split(Ljava/lang/String;)[Ljava/lang/String;
	move-result-object p0
	array-length v0, p0
	const/4 v1, 0x4
	const/4 v2, 0x0
	if-eq v0, v1, :cond_2
	return-object v2
	:cond_2
	const/4 v0, 0x1
	aget-object p0, p0, v0
	invoke-virtual {p0}, Ljava/lang/String;->isEmpty()Z
	move-result v0
	if-eqz v0, :cond_3
	return-object v2
	:cond_3
	return-object p0
.end method

.method private static getIdFromPublicKey(Ljava/security/PublicKey;)Ljava/lang/String;
	.locals 3

	invoke-interface {p0}, Ljava/security/PublicKey;->getEncoded()[B
	move-result-object p0
	:try_start_0
	const-string v0, "SHA1"
	invoke-static {v0}, Ljava/security/MessageDigest;->getInstance(Ljava/lang/String;)Ljava/security/MessageDigest;
	move-result-object v0
	invoke-virtual {v0, p0}, Ljava/security/MessageDigest;->digest([B)[B
	move-result-object p0
	const/4 v0, 0x0
	aget-byte v1, p0, v0
	and-int/lit8 v1, v1, 0xf
	add-int/lit8 v1, v1, 0x70
	and-int/lit16 v1, v1, 0xff
	int-to-byte v1, v1
	aput-byte v1, p0, v0
	const/16 v1, 0x8
	const/16 v2, 0xb
	invoke-static {p0, v0, v1, v2}, Landroid/util/Base64;->encodeToString([BIII)Ljava/lang/String;
	move-result-object p0
	:try_end_0
	.catch Ljava/security/NoSuchAlgorithmException; {:try_start_0 .. :try_end_0} :catch_0
	return-object p0
	:catch_0
	const-string p0, "ContentValues"
	const-string v0, "Unexpected error, device missing required algorithms"
	invoke-static {p0, v0}, Landroid/util/Log;->w(Ljava/lang/String;Ljava/lang/String;)I
	const/4 p0, 0x0
	return-object p0
.end method

.method private parseIidTokenFromJson(Ljava/lang/String;)Ljava/lang/String;
	.locals 1

	:try_start_0
	new-instance v0, Lorg/json/JSONObject;
	invoke-direct {v0, p1}, Lorg/json/JSONObject;-><init>(Ljava/lang/String;)V
	const-string p1, "token"
	invoke-virtual {v0, p1}, Lorg/json/JSONObject;->getString(Ljava/lang/String;)Ljava/lang/String;
	move-result-object p1
	:try_end_0
	.catch Lorg/json/JSONException; {:try_start_0 .. :try_end_0} :catch_0
	return-object p1
	:catch_0
	const/4 p1, 0x0
	return-object p1
.end method

.method private parseKey(Ljava/lang/String;)Ljava/security/PublicKey;
	.locals 2

	const/16 v0, 0x8
	:try_start_0
	invoke-static {p1, v0}, Landroid/util/Base64;->decode(Ljava/lang/String;I)[B
	move-result-object p1
	const-string v0, "RSA"
	invoke-static {v0}, Ljava/security/KeyFactory;->getInstance(Ljava/lang/String;)Ljava/security/KeyFactory;
	move-result-object v0
	new-instance v1, Ljava/security/spec/X509EncodedKeySpec;
	invoke-direct {v1, p1}, Ljava/security/spec/X509EncodedKeySpec;-><init>([B)V
	invoke-virtual {v0, v1}, Ljava/security/KeyFactory;->generatePublic(Ljava/security/spec/KeySpec;)Ljava/security/PublicKey;
	move-result-object p1
	:try_end_0
	.catch Ljava/lang/IllegalArgumentException; {:try_start_0 .. :try_end_0} :catch_2
	.catch Ljava/security/spec/InvalidKeySpecException; {:try_start_0 .. :try_end_0} :catch_1
	.catch Ljava/security/NoSuchAlgorithmException; {:try_start_0 .. :try_end_0} :catch_0
	return-object p1
	:catch_0
	move-exception p1
	goto :goto_0
	:catch_1
	move-exception p1
	goto :goto_0
	:catch_2
	move-exception p1
	:goto_0
	new-instance v0, Ljava/lang/StringBuilder;
	invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V
	const-string v1, "Invalid key stored "
	invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
	invoke-virtual {v0, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;
	invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
	move-result-object p1
	const-string v0, "ContentValues"
	invoke-static {v0, p1}, Landroid/util/Log;->w(Ljava/lang/String;Ljava/lang/String;)I
	const/4 p1, 0x0
	return-object p1
.end method

.method private readInstanceIdFromLocalStorage()Ljava/lang/String;
	.locals 4

	iget-object v0, p0, Lcom/google/firebase/installations/local/IidStore;->iidPrefs:Landroid/content/SharedPreferences;
	monitor-enter v0
	:try_start_0
	iget-object v1, p0, Lcom/google/firebase/installations/local/IidStore;->iidPrefs:Landroid/content/SharedPreferences;
	const-string v2, "|S|id"
	const/4 v3, 0x0
	invoke-interface {v1, v2, v3}, Landroid/content/SharedPreferences;->getString(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
	move-result-object v1
	monitor-exit v0
	return-object v1
	:catchall_0
	move-exception v1
	monitor-exit v0
	:try_end_0
	.catchall {:try_start_0 .. :try_end_0} :catchall_0
	throw v1
.end method

.method private readPublicKeyFromLocalStorageAndCalculateInstanceId()Ljava/lang/String;
	.locals 4

	iget-object v0, p0, Lcom/google/firebase/installations/local/IidStore;->iidPrefs:Landroid/content/SharedPreferences;
	monitor-enter v0
	:try_start_0
	iget-object v1, p0, Lcom/google/firebase/installations/local/IidStore;->iidPrefs:Landroid/content/SharedPreferences;
	const-string v2, "|S||P|"
	const/4 v3, 0x0
	invoke-interface {v1, v2, v3}, Landroid/content/SharedPreferences;->getString(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
	move-result-object v1
	if-nez v1, :cond_0
	monitor-exit v0
	return-object v3
	:cond_0
	invoke-direct {p0, v1}, Lcom/google/firebase/installations/local/IidStore;->parseKey(Ljava/lang/String;)Ljava/security/PublicKey;
	move-result-object v1
	if-nez v1, :cond_1
	monitor-exit v0
	return-object v3
	:cond_1
	invoke-static {v1}, Lcom/google/firebase/installations/local/IidStore;->getIdFromPublicKey(Ljava/security/PublicKey;)Ljava/lang/String;
	move-result-object v1
	monitor-exit v0
	return-object v1
	:catchall_0
	move-exception v1
	monitor-exit v0
	:try_end_0
	.catchall {:try_start_0 .. :try_end_0} :catchall_0
	throw v1
.end method

.method public readIid()Ljava/lang/String;
	.locals 2

	iget-object v0, p0, Lcom/google/firebase/installations/local/IidStore;->iidPrefs:Landroid/content/SharedPreferences;
	monitor-enter v0
	:try_start_0
	invoke-direct {p0}, Lcom/google/firebase/installations/local/IidStore;->readInstanceIdFromLocalStorage()Ljava/lang/String;
	move-result-object v1
	if-eqz v1, :cond_0
	monitor-exit v0
	return-object v1
	:cond_0
	invoke-direct {p0}, Lcom/google/firebase/installations/local/IidStore;->readPublicKeyFromLocalStorageAndCalculateInstanceId()Ljava/lang/String;
	move-result-object v1
	monitor-exit v0
	return-object v1
	:catchall_0
	move-exception v1
	monitor-exit v0
	:try_end_0
	.catchall {:try_start_0 .. :try_end_0} :catchall_0
	throw v1
.end method

.method public readToken()Ljava/lang/String;
	.locals 7

	iget-object v0, p0, Lcom/google/firebase/installations/local/IidStore;->iidPrefs:Landroid/content/SharedPreferences;
	monitor-enter v0
	:try_start_0
	sget-object v1, Lcom/google/firebase/installations/local/IidStore;->ALLOWABLE_SCOPES:[Ljava/lang/String;
	array-length v2, v1
	const/4 v3, 0x0
	:goto_0
	const/4 v4, 0x0
	if-ge v3, v2, :cond_2
	aget-object v5, v1, v3
	iget-object v6, p0, Lcom/google/firebase/installations/local/IidStore;->defaultSenderId:Ljava/lang/String;
	invoke-direct {p0, v6, v5}, Lcom/google/firebase/installations/local/IidStore;->createTokenKey(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
	move-result-object v5
	iget-object v6, p0, Lcom/google/firebase/installations/local/IidStore;->iidPrefs:Landroid/content/SharedPreferences;
	invoke-interface {v6, v5, v4}, Landroid/content/SharedPreferences;->getString(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
	move-result-object v4
	if-eqz v4, :cond_1
	invoke-virtual {v4}, Ljava/lang/String;->isEmpty()Z
	move-result v5
	if-nez v5, :cond_1
	const-string v1, "{"
	invoke-virtual {v4, v1}, Ljava/lang/String;->startsWith(Ljava/lang/String;)Z
	move-result v1
	if-eqz v1, :cond_0
	invoke-direct {p0, v4}, Lcom/google/firebase/installations/local/IidStore;->parseIidTokenFromJson(Ljava/lang/String;)Ljava/lang/String;
	move-result-object v4
	:cond_0
	monitor-exit v0
	return-object v4
	:cond_1
	add-int/lit8 v3, v3, 0x1
	goto :goto_0
	:cond_2
	monitor-exit v0
	return-object v4
	:catchall_0
	move-exception v1
	monitor-exit v0
	:try_end_0
	.catchall {:try_start_0 .. :try_end_0} :catchall_0
	throw v1
.end method