package com.google.android.gms.internal.measurement;

import android.os.Bundle;
import android.os.Parcel;
import java.util.concurrent.atomic.AtomicReference;

/* JADX INFO: loaded from: classes2.dex */
public final class u0 extends g0 implements x0 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final AtomicReference f20432a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public boolean f20433b;

    public u0() {
        super("com.google.android.gms.measurement.api.internal.IBundleReceiver");
        this.f20432a = new AtomicReference();
    }

    public static Object O(Class cls, Bundle bundle) {
        Object obj;
        if (bundle == null || (obj = bundle.get("r")) == null) {
            return null;
        }
        try {
            return cls.cast(obj);
        } catch (ClassCastException e10) {
            String.format("Unexpected object type. Expected, Received: %s, %s", cls.getCanonicalName(), obj.getClass().getCanonicalName());
            throw e10;
        }
    }

    @Override // com.google.android.gms.internal.measurement.g0
    public final boolean G(int i10, Parcel parcel, Parcel parcel2) {
        if (i10 != 1) {
            return false;
        }
        Bundle bundle = (Bundle) f0.a(parcel, Bundle.CREATOR);
        f0.d(parcel);
        H(bundle);
        parcel2.writeNoException();
        return true;
    }

    @Override // com.google.android.gms.internal.measurement.x0
    public final void H(Bundle bundle) {
        synchronized (this.f20432a) {
            try {
                try {
                    this.f20432a.set(bundle);
                    this.f20433b = true;
                } finally {
                    this.f20432a.notify();
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final Bundle M(long j10) {
        Bundle bundle;
        synchronized (this.f20432a) {
            if (!this.f20433b) {
                try {
                    this.f20432a.wait(j10);
                } catch (InterruptedException unused) {
                    return null;
                }
            }
            bundle = (Bundle) this.f20432a.get();
        }
        return bundle;
    }
}
