package c.o.a.n; import android.annotation.SuppressLint; import android.graphics.PointF; import android.graphics.Rect; import android.graphics.SurfaceTexture; import android.hardware.camera2.CameraAccessException; import android.hardware.camera2.CameraCaptureSession; import android.hardware.camera2.CameraCharacteristics; import android.hardware.camera2.CameraDevice; import android.hardware.camera2.CameraManager; import android.hardware.camera2.CaptureRequest; import android.hardware.camera2.CaptureResult; import android.hardware.camera2.TotalCaptureResult; import android.hardware.camera2.params.StreamConfigurationMap; import android.location.Location; import android.media.Image; import android.media.ImageReader; import android.os.Build; import android.os.Handler; import android.util.Pair; import android.util.Range; import android.util.Rational; import android.util.Size; import android.view.Surface; import android.view.SurfaceHolder; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.annotation.VisibleForTesting; import c.o.a.l; import c.o.a.n.i; import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.TaskCompletionSource; import com.otaliastudios.cameraview.CameraException; import com.otaliastudios.cameraview.CameraView; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Objects; import java.util.concurrent.Callable; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.ExecutionException; /* compiled from: Camera2Engine */ @RequiresApi(21) public class d extends g implements ImageReader.OnImageAvailableListener, c.o.a.n.o.c { /* renamed from: c0 reason: collision with root package name */ public final CameraManager f1477c0; /* renamed from: d0 reason: collision with root package name */ public String f1478d0; /* renamed from: e0 reason: collision with root package name */ public CameraDevice f1479e0; /* renamed from: f0 reason: collision with root package name */ public CameraCharacteristics f1480f0; /* renamed from: g0 reason: collision with root package name */ public CameraCaptureSession f1481g0; /* renamed from: h0 reason: collision with root package name */ public CaptureRequest.Builder f1482h0; /* renamed from: i0 reason: collision with root package name */ public TotalCaptureResult f1483i0; /* renamed from: j0 reason: collision with root package name */ public final c.o.a.n.q.b f1484j0; public ImageReader k0; public Surface l0; public Surface m0; public ImageReader n0; public final List o0; public c.o.a.n.r.g p0; public final CameraCaptureSession.CaptureCallback q0; /* compiled from: Camera2Engine */ public class a implements Runnable { public final /* synthetic */ c.o.a.m.f i; public final /* synthetic */ c.o.a.m.f j; public a(c.o.a.m.f fVar, c.o.a.m.f fVar2) { this.i = fVar; this.j = fVar2; } @Override // java.lang.Runnable public void run() { d dVar = d.this; boolean h1 = dVar.h1(dVar.f1482h0, this.i); d dVar2 = d.this; if (dVar2.m.f == c.o.a.n.v.e.PREVIEW) { dVar2.v = c.o.a.m.f.OFF; dVar2.h1(dVar2.f1482h0, this.i); try { d dVar3 = d.this; dVar3.f1481g0.capture(dVar3.f1482h0.build(), null, null); d dVar4 = d.this; dVar4.v = this.j; dVar4.h1(dVar4.f1482h0, this.i); d.this.k1(); } catch (CameraAccessException e) { throw d.this.o1(e); } } else if (h1) { dVar2.k1(); } } } /* compiled from: Camera2Engine */ public class b implements Runnable { public final /* synthetic */ Location i; public b(Location location) { this.i = location; } @Override // java.lang.Runnable public void run() { d dVar = d.this; CaptureRequest.Builder builder = dVar.f1482h0; Location location = dVar.B; if (location != null) { builder.set(CaptureRequest.JPEG_GPS_LOCATION, location); } d.this.k1(); } } /* compiled from: Camera2Engine */ public class c implements Runnable { public final /* synthetic */ c.o.a.m.m i; public c(c.o.a.m.m mVar) { this.i = mVar; } @Override // java.lang.Runnable public void run() { d dVar = d.this; if (dVar.m1(dVar.f1482h0, this.i)) { d.this.k1(); } } } /* compiled from: Camera2Engine */ /* renamed from: c.o.a.n.d$d reason: collision with other inner class name */ public class RunnableC0161d implements Runnable { public final /* synthetic */ c.o.a.m.h i; public RunnableC0161d(c.o.a.m.h hVar) { this.i = hVar; } @Override // java.lang.Runnable public void run() { d dVar = d.this; if (dVar.i1(dVar.f1482h0, this.i)) { d.this.k1(); } } } /* compiled from: Camera2Engine */ public class e implements Runnable { public final /* synthetic */ float i; public final /* synthetic */ boolean j; public final /* synthetic */ float k; public final /* synthetic */ PointF[] l; public e(float f, boolean z2, float f2, PointF[] pointFArr) { this.i = f; this.j = z2; this.k = f2; this.l = pointFArr; } @Override // java.lang.Runnable public void run() { d dVar = d.this; if (dVar.n1(dVar.f1482h0, this.i)) { d.this.k1(); if (this.j) { ((CameraView.b) d.this.l).f(this.k, this.l); } } } } /* compiled from: Camera2Engine */ public class f implements Runnable { public final /* synthetic */ float i; public final /* synthetic */ boolean j; public final /* synthetic */ float k; public final /* synthetic */ float[] l; public final /* synthetic */ PointF[] m; public f(float f, boolean z2, float f2, float[] fArr, PointF[] pointFArr) { this.i = f; this.j = z2; this.k = f2; this.l = fArr; this.m = pointFArr; } @Override // java.lang.Runnable public void run() { d dVar = d.this; if (dVar.g1(dVar.f1482h0, this.i)) { d.this.k1(); if (this.j) { ((CameraView.b) d.this.l).c(this.k, this.l, this.m); } } } } /* compiled from: Camera2Engine */ public class g implements Runnable { public final /* synthetic */ float i; public g(float f) { this.i = f; } @Override // java.lang.Runnable public void run() { d dVar = d.this; if (dVar.j1(dVar.f1482h0, this.i)) { d.this.k1(); } } } /* compiled from: Camera2Engine */ public class h implements Runnable { public h() { } @Override // java.lang.Runnable public void run() { d.this.X(); } } /* compiled from: Camera2Engine */ public class i extends CameraCaptureSession.CaptureCallback { public i() { } @Override // android.hardware.camera2.CameraCaptureSession.CaptureCallback public void onCaptureCompleted(@NonNull CameraCaptureSession cameraCaptureSession, @NonNull CaptureRequest captureRequest, @NonNull TotalCaptureResult totalCaptureResult) { d dVar = d.this; dVar.f1483i0 = totalCaptureResult; for (c.o.a.n.o.a aVar : dVar.o0) { aVar.b(d.this, captureRequest, totalCaptureResult); } } @Override // android.hardware.camera2.CameraCaptureSession.CaptureCallback public void onCaptureProgressed(@NonNull CameraCaptureSession cameraCaptureSession, @NonNull CaptureRequest captureRequest, @NonNull CaptureResult captureResult) { for (c.o.a.n.o.a aVar : d.this.o0) { aVar.d(d.this, captureRequest, captureResult); } } @Override // android.hardware.camera2.CameraCaptureSession.CaptureCallback public void onCaptureStarted(@NonNull CameraCaptureSession cameraCaptureSession, @NonNull CaptureRequest captureRequest, long j, long j2) { for (c.o.a.n.o.a aVar : d.this.o0) { aVar.c(d.this, captureRequest); } } } /* compiled from: Camera2Engine */ public class j implements Runnable { public final /* synthetic */ boolean i; public j(boolean z2) { this.i = z2; } @Override // java.lang.Runnable public void run() { c.o.a.n.v.e eVar = d.this.m.f; c.o.a.n.v.e eVar2 = c.o.a.n.v.e.BIND; if (!eVar.f(eVar2) || !d.this.O()) { d dVar = d.this; dVar.u = this.i; if (dVar.m.f.f(eVar2)) { d.this.Y(); return; } return; } d.this.k0(this.i); } } /* compiled from: Camera2Engine */ public class k implements Runnable { public final /* synthetic */ int i; public k(int i) { this.i = i; } @Override // java.lang.Runnable public void run() { c.o.a.n.v.e eVar = d.this.m.f; c.o.a.n.v.e eVar2 = c.o.a.n.v.e.BIND; if (!eVar.f(eVar2) || !d.this.O()) { d dVar = d.this; int i = this.i; if (i <= 0) { i = 35; } dVar.t = i; if (dVar.m.f.f(eVar2)) { d.this.Y(); return; } return; } d.this.g0(this.i); } } /* compiled from: Camera2Engine */ public class l implements Runnable { public final /* synthetic */ c.o.a.q.a i; public final /* synthetic */ PointF j; public final /* synthetic */ c.o.a.t.b k; /* compiled from: Camera2Engine */ public class a extends c.o.a.n.o.f { public final /* synthetic */ c.o.a.n.r.g a; /* compiled from: Camera2Engine */ /* renamed from: c.o.a.n.d$l$a$a reason: collision with other inner class name */ public class RunnableC0162a implements Runnable { public RunnableC0162a() { } @Override // java.lang.Runnable public void run() { d.b1(d.this); } } public a(c.o.a.n.r.g gVar) { this.a = gVar; } @Override // c.o.a.n.o.f public void b(@NonNull c.o.a.n.o.a aVar) { boolean z2; l lVar = l.this; i.g gVar = d.this.l; c.o.a.q.a aVar2 = lVar.i; Iterator it = this.a.f.iterator(); while (true) { z2 = true; if (it.hasNext()) { if (!it.next().g) { c.o.a.n.r.g.e.a(1, "isSuccessful:", "returning false."); z2 = false; break; } } else { c.o.a.n.r.g.e.a(1, "isSuccessful:", "returning true."); break; } } ((CameraView.b) gVar).d(aVar2, z2, l.this.j); d.this.m.e("reset metering", 0); if (d.this.a1()) { d dVar = d.this; c.o.a.n.v.f fVar = dVar.m; fVar.c("reset metering", true, dVar.V, new c.o.a.n.v.i(fVar, c.o.a.n.v.e.PREVIEW, new RunnableC0162a())); } } } public l(c.o.a.q.a aVar, PointF pointF, c.o.a.t.b bVar) { this.i = aVar; this.j = pointF; this.k = bVar; } @Override // java.lang.Runnable public void run() { d dVar = d.this; if (dVar.o.o) { ((CameraView.b) dVar.l).e(this.i, this.j); c.o.a.n.r.g p1 = d.this.p1(this.k); c.o.a.n.o.i iVar = new c.o.a.n.o.i(5000, p1); iVar.e(d.this); iVar.f(new a(p1)); } } } /* compiled from: Camera2Engine */ public class m extends CameraDevice.StateCallback { public final /* synthetic */ TaskCompletionSource a; public m(TaskCompletionSource taskCompletionSource) { this.a = taskCompletionSource; } @Override // android.hardware.camera2.CameraDevice.StateCallback public void onDisconnected(@NonNull CameraDevice cameraDevice) { CameraException cameraException = new CameraException(3); if (!this.a.a.o()) { this.a.a(cameraException); } else { i.i.a(1, "CameraDevice.StateCallback reported disconnection."); throw cameraException; } } @Override // android.hardware.camera2.CameraDevice.StateCallback public void onError(@NonNull CameraDevice cameraDevice, int i) { int i2 = 1; if (!this.a.a.o()) { TaskCompletionSource taskCompletionSource = this.a; Objects.requireNonNull(d.this); if (!(i == 1 || i == 2 || i == 3 || i == 4 || i == 5)) { i2 = 0; } taskCompletionSource.a(new CameraException(i2)); return; } i.i.a(3, "CameraDevice.StateCallback reported an error:", Integer.valueOf(i)); throw new CameraException(3); } @Override // android.hardware.camera2.CameraDevice.StateCallback public void onOpened(@NonNull CameraDevice cameraDevice) { int i; d.this.f1479e0 = cameraDevice; try { i.i.a(1, "onStartEngine:", "Opened camera device."); d dVar = d.this; dVar.f1480f0 = dVar.f1477c0.getCameraCharacteristics(dVar.f1478d0); boolean b = d.this.K.b(c.o.a.n.t.b.SENSOR, c.o.a.n.t.b.VIEW); int ordinal = d.this.A.ordinal(); if (ordinal == 0) { i = 256; } else if (ordinal == 1) { i = 32; } else { throw new IllegalArgumentException("Unknown format:" + d.this.A); } d dVar2 = d.this; dVar2.o = new c.o.a.n.u.b(dVar2.f1477c0, dVar2.f1478d0, b, i); d dVar3 = d.this; Objects.requireNonNull(dVar3); dVar3.q1(1); this.a.b(d.this.o); } catch (CameraAccessException e) { this.a.a(d.this.o1(e)); } } } /* compiled from: Camera2Engine */ public class n implements Callable { public final /* synthetic */ Object i; public n(Object obj) { this.i = obj; } /* Return type fixed from 'java.lang.Object' to match base method */ @Override // java.util.concurrent.Callable public Void call() throws Exception { c.o.a.x.b bVar = d.this.r; ((SurfaceHolder) this.i).setFixedSize(bVar.i, bVar.j); return null; } } /* compiled from: Camera2Engine */ public class o extends CameraCaptureSession.StateCallback { public final /* synthetic */ TaskCompletionSource a; public o(TaskCompletionSource taskCompletionSource) { this.a = taskCompletionSource; } @Override // android.hardware.camera2.CameraCaptureSession.StateCallback public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) { throw new RuntimeException(i.i.a(3, "onConfigureFailed! Session", cameraCaptureSession)); } @Override // android.hardware.camera2.CameraCaptureSession.StateCallback public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) { d.this.f1481g0 = cameraCaptureSession; i.i.a(1, "onStartBind:", "Completed"); this.a.b(null); } @Override // android.hardware.camera2.CameraCaptureSession.StateCallback public void onReady(@NonNull CameraCaptureSession cameraCaptureSession) { super.onReady(cameraCaptureSession); i.i.a(1, "CameraCaptureSession.StateCallback reported onReady."); } } /* compiled from: Camera2Engine */ public class p extends c.o.a.n.o.e { public final /* synthetic */ TaskCompletionSource e; public p(d dVar, TaskCompletionSource taskCompletionSource) { this.e = taskCompletionSource; } @Override // c.o.a.n.o.e, c.o.a.n.o.a public void b(@NonNull c.o.a.n.o.c cVar, @NonNull CaptureRequest captureRequest, @NonNull TotalCaptureResult totalCaptureResult) { l(Integer.MAX_VALUE); this.e.b(null); } } /* compiled from: Camera2Engine */ public class q extends c.o.a.n.o.f { public final /* synthetic */ l.a a; public q(l.a aVar) { this.a = aVar; } @Override // c.o.a.n.o.f public void b(@NonNull c.o.a.n.o.a aVar) { d dVar = d.this; dVar.G = false; dVar.P0(this.a); d.this.G = true; } } /* compiled from: Camera2Engine */ public class r extends c.o.a.n.o.f { public final /* synthetic */ l.a a; public r(l.a aVar) { this.a = aVar; } @Override // c.o.a.n.o.f public void b(@NonNull c.o.a.n.o.a aVar) { d dVar = d.this; dVar.F = false; dVar.O0(this.a); d.this.F = true; } } /* compiled from: Camera2Engine */ public class s implements Runnable { public s() { } @Override // java.lang.Runnable public void run() { d.b1(d.this); } } public d(i.g gVar) { super(gVar); if (c.o.a.n.q.b.a == null) { c.o.a.n.q.b.a = new c.o.a.n.q.b(); } this.f1484j0 = c.o.a.n.q.b.a; this.o0 = new CopyOnWriteArrayList(); this.q0 = new i(); this.f1477c0 = (CameraManager) ((CameraView.b) this.l).g().getSystemService("camera"); new c.o.a.n.o.g().e(this); } public static void b1(d dVar) { Objects.requireNonNull(dVar); new c.o.a.n.o.h(Arrays.asList(new f(dVar), new c.o.a.n.r.h())).e(dVar); } @Override // c.o.a.n.i public void F0(@NonNull c.o.a.m.m mVar) { c.o.a.m.m mVar2 = this.w; this.w = mVar; c.o.a.n.v.f fVar = this.m; fVar.b("white balance (" + mVar + ")", true, new c.o.a.n.v.h(fVar, c.o.a.n.v.e.ENGINE, new c(mVar2))); } @Override // c.o.a.n.i public void G0(float f2, @Nullable PointF[] pointFArr, boolean z2) { float f3 = this.C; this.C = f2; this.m.e("zoom", 20); c.o.a.n.v.f fVar = this.m; fVar.b("zoom", true, new c.o.a.n.v.h(fVar, c.o.a.n.v.e.ENGINE, new e(f3, z2, f2, pointFArr))); } @Override // c.o.a.n.i public void I0(@Nullable c.o.a.q.a aVar, @NonNull c.o.a.t.b bVar, @NonNull PointF pointF) { c.o.a.n.v.f fVar = this.m; fVar.b("autofocus (" + aVar + ")", true, new c.o.a.n.v.h(fVar, c.o.a.n.v.e.PREVIEW, new l(aVar, pointF, bVar))); } @Override // c.o.a.n.i @NonNull public Task P() { Handler handler; int i2; c.o.a.b bVar = i.i; bVar.a(1, "onStartBind:", "Started"); TaskCompletionSource taskCompletionSource = new TaskCompletionSource(); this.q = Q0(this.P); this.r = R0(); ArrayList arrayList = new ArrayList(); Class j2 = this.n.j(); Object i3 = this.n.i(); if (j2 == SurfaceHolder.class) { try { bVar.a(1, "onStartBind:", "Waiting on UI thread..."); c.i.a.f.e.o.c.c(c.i.a.f.e.o.c.g(c.i.a.f.n.g.a, new n(i3))); this.m0 = ((SurfaceHolder) i3).getSurface(); } catch (InterruptedException | ExecutionException e2) { throw new CameraException(e2, 1); } } else if (j2 == SurfaceTexture.class) { SurfaceTexture surfaceTexture = (SurfaceTexture) i3; c.o.a.x.b bVar2 = this.r; surfaceTexture.setDefaultBufferSize(bVar2.i, bVar2.j); this.m0 = new Surface(surfaceTexture); } else { throw new RuntimeException("Unknown CameraPreview output class."); } arrayList.add(this.m0); if (this.P == c.o.a.m.i.PICTURE) { int ordinal = this.A.ordinal(); if (ordinal == 0) { i2 = 256; } else if (ordinal == 1) { i2 = 32; } else { StringBuilder L = c.d.b.a.a.L("Unknown format:"); L.append(this.A); throw new IllegalArgumentException(L.toString()); } c.o.a.x.b bVar3 = this.q; ImageReader newInstance = ImageReader.newInstance(bVar3.i, bVar3.j, i2, 2); this.n0 = newInstance; arrayList.add(newInstance.getSurface()); } if (this.u) { List s1 = s1(); boolean b2 = this.K.b(c.o.a.n.t.b.SENSOR, c.o.a.n.t.b.VIEW); ArrayList arrayList2 = (ArrayList) s1; ArrayList arrayList3 = new ArrayList(arrayList2.size()); Iterator it = arrayList2.iterator(); while (it.hasNext()) { c.o.a.x.b bVar4 = (c.o.a.x.b) it.next(); if (b2) { bVar4 = bVar4.f(); } arrayList3.add(bVar4); } c.o.a.x.b bVar5 = this.r; c.o.a.x.a f2 = c.o.a.x.a.f(bVar5.i, bVar5.j); if (b2) { f2 = c.o.a.x.a.f(f2.k, f2.j); } int i4 = this.Y; int i5 = this.Z; if (i4 <= 0 || i4 == Integer.MAX_VALUE) { i4 = 640; } if (i5 <= 0 || i5 == Integer.MAX_VALUE) { i5 = 640; } c.o.a.x.b bVar6 = new c.o.a.x.b(i4, i5); c.o.a.b bVar7 = i.i; bVar7.a(1, "computeFrameProcessingSize:", "targetRatio:", f2, "targetMaxSize:", bVar6); c.o.a.x.c p0 = c.i.a.f.e.o.c.p0(new c.o.a.x.d(f2.i(), 0.0f)); c.o.a.x.c b3 = c.i.a.f.e.o.c.b(c.i.a.f.e.o.c.Y(i5), c.i.a.f.e.o.c.Z(i4), new c.o.a.x.e()); c.o.a.x.b bVar8 = ((c.o.a.x.l) c.i.a.f.e.o.c.d0(c.i.a.f.e.o.c.b(p0, b3), b3, new c.o.a.x.f())).a(arrayList3).get(0); if (arrayList3.contains(bVar8)) { if (b2) { bVar8 = bVar8.f(); } bVar7.a(1, "computeFrameProcessingSize:", "result:", bVar8, "flip:", Boolean.valueOf(b2)); this.f1487s = bVar8; ImageReader newInstance2 = ImageReader.newInstance(bVar8.i, bVar8.j, this.t, this.f1485a0 + 1); this.k0 = newInstance2; handler = null; newInstance2.setOnImageAvailableListener(this, null); Surface surface = this.k0.getSurface(); this.l0 = surface; arrayList.add(surface); } else { throw new RuntimeException("SizeSelectors must not return Sizes other than those in the input list."); } } else { handler = null; this.k0 = null; this.f1487s = null; this.l0 = null; } try { this.f1479e0.createCaptureSession(arrayList, new o(taskCompletionSource), handler); return taskCompletionSource.a; } catch (CameraAccessException e3) { throw o1(e3); } } @Override // c.o.a.n.i @NonNull @SuppressLint({"MissingPermission"}) public Task Q() { TaskCompletionSource taskCompletionSource = new TaskCompletionSource(); try { this.f1477c0.openCamera(this.f1478d0, new m(taskCompletionSource), (Handler) null); return taskCompletionSource.a; } catch (CameraAccessException e2) { throw o1(e2); } } @Override // c.o.a.n.i @NonNull public Task R() { c.o.a.b bVar = i.i; bVar.a(1, "onStartPreview:", "Dispatching onCameraPreviewStreamSizeChanged."); ((CameraView.b) this.l).h(); c.o.a.n.t.b bVar2 = c.o.a.n.t.b.VIEW; c.o.a.x.b C = C(bVar2); if (C != null) { this.n.s(C.i, C.j); this.n.r(this.K.c(c.o.a.n.t.b.BASE, bVar2, 1)); if (this.u) { S0().e(this.t, this.f1487s, this.K); } bVar.a(1, "onStartPreview:", "Starting preview."); c1(new Surface[0]); l1(false, 2); bVar.a(1, "onStartPreview:", "Started preview."); TaskCompletionSource taskCompletionSource = new TaskCompletionSource(); new p(this, taskCompletionSource).e(this); return taskCompletionSource.a; } throw new IllegalStateException("previewStreamSize should not be null at this point."); } @Override // c.o.a.n.i @NonNull public Task S() { c.o.a.b bVar = i.i; bVar.a(1, "onStopBind:", "About to clean up."); this.l0 = null; this.m0 = null; this.r = null; this.q = null; this.f1487s = null; ImageReader imageReader = this.k0; if (imageReader != null) { imageReader.close(); this.k0 = null; } ImageReader imageReader2 = this.n0; if (imageReader2 != null) { imageReader2.close(); this.n0 = null; } this.f1481g0.close(); this.f1481g0 = null; bVar.a(1, "onStopBind:", "Returning."); return c.i.a.f.e.o.c.F(null); } @Override // c.o.a.n.i @NonNull public Task T() { try { c.o.a.b bVar = i.i; bVar.a(1, "onStopEngine:", "Clean up.", "Releasing camera."); this.f1479e0.close(); bVar.a(1, "onStopEngine:", "Clean up.", "Released camera."); } catch (Exception e2) { i.i.a(2, "onStopEngine:", "Clean up.", "Exception while releasing camera.", e2); } this.f1479e0 = null; i.i.a(1, "onStopEngine:", "Aborting actions."); for (c.o.a.n.o.a aVar : this.o0) { aVar.a(this); } this.f1480f0 = null; this.o = null; this.f1482h0 = null; i.i.a(2, "onStopEngine:", "Returning."); return c.i.a.f.e.o.c.F(null); } @Override // c.o.a.n.g @NonNull public List T0() { try { StreamConfigurationMap streamConfigurationMap = (StreamConfigurationMap) this.f1477c0.getCameraCharacteristics(this.f1478d0).get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); if (streamConfigurationMap != null) { Size[] outputSizes = streamConfigurationMap.getOutputSizes(this.n.j()); ArrayList arrayList = new ArrayList(outputSizes.length); for (Size size : outputSizes) { c.o.a.x.b bVar = new c.o.a.x.b(size.getWidth(), size.getHeight()); if (!arrayList.contains(bVar)) { arrayList.add(bVar); } } return arrayList; } throw new RuntimeException("StreamConfigurationMap is null. Should not happen."); } catch (CameraAccessException e2) { throw o1(e2); } } @Override // c.o.a.n.i @NonNull public Task U() { c.o.a.b bVar = i.i; bVar.a(1, "onStopPreview:", "Started."); this.p = null; if (this.u) { S0().d(); } this.f1482h0.removeTarget(this.m0); Surface surface = this.l0; if (surface != null) { this.f1482h0.removeTarget(surface); } this.f1483i0 = null; bVar.a(1, "onStopPreview:", "Returning."); return c.i.a.f.e.o.c.F(null); } @Override // c.o.a.n.g @NonNull public c.o.a.p.c V0(int i2) { return new c.o.a.p.e(i2); } @Override // c.o.a.n.g public void X0() { i.i.a(1, "onPreviewStreamSizeChanged:", "Calling restartBind()."); Y(); } @Override // c.o.a.n.g public void Y0(@NonNull l.a aVar, boolean z2) { if (z2) { i.i.a(1, "onTakePicture:", "doMetering is true. Delaying."); c.o.a.n.o.i iVar = new c.o.a.n.o.i(2500, p1(null)); iVar.f(new r(aVar)); iVar.e(this); return; } i.i.a(1, "onTakePicture:", "doMetering is false. Performing."); c.o.a.n.t.a aVar2 = this.K; c.o.a.n.t.b bVar = c.o.a.n.t.b.SENSOR; c.o.a.n.t.b bVar2 = c.o.a.n.t.b.OUTPUT; aVar.f1473c = aVar2.c(bVar, bVar2, 2); aVar.d = w(bVar2); try { CaptureRequest.Builder createCaptureRequest = this.f1479e0.createCaptureRequest(2); d1(createCaptureRequest, this.f1482h0); c.o.a.v.b bVar3 = new c.o.a.v.b(aVar, this, createCaptureRequest, this.n0); this.p = bVar3; bVar3.c(); } catch (CameraAccessException e2) { throw o1(e2); } } @Override // c.o.a.n.g public void Z0(@NonNull l.a aVar, @NonNull c.o.a.x.a aVar2, boolean z2) { if (z2) { i.i.a(1, "onTakePictureSnapshot:", "doMetering is true. Delaying."); c.o.a.n.o.i iVar = new c.o.a.n.o.i(2500, p1(null)); iVar.f(new q(aVar)); iVar.e(this); return; } i.i.a(1, "onTakePictureSnapshot:", "doMetering is false. Performing."); if (this.n instanceof c.o.a.w.e) { c.o.a.n.t.b bVar = c.o.a.n.t.b.OUTPUT; aVar.d = F(bVar); aVar.f1473c = this.K.c(c.o.a.n.t.b.VIEW, bVar, 1); c.o.a.v.f fVar = new c.o.a.v.f(aVar, this, (c.o.a.w.e) this.n, aVar2); this.p = fVar; fVar.c(); return; } throw new RuntimeException("takePictureSnapshot with Camera2 is only supported with Preview.GL_SURFACE"); } @Override // c.o.a.n.g, c.o.a.v.d.a public void a(@Nullable l.a aVar, @Nullable Exception exc) { boolean z2 = this.p instanceof c.o.a.v.b; super.a(aVar, exc); if ((z2 && this.F) || (!z2 && this.G)) { c.o.a.n.v.f fVar = this.m; fVar.b("reset metering after picture", true, new c.o.a.n.v.h(fVar, c.o.a.n.v.e.PREVIEW, new s())); } } @Override // c.o.a.n.i public final boolean c(@NonNull c.o.a.m.e eVar) { Objects.requireNonNull(this.f1484j0); int intValue = c.o.a.n.q.b.b.get(eVar).intValue(); try { String[] cameraIdList = this.f1477c0.getCameraIdList(); i.i.a(1, "collectCameraInfo", "Facing:", eVar, "Internal:", Integer.valueOf(intValue), "Cameras:", Integer.valueOf(cameraIdList.length)); for (String str : cameraIdList) { try { CameraCharacteristics cameraCharacteristics = this.f1477c0.getCameraCharacteristics(str); if (intValue == ((Integer) u1(cameraCharacteristics, CameraCharacteristics.LENS_FACING, -99)).intValue()) { this.f1478d0 = str; this.K.f(eVar, ((Integer) u1(cameraCharacteristics, CameraCharacteristics.SENSOR_ORIENTATION, 0)).intValue()); return true; } } catch (CameraAccessException unused) { } } return false; } catch (CameraAccessException e2) { throw o1(e2); } } public final void c1(@NonNull Surface... surfaceArr) { this.f1482h0.addTarget(this.m0); Surface surface = this.l0; if (surface != null) { this.f1482h0.addTarget(surface); } for (Surface surface2 : surfaceArr) { if (surface2 != null) { this.f1482h0.addTarget(surface2); } else { throw new IllegalArgumentException("Should not add a null surface."); } } } @Override // c.o.a.n.i public void d0(float f2, @NonNull float[] fArr, @Nullable PointF[] pointFArr, boolean z2) { float f3 = this.D; this.D = f2; this.m.e("exposure correction", 20); c.o.a.n.v.f fVar = this.m; fVar.b("exposure correction", true, new c.o.a.n.v.h(fVar, c.o.a.n.v.e.ENGINE, new f(f3, z2, f2, fArr, pointFArr))); } public final void d1(@NonNull CaptureRequest.Builder builder, @Nullable CaptureRequest.Builder builder2) { i.i.a(1, "applyAllParameters:", "called for tag", builder.build().getTag()); builder.set(CaptureRequest.CONTROL_MODE, 1); f1(builder); h1(builder, c.o.a.m.f.OFF); Location location = this.B; if (location != null) { builder.set(CaptureRequest.JPEG_GPS_LOCATION, location); } m1(builder, c.o.a.m.m.AUTO); i1(builder, c.o.a.m.h.OFF); n1(builder, 0.0f); g1(builder, 0.0f); j1(builder, 0.0f); if (builder2 != null) { CaptureRequest.Key key = CaptureRequest.CONTROL_AF_REGIONS; builder.set(key, builder2.get(key)); CaptureRequest.Key key2 = CaptureRequest.CONTROL_AE_REGIONS; builder.set(key2, builder2.get(key2)); CaptureRequest.Key key3 = CaptureRequest.CONTROL_AWB_REGIONS; builder.set(key3, builder2.get(key3)); CaptureRequest.Key key4 = CaptureRequest.CONTROL_AF_MODE; builder.set(key4, builder2.get(key4)); } } public void e1(@NonNull c.o.a.n.o.a aVar, @NonNull CaptureRequest.Builder builder) throws CameraAccessException { if (this.m.f == c.o.a.n.v.e.PREVIEW && !O()) { this.f1481g0.capture(builder.build(), this.q0, null); } } @Override // c.o.a.n.i public void f0(@NonNull c.o.a.m.f fVar) { c.o.a.m.f fVar2 = this.v; this.v = fVar; c.o.a.n.v.f fVar3 = this.m; fVar3.b("flash (" + fVar + ")", true, new c.o.a.n.v.h(fVar3, c.o.a.n.v.e.ENGINE, new a(fVar2, fVar))); } public void f1(@NonNull CaptureRequest.Builder builder) { int[] iArr = (int[]) t1(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES, new int[0]); ArrayList arrayList = new ArrayList(); for (int i2 : iArr) { arrayList.add(Integer.valueOf(i2)); } if (this.P == c.o.a.m.i.VIDEO && arrayList.contains(3)) { builder.set(CaptureRequest.CONTROL_AF_MODE, 3); } else if (arrayList.contains(4)) { builder.set(CaptureRequest.CONTROL_AF_MODE, 4); } else if (arrayList.contains(1)) { builder.set(CaptureRequest.CONTROL_AF_MODE, 1); } else if (arrayList.contains(0)) { builder.set(CaptureRequest.CONTROL_AF_MODE, 0); builder.set(CaptureRequest.LENS_FOCUS_DISTANCE, Float.valueOf(0.0f)); } } @Override // c.o.a.n.i public void g0(int i2) { if (this.t == 0) { this.t = 35; } this.m.b(c.d.b.a.a.n("frame processing format (", i2, ")"), true, new k(i2)); } public boolean g1(@NonNull CaptureRequest.Builder builder, float f2) { if (this.o.l) { builder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, Integer.valueOf(Math.round(((Rational) t1(CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP, new Rational(1, 1))).floatValue() * this.D))); return true; } this.D = f2; return false; } public boolean h1(@NonNull CaptureRequest.Builder builder, @NonNull c.o.a.m.f fVar) { if (this.o.c(this.v)) { int[] iArr = (int[]) t1(CameraCharacteristics.CONTROL_AE_AVAILABLE_MODES, new int[0]); ArrayList arrayList = new ArrayList(); for (int i2 : iArr) { arrayList.add(Integer.valueOf(i2)); } c.o.a.n.q.b bVar = this.f1484j0; c.o.a.m.f fVar2 = this.v; Objects.requireNonNull(bVar); ArrayList arrayList2 = new ArrayList(); int ordinal = fVar2.ordinal(); if (ordinal == 0) { arrayList2.add(new Pair(1, 0)); arrayList2.add(new Pair(0, 0)); } else if (ordinal == 1) { arrayList2.add(new Pair(3, 0)); } else if (ordinal == 2) { arrayList2.add(new Pair(2, 0)); arrayList2.add(new Pair(4, 0)); } else if (ordinal == 3) { arrayList2.add(new Pair(1, 2)); arrayList2.add(new Pair(0, 2)); } Iterator it = arrayList2.iterator(); while (it.hasNext()) { Pair pair = (Pair) it.next(); if (arrayList.contains(pair.first)) { c.o.a.b bVar2 = i.i; bVar2.a(1, "applyFlash: setting CONTROL_AE_MODE to", pair.first); bVar2.a(1, "applyFlash: setting FLASH_MODE to", pair.second); builder.set(CaptureRequest.CONTROL_AE_MODE, pair.first); builder.set(CaptureRequest.FLASH_MODE, pair.second); return true; } } } this.v = fVar; return false; } public boolean i1(@NonNull CaptureRequest.Builder builder, @NonNull c.o.a.m.h hVar) { if (this.o.c(this.f1490z)) { c.o.a.n.q.b bVar = this.f1484j0; c.o.a.m.h hVar2 = this.f1490z; Objects.requireNonNull(bVar); builder.set(CaptureRequest.CONTROL_SCENE_MODE, Integer.valueOf(c.o.a.n.q.b.d.get(hVar2).intValue())); return true; } this.f1490z = hVar; return false; } /* JADX WARNING: Removed duplicated region for block: B:11:0x0038 */ public boolean j1(@NonNull CaptureRequest.Builder builder, float f2) { Range[] rangeArr = (Range[]) t1(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, new Range[0]); Arrays.sort(rangeArr, new e(this, this.I && this.H != 0.0f)); float f3 = this.H; if (f3 == 0.0f) { Iterator it = ((ArrayList) r1(rangeArr)).iterator(); while (it.hasNext()) { Range range = (Range) it.next(); if (range.contains((Range) 30) || range.contains((Range) 24)) { builder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, range); return true; } while (it.hasNext()) { } } } else { float min = Math.min(f3, this.o.q); this.H = min; this.H = Math.max(min, this.o.p); Iterator it2 = ((ArrayList) r1(rangeArr)).iterator(); while (it2.hasNext()) { Range range2 = (Range) it2.next(); if (range2.contains((Range) Integer.valueOf(Math.round(this.H)))) { builder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, range2); return true; } } } this.H = f2; return false; } @Override // c.o.a.n.i public void k0(boolean z2) { c.o.a.n.v.f fVar = this.m; fVar.b("has frame processors (" + z2 + ")", true, new j(z2)); } public void k1() { l1(true, 3); } @Override // c.o.a.n.i public void l0(@NonNull c.o.a.m.h hVar) { c.o.a.m.h hVar2 = this.f1490z; this.f1490z = hVar; c.o.a.n.v.f fVar = this.m; fVar.b("hdr (" + hVar + ")", true, new c.o.a.n.v.h(fVar, c.o.a.n.v.e.ENGINE, new RunnableC0161d(hVar2))); } public final void l1(boolean z2, int i2) { if ((this.m.f == c.o.a.n.v.e.PREVIEW && !O()) || !z2) { try { this.f1481g0.setRepeatingRequest(this.f1482h0.build(), this.q0, null); } catch (CameraAccessException e2) { throw new CameraException(e2, i2); } catch (IllegalStateException e3) { c.o.a.b bVar = i.i; c.o.a.n.v.f fVar = this.m; bVar.a(3, "applyRepeatingRequestBuilder: session is invalid!", e3, "checkStarted:", Boolean.valueOf(z2), "currentThread:", Thread.currentThread().getName(), "state:", fVar.f, "targetState:", fVar.g); throw new CameraException(3); } } } @Override // c.o.a.n.i public void m0(@Nullable Location location) { Location location2 = this.B; this.B = location; c.o.a.n.v.f fVar = this.m; fVar.b("location", true, new c.o.a.n.v.h(fVar, c.o.a.n.v.e.ENGINE, new b(location2))); } public boolean m1(@NonNull CaptureRequest.Builder builder, @NonNull c.o.a.m.m mVar) { if (this.o.c(this.w)) { c.o.a.n.q.b bVar = this.f1484j0; c.o.a.m.m mVar2 = this.w; Objects.requireNonNull(bVar); builder.set(CaptureRequest.CONTROL_AWB_MODE, Integer.valueOf(c.o.a.n.q.b.f1493c.get(mVar2).intValue())); return true; } this.w = mVar; return false; } public boolean n1(@NonNull CaptureRequest.Builder builder, float f2) { if (this.o.k) { float floatValue = ((Float) t1(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, Float.valueOf(1.0f))).floatValue(); float f3 = floatValue - 1.0f; Rect rect = (Rect) t1(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE, new Rect()); int height = (int) (((float) rect.height()) / floatValue); int width = rect.width() - ((int) (((float) rect.width()) / floatValue)); int height2 = rect.height() - height; float f4 = ((this.C * f3) + 1.0f) - 1.0f; int i2 = (int) (((((float) width) * f4) / f3) / 2.0f); int i3 = (int) (((((float) height2) * f4) / f3) / 2.0f); builder.set(CaptureRequest.SCALER_CROP_REGION, new Rect(i2, i3, rect.width() - i2, rect.height() - i3)); return true; } this.C = f2; return false; } @NonNull public final CameraException o1(@NonNull CameraAccessException cameraAccessException) { int reason = cameraAccessException.getReason(); int i2 = 3; if (reason != 1) { if (!(reason == 2 || reason == 3)) { if (!(reason == 4 || reason == 5)) { i2 = 0; } } return new CameraException(cameraAccessException, i2); } i2 = 1; return new CameraException(cameraAccessException, i2); } @Override // android.media.ImageReader.OnImageAvailableListener public void onImageAvailable(ImageReader imageReader) { i.i.a(0, "onImageAvailable:", "trying to acquire Image."); Image image = null; try { image = imageReader.acquireLatestImage(); } catch (Exception unused) { } if (image == null) { i.i.a(2, "onImageAvailable:", "failed to acquire Image!"); } else if (this.m.f != c.o.a.n.v.e.PREVIEW || O()) { i.i.a(1, "onImageAvailable:", "Image acquired in wrong state. Closing it now."); image.close(); } else { c.o.a.p.b a2 = S0().a(image, System.currentTimeMillis()); if (a2 != null) { i.i.a(0, "onImageAvailable:", "Image acquired, dispatching."); ((CameraView.b) this.l).b(a2); return; } i.i.a(1, "onImageAvailable:", "Image acquired, but no free frames. DROPPING."); } } @Override // c.o.a.n.i public void p0(@NonNull c.o.a.m.j jVar) { if (jVar != this.A) { this.A = jVar; c.o.a.n.v.f fVar = this.m; fVar.b("picture format (" + jVar + ")", true, new c.o.a.n.v.h(fVar, c.o.a.n.v.e.ENGINE, new h())); } } @NonNull public final c.o.a.n.r.g p1(@Nullable c.o.a.t.b bVar) { c.o.a.n.r.g gVar = this.p0; if (gVar != null) { gVar.a(this); } CaptureRequest.Builder builder = this.f1482h0; boolean z2 = false; int[] iArr = (int[]) t1(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES, new int[0]); ArrayList arrayList = new ArrayList(); for (int i2 : iArr) { arrayList.add(Integer.valueOf(i2)); } if (arrayList.contains(1)) { builder.set(CaptureRequest.CONTROL_AF_MODE, 1); } else if (this.P == c.o.a.m.i.VIDEO && arrayList.contains(3)) { builder.set(CaptureRequest.CONTROL_AF_MODE, 3); } else if (arrayList.contains(4)) { builder.set(CaptureRequest.CONTROL_AF_MODE, 4); } if (bVar == null) { z2 = true; } c.o.a.n.r.g gVar2 = new c.o.a.n.r.g(this, bVar, z2); this.p0 = gVar2; return gVar2; } @NonNull public final CaptureRequest.Builder q1(int i2) throws CameraAccessException { CaptureRequest.Builder builder = this.f1482h0; CaptureRequest.Builder createCaptureRequest = this.f1479e0.createCaptureRequest(i2); this.f1482h0 = createCaptureRequest; createCaptureRequest.setTag(Integer.valueOf(i2)); d1(this.f1482h0, builder); return this.f1482h0; } @NonNull public List> r1(@NonNull Range[] rangeArr) { ArrayList arrayList = new ArrayList(); int round = Math.round(this.o.p); int round2 = Math.round(this.o.q); for (Range range : rangeArr) { if (range.contains((Range) Integer.valueOf(round)) && range.contains((Range) Integer.valueOf(round2))) { c.o.a.b bVar = c.o.a.r.b.a; String str = Build.MODEL; boolean z2 = true; String str2 = Build.MANUFACTURER; bVar.a(1, "Build.MODEL:", str, "Build.BRAND:", Build.BRAND, "Build.MANUFACTURER:", str2); List> list = c.o.a.r.b.b.get(str2 + " " + str); if (list != null && list.contains(range)) { bVar.a(1, "Dropping range:", range); z2 = false; } if (z2) { arrayList.add(range); } } } return arrayList; } @NonNull public List s1() { try { StreamConfigurationMap streamConfigurationMap = (StreamConfigurationMap) this.f1477c0.getCameraCharacteristics(this.f1478d0).get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); if (streamConfigurationMap != null) { Size[] outputSizes = streamConfigurationMap.getOutputSizes(this.t); ArrayList arrayList = new ArrayList(outputSizes.length); for (Size size : outputSizes) { c.o.a.x.b bVar = new c.o.a.x.b(size.getWidth(), size.getHeight()); if (!arrayList.contains(bVar)) { arrayList.add(bVar); } } return arrayList; } throw new RuntimeException("StreamConfigurationMap is null. Should not happen."); } catch (CameraAccessException e2) { throw o1(e2); } } @Override // c.o.a.n.i public void t0(boolean z2) { this.E = z2; c.i.a.f.e.o.c.F(null); } @NonNull @VisibleForTesting public T t1(@NonNull CameraCharacteristics.Key key, @NonNull T t) { T t2 = (T) this.f1480f0.get(key); return t2 == null ? t : t2; } @NonNull public final T u1(@NonNull CameraCharacteristics cameraCharacteristics, @NonNull CameraCharacteristics.Key key, @NonNull T t) { T t2 = (T) cameraCharacteristics.get(key); return t2 == null ? t : t2; } @Override // c.o.a.n.i public void v0(float f2) { float f3 = this.H; this.H = f2; c.o.a.n.v.f fVar = this.m; fVar.b("preview fps (" + f2 + ")", true, new c.o.a.n.v.h(fVar, c.o.a.n.v.e.ENGINE, new g(f3))); } }