package com.google.android.gms.internal.ads; import android.app.Activity; import android.app.Application; import android.app.KeyguardManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.IntentFilter; import android.graphics.Rect; import android.os.Bundle; import android.os.PowerManager; import android.util.DisplayMetrics; import android.view.View; import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowManager; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import java.lang.ref.WeakReference; import java.util.HashSet; /* loaded from: classes3.dex */ public final class zzayl implements View.OnAttachStateChangeListener, ViewTreeObserver.OnGlobalLayoutListener, ViewTreeObserver.OnScrollChangedListener, Application.ActivityLifecycleCallbacks { private static final long zzc = ((Long) com.google.android.gms.ads.internal.client.zzbe.zzc().zza(zzbcl.zzbv)).longValue(); @Nullable @VisibleForTesting BroadcastReceiver zza; final WeakReference zzb; private final Context zzd; private Application zze; private final WindowManager zzf; private final PowerManager zzg; private final KeyguardManager zzh; private WeakReference zzi; private zzayx zzj; private final com.google.android.gms.ads.internal.util.zzbx zzk = new com.google.android.gms.ads.internal.util.zzbx(zzc); private boolean zzl = false; private int zzm = -1; private final HashSet zzn = new HashSet(); private final DisplayMetrics zzo; private final Rect zzp; public zzayl(Context context, View view) { Context applicationContext = context.getApplicationContext(); this.zzd = applicationContext; WindowManager windowManager = (WindowManager) applicationContext.getSystemService("window"); this.zzf = windowManager; this.zzg = (PowerManager) applicationContext.getSystemService("power"); this.zzh = (KeyguardManager) applicationContext.getSystemService("keyguard"); if (applicationContext instanceof Application) { Application application = (Application) applicationContext; this.zze = application; this.zzj = new zzayx(application, this); } this.zzo = context.getResources().getDisplayMetrics(); Rect rect = new Rect(); this.zzp = rect; rect.right = windowManager.getDefaultDisplay().getWidth(); rect.bottom = windowManager.getDefaultDisplay().getHeight(); WeakReference weakReference = this.zzb; View view2 = weakReference != null ? (View) weakReference.get() : null; if (view2 != null) { view2.removeOnAttachStateChangeListener(this); zzm(view2); } this.zzb = new WeakReference(view); if (view != null) { if (view.isAttachedToWindow()) { zzl(view); } view.addOnAttachStateChangeListener(this); } } private final int zzh(int i) { return (int) (i / this.zzo.density); } private final void zzi(Activity activity, int i) { Window window; if (this.zzb == null || (window = activity.getWindow()) == null) { return; } WeakReference weakReference = this.zzb; View peekDecorView = window.peekDecorView(); View view = (View) weakReference.get(); if (view == null || peekDecorView == null || view.getRootView() != peekDecorView.getRootView()) { return; } this.zzm = i; } /* JADX INFO: Access modifiers changed from: private */ /* JADX WARN: Code restructure failed: missing block: B:106:0x0158, code lost: if (r9 == 0) goto L54; */ /* JADX WARN: Code restructure failed: missing block: B:44:0x0133, code lost: if (r9 == 0) goto L54; */ /* JADX WARN: Code restructure failed: missing block: B:45:0x0135, code lost: r3 = 1; r13 = true; r14 = true; r9 = 0; */ /* JADX WARN: Multi-variable type inference failed */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ public final void zzj(int r35) { /* Method dump skipped, instructions count: 574 To view this dump add '--comments-level debug' option */ throw new UnsupportedOperationException("Method not decompiled: com.google.android.gms.internal.ads.zzayl.zzj(int):void"); } private final void zzk() { com.google.android.gms.ads.internal.util.zzs.zza.post(new Runnable() { // from class: com.google.android.gms.internal.ads.zzayh @Override // java.lang.Runnable public final void run() { zzayl.this.zzd(); } }); } private final void zzl(View view) { ViewTreeObserver viewTreeObserver = view.getViewTreeObserver(); if (viewTreeObserver.isAlive()) { this.zzi = new WeakReference(viewTreeObserver); viewTreeObserver.addOnScrollChangedListener(this); viewTreeObserver.addOnGlobalLayoutListener(this); } if (this.zza == null) { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("android.intent.action.SCREEN_ON"); intentFilter.addAction("android.intent.action.SCREEN_OFF"); intentFilter.addAction("android.intent.action.USER_PRESENT"); this.zza = new zzayi(this); com.google.android.gms.ads.internal.zzv.zzw().zzc(this.zzd, this.zza, intentFilter); } Application application = this.zze; if (application != null) { try { application.registerActivityLifecycleCallbacks(this.zzj); } catch (Exception e) { com.google.android.gms.ads.internal.util.client.zzo.zzh("Error registering activity lifecycle callbacks.", e); } } } private final void zzm(View view) { try { WeakReference weakReference = this.zzi; if (weakReference != null) { ViewTreeObserver viewTreeObserver = (ViewTreeObserver) weakReference.get(); if (viewTreeObserver != null && viewTreeObserver.isAlive()) { viewTreeObserver.removeOnScrollChangedListener(this); viewTreeObserver.removeGlobalOnLayoutListener(this); } this.zzi = null; } } catch (Exception e) { com.google.android.gms.ads.internal.util.client.zzo.zzh("Error while unregistering listeners from the last ViewTreeObserver.", e); } try { ViewTreeObserver viewTreeObserver2 = view.getViewTreeObserver(); if (viewTreeObserver2.isAlive()) { viewTreeObserver2.removeOnScrollChangedListener(this); viewTreeObserver2.removeGlobalOnLayoutListener(this); } } catch (Exception e2) { com.google.android.gms.ads.internal.util.client.zzo.zzh("Error while unregistering listeners from the ViewTreeObserver.", e2); } if (this.zza != null) { try { com.google.android.gms.ads.internal.zzv.zzw().zzd(this.zzd, this.zza); } catch (IllegalStateException e3) { com.google.android.gms.ads.internal.util.client.zzo.zzh("Failed trying to unregister the receiver", e3); } catch (Exception e4) { com.google.android.gms.ads.internal.zzv.zzp().zzw(e4, "ActiveViewUnit.stopScreenStatusMonitoring"); } this.zza = null; } Application application = this.zze; if (application != null) { try { application.unregisterActivityLifecycleCallbacks(this.zzj); } catch (Exception e5) { com.google.android.gms.ads.internal.util.client.zzo.zzh("Error registering activity lifecycle callbacks.", e5); } } } @Override // android.app.Application.ActivityLifecycleCallbacks public final void onActivityCreated(Activity activity, Bundle bundle) { zzi(activity, 0); zzj(3); zzk(); } @Override // android.app.Application.ActivityLifecycleCallbacks public final void onActivityDestroyed(Activity activity) { zzj(3); zzk(); } @Override // android.app.Application.ActivityLifecycleCallbacks public final void onActivityPaused(Activity activity) { zzi(activity, 4); zzj(3); zzk(); } @Override // android.app.Application.ActivityLifecycleCallbacks public final void onActivityResumed(Activity activity) { zzi(activity, 0); zzj(3); zzk(); } @Override // android.app.Application.ActivityLifecycleCallbacks public final void onActivitySaveInstanceState(Activity activity, Bundle bundle) { zzj(3); zzk(); } @Override // android.app.Application.ActivityLifecycleCallbacks public final void onActivityStarted(Activity activity) { zzi(activity, 0); zzj(3); zzk(); } @Override // android.app.Application.ActivityLifecycleCallbacks public final void onActivityStopped(Activity activity) { zzj(3); zzk(); } @Override // android.view.ViewTreeObserver.OnGlobalLayoutListener public final void onGlobalLayout() { zzj(2); zzk(); } @Override // android.view.ViewTreeObserver.OnScrollChangedListener public final void onScrollChanged() { zzj(1); } @Override // android.view.View.OnAttachStateChangeListener public final void onViewAttachedToWindow(View view) { this.zzm = -1; zzl(view); zzj(3); } @Override // android.view.View.OnAttachStateChangeListener public final void onViewDetachedFromWindow(View view) { this.zzm = -1; zzj(3); zzk(); zzm(view); } public final Rect zza(Rect rect) { return new Rect(zzh(rect.left), zzh(rect.top), zzh(rect.right), zzh(rect.bottom)); } public final void zzc(zzayk zzaykVar) { this.zzn.add(zzaykVar); zzj(3); } public final /* synthetic */ void zzd() { zzj(3); } public final void zze(zzayk zzaykVar) { this.zzn.remove(zzaykVar); } public final void zzf() { this.zzk.zza(zzc); } public final void zzg(long j) { this.zzk.zza(j); } }