- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
424 lines
21 KiB
Java
424 lines
21 KiB
Java
package androidx.fragment.app.strictmode;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.os.Handler;
|
|
import android.os.Looper;
|
|
import android.util.Log;
|
|
import android.view.ViewGroup;
|
|
import androidx.annotation.RestrictTo;
|
|
import androidx.annotation.VisibleForTesting;
|
|
import androidx.fragment.app.Fragment;
|
|
import androidx.fragment.app.FragmentManager;
|
|
import androidx.fragment.app.strictmode.FragmentStrictMode;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.LinkedHashSet;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import kotlin.collections.CollectionsKt___CollectionsKt;
|
|
import kotlin.collections.MapsKt__MapsKt;
|
|
import kotlin.collections.SetsKt__SetsKt;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlin.jvm.internal.Intrinsics;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class FragmentStrictMode {
|
|
private static final String TAG = "FragmentStrictMode";
|
|
public static final FragmentStrictMode INSTANCE = new FragmentStrictMode();
|
|
private static Policy defaultPolicy = Policy.LAX;
|
|
|
|
public enum Flag {
|
|
PENALTY_LOG,
|
|
PENALTY_DEATH,
|
|
DETECT_FRAGMENT_REUSE,
|
|
DETECT_FRAGMENT_TAG_USAGE,
|
|
DETECT_RETAIN_INSTANCE_USAGE,
|
|
DETECT_SET_USER_VISIBLE_HINT,
|
|
DETECT_TARGET_FRAGMENT_USAGE,
|
|
DETECT_WRONG_FRAGMENT_CONTAINER
|
|
}
|
|
|
|
public interface OnViolationListener {
|
|
void onViolation(Violation violation);
|
|
}
|
|
|
|
public final Policy getDefaultPolicy() {
|
|
return defaultPolicy;
|
|
}
|
|
|
|
public final void setDefaultPolicy(Policy policy) {
|
|
Intrinsics.checkNotNullParameter(policy, "<set-?>");
|
|
defaultPolicy = policy;
|
|
}
|
|
|
|
private FragmentStrictMode() {
|
|
}
|
|
|
|
private final Policy getNearestPolicy(Fragment fragment) {
|
|
while (fragment != null) {
|
|
if (fragment.isAdded()) {
|
|
FragmentManager parentFragmentManager = fragment.getParentFragmentManager();
|
|
Intrinsics.checkNotNullExpressionValue(parentFragmentManager, "declaringFragment.parentFragmentManager");
|
|
if (parentFragmentManager.getStrictModePolicy() != null) {
|
|
Policy strictModePolicy = parentFragmentManager.getStrictModePolicy();
|
|
Intrinsics.checkNotNull(strictModePolicy);
|
|
return strictModePolicy;
|
|
}
|
|
}
|
|
fragment = fragment.getParentFragment();
|
|
}
|
|
return defaultPolicy;
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public static final void onFragmentReuse(Fragment fragment, String previousFragmentId) {
|
|
Intrinsics.checkNotNullParameter(fragment, "fragment");
|
|
Intrinsics.checkNotNullParameter(previousFragmentId, "previousFragmentId");
|
|
FragmentReuseViolation fragmentReuseViolation = new FragmentReuseViolation(fragment, previousFragmentId);
|
|
FragmentStrictMode fragmentStrictMode = INSTANCE;
|
|
fragmentStrictMode.logIfDebuggingEnabled(fragmentReuseViolation);
|
|
Policy nearestPolicy = fragmentStrictMode.getNearestPolicy(fragment);
|
|
if (nearestPolicy.getFlags$fragment_release().contains(Flag.DETECT_FRAGMENT_REUSE) && fragmentStrictMode.shouldHandlePolicyViolation(nearestPolicy, fragment.getClass(), fragmentReuseViolation.getClass())) {
|
|
fragmentStrictMode.handlePolicyViolation(nearestPolicy, fragmentReuseViolation);
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public static final void onFragmentTagUsage(Fragment fragment, ViewGroup viewGroup) {
|
|
Intrinsics.checkNotNullParameter(fragment, "fragment");
|
|
FragmentTagUsageViolation fragmentTagUsageViolation = new FragmentTagUsageViolation(fragment, viewGroup);
|
|
FragmentStrictMode fragmentStrictMode = INSTANCE;
|
|
fragmentStrictMode.logIfDebuggingEnabled(fragmentTagUsageViolation);
|
|
Policy nearestPolicy = fragmentStrictMode.getNearestPolicy(fragment);
|
|
if (nearestPolicy.getFlags$fragment_release().contains(Flag.DETECT_FRAGMENT_TAG_USAGE) && fragmentStrictMode.shouldHandlePolicyViolation(nearestPolicy, fragment.getClass(), fragmentTagUsageViolation.getClass())) {
|
|
fragmentStrictMode.handlePolicyViolation(nearestPolicy, fragmentTagUsageViolation);
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public static final void onSetRetainInstanceUsage(Fragment fragment) {
|
|
Intrinsics.checkNotNullParameter(fragment, "fragment");
|
|
SetRetainInstanceUsageViolation setRetainInstanceUsageViolation = new SetRetainInstanceUsageViolation(fragment);
|
|
FragmentStrictMode fragmentStrictMode = INSTANCE;
|
|
fragmentStrictMode.logIfDebuggingEnabled(setRetainInstanceUsageViolation);
|
|
Policy nearestPolicy = fragmentStrictMode.getNearestPolicy(fragment);
|
|
if (nearestPolicy.getFlags$fragment_release().contains(Flag.DETECT_RETAIN_INSTANCE_USAGE) && fragmentStrictMode.shouldHandlePolicyViolation(nearestPolicy, fragment.getClass(), setRetainInstanceUsageViolation.getClass())) {
|
|
fragmentStrictMode.handlePolicyViolation(nearestPolicy, setRetainInstanceUsageViolation);
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public static final void onGetRetainInstanceUsage(Fragment fragment) {
|
|
Intrinsics.checkNotNullParameter(fragment, "fragment");
|
|
GetRetainInstanceUsageViolation getRetainInstanceUsageViolation = new GetRetainInstanceUsageViolation(fragment);
|
|
FragmentStrictMode fragmentStrictMode = INSTANCE;
|
|
fragmentStrictMode.logIfDebuggingEnabled(getRetainInstanceUsageViolation);
|
|
Policy nearestPolicy = fragmentStrictMode.getNearestPolicy(fragment);
|
|
if (nearestPolicy.getFlags$fragment_release().contains(Flag.DETECT_RETAIN_INSTANCE_USAGE) && fragmentStrictMode.shouldHandlePolicyViolation(nearestPolicy, fragment.getClass(), getRetainInstanceUsageViolation.getClass())) {
|
|
fragmentStrictMode.handlePolicyViolation(nearestPolicy, getRetainInstanceUsageViolation);
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public static final void onSetUserVisibleHint(Fragment fragment, boolean z) {
|
|
Intrinsics.checkNotNullParameter(fragment, "fragment");
|
|
SetUserVisibleHintViolation setUserVisibleHintViolation = new SetUserVisibleHintViolation(fragment, z);
|
|
FragmentStrictMode fragmentStrictMode = INSTANCE;
|
|
fragmentStrictMode.logIfDebuggingEnabled(setUserVisibleHintViolation);
|
|
Policy nearestPolicy = fragmentStrictMode.getNearestPolicy(fragment);
|
|
if (nearestPolicy.getFlags$fragment_release().contains(Flag.DETECT_SET_USER_VISIBLE_HINT) && fragmentStrictMode.shouldHandlePolicyViolation(nearestPolicy, fragment.getClass(), setUserVisibleHintViolation.getClass())) {
|
|
fragmentStrictMode.handlePolicyViolation(nearestPolicy, setUserVisibleHintViolation);
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public static final void onSetTargetFragmentUsage(Fragment violatingFragment, Fragment targetFragment, int i) {
|
|
Intrinsics.checkNotNullParameter(violatingFragment, "violatingFragment");
|
|
Intrinsics.checkNotNullParameter(targetFragment, "targetFragment");
|
|
SetTargetFragmentUsageViolation setTargetFragmentUsageViolation = new SetTargetFragmentUsageViolation(violatingFragment, targetFragment, i);
|
|
FragmentStrictMode fragmentStrictMode = INSTANCE;
|
|
fragmentStrictMode.logIfDebuggingEnabled(setTargetFragmentUsageViolation);
|
|
Policy nearestPolicy = fragmentStrictMode.getNearestPolicy(violatingFragment);
|
|
if (nearestPolicy.getFlags$fragment_release().contains(Flag.DETECT_TARGET_FRAGMENT_USAGE) && fragmentStrictMode.shouldHandlePolicyViolation(nearestPolicy, violatingFragment.getClass(), setTargetFragmentUsageViolation.getClass())) {
|
|
fragmentStrictMode.handlePolicyViolation(nearestPolicy, setTargetFragmentUsageViolation);
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public static final void onGetTargetFragmentUsage(Fragment fragment) {
|
|
Intrinsics.checkNotNullParameter(fragment, "fragment");
|
|
GetTargetFragmentUsageViolation getTargetFragmentUsageViolation = new GetTargetFragmentUsageViolation(fragment);
|
|
FragmentStrictMode fragmentStrictMode = INSTANCE;
|
|
fragmentStrictMode.logIfDebuggingEnabled(getTargetFragmentUsageViolation);
|
|
Policy nearestPolicy = fragmentStrictMode.getNearestPolicy(fragment);
|
|
if (nearestPolicy.getFlags$fragment_release().contains(Flag.DETECT_TARGET_FRAGMENT_USAGE) && fragmentStrictMode.shouldHandlePolicyViolation(nearestPolicy, fragment.getClass(), getTargetFragmentUsageViolation.getClass())) {
|
|
fragmentStrictMode.handlePolicyViolation(nearestPolicy, getTargetFragmentUsageViolation);
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public static final void onGetTargetFragmentRequestCodeUsage(Fragment fragment) {
|
|
Intrinsics.checkNotNullParameter(fragment, "fragment");
|
|
GetTargetFragmentRequestCodeUsageViolation getTargetFragmentRequestCodeUsageViolation = new GetTargetFragmentRequestCodeUsageViolation(fragment);
|
|
FragmentStrictMode fragmentStrictMode = INSTANCE;
|
|
fragmentStrictMode.logIfDebuggingEnabled(getTargetFragmentRequestCodeUsageViolation);
|
|
Policy nearestPolicy = fragmentStrictMode.getNearestPolicy(fragment);
|
|
if (nearestPolicy.getFlags$fragment_release().contains(Flag.DETECT_TARGET_FRAGMENT_USAGE) && fragmentStrictMode.shouldHandlePolicyViolation(nearestPolicy, fragment.getClass(), getTargetFragmentRequestCodeUsageViolation.getClass())) {
|
|
fragmentStrictMode.handlePolicyViolation(nearestPolicy, getTargetFragmentRequestCodeUsageViolation);
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public static final void onWrongFragmentContainer(Fragment fragment, ViewGroup container) {
|
|
Intrinsics.checkNotNullParameter(fragment, "fragment");
|
|
Intrinsics.checkNotNullParameter(container, "container");
|
|
WrongFragmentContainerViolation wrongFragmentContainerViolation = new WrongFragmentContainerViolation(fragment, container);
|
|
FragmentStrictMode fragmentStrictMode = INSTANCE;
|
|
fragmentStrictMode.logIfDebuggingEnabled(wrongFragmentContainerViolation);
|
|
Policy nearestPolicy = fragmentStrictMode.getNearestPolicy(fragment);
|
|
if (nearestPolicy.getFlags$fragment_release().contains(Flag.DETECT_WRONG_FRAGMENT_CONTAINER) && fragmentStrictMode.shouldHandlePolicyViolation(nearestPolicy, fragment.getClass(), wrongFragmentContainerViolation.getClass())) {
|
|
fragmentStrictMode.handlePolicyViolation(nearestPolicy, wrongFragmentContainerViolation);
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@VisibleForTesting
|
|
public final void onPolicyViolation(Violation violation) {
|
|
Intrinsics.checkNotNullParameter(violation, "violation");
|
|
logIfDebuggingEnabled(violation);
|
|
Fragment fragment = violation.getFragment();
|
|
Policy nearestPolicy = getNearestPolicy(fragment);
|
|
if (shouldHandlePolicyViolation(nearestPolicy, fragment.getClass(), violation.getClass())) {
|
|
handlePolicyViolation(nearestPolicy, violation);
|
|
}
|
|
}
|
|
|
|
private final void logIfDebuggingEnabled(Violation violation) {
|
|
if (FragmentManager.isLoggingEnabled(3)) {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("StrictMode violation in ");
|
|
sb.append(violation.getFragment().getClass().getName());
|
|
}
|
|
}
|
|
|
|
private final boolean shouldHandlePolicyViolation(Policy policy, Class<? extends Fragment> cls, Class<? extends Violation> cls2) {
|
|
boolean contains;
|
|
Set<Class<? extends Violation>> set = policy.getMAllowedViolations$fragment_release().get(cls.getName());
|
|
if (set == null) {
|
|
return true;
|
|
}
|
|
if (!Intrinsics.areEqual(cls2.getSuperclass(), Violation.class)) {
|
|
contains = CollectionsKt___CollectionsKt.contains(set, cls2.getSuperclass());
|
|
if (contains) {
|
|
return false;
|
|
}
|
|
}
|
|
return !set.contains(cls2);
|
|
}
|
|
|
|
private final void handlePolicyViolation(final Policy policy, final Violation violation) {
|
|
Fragment fragment = violation.getFragment();
|
|
final String name = fragment.getClass().getName();
|
|
if (policy.getFlags$fragment_release().contains(Flag.PENALTY_LOG)) {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Policy violation in ");
|
|
sb.append(name);
|
|
}
|
|
if (policy.getListener$fragment_release() != null) {
|
|
runOnHostThread(fragment, new Runnable() { // from class: androidx.fragment.app.strictmode.FragmentStrictMode$$ExternalSyntheticLambda0
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
FragmentStrictMode.m154handlePolicyViolation$lambda0(FragmentStrictMode.Policy.this, violation);
|
|
}
|
|
});
|
|
}
|
|
if (policy.getFlags$fragment_release().contains(Flag.PENALTY_DEATH)) {
|
|
runOnHostThread(fragment, new Runnable() { // from class: androidx.fragment.app.strictmode.FragmentStrictMode$$ExternalSyntheticLambda1
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
FragmentStrictMode.m155handlePolicyViolation$lambda1(name, violation);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
/* renamed from: handlePolicyViolation$lambda-0, reason: not valid java name */
|
|
public static final void m154handlePolicyViolation$lambda0(Policy policy, Violation violation) {
|
|
Intrinsics.checkNotNullParameter(policy, "$policy");
|
|
Intrinsics.checkNotNullParameter(violation, "$violation");
|
|
policy.getListener$fragment_release().onViolation(violation);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
/* renamed from: handlePolicyViolation$lambda-1, reason: not valid java name */
|
|
public static final void m155handlePolicyViolation$lambda1(String str, Violation violation) {
|
|
Intrinsics.checkNotNullParameter(violation, "$violation");
|
|
Log.e(TAG, "Policy violation with PENALTY_DEATH in " + str, violation);
|
|
throw violation;
|
|
}
|
|
|
|
private final void runOnHostThread(Fragment fragment, Runnable runnable) {
|
|
if (fragment.isAdded()) {
|
|
Handler handler = fragment.getParentFragmentManager().getHost().getHandler();
|
|
Intrinsics.checkNotNullExpressionValue(handler, "fragment.parentFragmentManager.host.handler");
|
|
if (Intrinsics.areEqual(handler.getLooper(), Looper.myLooper())) {
|
|
runnable.run();
|
|
return;
|
|
} else {
|
|
handler.post(runnable);
|
|
return;
|
|
}
|
|
}
|
|
runnable.run();
|
|
}
|
|
|
|
public static final class Policy {
|
|
public static final Companion Companion = new Companion(null);
|
|
public static final Policy LAX;
|
|
private final Set<Flag> flags;
|
|
private final OnViolationListener listener;
|
|
private final Map<String, Set<Class<? extends Violation>>> mAllowedViolations;
|
|
|
|
public final Set<Flag> getFlags$fragment_release() {
|
|
return this.flags;
|
|
}
|
|
|
|
public final OnViolationListener getListener$fragment_release() {
|
|
return this.listener;
|
|
}
|
|
|
|
public final Map<String, Set<Class<? extends Violation>>> getMAllowedViolations$fragment_release() {
|
|
return this.mAllowedViolations;
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public Policy(Set<? extends Flag> flags, OnViolationListener onViolationListener, Map<String, ? extends Set<Class<? extends Violation>>> allowedViolations) {
|
|
Intrinsics.checkNotNullParameter(flags, "flags");
|
|
Intrinsics.checkNotNullParameter(allowedViolations, "allowedViolations");
|
|
this.flags = flags;
|
|
this.listener = onViolationListener;
|
|
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
|
for (Map.Entry<String, ? extends Set<Class<? extends Violation>>> entry : allowedViolations.entrySet()) {
|
|
linkedHashMap.put(entry.getKey(), entry.getValue());
|
|
}
|
|
this.mAllowedViolations = linkedHashMap;
|
|
}
|
|
|
|
public static final class Builder {
|
|
private OnViolationListener listener;
|
|
private final Set<Flag> flags = new LinkedHashSet();
|
|
private final Map<String, Set<Class<? extends Violation>>> mAllowedViolations = new LinkedHashMap();
|
|
|
|
@SuppressLint({"BuilderSetStyle"})
|
|
public final Builder penaltyListener(OnViolationListener listener) {
|
|
Intrinsics.checkNotNullParameter(listener, "listener");
|
|
this.listener = listener;
|
|
return this;
|
|
}
|
|
|
|
@SuppressLint({"BuilderSetStyle"})
|
|
public final Builder penaltyLog() {
|
|
this.flags.add(Flag.PENALTY_LOG);
|
|
return this;
|
|
}
|
|
|
|
@SuppressLint({"BuilderSetStyle"})
|
|
public final Builder penaltyDeath() {
|
|
this.flags.add(Flag.PENALTY_DEATH);
|
|
return this;
|
|
}
|
|
|
|
@SuppressLint({"BuilderSetStyle"})
|
|
public final Builder detectFragmentReuse() {
|
|
this.flags.add(Flag.DETECT_FRAGMENT_REUSE);
|
|
return this;
|
|
}
|
|
|
|
@SuppressLint({"BuilderSetStyle"})
|
|
public final Builder detectFragmentTagUsage() {
|
|
this.flags.add(Flag.DETECT_FRAGMENT_TAG_USAGE);
|
|
return this;
|
|
}
|
|
|
|
@SuppressLint({"BuilderSetStyle"})
|
|
public final Builder detectRetainInstanceUsage() {
|
|
this.flags.add(Flag.DETECT_RETAIN_INSTANCE_USAGE);
|
|
return this;
|
|
}
|
|
|
|
@SuppressLint({"BuilderSetStyle"})
|
|
public final Builder detectSetUserVisibleHint() {
|
|
this.flags.add(Flag.DETECT_SET_USER_VISIBLE_HINT);
|
|
return this;
|
|
}
|
|
|
|
@SuppressLint({"BuilderSetStyle"})
|
|
public final Builder detectTargetFragmentUsage() {
|
|
this.flags.add(Flag.DETECT_TARGET_FRAGMENT_USAGE);
|
|
return this;
|
|
}
|
|
|
|
@SuppressLint({"BuilderSetStyle"})
|
|
public final Builder detectWrongFragmentContainer() {
|
|
this.flags.add(Flag.DETECT_WRONG_FRAGMENT_CONTAINER);
|
|
return this;
|
|
}
|
|
|
|
@SuppressLint({"BuilderSetStyle"})
|
|
public final Builder allowViolation(Class<? extends Fragment> fragmentClass, Class<? extends Violation> violationClass) {
|
|
Intrinsics.checkNotNullParameter(fragmentClass, "fragmentClass");
|
|
Intrinsics.checkNotNullParameter(violationClass, "violationClass");
|
|
String fragmentClassString = fragmentClass.getName();
|
|
Intrinsics.checkNotNullExpressionValue(fragmentClassString, "fragmentClassString");
|
|
return allowViolation(fragmentClassString, violationClass);
|
|
}
|
|
|
|
@SuppressLint({"BuilderSetStyle"})
|
|
public final Builder allowViolation(String fragmentClass, Class<? extends Violation> violationClass) {
|
|
Intrinsics.checkNotNullParameter(fragmentClass, "fragmentClass");
|
|
Intrinsics.checkNotNullParameter(violationClass, "violationClass");
|
|
Set<Class<? extends Violation>> set = this.mAllowedViolations.get(fragmentClass);
|
|
if (set == null) {
|
|
set = new LinkedHashSet<>();
|
|
}
|
|
set.add(violationClass);
|
|
this.mAllowedViolations.put(fragmentClass, set);
|
|
return this;
|
|
}
|
|
|
|
public final Policy build() {
|
|
if (this.listener == null && !this.flags.contains(Flag.PENALTY_DEATH)) {
|
|
penaltyLog();
|
|
}
|
|
return new Policy(this.flags, this.listener, this.mAllowedViolations);
|
|
}
|
|
}
|
|
|
|
public static final class Companion {
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
private Companion() {
|
|
}
|
|
}
|
|
|
|
static {
|
|
Set emptySet;
|
|
Map emptyMap;
|
|
emptySet = SetsKt__SetsKt.emptySet();
|
|
emptyMap = MapsKt__MapsKt.emptyMap();
|
|
LAX = new Policy(emptySet, null, emptyMap);
|
|
}
|
|
}
|
|
}
|