alexandroid/decompiled/jadx/sources/com/google/firebase/messaging/SharedPreferencesQueue.java
KaKi87 a47fad5135 📦 Add decompiled Alexa 2.2.730155.0 (jadx, apktool, Hermes strings)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 00:04:16 +01:00

199 lines
5.9 KiB
Java

package com.google.firebase.messaging;
import android.content.SharedPreferences;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.GuardedBy;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.annotation.WorkerThread;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Executor;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
/* loaded from: classes8.dex */
final class SharedPreferencesQueue {
private final String itemSeparator;
private final String queueName;
private final SharedPreferences sharedPreferences;
private final Executor syncExecutor;
@GuardedBy("internalQueue")
@VisibleForTesting
final ArrayDeque<String> internalQueue = new ArrayDeque<>();
@GuardedBy("internalQueue")
private boolean bulkOperation = false;
private SharedPreferencesQueue(SharedPreferences sharedPreferences, String str, String str2, Executor executor) {
this.sharedPreferences = sharedPreferences;
this.queueName = str;
this.itemSeparator = str2;
this.syncExecutor = executor;
}
@GuardedBy("internalQueue")
private boolean checkAndSyncState(boolean z) {
if (z && !this.bulkOperation) {
syncStateAsync();
}
return z;
}
@WorkerThread
public static SharedPreferencesQueue createInstance(SharedPreferences sharedPreferences, String str, String str2, Executor executor) {
SharedPreferencesQueue sharedPreferencesQueue = new SharedPreferencesQueue(sharedPreferences, str, str2, executor);
sharedPreferencesQueue.initQueue();
return sharedPreferencesQueue;
}
@WorkerThread
private void initQueue() {
synchronized (this.internalQueue) {
try {
this.internalQueue.clear();
String string = this.sharedPreferences.getString(this.queueName, "");
if (!TextUtils.isEmpty(string) && string.contains(this.itemSeparator)) {
String[] split = string.split(this.itemSeparator, -1);
if (split.length == 0) {
Log.e(Constants.TAG, "Corrupted queue. Please check the queue contents and item separator provided");
}
for (String str : split) {
if (!TextUtils.isEmpty(str)) {
this.internalQueue.add(str);
}
}
}
} finally {
}
}
}
/* JADX INFO: Access modifiers changed from: private */
@WorkerThread
public void syncState() {
synchronized (this.internalQueue) {
this.sharedPreferences.edit().putString(this.queueName, serialize()).commit();
}
}
private void syncStateAsync() {
this.syncExecutor.execute(new SharedPreferencesQueue$$ExternalSyntheticLambda0(this, 0));
}
public boolean add(@NonNull String str) {
boolean checkAndSyncState;
if (TextUtils.isEmpty(str) || str.contains(this.itemSeparator)) {
return false;
}
synchronized (this.internalQueue) {
checkAndSyncState = checkAndSyncState(this.internalQueue.add(str));
}
return checkAndSyncState;
}
@GuardedBy("internalQueue")
public void beginTransaction() {
this.bulkOperation = true;
}
@VisibleForTesting
public void beginTransactionSync() {
synchronized (this.internalQueue) {
beginTransaction();
}
}
public void clear() {
synchronized (this.internalQueue) {
this.internalQueue.clear();
checkAndSyncState(true);
}
}
@GuardedBy("internalQueue")
public void commitTransaction() {
this.bulkOperation = false;
syncStateAsync();
}
@VisibleForTesting
public void commitTransactionSync() {
synchronized (this.internalQueue) {
commitTransaction();
}
}
@Nullable
public String peek() {
String peek;
synchronized (this.internalQueue) {
peek = this.internalQueue.peek();
}
return peek;
}
public String remove() {
String checkAndSyncState;
synchronized (this.internalQueue) {
checkAndSyncState = checkAndSyncState(this.internalQueue.remove());
}
return checkAndSyncState;
}
@NonNull
@GuardedBy("internalQueue")
public String serialize() {
StringBuilder sb = new StringBuilder();
Iterator<String> it2 = this.internalQueue.iterator();
while (it2.hasNext()) {
sb.append(it2.next());
sb.append(this.itemSeparator);
}
return sb.toString();
}
@VisibleForTesting
public String serializeSync() {
String serialize;
synchronized (this.internalQueue) {
serialize = serialize();
}
return serialize;
}
public int size() {
int size;
synchronized (this.internalQueue) {
size = this.internalQueue.size();
}
return size;
}
@NonNull
public List<String> toList() {
ArrayList arrayList;
synchronized (this.internalQueue) {
arrayList = new ArrayList(this.internalQueue);
}
return arrayList;
}
@GuardedBy("internalQueue")
private String checkAndSyncState(String str) {
checkAndSyncState(str != null);
return str;
}
public boolean remove(@Nullable Object obj) {
boolean checkAndSyncState;
synchronized (this.internalQueue) {
checkAndSyncState = checkAndSyncState(this.internalQueue.remove(obj));
}
return checkAndSyncState;
}
}