Rabbit-R1/original r1/java/sources/androidx/appcompat/app/LayoutIncludeDetector.java

67 lines
2.2 KiB
Java
Raw Normal View History

2024-05-21 16:08:36 -05:00
package androidx.appcompat.app;
import android.util.AttributeSet;
import java.lang.ref.WeakReference;
import java.util.ArrayDeque;
import java.util.Deque;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/* loaded from: classes.dex */
class LayoutIncludeDetector {
private final Deque<WeakReference<XmlPullParser>> mXmlParserStack = new ArrayDeque();
/* JADX INFO: Access modifiers changed from: package-private */
public boolean detect(AttributeSet attributeSet) {
if (!(attributeSet instanceof XmlPullParser)) {
return false;
}
XmlPullParser xmlPullParser = (XmlPullParser) attributeSet;
if (xmlPullParser.getDepth() != 1) {
return false;
}
XmlPullParser popOutdatedAttrHolders = popOutdatedAttrHolders(this.mXmlParserStack);
this.mXmlParserStack.push(new WeakReference<>(xmlPullParser));
return shouldInheritContext(xmlPullParser, popOutdatedAttrHolders);
}
private static boolean shouldInheritContext(XmlPullParser xmlPullParser, XmlPullParser xmlPullParser2) {
if (xmlPullParser2 == null || xmlPullParser == xmlPullParser2) {
return false;
}
try {
if (xmlPullParser2.getEventType() == 2) {
return "include".equals(xmlPullParser2.getName());
}
return false;
} catch (XmlPullParserException unused) {
return false;
}
}
private static XmlPullParser popOutdatedAttrHolders(Deque<WeakReference<XmlPullParser>> deque) {
while (!deque.isEmpty()) {
XmlPullParser xmlPullParser = deque.peek().get();
if (!isParserOutdated(xmlPullParser)) {
return xmlPullParser;
}
deque.pop();
}
return null;
}
private static boolean isParserOutdated(XmlPullParser xmlPullParser) {
if (xmlPullParser == null) {
return true;
}
try {
if (xmlPullParser.getEventType() != 3) {
return xmlPullParser.getEventType() == 1;
}
return true;
} catch (XmlPullParserException unused) {
return true;
}
}
}