package androidx.activity; import android.app.Activity; import android.view.View; import android.view.inputmethod.InputMethodManager; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.e; import androidx.lifecycle.g; import java.lang.reflect.Field; /* loaded from: classes.dex */ final class ImmLeaksCleaner implements g { /* renamed from: b, reason: collision with root package name */ private static int f241b; /* renamed from: c, reason: collision with root package name */ private static Field f242c; /* renamed from: d, reason: collision with root package name */ private static Field f243d; /* renamed from: e, reason: collision with root package name */ private static Field f244e; /* renamed from: a, reason: collision with root package name */ private Activity f245a; ImmLeaksCleaner(Activity activity) { this.f245a = activity; } private static void a() { try { f241b = 2; Field declaredField = InputMethodManager.class.getDeclaredField("mServedView"); f243d = declaredField; declaredField.setAccessible(true); Field declaredField2 = InputMethodManager.class.getDeclaredField("mNextServedView"); f244e = declaredField2; declaredField2.setAccessible(true); Field declaredField3 = InputMethodManager.class.getDeclaredField("mH"); f242c = declaredField3; declaredField3.setAccessible(true); f241b = 1; } catch (NoSuchFieldException unused) { } } @Override // androidx.lifecycle.g public void onStateChanged(LifecycleOwner lifecycleOwner, e.b bVar) { if (bVar != e.b.ON_DESTROY) { return; } if (f241b == 0) { a(); } if (f241b == 1) { InputMethodManager inputMethodManager = (InputMethodManager) this.f245a.getSystemService("input_method"); try { Object obj = f242c.get(inputMethodManager); if (obj == null) { return; } synchronized (obj) { try { try { View view = (View) f243d.get(inputMethodManager); if (view == null) { return; } if (view.isAttachedToWindow()) { return; } try { f244e.set(inputMethodManager, null); inputMethodManager.isActive(); } catch (IllegalAccessException unused) { } } catch (ClassCastException unused2) { } catch (IllegalAccessException unused3) { } } catch (Throwable th) { throw th; } } } catch (IllegalAccessException unused4) { } } } }