package com.google.android.gms.common.api.internal; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Looper; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import com.google.android.gms.internal.common.zzi; import java.io.FileDescriptor; import java.io.PrintWriter; import java.lang.ref.WeakReference; import java.util.Collections; import java.util.Iterator; import java.util.Map; import java.util.WeakHashMap; import o.nyh; /* loaded from: classes.dex */ public final class zzd extends Fragment implements LifecycleFragment { private static final WeakHashMap zza = new WeakHashMap(); private final Map zzb = Collections.synchronizedMap(new nyh()); private int zzc = 0; private Bundle zzd; public static zzd zzc(FragmentActivity fragmentActivity) { zzd zzdVar; WeakHashMap weakHashMap = zza; WeakReference weakReference = (WeakReference) weakHashMap.get(fragmentActivity); if (weakReference != null && (zzdVar = (zzd) weakReference.get()) != null) { return zzdVar; } try { zzd zzdVar2 = (zzd) fragmentActivity.getSupportFragmentManager().findFragmentByTag("SupportLifecycleFragmentImpl"); if (zzdVar2 == null || zzdVar2.isRemoving()) { zzdVar2 = new zzd(); fragmentActivity.getSupportFragmentManager().a().b(zzdVar2, "SupportLifecycleFragmentImpl").a(); } weakHashMap.put(fragmentActivity, new WeakReference(zzdVar2)); return zzdVar2; } catch (ClassCastException e) { throw new IllegalStateException("Fragment with tag SupportLifecycleFragmentImpl is not a SupportLifecycleFragmentImpl", e); } } @Override // com.google.android.gms.common.api.internal.LifecycleFragment public final void addCallback(String str, LifecycleCallback lifecycleCallback) { if (!this.zzb.containsKey(str)) { this.zzb.put(str, lifecycleCallback); if (this.zzc > 0) { new zzi(Looper.getMainLooper()).post(new zzc(this, lifecycleCallback, str)); return; } return; } throw new IllegalArgumentException("LifecycleCallback with tag " + str + " already added to this fragment."); } @Override // androidx.fragment.app.Fragment public final void dump(String str, FileDescriptor fileDescriptor, PrintWriter printWriter, String[] strArr) { super.dump(str, fileDescriptor, printWriter, strArr); Iterator it = this.zzb.values().iterator(); while (it.hasNext()) { ((LifecycleCallback) it.next()).dump(str, fileDescriptor, printWriter, strArr); } } @Override // com.google.android.gms.common.api.internal.LifecycleFragment public final T getCallbackOrNull(String str, Class cls) { return cls.cast(this.zzb.get(str)); } @Override // com.google.android.gms.common.api.internal.LifecycleFragment public final /* synthetic */ Activity getLifecycleActivity() { return getActivity(); } @Override // androidx.fragment.app.Fragment public final void onActivityResult(int i, int i2, Intent intent) { super.onActivityResult(i, i2, intent); Iterator it = this.zzb.values().iterator(); while (it.hasNext()) { ((LifecycleCallback) it.next()).onActivityResult(i, i2, intent); } } @Override // androidx.fragment.app.Fragment public final void onCreate(Bundle bundle) { super.onCreate(bundle); this.zzc = 1; this.zzd = bundle; for (Map.Entry entry : this.zzb.entrySet()) { ((LifecycleCallback) entry.getValue()).onCreate(bundle != null ? bundle.getBundle((String) entry.getKey()) : null); } } @Override // androidx.fragment.app.Fragment public final void onDestroy() { super.onDestroy(); this.zzc = 5; Iterator it = this.zzb.values().iterator(); while (it.hasNext()) { ((LifecycleCallback) it.next()).onDestroy(); } } @Override // androidx.fragment.app.Fragment public final void onResume() { super.onResume(); this.zzc = 3; Iterator it = this.zzb.values().iterator(); while (it.hasNext()) { ((LifecycleCallback) it.next()).onResume(); } } @Override // androidx.fragment.app.Fragment public final void onSaveInstanceState(Bundle bundle) { super.onSaveInstanceState(bundle); if (bundle == null) { return; } for (Map.Entry entry : this.zzb.entrySet()) { Bundle bundle2 = new Bundle(); ((LifecycleCallback) entry.getValue()).onSaveInstanceState(bundle2); bundle.putBundle((String) entry.getKey(), bundle2); } } @Override // androidx.fragment.app.Fragment public final void onStart() { super.onStart(); this.zzc = 2; Iterator it = this.zzb.values().iterator(); while (it.hasNext()) { ((LifecycleCallback) it.next()).onStart(); } } @Override // androidx.fragment.app.Fragment public final void onStop() { super.onStop(); this.zzc = 4; Iterator it = this.zzb.values().iterator(); while (it.hasNext()) { ((LifecycleCallback) it.next()).onStop(); } } @Override // com.google.android.gms.common.api.internal.LifecycleFragment public final boolean isStarted() { return this.zzc >= 2; } @Override // com.google.android.gms.common.api.internal.LifecycleFragment public final boolean isCreated() { return this.zzc > 0; } }