417 lines
15 KiB
Java
417 lines
15 KiB
Java
package com.google.android.gms.common.data;
|
|
|
|
import android.database.CharArrayBuffer;
|
|
import android.database.Cursor;
|
|
import android.database.CursorIndexOutOfBoundsException;
|
|
import android.database.CursorWindow;
|
|
import android.os.Bundle;
|
|
import android.os.Parcel;
|
|
import android.os.Parcelable;
|
|
import android.util.Log;
|
|
import com.google.android.gms.common.annotation.KeepName;
|
|
import com.google.android.gms.common.internal.Preconditions;
|
|
import com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable;
|
|
import com.google.android.gms.common.internal.safeparcel.SafeParcelWriter;
|
|
import com.google.android.gms.common.sqlite.CursorWrapper;
|
|
import java.io.Closeable;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
@KeepName
|
|
/* loaded from: classes.dex */
|
|
public final class DataHolder extends AbstractSafeParcelable implements Closeable {
|
|
public static final Parcelable.Creator<DataHolder> CREATOR = new zac();
|
|
private static final Builder zalx = new zab(new String[0], null);
|
|
private boolean mClosed;
|
|
private final int zale;
|
|
private final String[] zalp;
|
|
private Bundle zalq;
|
|
private final CursorWindow[] zalr;
|
|
private final int zals;
|
|
private final Bundle zalt;
|
|
private int[] zalu;
|
|
private int zalv;
|
|
private boolean zalw;
|
|
|
|
public static class zaa extends RuntimeException {
|
|
public zaa(String str) {
|
|
super(str);
|
|
}
|
|
}
|
|
|
|
DataHolder(int i, String[] strArr, CursorWindow[] cursorWindowArr, int i2, Bundle bundle) {
|
|
this.mClosed = false;
|
|
this.zalw = true;
|
|
this.zale = i;
|
|
this.zalp = strArr;
|
|
this.zalr = cursorWindowArr;
|
|
this.zals = i2;
|
|
this.zalt = bundle;
|
|
}
|
|
|
|
public static Builder builder(String[] strArr) {
|
|
return new Builder(strArr, null, 0 == true ? 1 : 0);
|
|
}
|
|
|
|
public static DataHolder empty(int i) {
|
|
return new DataHolder(zalx, i, (Bundle) null);
|
|
}
|
|
|
|
private static CursorWindow[] zaa(CursorWrapper cursorWrapper) {
|
|
int i;
|
|
ArrayList arrayList = new ArrayList();
|
|
try {
|
|
int count = cursorWrapper.getCount();
|
|
CursorWindow window = cursorWrapper.getWindow();
|
|
if (window == null || window.getStartPosition() != 0) {
|
|
i = 0;
|
|
} else {
|
|
window.acquireReference();
|
|
cursorWrapper.a(null);
|
|
arrayList.add(window);
|
|
i = window.getNumRows();
|
|
}
|
|
while (i < count) {
|
|
if (!cursorWrapper.moveToPosition(i)) {
|
|
break;
|
|
}
|
|
CursorWindow window2 = cursorWrapper.getWindow();
|
|
if (window2 != null) {
|
|
window2.acquireReference();
|
|
cursorWrapper.a(null);
|
|
} else {
|
|
window2 = new CursorWindow(false);
|
|
window2.setStartPosition(i);
|
|
cursorWrapper.fillWindow(i, window2);
|
|
}
|
|
if (window2.getNumRows() == 0) {
|
|
break;
|
|
}
|
|
arrayList.add(window2);
|
|
i = window2.getStartPosition() + window2.getNumRows();
|
|
}
|
|
cursorWrapper.close();
|
|
return (CursorWindow[]) arrayList.toArray(new CursorWindow[arrayList.size()]);
|
|
} catch (Throwable th) {
|
|
cursorWrapper.close();
|
|
throw th;
|
|
}
|
|
}
|
|
|
|
@Override // java.io.Closeable, java.lang.AutoCloseable
|
|
public final void close() {
|
|
synchronized (this) {
|
|
if (!this.mClosed) {
|
|
this.mClosed = true;
|
|
for (int i = 0; i < this.zalr.length; i++) {
|
|
this.zalr[i].close();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
protected final void finalize() throws Throwable {
|
|
try {
|
|
if (this.zalw && this.zalr.length > 0 && !isClosed()) {
|
|
close();
|
|
String obj = toString();
|
|
StringBuilder sb = new StringBuilder(String.valueOf(obj).length() + 178);
|
|
sb.append("Internal data leak within a DataBuffer object detected! Be sure to explicitly call release() on all DataBuffer extending objects when you are done with them. (internal object: ");
|
|
sb.append(obj);
|
|
sb.append(")");
|
|
Log.e("DataBuffer", sb.toString());
|
|
}
|
|
} finally {
|
|
super.finalize();
|
|
}
|
|
}
|
|
|
|
public final boolean getBoolean(String str, int i, int i2) {
|
|
zaa(str, i);
|
|
return Long.valueOf(this.zalr[i2].getLong(i, this.zalq.getInt(str))).longValue() == 1;
|
|
}
|
|
|
|
public final byte[] getByteArray(String str, int i, int i2) {
|
|
zaa(str, i);
|
|
return this.zalr[i2].getBlob(i, this.zalq.getInt(str));
|
|
}
|
|
|
|
public final int getCount() {
|
|
return this.zalv;
|
|
}
|
|
|
|
public final int getInteger(String str, int i, int i2) {
|
|
zaa(str, i);
|
|
return this.zalr[i2].getInt(i, this.zalq.getInt(str));
|
|
}
|
|
|
|
public final long getLong(String str, int i, int i2) {
|
|
zaa(str, i);
|
|
return this.zalr[i2].getLong(i, this.zalq.getInt(str));
|
|
}
|
|
|
|
public final Bundle getMetadata() {
|
|
return this.zalt;
|
|
}
|
|
|
|
public final int getStatusCode() {
|
|
return this.zals;
|
|
}
|
|
|
|
public final String getString(String str, int i, int i2) {
|
|
zaa(str, i);
|
|
return this.zalr[i2].getString(i, this.zalq.getInt(str));
|
|
}
|
|
|
|
public final int getWindowIndex(int i) {
|
|
int i2 = 0;
|
|
Preconditions.b(i >= 0 && i < this.zalv);
|
|
while (true) {
|
|
int[] iArr = this.zalu;
|
|
if (i2 >= iArr.length) {
|
|
break;
|
|
}
|
|
if (i < iArr[i2]) {
|
|
i2--;
|
|
break;
|
|
}
|
|
i2++;
|
|
}
|
|
return i2 == this.zalu.length ? i2 - 1 : i2;
|
|
}
|
|
|
|
public final boolean hasColumn(String str) {
|
|
return this.zalq.containsKey(str);
|
|
}
|
|
|
|
public final boolean hasNull(String str, int i, int i2) {
|
|
zaa(str, i);
|
|
return this.zalr[i2].isNull(i, this.zalq.getInt(str));
|
|
}
|
|
|
|
public final boolean isClosed() {
|
|
boolean z;
|
|
synchronized (this) {
|
|
z = this.mClosed;
|
|
}
|
|
return z;
|
|
}
|
|
|
|
@Override // android.os.Parcelable
|
|
public final void writeToParcel(Parcel parcel, int i) {
|
|
int a = SafeParcelWriter.a(parcel);
|
|
SafeParcelWriter.a(parcel, 1, this.zalp, false);
|
|
SafeParcelWriter.a(parcel, 2, (Parcelable[]) this.zalr, i, false);
|
|
SafeParcelWriter.a(parcel, 3, getStatusCode());
|
|
SafeParcelWriter.a(parcel, 4, getMetadata(), false);
|
|
SafeParcelWriter.a(parcel, 1000, this.zale);
|
|
SafeParcelWriter.a(parcel, a);
|
|
if ((i & 1) != 0) {
|
|
close();
|
|
}
|
|
}
|
|
|
|
public final double zab(String str, int i, int i2) {
|
|
zaa(str, i);
|
|
return this.zalr[i2].getDouble(i, this.zalq.getInt(str));
|
|
}
|
|
|
|
public final void zaca() {
|
|
this.zalq = new Bundle();
|
|
int i = 0;
|
|
int i2 = 0;
|
|
while (true) {
|
|
String[] strArr = this.zalp;
|
|
if (i2 >= strArr.length) {
|
|
break;
|
|
}
|
|
this.zalq.putInt(strArr[i2], i2);
|
|
i2++;
|
|
}
|
|
this.zalu = new int[this.zalr.length];
|
|
int i3 = 0;
|
|
while (true) {
|
|
CursorWindow[] cursorWindowArr = this.zalr;
|
|
if (i >= cursorWindowArr.length) {
|
|
this.zalv = i3;
|
|
return;
|
|
}
|
|
this.zalu[i] = i3;
|
|
i3 += this.zalr[i].getNumRows() - (i3 - cursorWindowArr[i].getStartPosition());
|
|
i++;
|
|
}
|
|
}
|
|
|
|
public static class Builder {
|
|
private final String[] a;
|
|
private final ArrayList<HashMap<String, Object>> b;
|
|
|
|
private Builder(String[] strArr, String str) {
|
|
Preconditions.a(strArr);
|
|
this.a = strArr;
|
|
this.b = new ArrayList<>();
|
|
new HashMap();
|
|
}
|
|
|
|
/* synthetic */ Builder(String[] strArr, String str, zab zabVar) {
|
|
this(strArr, null);
|
|
}
|
|
}
|
|
|
|
public DataHolder(String[] strArr, CursorWindow[] cursorWindowArr, int i, Bundle bundle) {
|
|
this.mClosed = false;
|
|
this.zalw = true;
|
|
this.zale = 1;
|
|
Preconditions.a(strArr);
|
|
this.zalp = strArr;
|
|
Preconditions.a(cursorWindowArr);
|
|
this.zalr = cursorWindowArr;
|
|
this.zals = i;
|
|
this.zalt = bundle;
|
|
zaca();
|
|
}
|
|
|
|
private DataHolder(CursorWrapper cursorWrapper, int i, Bundle bundle) {
|
|
this(cursorWrapper.getColumnNames(), zaa(cursorWrapper), i, bundle);
|
|
}
|
|
|
|
public DataHolder(Cursor cursor, int i, Bundle bundle) {
|
|
this(new CursorWrapper(cursor), i, bundle);
|
|
}
|
|
|
|
private DataHolder(Builder builder, int i, Bundle bundle) {
|
|
this(builder.a, zaa(builder, -1), i, (Bundle) null);
|
|
}
|
|
|
|
private DataHolder(Builder builder, int i, Bundle bundle, int i2) {
|
|
this(builder.a, zaa(builder, -1), i, bundle);
|
|
}
|
|
|
|
/* synthetic */ DataHolder(Builder builder, int i, Bundle bundle, zab zabVar) {
|
|
this(builder, i, (Bundle) null);
|
|
}
|
|
|
|
private static CursorWindow[] zaa(Builder builder, int i) {
|
|
if (builder.a.length == 0) {
|
|
return new CursorWindow[0];
|
|
}
|
|
List subList = (i < 0 || i >= builder.b.size()) ? builder.b : builder.b.subList(0, i);
|
|
int size = subList.size();
|
|
CursorWindow cursorWindow = new CursorWindow(false);
|
|
ArrayList arrayList = new ArrayList();
|
|
arrayList.add(cursorWindow);
|
|
cursorWindow.setNumColumns(builder.a.length);
|
|
CursorWindow cursorWindow2 = cursorWindow;
|
|
int i2 = 0;
|
|
boolean z = false;
|
|
while (i2 < size) {
|
|
try {
|
|
if (!cursorWindow2.allocRow()) {
|
|
StringBuilder sb = new StringBuilder(72);
|
|
sb.append("Allocating additional cursor window for large data set (row ");
|
|
sb.append(i2);
|
|
sb.append(")");
|
|
Log.d("DataHolder", sb.toString());
|
|
cursorWindow2 = new CursorWindow(false);
|
|
cursorWindow2.setStartPosition(i2);
|
|
cursorWindow2.setNumColumns(builder.a.length);
|
|
arrayList.add(cursorWindow2);
|
|
if (!cursorWindow2.allocRow()) {
|
|
Log.e("DataHolder", "Unable to allocate row to hold data.");
|
|
arrayList.remove(cursorWindow2);
|
|
return (CursorWindow[]) arrayList.toArray(new CursorWindow[arrayList.size()]);
|
|
}
|
|
}
|
|
Map map = (Map) subList.get(i2);
|
|
boolean z2 = true;
|
|
for (int i3 = 0; i3 < builder.a.length && z2; i3++) {
|
|
String str = builder.a[i3];
|
|
Object obj = map.get(str);
|
|
if (obj == null) {
|
|
z2 = cursorWindow2.putNull(i2, i3);
|
|
} else if (obj instanceof String) {
|
|
z2 = cursorWindow2.putString((String) obj, i2, i3);
|
|
} else if (obj instanceof Long) {
|
|
z2 = cursorWindow2.putLong(((Long) obj).longValue(), i2, i3);
|
|
} else if (obj instanceof Integer) {
|
|
z2 = cursorWindow2.putLong(((Integer) obj).intValue(), i2, i3);
|
|
} else if (obj instanceof Boolean) {
|
|
z2 = cursorWindow2.putLong(((Boolean) obj).booleanValue() ? 1L : 0L, i2, i3);
|
|
} else if (obj instanceof byte[]) {
|
|
z2 = cursorWindow2.putBlob((byte[]) obj, i2, i3);
|
|
} else if (obj instanceof Double) {
|
|
z2 = cursorWindow2.putDouble(((Double) obj).doubleValue(), i2, i3);
|
|
} else if (obj instanceof Float) {
|
|
z2 = cursorWindow2.putDouble(((Float) obj).floatValue(), i2, i3);
|
|
} else {
|
|
String valueOf = String.valueOf(obj);
|
|
StringBuilder sb2 = new StringBuilder(String.valueOf(str).length() + 32 + String.valueOf(valueOf).length());
|
|
sb2.append("Unsupported object for column ");
|
|
sb2.append(str);
|
|
sb2.append(": ");
|
|
sb2.append(valueOf);
|
|
throw new IllegalArgumentException(sb2.toString());
|
|
}
|
|
}
|
|
if (z2) {
|
|
z = false;
|
|
} else if (!z) {
|
|
StringBuilder sb3 = new StringBuilder(74);
|
|
sb3.append("Couldn't populate window data for row ");
|
|
sb3.append(i2);
|
|
sb3.append(" - allocating new window.");
|
|
Log.d("DataHolder", sb3.toString());
|
|
cursorWindow2.freeLastRow();
|
|
cursorWindow2 = new CursorWindow(false);
|
|
cursorWindow2.setStartPosition(i2);
|
|
cursorWindow2.setNumColumns(builder.a.length);
|
|
arrayList.add(cursorWindow2);
|
|
i2--;
|
|
z = true;
|
|
} else {
|
|
throw new zaa("Could not add the value to a new CursorWindow. The size of value may be larger than what a CursorWindow can handle.");
|
|
}
|
|
i2++;
|
|
} catch (RuntimeException e) {
|
|
int size2 = arrayList.size();
|
|
for (int i4 = 0; i4 < size2; i4++) {
|
|
((CursorWindow) arrayList.get(i4)).close();
|
|
}
|
|
throw e;
|
|
}
|
|
}
|
|
return (CursorWindow[]) arrayList.toArray(new CursorWindow[arrayList.size()]);
|
|
}
|
|
|
|
/* synthetic */ DataHolder(Builder builder, int i, Bundle bundle, int i2, zab zabVar) {
|
|
this(builder, i, bundle, -1);
|
|
}
|
|
|
|
private final void zaa(String str, int i) {
|
|
Bundle bundle = this.zalq;
|
|
if (bundle != null && bundle.containsKey(str)) {
|
|
if (!isClosed()) {
|
|
if (i < 0 || i >= this.zalv) {
|
|
throw new CursorIndexOutOfBoundsException(i, this.zalv);
|
|
}
|
|
return;
|
|
}
|
|
throw new IllegalArgumentException("Buffer is closed.");
|
|
}
|
|
String valueOf = String.valueOf(str);
|
|
throw new IllegalArgumentException(valueOf.length() != 0 ? "No such column: ".concat(valueOf) : new String("No such column: "));
|
|
}
|
|
|
|
public final float zaa(String str, int i, int i2) {
|
|
zaa(str, i);
|
|
return this.zalr[i2].getFloat(i, this.zalq.getInt(str));
|
|
}
|
|
|
|
public final void zaa(String str, int i, int i2, CharArrayBuffer charArrayBuffer) {
|
|
zaa(str, i);
|
|
this.zalr[i2].copyStringToBuffer(i, this.zalq.getInt(str), charArrayBuffer);
|
|
}
|
|
}
|