2021-06-27 20:44:35 +00:00
|
|
|
package androidx.activity;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
|
|
|
import androidx.annotation.MainThread;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.RequiresApi;
|
|
|
|
import androidx.lifecycle.Lifecycle;
|
|
|
|
import androidx.lifecycle.LifecycleEventObserver;
|
|
|
|
import androidx.lifecycle.LifecycleOwner;
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
@RequiresApi(19)
|
2022-03-02 20:59:20 +00:00
|
|
|
/* loaded from: classes.dex */
|
2021-06-27 20:44:35 +00:00
|
|
|
public final class ImmLeaksCleaner implements LifecycleEventObserver {
|
|
|
|
private static final int INIT_FAILED = 2;
|
|
|
|
private static final int INIT_SUCCESS = 1;
|
|
|
|
private static final int NOT_INITIALIAZED = 0;
|
|
|
|
private static Field sHField;
|
|
|
|
private static Field sNextServedViewField;
|
|
|
|
private static int sReflectedFieldsInitialized;
|
|
|
|
private static Field sServedViewField;
|
|
|
|
private Activity mActivity;
|
|
|
|
|
|
|
|
public ImmLeaksCleaner(Activity activity) {
|
|
|
|
this.mActivity = activity;
|
|
|
|
}
|
|
|
|
|
|
|
|
@MainThread
|
|
|
|
private static void initializeReflectiveFields() {
|
|
|
|
try {
|
|
|
|
sReflectedFieldsInitialized = 2;
|
|
|
|
Field declaredField = InputMethodManager.class.getDeclaredField("mServedView");
|
|
|
|
sServedViewField = declaredField;
|
|
|
|
declaredField.setAccessible(true);
|
|
|
|
Field declaredField2 = InputMethodManager.class.getDeclaredField("mNextServedView");
|
|
|
|
sNextServedViewField = declaredField2;
|
|
|
|
declaredField2.setAccessible(true);
|
|
|
|
Field declaredField3 = InputMethodManager.class.getDeclaredField("mH");
|
|
|
|
sHField = declaredField3;
|
|
|
|
declaredField3.setAccessible(true);
|
|
|
|
sReflectedFieldsInitialized = 1;
|
|
|
|
} catch (NoSuchFieldException unused) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // androidx.lifecycle.LifecycleEventObserver
|
|
|
|
public void onStateChanged(@NonNull LifecycleOwner lifecycleOwner, @NonNull Lifecycle.Event event) {
|
|
|
|
if (event == Lifecycle.Event.ON_DESTROY) {
|
|
|
|
if (sReflectedFieldsInitialized == 0) {
|
|
|
|
initializeReflectiveFields();
|
|
|
|
}
|
|
|
|
if (sReflectedFieldsInitialized == 1) {
|
|
|
|
InputMethodManager inputMethodManager = (InputMethodManager) this.mActivity.getSystemService("input_method");
|
|
|
|
try {
|
|
|
|
Object obj = sHField.get(inputMethodManager);
|
|
|
|
if (obj != null) {
|
|
|
|
synchronized (obj) {
|
|
|
|
try {
|
2022-03-02 20:59:20 +00:00
|
|
|
try {
|
|
|
|
View view = (View) sServedViewField.get(inputMethodManager);
|
|
|
|
if (view != null) {
|
|
|
|
if (!view.isAttachedToWindow()) {
|
|
|
|
try {
|
|
|
|
sNextServedViewField.set(inputMethodManager, null);
|
|
|
|
inputMethodManager.isActive();
|
|
|
|
} catch (IllegalAccessException unused) {
|
|
|
|
}
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-02 20:59:20 +00:00
|
|
|
} catch (Throwable th) {
|
|
|
|
throw th;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
2022-03-02 20:59:20 +00:00
|
|
|
} catch (ClassCastException unused2) {
|
|
|
|
} catch (IllegalAccessException unused3) {
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IllegalAccessException unused4) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|