mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-18 20:07:19 +01:00
128 lines
4.5 KiB
Java
128 lines
4.5 KiB
Java
package com.google.firebase.messaging;
|
|
|
|
import android.content.Context;
|
|
import android.content.SharedPreferences;
|
|
import android.text.TextUtils;
|
|
import android.util.Log;
|
|
import androidx.core.content.ContextCompat;
|
|
import androidx.room.util.TableInfo$$ExternalSyntheticOutline0;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes8.dex */
|
|
class Store {
|
|
static final String NO_BACKUP_FILE = "com.google.android.gms.appid-no-backup";
|
|
static final String PREFERENCES = "com.google.android.gms.appid";
|
|
private static final String SCOPE_ALL = "*";
|
|
private static final String STORE_KEY_TOKEN = "|T|";
|
|
final SharedPreferences store;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public static class Token {
|
|
private static final String KEY_APP_VERSION = "appVersion";
|
|
private static final String KEY_TIMESTAMP = "timestamp";
|
|
private static final String KEY_TOKEN = "token";
|
|
private static final long REFRESH_PERIOD_MILLIS = 604800000;
|
|
final String appVersion;
|
|
final long timestamp;
|
|
final String token;
|
|
|
|
private Token(String str, String str2, long j) {
|
|
this.token = str;
|
|
this.appVersion = str2;
|
|
this.timestamp = j;
|
|
}
|
|
|
|
public static String encode(String str, String str2, long j) {
|
|
try {
|
|
JSONObject jSONObject = new JSONObject();
|
|
jSONObject.put("token", str);
|
|
jSONObject.put(KEY_APP_VERSION, str2);
|
|
jSONObject.put("timestamp", j);
|
|
return jSONObject.toString();
|
|
} catch (JSONException e) {
|
|
Log.w(Constants.TAG, "Failed to encode token: " + e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static Token parse(String str) {
|
|
if (TextUtils.isEmpty(str)) {
|
|
return null;
|
|
}
|
|
if (!str.startsWith("{")) {
|
|
return new Token(str, null, 0L);
|
|
}
|
|
try {
|
|
JSONObject jSONObject = new JSONObject(str);
|
|
return new Token(jSONObject.getString("token"), jSONObject.getString(KEY_APP_VERSION), jSONObject.getLong("timestamp"));
|
|
} catch (JSONException e) {
|
|
Log.w(Constants.TAG, "Failed to parse token: " + e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public boolean needsRefresh(String str) {
|
|
return System.currentTimeMillis() > this.timestamp + REFRESH_PERIOD_MILLIS || !str.equals(this.appVersion);
|
|
}
|
|
}
|
|
|
|
public Store(Context context) {
|
|
this.store = context.getSharedPreferences(PREFERENCES, 0);
|
|
checkForRestore(context, NO_BACKUP_FILE);
|
|
}
|
|
|
|
private void checkForRestore(Context context, String str) {
|
|
File file = new File(ContextCompat.getNoBackupFilesDir(context), str);
|
|
if (file.exists()) {
|
|
return;
|
|
}
|
|
try {
|
|
if (!file.createNewFile() || isEmpty()) {
|
|
return;
|
|
}
|
|
Log.i(Constants.TAG, "App restored, clearing state");
|
|
deleteAll();
|
|
} catch (IOException e) {
|
|
if (Log.isLoggable(Constants.TAG, 3)) {
|
|
e.getMessage();
|
|
}
|
|
}
|
|
}
|
|
|
|
private String createTokenKey(String str, String str2) {
|
|
return TableInfo$$ExternalSyntheticOutline0.m$1(str, STORE_KEY_TOKEN, str2, "|*");
|
|
}
|
|
|
|
public synchronized void deleteAll() {
|
|
this.store.edit().clear().commit();
|
|
}
|
|
|
|
public synchronized void deleteToken(String str, String str2) {
|
|
String createTokenKey = createTokenKey(str, str2);
|
|
SharedPreferences.Editor edit = this.store.edit();
|
|
edit.remove(createTokenKey);
|
|
edit.commit();
|
|
}
|
|
|
|
public synchronized Token getToken(String str, String str2) {
|
|
return Token.parse(this.store.getString(createTokenKey(str, str2), null));
|
|
}
|
|
|
|
public synchronized boolean isEmpty() {
|
|
return this.store.getAll().isEmpty();
|
|
}
|
|
|
|
public synchronized void saveToken(String str, String str2, String str3, String str4) {
|
|
String encode = Token.encode(str3, str4, System.currentTimeMillis());
|
|
if (encode == null) {
|
|
return;
|
|
}
|
|
SharedPreferences.Editor edit = this.store.edit();
|
|
edit.putString(createTokenKey(str, str2), encode);
|
|
edit.commit();
|
|
}
|
|
}
|