413 lines
16 KiB
Java
413 lines
16 KiB
Java
package com.airbnb.deeplinkdispatch.base;
|
|
|
|
import com.airbnb.deeplinkdispatch.DeepLinkEntry;
|
|
import com.airbnb.deeplinkdispatch.DeepLinkMatchResult;
|
|
import com.airbnb.deeplinkdispatch.DeepLinkUri;
|
|
import com.airbnb.deeplinkdispatch.MatchType;
|
|
import com.airbnb.deeplinkdispatch.NodeMetadata;
|
|
import com.airbnb.deeplinkdispatch.UrlTreeKt;
|
|
import com.google.common.primitives.UnsignedBytes;
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class MatchIndex {
|
|
public static final char ALLOWED_VALUES_SEPARATOR = '|';
|
|
private static final String ALLOWED_VALUES_SEPARATOR_REGEX_STRING = "\\|";
|
|
public static final int HEADER_CHILDREN_LENGTH = 4;
|
|
public static final int HEADER_LENGTH = 9;
|
|
public static final int HEADER_MATCH_LENGTH = 2;
|
|
public static final int HEADER_NODE_METADATA_LENGTH = 1;
|
|
public static final int HEADER_VALUE_LENGTH = 2;
|
|
public static final int MATCH_DATA_CLASS_LENGTH = 2;
|
|
public static final int MATCH_DATA_METHOD_LENGTH = 1;
|
|
public static final int MATCH_DATA_TYPE_LENGTH = 1;
|
|
public static final int MATCH_DATA_URL_TEMPLATE_LENGTH = 2;
|
|
public static final String MATCH_INDEX_ENCODING = "ISO_8859_1";
|
|
public static final String MATCH_PARAM_DIVIDER_CHAR = "\u001e";
|
|
public static final String ROOT_VALUE = "r";
|
|
public final byte[] byteArray;
|
|
public static final char[] VARIABLE_DELIMITER = {UrlTreeKt.componentParamPrefixChar, UrlTreeKt.componentParamSuffixChar};
|
|
public static final char[] ALLOWED_VALUES_DELIMITER = {'(', ')'};
|
|
|
|
public MatchIndex(byte[] bArr) {
|
|
this.byteArray = bArr;
|
|
}
|
|
|
|
/* JADX WARN: Removed duplicated region for block: B:17:0x0099 */
|
|
/* JADX WARN: Removed duplicated region for block: B:23:0x0098 A[SYNTHETIC] */
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct add '--show-bad-code' argument
|
|
*/
|
|
public com.airbnb.deeplinkdispatch.DeepLinkMatchResult matchUri(com.airbnb.deeplinkdispatch.DeepLinkUri r17, java.util.List<com.airbnb.deeplinkdispatch.UrlElement> r18, java.util.Map<java.lang.String, java.lang.String> r19, int r20, int r21, int r22, java.util.Map<byte[], byte[]> r23) {
|
|
/*
|
|
r16 = this;
|
|
r8 = r16
|
|
r9 = r20
|
|
r10 = 0
|
|
r12 = r18
|
|
r11 = r21
|
|
r0 = r10
|
|
La:
|
|
java.lang.Object r1 = r12.get(r9)
|
|
com.airbnb.deeplinkdispatch.UrlElement r1 = (com.airbnb.deeplinkdispatch.UrlElement) r1
|
|
byte r2 = r1.getTypeFlag()
|
|
byte[] r1 = r1.getValue()
|
|
r13 = r23
|
|
com.airbnb.deeplinkdispatch.base.CompareResult r1 = r8.compareValue(r11, r2, r1, r13)
|
|
r14 = -1
|
|
if (r1 == 0) goto L94
|
|
java.lang.String r2 = r1.getPlaceholderValue()
|
|
boolean r2 = r2.isEmpty()
|
|
r3 = 1
|
|
if (r2 != 0) goto L4d
|
|
if (r19 == 0) goto L31
|
|
r2 = r19
|
|
goto L35
|
|
L31:
|
|
java.util.Map r2 = java.util.Collections.emptyMap()
|
|
L35:
|
|
java.util.HashMap r4 = new java.util.HashMap
|
|
r4.<init>(r2)
|
|
java.lang.String r2 = r1.getPlaceholderValue()
|
|
java.lang.String r5 = com.airbnb.deeplinkdispatch.base.MatchIndex.MATCH_PARAM_DIVIDER_CHAR
|
|
java.lang.String[] r2 = r2.split(r5, r14)
|
|
r5 = 0
|
|
r5 = r2[r5]
|
|
r2 = r2[r3]
|
|
r4.put(r5, r2)
|
|
goto L4f
|
|
L4d:
|
|
r4 = r19
|
|
L4f:
|
|
int r2 = r18.size()
|
|
int r2 = r2 - r3
|
|
if (r9 < r2) goto L6d
|
|
boolean r2 = r1.isEmptyConfigurablePathSegmentMatch()
|
|
if (r2 != 0) goto L6d
|
|
int r1 = r8.getMatchLength(r11)
|
|
if (r1 <= 0) goto L94
|
|
int r0 = r8.getMatchDataPos(r11)
|
|
r15 = r17
|
|
com.airbnb.deeplinkdispatch.DeepLinkMatchResult r0 = r8.getMatchResultFromIndex(r1, r0, r15, r4)
|
|
goto L96
|
|
L6d:
|
|
r15 = r17
|
|
int r5 = r8.getChildrenPos(r11)
|
|
if (r5 == r14) goto L96
|
|
boolean r0 = r1.isEmptyConfigurablePathSegmentMatch()
|
|
if (r0 == 0) goto L7d
|
|
r6 = r9
|
|
goto L80
|
|
L7d:
|
|
int r0 = r9 + 1
|
|
r6 = r0
|
|
L80:
|
|
int r7 = r8.getElementBoundaryPos(r11)
|
|
r0 = r16
|
|
r1 = r17
|
|
r2 = r18
|
|
r3 = r4
|
|
r4 = r6
|
|
r6 = r7
|
|
r7 = r23
|
|
com.airbnb.deeplinkdispatch.DeepLinkMatchResult r0 = r0.matchUri(r1, r2, r3, r4, r5, r6, r7)
|
|
goto L96
|
|
L94:
|
|
r15 = r17
|
|
L96:
|
|
if (r0 == 0) goto L99
|
|
return r0
|
|
L99:
|
|
r1 = r22
|
|
int r11 = r8.getNextElementStartPosition(r11, r1)
|
|
if (r11 != r14) goto La
|
|
return r10
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.airbnb.deeplinkdispatch.base.MatchIndex.matchUri(com.airbnb.deeplinkdispatch.DeepLinkUri, java.util.List, java.util.Map, int, int, int, java.util.Map):com.airbnb.deeplinkdispatch.DeepLinkMatchResult");
|
|
}
|
|
|
|
public List<DeepLinkEntry> getAllEntries(int i, int i2) {
|
|
ArrayList arrayList = new ArrayList();
|
|
do {
|
|
int matchLength = getMatchLength(i);
|
|
if (matchLength > 0) {
|
|
arrayList.add(getDeepLinkEntryFromIndex(this.byteArray, matchLength, getMatchDataPos(i)));
|
|
}
|
|
if (getChildrenPos(i) != -1) {
|
|
arrayList.addAll(getAllEntries(getChildrenPos(i), getElementBoundaryPos(i)));
|
|
}
|
|
i = getNextElementStartPosition(i, i2);
|
|
} while (i != -1);
|
|
return arrayList;
|
|
}
|
|
|
|
public DeepLinkMatchResult getMatchResultFromIndex(int i, int i2, DeepLinkUri deepLinkUri, Map<String, String> map) {
|
|
DeepLinkEntry deepLinkEntryFromIndex = getDeepLinkEntryFromIndex(this.byteArray, i, i2);
|
|
if (deepLinkEntryFromIndex == null) {
|
|
return null;
|
|
}
|
|
return new DeepLinkMatchResult(deepLinkEntryFromIndex, Collections.singletonMap(deepLinkUri, map));
|
|
}
|
|
|
|
private static DeepLinkEntry getDeepLinkEntryFromIndex(byte[] bArr, int i, int i2) {
|
|
if (i == 0) {
|
|
return null;
|
|
}
|
|
MatchType fromInt = MatchType.fromInt(readOneByteAsInt(bArr, i2));
|
|
int readTwoBytesAsInt = readTwoBytesAsInt(bArr, i2 + 1);
|
|
int i3 = i2 + 3;
|
|
String stringFromByteArray = getStringFromByteArray(bArr, i3, readTwoBytesAsInt);
|
|
int i4 = i3 + readTwoBytesAsInt;
|
|
int readTwoBytesAsInt2 = readTwoBytesAsInt(bArr, i4);
|
|
int i5 = i4 + 2;
|
|
String stringFromByteArray2 = getStringFromByteArray(bArr, i5, readTwoBytesAsInt2);
|
|
int i6 = i5 + readTwoBytesAsInt2;
|
|
int readOneByteAsInt = readOneByteAsInt(bArr, i6);
|
|
String stringFromByteArray3 = readOneByteAsInt > 0 ? getStringFromByteArray(bArr, i6 + 1, readOneByteAsInt) : null;
|
|
int i7 = AnonymousClass1.$SwitchMap$com$airbnb$deeplinkdispatch$MatchType[fromInt.ordinal()];
|
|
if (i7 == 1) {
|
|
return new DeepLinkEntry.ActivityDeeplinkEntry(stringFromByteArray, stringFromByteArray2);
|
|
}
|
|
if (i7 == 2) {
|
|
return new DeepLinkEntry.MethodDeeplinkEntry(stringFromByteArray, stringFromByteArray2, stringFromByteArray3);
|
|
}
|
|
if (i7 == 3) {
|
|
return new DeepLinkEntry.HandlerDeepLinkEntry(stringFromByteArray, stringFromByteArray2);
|
|
}
|
|
throw new IllegalStateException("Unhandled match type: ".concat(String.valueOf(fromInt)));
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: com.airbnb.deeplinkdispatch.base.MatchIndex$1, reason: invalid class name */
|
|
/* loaded from: classes.dex */
|
|
public static /* synthetic */ class AnonymousClass1 {
|
|
static final int[] $SwitchMap$com$airbnb$deeplinkdispatch$MatchType;
|
|
|
|
static {
|
|
int[] iArr = new int[MatchType.values().length];
|
|
$SwitchMap$com$airbnb$deeplinkdispatch$MatchType = iArr;
|
|
try {
|
|
iArr[MatchType.Activity.ordinal()] = 1;
|
|
} catch (NoSuchFieldError unused) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$airbnb$deeplinkdispatch$MatchType[MatchType.Method.ordinal()] = 2;
|
|
} catch (NoSuchFieldError unused2) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$airbnb$deeplinkdispatch$MatchType[MatchType.Handler.ordinal()] = 3;
|
|
} catch (NoSuchFieldError unused3) {
|
|
}
|
|
}
|
|
}
|
|
|
|
private CompareResult compareValue(int i, byte b, byte[] bArr, Map<byte[], byte[]> map) {
|
|
int i2 = i + 9;
|
|
NodeMetadata nodeMetadata = new NodeMetadata(this.byteArray[i]);
|
|
if (nodeMetadata.isComponentTypeMismatch(b)) {
|
|
return null;
|
|
}
|
|
int valueLength = getValueLength(i);
|
|
if (valueLength != bArr.length && nodeMetadata.isValueLiteralValue) {
|
|
return null;
|
|
}
|
|
if (nodeMetadata.isComponentParam) {
|
|
return compareComponentParam(i2, valueLength, bArr, VARIABLE_DELIMITER);
|
|
}
|
|
if (nodeMetadata.isConfigurablePathSegment) {
|
|
return compareConfigurablePathSegment(bArr, map, i2, valueLength);
|
|
}
|
|
return arrayCompare(this.byteArray, i2, valueLength, bArr);
|
|
}
|
|
|
|
private CompareResult arrayCompare(byte[] bArr, int i, int i2, byte[] bArr2) {
|
|
if (i2 != bArr2.length) {
|
|
return null;
|
|
}
|
|
for (int i3 = 0; i3 < i2; i3++) {
|
|
if (bArr2[i3] != bArr[i + i3]) {
|
|
return null;
|
|
}
|
|
}
|
|
return new CompareResult("", false);
|
|
}
|
|
|
|
private CompareResult compareConfigurablePathSegment(byte[] bArr, Map<byte[], byte[]> map, int i, int i2) {
|
|
byte[] bArr2 = null;
|
|
for (Map.Entry<byte[], byte[]> entry : map.entrySet()) {
|
|
if (arrayCompare(this.byteArray, i, i2, entry.getKey()) != null) {
|
|
bArr2 = entry.getValue();
|
|
}
|
|
}
|
|
if (bArr2 == null) {
|
|
return null;
|
|
}
|
|
if (bArr2.length == 0) {
|
|
return new CompareResult("", true);
|
|
}
|
|
if (arrayCompare(bArr, 0, bArr.length, bArr2) != null) {
|
|
return new CompareResult("", false);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private CompareResult compareComponentParam(int i, int i2, byte[] bArr, char[] cArr) {
|
|
int length = bArr.length;
|
|
byte[] bArr2 = this.byteArray;
|
|
if ((bArr2[i] == cArr[0] && bArr2[i + 1] == cArr[1]) || length == 0) {
|
|
return null;
|
|
}
|
|
int i3 = 0;
|
|
while (i3 < length) {
|
|
int i4 = i + i3;
|
|
byte b = this.byteArray[i4];
|
|
boolean z = b == bArr[i3] && i3 == length + (-1) && i2 > length;
|
|
if (b == cArr[0] || z) {
|
|
int i5 = i2 - 1;
|
|
int i6 = length - 1;
|
|
while (i5 >= 0) {
|
|
int i7 = i + i5;
|
|
byte b2 = this.byteArray[i7];
|
|
if (b2 == cArr[1]) {
|
|
if (z) {
|
|
i3++;
|
|
}
|
|
int i8 = (i6 - i3) + 1;
|
|
byte[] bArr3 = new byte[i8];
|
|
int i9 = i + i3;
|
|
int i10 = (i7 - i9) - 1;
|
|
byte[] bArr4 = new byte[i10];
|
|
System.arraycopy(bArr, i3, bArr3, 0, i8);
|
|
System.arraycopy(this.byteArray, i9 + 1, bArr4, 0, i10);
|
|
int verifyAllowedValues = verifyAllowedValues(bArr4, bArr3);
|
|
if (verifyAllowedValues < 0) {
|
|
return null;
|
|
}
|
|
if (verifyAllowedValues != Integer.MAX_VALUE) {
|
|
bArr4 = Arrays.copyOfRange(bArr4, 0, verifyAllowedValues);
|
|
}
|
|
String str = new String(bArr4);
|
|
String str2 = MATCH_PARAM_DIVIDER_CHAR;
|
|
String str3 = new String(bArr3);
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append(str);
|
|
sb.append(str2);
|
|
sb.append(str3);
|
|
return new CompareResult(sb.toString(), false);
|
|
}
|
|
if (b2 != bArr[i6]) {
|
|
return null;
|
|
}
|
|
i5--;
|
|
i6--;
|
|
}
|
|
}
|
|
if (this.byteArray[i4] != bArr[i3]) {
|
|
return null;
|
|
}
|
|
i3++;
|
|
}
|
|
return new CompareResult("", false);
|
|
}
|
|
|
|
private int verifyAllowedValues(byte[] bArr, byte[] bArr2) {
|
|
int charPos;
|
|
char[] cArr = ALLOWED_VALUES_DELIMITER;
|
|
int charPos2 = charPos(bArr, cArr[0]);
|
|
if (charPos2 == -1 || charPos2 > (charPos = charPos(bArr, cArr[1]))) {
|
|
return Integer.MAX_VALUE;
|
|
}
|
|
if (Arrays.binarySearch(new String(Arrays.copyOfRange(bArr, charPos2 + 1, charPos)).split(ALLOWED_VALUES_SEPARATOR_REGEX_STRING), new String(bArr2)) >= 0) {
|
|
return charPos2;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
private int charPos(byte[] bArr, char c) {
|
|
if (bArr == null) {
|
|
return -1;
|
|
}
|
|
for (int i = 0; i < bArr.length; i++) {
|
|
if (bArr[i] == c) {
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
private int getNextElementStartPosition(int i, int i2) {
|
|
int elementBoundaryPos = getElementBoundaryPos(i);
|
|
if (elementBoundaryPos == i2) {
|
|
return -1;
|
|
}
|
|
return elementBoundaryPos;
|
|
}
|
|
|
|
private int getElementBoundaryPos(int i) {
|
|
return getMatchDataPos(i) + getMatchLength(i) + getChildrenLength(i);
|
|
}
|
|
|
|
private int getChildrenPos(int i) {
|
|
if (getChildrenLength(i) == 0) {
|
|
return -1;
|
|
}
|
|
return getMatchDataPos(i) + getMatchLength(i);
|
|
}
|
|
|
|
private int getMatchDataPos(int i) {
|
|
return i + 9 + getValueLength(i);
|
|
}
|
|
|
|
private int getValueLength(int i) {
|
|
return readTwoBytesAsInt(this.byteArray, i + 1);
|
|
}
|
|
|
|
private int getMatchLength(int i) {
|
|
return readTwoBytesAsInt(this.byteArray, i + 3);
|
|
}
|
|
|
|
private int getChildrenLength(int i) {
|
|
return readFourBytesAsInt(this.byteArray, i + 5);
|
|
}
|
|
|
|
public int length() {
|
|
return this.byteArray.length;
|
|
}
|
|
|
|
private static int readOneByteAsInt(byte[] bArr, int i) {
|
|
return bArr[i] & UnsignedBytes.MAX_VALUE;
|
|
}
|
|
|
|
private static int readTwoBytesAsInt(byte[] bArr, int i) {
|
|
return readOneByteAsInt(bArr, i + 1) | (readOneByteAsInt(bArr, i) << 8);
|
|
}
|
|
|
|
private static int readFourBytesAsInt(byte[] bArr, int i) {
|
|
return readOneByteAsInt(bArr, i + 3) | (readOneByteAsInt(bArr, i) << 24) | (readOneByteAsInt(bArr, i + 1) << 16) | (readOneByteAsInt(bArr, i + 2) << 8);
|
|
}
|
|
|
|
private static String getStringFromByteArray(byte[] bArr, int i, int i2) {
|
|
byte[] bArr2 = new byte[i2];
|
|
System.arraycopy(bArr, i, bArr2, 0, i2);
|
|
try {
|
|
return new String(bArr2, "utf-8");
|
|
} catch (UnsupportedEncodingException unused) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static String getMatchIdxFileName(String str) {
|
|
String lowerCase = str.toLowerCase();
|
|
StringBuilder sb = new StringBuilder("dld_match_");
|
|
sb.append(lowerCase);
|
|
sb.append(".idx");
|
|
return sb.toString();
|
|
}
|
|
}
|