58 lines
2.0 KiB
Java
58 lines
2.0 KiB
Java
|
package com.google.firebase.installations;
|
||
|
|
||
|
import android.text.TextUtils;
|
||
|
import com.google.firebase.installations.local.PersistedInstallationEntry;
|
||
|
import com.google.firebase.installations.time.Clock;
|
||
|
import com.google.firebase.installations.time.SystemClock;
|
||
|
import java.util.concurrent.TimeUnit;
|
||
|
import java.util.regex.Pattern;
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
public final class Utils {
|
||
|
private static Utils singleton;
|
||
|
private final Clock clock;
|
||
|
public static final long AUTH_TOKEN_EXPIRATION_BUFFER_IN_SECS = TimeUnit.HOURS.toSeconds(1);
|
||
|
private static final Pattern API_KEY_FORMAT = Pattern.compile("\\AA[\\w-]{38}\\z");
|
||
|
|
||
|
private Utils(Clock clock) {
|
||
|
this.clock = clock;
|
||
|
}
|
||
|
|
||
|
public static Utils getInstance() {
|
||
|
return getInstance(SystemClock.getInstance());
|
||
|
}
|
||
|
|
||
|
public static Utils getInstance(Clock clock) {
|
||
|
if (singleton == null) {
|
||
|
singleton = new Utils(clock);
|
||
|
}
|
||
|
return singleton;
|
||
|
}
|
||
|
|
||
|
public final boolean isAuthTokenExpired(PersistedInstallationEntry persistedInstallationEntry) {
|
||
|
return TextUtils.isEmpty(persistedInstallationEntry.getAuthToken()) || persistedInstallationEntry.getTokenCreationEpochInSecs() + persistedInstallationEntry.getExpiresInSecs() < currentTimeInSecs() + AUTH_TOKEN_EXPIRATION_BUFFER_IN_SECS;
|
||
|
}
|
||
|
|
||
|
public final long currentTimeInSecs() {
|
||
|
return TimeUnit.MILLISECONDS.toSeconds(currentTimeInMillis());
|
||
|
}
|
||
|
|
||
|
public final long currentTimeInMillis() {
|
||
|
return this.clock.currentTimeMillis();
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public static boolean isValidAppIdFormat(String str) {
|
||
|
return str.contains(":");
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public static boolean isValidApiKeyFormat(String str) {
|
||
|
return API_KEY_FORMAT.matcher(str).matches();
|
||
|
}
|
||
|
|
||
|
public final long getRandomDelayForSyncPrevention() {
|
||
|
return (long) (Math.random() * 1000.0d);
|
||
|
}
|
||
|
}
|