alexandroid/decompiled/jadx/sources/com/facebook/datasource/IncreasingQualityDataSourceSupplier.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

320 lines
13 KiB
Java

package com.facebook.datasource;
import com.facebook.common.executors.CallerThreadExecutor;
import com.facebook.common.internal.Objects;
import com.facebook.common.internal.Preconditions;
import com.facebook.common.internal.Supplier;
import com.facebook.infer.annotation.Nullsafe;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
@ThreadSafe
@Nullsafe(Nullsafe.Mode.LOCAL)
/* loaded from: classes6.dex */
public class IncreasingQualityDataSourceSupplier<T> implements Supplier<DataSource<T>> {
private final boolean mDataSourceLazy;
private final List<Supplier<DataSource<T>>> mDataSourceSuppliers;
private IncreasingQualityDataSourceSupplier(List<Supplier<DataSource<T>>> list, boolean z) {
Preconditions.checkArgument(!list.isEmpty(), "List of suppliers is empty!");
this.mDataSourceSuppliers = list;
this.mDataSourceLazy = z;
}
public static <T> IncreasingQualityDataSourceSupplier<T> create(List<Supplier<DataSource<T>>> list) {
return create(list, false);
}
public boolean equals(@Nullable Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof IncreasingQualityDataSourceSupplier) {
return Objects.equal(this.mDataSourceSuppliers, ((IncreasingQualityDataSourceSupplier) obj).mDataSourceSuppliers);
}
return false;
}
@Override // com.facebook.common.internal.Supplier
public DataSource<T> get() {
return new IncreasingQualityDataSource();
}
public int hashCode() {
return this.mDataSourceSuppliers.hashCode();
}
public String toString() {
return Objects.toStringHelper(this).add("list", this.mDataSourceSuppliers).toString();
}
public static <T> IncreasingQualityDataSourceSupplier<T> create(List<Supplier<DataSource<T>>> list, boolean z) {
return new IncreasingQualityDataSourceSupplier<>(list, z);
}
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
@ThreadSafe
public class IncreasingQualityDataSource extends AbstractDataSource<T> {
@GuardedBy("IncreasingQualityDataSource.this")
@Nullable
private ArrayList<DataSource<T>> mDataSources;
@Nullable
private Throwable mDelayedError;
@Nullable
private Map<String, Object> mDelayedExtras;
private AtomicInteger mFinishedDataSources;
@GuardedBy("IncreasingQualityDataSource.this")
private int mIndexOfDataSourceWithResult;
private int mNumberOfDataSources;
public IncreasingQualityDataSource() {
if (IncreasingQualityDataSourceSupplier.this.mDataSourceLazy) {
return;
}
ensureDataSourceInitialized();
}
private void closeSafely(DataSource<T> dataSource) {
if (dataSource != null) {
dataSource.close();
}
}
private void ensureDataSourceInitialized() {
if (this.mFinishedDataSources != null) {
return;
}
synchronized (this) {
try {
if (this.mFinishedDataSources == null) {
this.mFinishedDataSources = new AtomicInteger(0);
int size = IncreasingQualityDataSourceSupplier.this.mDataSourceSuppliers.size();
this.mNumberOfDataSources = size;
this.mIndexOfDataSourceWithResult = size;
this.mDataSources = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
DataSource<T> dataSource = (DataSource) ((Supplier) IncreasingQualityDataSourceSupplier.this.mDataSourceSuppliers.get(i)).get();
this.mDataSources.add(dataSource);
dataSource.subscribe(new InternalDataSubscriber(i), CallerThreadExecutor.getInstance());
if (!dataSource.hasResult()) {
}
}
}
} finally {
}
}
}
@Nullable
private synchronized DataSource<T> getAndClearDataSource(int i) {
DataSource<T> dataSource;
ArrayList<DataSource<T>> arrayList = this.mDataSources;
dataSource = null;
if (arrayList != null && i < arrayList.size()) {
dataSource = this.mDataSources.set(i, null);
}
return dataSource;
}
@Nullable
private synchronized DataSource<T> getDataSource(int i) {
ArrayList<DataSource<T>> arrayList;
arrayList = this.mDataSources;
return (arrayList == null || i >= arrayList.size()) ? null : this.mDataSources.get(i);
}
@Nullable
private synchronized DataSource<T> getDataSourceWithResult() {
return getDataSource(this.mIndexOfDataSourceWithResult);
}
private void maybeSetFailure() {
Throwable th;
if (this.mFinishedDataSources.incrementAndGet() != this.mNumberOfDataSources || (th = this.mDelayedError) == null) {
return;
}
setFailure(th, this.mDelayedExtras);
}
/* JADX WARN: Removed duplicated region for block: B:17:0x0024 A[LOOP:0: B:16:0x0022->B:17:0x0024, LOOP_END] */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
private void maybeSetIndexOfDataSourceWithResult(int r3, com.facebook.datasource.DataSource<T> r4, boolean r5) {
/*
r2 = this;
monitor-enter(r2)
int r0 = r2.mIndexOfDataSourceWithResult // Catch: java.lang.Throwable -> L1b
com.facebook.datasource.DataSource r1 = r2.getDataSource(r3) // Catch: java.lang.Throwable -> L1b
if (r4 != r1) goto L2f
int r4 = r2.mIndexOfDataSourceWithResult // Catch: java.lang.Throwable -> L1b
if (r3 != r4) goto Le
goto L2f
Le:
com.facebook.datasource.DataSource r4 = r2.getDataSourceWithResult() // Catch: java.lang.Throwable -> L1b
if (r4 == 0) goto L1f
if (r5 == 0) goto L1d
int r4 = r2.mIndexOfDataSourceWithResult // Catch: java.lang.Throwable -> L1b
if (r3 >= r4) goto L1d
goto L1f
L1b:
r3 = move-exception
goto L31
L1d:
r3 = r0
goto L21
L1f:
r2.mIndexOfDataSourceWithResult = r3 // Catch: java.lang.Throwable -> L1b
L21:
monitor-exit(r2) // Catch: java.lang.Throwable -> L1b
L22:
if (r0 <= r3) goto L2e
com.facebook.datasource.DataSource r4 = r2.getAndClearDataSource(r0)
r2.closeSafely(r4)
int r0 = r0 + (-1)
goto L22
L2e:
return
L2f:
monitor-exit(r2) // Catch: java.lang.Throwable -> L1b
return
L31:
monitor-exit(r2) // Catch: java.lang.Throwable -> L1b
throw r3
*/
throw new UnsupportedOperationException("Method not decompiled: com.facebook.datasource.IncreasingQualityDataSourceSupplier.IncreasingQualityDataSource.maybeSetIndexOfDataSourceWithResult(int, com.facebook.datasource.DataSource, boolean):void");
}
/* JADX INFO: Access modifiers changed from: private */
public void onDataSourceFailed(int i, DataSource<T> dataSource) {
closeSafely(tryGetAndClearDataSource(i, dataSource));
if (i == 0) {
this.mDelayedError = dataSource.getFailureCause();
this.mDelayedExtras = dataSource.getExtras();
}
maybeSetFailure();
}
/* JADX INFO: Access modifiers changed from: private */
public void onDataSourceNewResult(int i, DataSource<T> dataSource) {
maybeSetIndexOfDataSourceWithResult(i, dataSource, dataSource.isFinished());
if (dataSource == getDataSourceWithResult()) {
setResult(null, i == 0 && dataSource.isFinished(), dataSource.getExtras());
}
maybeSetFailure();
}
@Nullable
private synchronized DataSource<T> tryGetAndClearDataSource(int i, DataSource<T> dataSource) {
if (dataSource == getDataSourceWithResult()) {
return null;
}
if (dataSource != getDataSource(i)) {
return dataSource;
}
return getAndClearDataSource(i);
}
@Override // com.facebook.datasource.AbstractDataSource, com.facebook.datasource.DataSource
public boolean close() {
if (IncreasingQualityDataSourceSupplier.this.mDataSourceLazy) {
ensureDataSourceInitialized();
}
synchronized (this) {
try {
if (!super.close()) {
return false;
}
ArrayList<DataSource<T>> arrayList = this.mDataSources;
this.mDataSources = null;
if (arrayList == null) {
return true;
}
for (int i = 0; i < arrayList.size(); i++) {
closeSafely(arrayList.get(i));
}
return true;
} catch (Throwable th) {
throw th;
}
}
}
@Override // com.facebook.datasource.AbstractDataSource, com.facebook.datasource.DataSource
@Nullable
public synchronized T getResult() {
DataSource<T> dataSourceWithResult;
try {
if (IncreasingQualityDataSourceSupplier.this.mDataSourceLazy) {
ensureDataSourceInitialized();
}
dataSourceWithResult = getDataSourceWithResult();
} catch (Throwable th) {
throw th;
}
return dataSourceWithResult != null ? dataSourceWithResult.getResult() : null;
}
@Override // com.facebook.datasource.AbstractDataSource, com.facebook.datasource.DataSource
public synchronized boolean hasResult() {
boolean z;
try {
if (IncreasingQualityDataSourceSupplier.this.mDataSourceLazy) {
ensureDataSourceInitialized();
}
DataSource<T> dataSourceWithResult = getDataSourceWithResult();
if (dataSourceWithResult != null) {
z = dataSourceWithResult.hasResult();
}
} catch (Throwable th) {
throw th;
}
return z;
}
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
public class InternalDataSubscriber implements DataSubscriber<T> {
private int mIndex;
public InternalDataSubscriber(int i) {
this.mIndex = i;
}
@Override // com.facebook.datasource.DataSubscriber
public void onFailure(DataSource<T> dataSource) {
IncreasingQualityDataSource.this.onDataSourceFailed(this.mIndex, dataSource);
}
@Override // com.facebook.datasource.DataSubscriber
public void onNewResult(DataSource<T> dataSource) {
if (dataSource.hasResult()) {
IncreasingQualityDataSource.this.onDataSourceNewResult(this.mIndex, dataSource);
} else if (dataSource.isFinished()) {
IncreasingQualityDataSource.this.onDataSourceFailed(this.mIndex, dataSource);
}
}
@Override // com.facebook.datasource.DataSubscriber
public void onProgressUpdate(DataSource<T> dataSource) {
if (this.mIndex == 0) {
IncreasingQualityDataSource.this.setProgress(dataSource.getProgress());
}
}
@Override // com.facebook.datasource.DataSubscriber
public void onCancellation(DataSource<T> dataSource) {
}
}
}
}