2021-12-17 21:59:34 +00:00
package b.i.c.s ;
2021-08-03 07:33:18 +00:00
import android.content.Context ;
import android.content.SharedPreferences ;
import android.text.TextUtils ;
import android.util.Log ;
import androidx.annotation.GuardedBy ;
import androidx.collection.ArrayMap ;
import androidx.core.content.ContextCompat ;
2021-12-17 21:59:34 +00:00
import b.i.c.c ;
2021-08-03 07:33:18 +00:00
import com.google.firebase.iid.FirebaseInstanceId ;
import java.io.File ;
import java.io.IOException ;
import java.util.Map ;
import java.util.concurrent.TimeUnit ;
import org.json.JSONException ;
import org.json.JSONObject ;
/* compiled from: com.google.firebase:firebase-iid@@21.0.0 */
public class w {
public final SharedPreferences a ;
2021-12-17 21:59:34 +00:00
/* renamed from: b reason: collision with root package name */
public final Context f1760b ;
@GuardedBy ( " this " )
public final Map < String , Long > c = new ArrayMap ( ) ;
2021-08-03 07:33:18 +00:00
/* compiled from: com.google.firebase:firebase-iid@@21.0.0 */
public static class a {
public static final long a = TimeUnit . DAYS . toMillis ( 7 ) ;
2021-12-17 21:59:34 +00:00
/* renamed from: b reason: collision with root package name */
public static final /* synthetic */ int f1761b = 0 ;
public final String c ;
2021-08-03 07:33:18 +00:00
public final String d ;
public final long e ;
public a ( String str , String str2 , long j ) {
2021-12-17 21:59:34 +00:00
this . c = str ;
2021-08-03 07:33:18 +00:00
this . d = str2 ;
this . e = j ;
}
public static String a ( String str , String str2 , long j ) {
try {
JSONObject jSONObject = new JSONObject ( ) ;
jSONObject . put ( " token " , str ) ;
jSONObject . put ( " appVersion " , str2 ) ;
jSONObject . put ( " timestamp " , j ) ;
return jSONObject . toString ( ) ;
} catch ( JSONException e ) {
String valueOf = String . valueOf ( e ) ;
2021-12-17 21:59:34 +00:00
b . d . b . a . a . f0 ( valueOf . length ( ) + 24 , " Failed to encode token: " , valueOf , " FirebaseInstanceId " ) ;
2021-08-03 07:33:18 +00:00
return null ;
}
}
public static a b ( String str ) {
if ( TextUtils . isEmpty ( str ) ) {
return null ;
}
if ( ! str . startsWith ( " { " ) ) {
return new a ( str , null , 0 ) ;
}
try {
JSONObject jSONObject = new JSONObject ( str ) ;
return new a ( jSONObject . getString ( " token " ) , jSONObject . getString ( " appVersion " ) , jSONObject . getLong ( " timestamp " ) ) ;
} catch ( JSONException e ) {
String valueOf = String . valueOf ( e ) ;
2021-12-17 21:59:34 +00:00
b . d . b . a . a . f0 ( valueOf . length ( ) + 23 , " Failed to parse token: " , valueOf , " FirebaseInstanceId " ) ;
2021-08-03 07:33:18 +00:00
return null ;
}
}
}
public w ( Context context ) {
boolean isEmpty ;
2021-12-17 21:59:34 +00:00
this . f1760b = context ;
2021-08-03 07:33:18 +00:00
SharedPreferences sharedPreferences = context . getSharedPreferences ( " com.google.android.gms.appid " , 0 ) ;
this . a = sharedPreferences ;
File file = new File ( ContextCompat . getNoBackupFilesDir ( context ) , " com.google.android.gms.appid-no-backup " ) ;
if ( ! file . exists ( ) ) {
try {
if ( file . createNewFile ( ) ) {
synchronized ( this ) {
isEmpty = sharedPreferences . getAll ( ) . isEmpty ( ) ;
}
if ( ! isEmpty ) {
Log . i ( " FirebaseInstanceId " , " App restored, clearing state " ) ;
c ( ) ;
2021-12-18 07:39:31 +00:00
w wVar = FirebaseInstanceId . f3070b ;
2021-08-03 07:33:18 +00:00
synchronized ( FirebaseInstanceId . getInstance ( c . b ( ) ) ) {
2021-12-18 07:39:31 +00:00
FirebaseInstanceId . f3070b . c ( ) ;
2021-08-03 07:33:18 +00:00
}
}
}
} catch ( IOException e ) {
if ( Log . isLoggable ( " FirebaseInstanceId " , 3 ) ) {
String valueOf = String . valueOf ( e . getMessage ( ) ) ;
Log . d ( " FirebaseInstanceId " , valueOf . length ( ) ! = 0 ? " Error creating file in no backup dir: " . concat ( valueOf ) : new String ( " Error creating file in no backup dir: " ) ) ;
}
}
}
}
public static String a ( String str , String str2 ) {
2021-12-17 21:59:34 +00:00
return b . d . b . a . a . j ( str2 . length ( ) + b . d . b . a . a . b ( str , 3 ) , str , " |S| " , str2 ) ;
2021-08-03 07:33:18 +00:00
}
public final String b ( String str , String str2 , String str3 ) {
2021-12-17 21:59:34 +00:00
StringBuilder Q = b . d . b . a . a . Q ( b . d . b . a . a . b ( str3 , b . d . b . a . a . b ( str2 , b . d . b . a . a . b ( str , 4 ) ) ) , str , " |T| " , str2 , " | " ) ;
2021-11-05 06:48:17 +00:00
Q . append ( str3 ) ;
return Q . toString ( ) ;
2021-08-03 07:33:18 +00:00
}
public synchronized void c ( ) {
2021-12-17 21:59:34 +00:00
this . c . clear ( ) ;
2021-08-03 07:33:18 +00:00
this . a . edit ( ) . clear ( ) . commit ( ) ;
}
public final long d ( String str ) {
long currentTimeMillis = System . currentTimeMillis ( ) ;
if ( ! this . a . contains ( a ( str , " cre " ) ) ) {
SharedPreferences . Editor edit = this . a . edit ( ) ;
edit . putString ( a ( str , " cre " ) , String . valueOf ( currentTimeMillis ) ) ;
edit . commit ( ) ;
return currentTimeMillis ;
}
String string = this . a . getString ( a ( str , " cre " ) , null ) ;
if ( string ! = null ) {
try {
return Long . parseLong ( string ) ;
} catch ( NumberFormatException unused ) {
}
}
return 0 ;
}
}