package com.applovin.impl; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.view.WindowManager; import com.applovin.impl.sdk.ad.b; import com.applovin.sdk.AppLovinSdkUtils; /* loaded from: classes.dex */ public class yg { private final Activity a; private final int b; private final int c; private final boolean d; private final boolean e; private int a(int i, boolean z) { if (z && this.e) { if (i == 0) { return 0; } if (i == 1) { return 9; } if (i == 2) { return 8; } return i == 3 ? 1 : -1; } if (i == 0) { return 1; } if (i == 1) { return 0; } if (i == 2) { return 9; } return i == 3 ? 8 : -1; } public yg(Activity activity) { this.a = activity; int c = yp.c(activity); this.c = c; boolean isTablet = AppLovinSdkUtils.isTablet(activity); this.d = isTablet; this.b = a(c, isTablet); this.e = isTablet && 2 == a(activity); } private static int a(Context context) { Configuration configuration = context.getResources().getConfiguration(); int rotation = ((WindowManager) context.getSystemService("window")).getDefaultDisplay().getRotation(); return (((rotation == 0 || rotation == 2) && configuration.orientation == 2) || ((rotation == 1 || rotation == 3) && configuration.orientation == 1)) ? 2 : 1; } public void a(com.applovin.impl.sdk.ad.b bVar) { int i; if (bVar.E0() && (i = this.b) != -1) { a(i); } else { a(bVar.e0()); } } private void a(b.c cVar) { if (cVar != b.c.ACTIVITY_PORTRAIT) { if (cVar == b.c.ACTIVITY_LANDSCAPE) { if (this.d && this.e) { int i = this.c; if (i != 0 && i != 2) { a(0); return; } else { a(i != 2 ? 0 : 8); return; } } int i2 = this.c; if (i2 != 1 && i2 != 3) { a(0); return; } else { a(i2 == 1 ? 0 : 8); return; } } return; } if (!this.d || !this.e) { int i3 = this.c; if (i3 != 0 && i3 != 2) { a(1); return; } else { a(i3 != 0 ? 9 : 1); return; } } int i4 = this.c; if (i4 != 1 && i4 != 3) { a(1); } else if (i4 == 1) { a(9); } else { a(1); } } private void a(int i) { try { this.a.setRequestedOrientation(i); } catch (Throwable unused) { } } }