package com.applovin.impl; import android.content.Context; import android.graphics.SurfaceTexture; import android.os.Handler; import android.os.HandlerThread; import android.os.Message; import android.view.Surface; /* loaded from: classes.dex */ public final class h7 extends Surface { private static int d; private static boolean f; public final boolean a; private final b b; private boolean c; public static synchronized boolean b(Context context) { boolean z; synchronized (h7.class) { try { if (!f) { d = a(context); f = true; } z = d != 0; } catch (Throwable th) { throw th; } } return z; } private h7(b bVar, SurfaceTexture surfaceTexture, boolean z) { super(surfaceTexture); this.b = bVar; this.a = z; } @Override // android.view.Surface public void release() { super.release(); synchronized (this.b) { try { if (!this.c) { this.b.a(); this.c = true; } } catch (Throwable th) { throw th; } } } private static int a(Context context) { if (ba.a(context)) { return ba.c() ? 1 : 2; } return 0; } public static class b extends HandlerThread implements Handler.Callback { private n7 a; private Handler b; private Error c; private RuntimeException d; private h7 f; public b() { super("ExoPlayer:DummySurface"); } public h7 a(int i) { boolean z; start(); this.b = new Handler(getLooper(), this); this.a = new n7(this.b); synchronized (this) { z = false; this.b.obtainMessage(1, i, 0).sendToTarget(); while (this.f == null && this.d == null && this.c == null) { try { wait(); } catch (InterruptedException unused) { z = true; } } } if (z) { Thread.currentThread().interrupt(); } RuntimeException runtimeException = this.d; if (runtimeException != null) { throw runtimeException; } Error error = this.c; if (error == null) { return (h7) b1.a(this.f); } throw error; } @Override // android.os.Handler.Callback public boolean handleMessage(Message message) { int i = message.what; try { if (i != 1) { if (i != 2) { return true; } try { b(); } finally { try { return true; } finally { } } return true; } try { b(message.arg1); synchronized (this) { notify(); } } catch (Error e) { pc.a("DummySurface", "Failed to initialize dummy surface", e); this.c = e; synchronized (this) { notify(); } } catch (RuntimeException e2) { pc.a("DummySurface", "Failed to initialize dummy surface", e2); this.d = e2; synchronized (this) { notify(); } } return true; } catch (Throwable th) { synchronized (this) { notify(); throw th; } } } private void b(int i) { b1.a(this.a); this.a.a(i); this.f = new h7(this, this.a.c(), i != 0); } public void a() { b1.a(this.b); this.b.sendEmptyMessage(2); } private void b() { b1.a(this.a); this.a.d(); } } public static h7 a(Context context, boolean z) { b1.b(!z || b(context)); return new b().a(z ? d : 0); } }