package io.grpc.okhttp; import com.google.common.base.Preconditions; import io.flutter.embedding.android.KeyboardMap; import io.grpc.okhttp.OkHttpFrameLogger; import io.grpc.okhttp.internal.framed.ErrorCode; import io.grpc.okhttp.internal.framed.FrameWriter; import io.grpc.okhttp.internal.framed.Header; import io.grpc.okhttp.internal.framed.Settings; import java.io.IOException; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import o.C15111ghZ; import o.C15155gij; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public final class ExceptionHandlingFrameWriter implements FrameWriter { private static final Logger log = Logger.getLogger(OkHttpClientTransport.class.getName()); private final OkHttpFrameLogger frameLogger; private final FrameWriter frameWriter; private final TransportExceptionHandler transportExceptionHandler; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public interface TransportExceptionHandler { void onException(Throwable th); } /* JADX INFO: Access modifiers changed from: package-private */ public ExceptionHandlingFrameWriter(TransportExceptionHandler transportExceptionHandler, FrameWriter frameWriter) { this(transportExceptionHandler, frameWriter, new OkHttpFrameLogger(Level.FINE, (Class) OkHttpClientTransport.class)); } /* JADX INFO: Access modifiers changed from: package-private */ public ExceptionHandlingFrameWriter(TransportExceptionHandler transportExceptionHandler, FrameWriter frameWriter, OkHttpFrameLogger okHttpFrameLogger) { this.transportExceptionHandler = (TransportExceptionHandler) Preconditions.checkNotNull(transportExceptionHandler, "transportExceptionHandler"); this.frameWriter = (FrameWriter) Preconditions.checkNotNull(frameWriter, "frameWriter"); this.frameLogger = (OkHttpFrameLogger) Preconditions.checkNotNull(okHttpFrameLogger, "frameLogger"); } @Override // io.grpc.okhttp.internal.framed.FrameWriter public final void connectionPreface() { try { this.frameWriter.connectionPreface(); } catch (IOException e) { this.transportExceptionHandler.onException(e); } } @Override // io.grpc.okhttp.internal.framed.FrameWriter public final void ackSettings(Settings settings) { this.frameLogger.logSettingsAck(OkHttpFrameLogger.Direction.OUTBOUND); try { this.frameWriter.ackSettings(settings); } catch (IOException e) { this.transportExceptionHandler.onException(e); } } @Override // io.grpc.okhttp.internal.framed.FrameWriter public final void pushPromise(int i, int i2, List
list) { this.frameLogger.logPushPromise(OkHttpFrameLogger.Direction.OUTBOUND, i, i2, list); try { this.frameWriter.pushPromise(i, i2, list); } catch (IOException e) { this.transportExceptionHandler.onException(e); } } @Override // io.grpc.okhttp.internal.framed.FrameWriter public final void flush() { try { this.frameWriter.flush(); } catch (IOException e) { this.transportExceptionHandler.onException(e); } } @Override // io.grpc.okhttp.internal.framed.FrameWriter public final void synStream(boolean z, boolean z2, int i, int i2, List
list) { try { this.frameWriter.synStream(z, z2, i, i2, list); } catch (IOException e) { this.transportExceptionHandler.onException(e); } } @Override // io.grpc.okhttp.internal.framed.FrameWriter public final void synReply(boolean z, int i, List
list) { try { this.frameWriter.synReply(z, i, list); } catch (IOException e) { this.transportExceptionHandler.onException(e); } } @Override // io.grpc.okhttp.internal.framed.FrameWriter public final void headers(int i, List
list) { this.frameLogger.logHeaders(OkHttpFrameLogger.Direction.OUTBOUND, i, list, false); try { this.frameWriter.headers(i, list); } catch (IOException e) { this.transportExceptionHandler.onException(e); } } @Override // io.grpc.okhttp.internal.framed.FrameWriter public final void rstStream(int i, ErrorCode errorCode) { this.frameLogger.logRstStream(OkHttpFrameLogger.Direction.OUTBOUND, i, errorCode); try { this.frameWriter.rstStream(i, errorCode); } catch (IOException e) { this.transportExceptionHandler.onException(e); } } @Override // io.grpc.okhttp.internal.framed.FrameWriter public final int maxDataLength() { return this.frameWriter.maxDataLength(); } @Override // io.grpc.okhttp.internal.framed.FrameWriter public final void data(boolean z, int i, C15111ghZ c15111ghZ, int i2) { this.frameLogger.logData(OkHttpFrameLogger.Direction.OUTBOUND, i, c15111ghZ, i2, z); try { this.frameWriter.data(z, i, c15111ghZ, i2); } catch (IOException e) { this.transportExceptionHandler.onException(e); } } @Override // io.grpc.okhttp.internal.framed.FrameWriter public final void settings(Settings settings) { this.frameLogger.logSettings(OkHttpFrameLogger.Direction.OUTBOUND, settings); try { this.frameWriter.settings(settings); } catch (IOException e) { this.transportExceptionHandler.onException(e); } } @Override // io.grpc.okhttp.internal.framed.FrameWriter public final void ping(boolean z, int i, int i2) { if (z) { this.frameLogger.logPingAck(OkHttpFrameLogger.Direction.OUTBOUND, (KeyboardMap.kValueMask & i2) | (i << 32)); } else { this.frameLogger.logPing(OkHttpFrameLogger.Direction.OUTBOUND, (KeyboardMap.kValueMask & i2) | (i << 32)); } try { this.frameWriter.ping(z, i, i2); } catch (IOException e) { this.transportExceptionHandler.onException(e); } } @Override // io.grpc.okhttp.internal.framed.FrameWriter public final void goAway(int i, ErrorCode errorCode, byte[] bArr) { this.frameLogger.logGoAway(OkHttpFrameLogger.Direction.OUTBOUND, i, errorCode, C15155gij.e(bArr)); try { this.frameWriter.goAway(i, errorCode, bArr); this.frameWriter.flush(); } catch (IOException e) { this.transportExceptionHandler.onException(e); } } @Override // io.grpc.okhttp.internal.framed.FrameWriter public final void windowUpdate(int i, long j) { this.frameLogger.logWindowsUpdate(OkHttpFrameLogger.Direction.OUTBOUND, i, j); try { this.frameWriter.windowUpdate(i, j); } catch (IOException e) { this.transportExceptionHandler.onException(e); } } @Override // java.io.Closeable, java.lang.AutoCloseable public final void close() { try { this.frameWriter.close(); } catch (IOException e) { log.log(getLogLevel(e), "Failed closing connection", (Throwable) e); } } static Level getLogLevel(Throwable th) { if (th.getClass().equals(IOException.class)) { return Level.FINE; } return Level.INFO; } }