alexandroid/decompiled/jadx/sources/androidx/profileinstaller/DeviceProfileWriter.java
KaKi87 a47fad5135 📦 Add decompiled Alexa 2.2.730155.0 (jadx, apktool, Hermes strings)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 00:04:16 +01:00

325 lines
12 KiB
Java

package androidx.profileinstaller;
import android.content.res.AssetManager;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.profileinstaller.ProfileInstaller;
import it.innove.Peripheral$$ExternalSyntheticLambda3;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.util.concurrent.Executor;
import rx.Single$$ExternalSyntheticBUOutline0;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
@RestrictTo({RestrictTo.Scope.LIBRARY})
/* loaded from: classes14.dex */
public class DeviceProfileWriter {
@NonNull
private final String mApkName;
@NonNull
private final AssetManager mAssetManager;
@NonNull
private final File mCurProfile;
@NonNull
private final ProfileInstaller.DiagnosticsCallback mDiagnostics;
@NonNull
private final Executor mExecutor;
@Nullable
private DexProfileData[] mProfile;
@NonNull
private final String mProfileMetaSourceLocation;
@NonNull
private final String mProfileSourceLocation;
@Nullable
private byte[] mTranscodedProfile;
private boolean mDeviceSupportsAotProfile = false;
@Nullable
private final byte[] mDesiredVersion = desiredVersion();
@RestrictTo({RestrictTo.Scope.LIBRARY})
public DeviceProfileWriter(@NonNull AssetManager assetManager, @NonNull Executor executor, @NonNull ProfileInstaller.DiagnosticsCallback diagnosticsCallback, @NonNull String str, @NonNull String str2, @NonNull String str3, @NonNull File file) {
this.mAssetManager = assetManager;
this.mExecutor = executor;
this.mDiagnostics = diagnosticsCallback;
this.mApkName = str;
this.mProfileSourceLocation = str2;
this.mProfileMetaSourceLocation = str3;
this.mCurProfile = file;
}
@Nullable
private DeviceProfileWriter addMetadata(DexProfileData[] dexProfileDataArr, byte[] bArr) {
InputStream openStreamFromAssets;
try {
openStreamFromAssets = openStreamFromAssets(this.mAssetManager, this.mProfileMetaSourceLocation);
} catch (FileNotFoundException e) {
this.mDiagnostics.onResultReceived(9, e);
} catch (IOException e2) {
this.mDiagnostics.onResultReceived(7, e2);
} catch (IllegalStateException e3) {
this.mProfile = null;
this.mDiagnostics.onResultReceived(8, e3);
}
if (openStreamFromAssets == null) {
if (openStreamFromAssets != null) {
openStreamFromAssets.close();
}
return null;
}
try {
this.mProfile = ProfileTranscoder.readMeta(openStreamFromAssets, ProfileTranscoder.readHeader(openStreamFromAssets, ProfileTranscoder.MAGIC_PROFM), bArr, dexProfileDataArr);
openStreamFromAssets.close();
return this;
} catch (Throwable th) {
try {
openStreamFromAssets.close();
} catch (Throwable th2) {
th.addSuppressed(th2);
}
throw th;
}
}
private void assertDeviceAllowsProfileInstallerAotWritesCalled() {
if (this.mDeviceSupportsAotProfile) {
return;
}
Single$$ExternalSyntheticBUOutline0.m$2("This device doesn't support aot. Did you call deviceSupportsAotProfile()?");
}
@Nullable
private static byte[] desiredVersion() {
int i = Build.VERSION.SDK_INT;
if (i >= 31) {
return ProfileVersion.V015_S;
}
if (i == 29 || i == 30) {
return ProfileVersion.V010_P;
}
return null;
}
@Nullable
private InputStream getProfileInputStream(AssetManager assetManager) {
try {
return openStreamFromAssets(assetManager, this.mProfileSourceLocation);
} catch (FileNotFoundException e) {
this.mDiagnostics.onResultReceived(6, e);
return null;
} catch (IOException e2) {
this.mDiagnostics.onResultReceived(7, e2);
return null;
}
}
/* JADX INFO: Access modifiers changed from: private */
public /* synthetic */ void lambda$result$0(int i, Object obj) {
this.mDiagnostics.onResultReceived(i, obj);
}
@Nullable
private InputStream openStreamFromAssets(AssetManager assetManager, String str) throws IOException {
try {
return assetManager.openFd(str).createInputStream();
} catch (FileNotFoundException e) {
String message = e.getMessage();
if (message != null && message.contains("compressed")) {
this.mDiagnostics.onDiagnosticReceived(5, null);
}
return null;
}
}
@Nullable
private DexProfileData[] readProfileInternal(InputStream inputStream) {
try {
try {
try {
DexProfileData[] readProfile = ProfileTranscoder.readProfile(inputStream, ProfileTranscoder.readHeader(inputStream, ProfileTranscoder.MAGIC_PROF), this.mApkName);
try {
inputStream.close();
return readProfile;
} catch (IOException e) {
this.mDiagnostics.onResultReceived(7, e);
return readProfile;
}
} catch (IllegalStateException e2) {
this.mDiagnostics.onResultReceived(8, e2);
return null;
}
} catch (IOException e3) {
this.mDiagnostics.onResultReceived(7, e3);
return null;
}
} finally {
try {
inputStream.close();
} catch (IOException e4) {
this.mDiagnostics.onResultReceived(7, e4);
}
}
}
private static boolean requiresMetadata() {
return Build.VERSION.SDK_INT >= 31;
}
private void result(int i, @Nullable Object obj) {
this.mExecutor.execute(new Peripheral$$ExternalSyntheticLambda3(this, i, obj, 5));
}
@RestrictTo({RestrictTo.Scope.LIBRARY})
public boolean deviceAllowsProfileInstallerAotWrites() {
if (this.mDesiredVersion == null) {
result(3, Integer.valueOf(Build.VERSION.SDK_INT));
return false;
}
boolean exists = this.mCurProfile.exists();
File file = this.mCurProfile;
if (!exists) {
try {
if (!file.createNewFile()) {
result(4, null);
return false;
}
} catch (IOException unused) {
result(4, null);
return false;
}
} else if (!file.canWrite()) {
result(4, null);
return false;
}
this.mDeviceSupportsAotProfile = true;
return true;
}
@NonNull
@RestrictTo({RestrictTo.Scope.LIBRARY})
public DeviceProfileWriter read() {
DeviceProfileWriter addMetadata;
assertDeviceAllowsProfileInstallerAotWritesCalled();
if (this.mDesiredVersion != null) {
InputStream profileInputStream = getProfileInputStream(this.mAssetManager);
if (profileInputStream != null) {
this.mProfile = readProfileInternal(profileInputStream);
}
DexProfileData[] dexProfileDataArr = this.mProfile;
if (dexProfileDataArr != null && requiresMetadata() && (addMetadata = addMetadata(dexProfileDataArr, this.mDesiredVersion)) != null) {
return addMetadata;
}
}
return this;
}
@NonNull
@RestrictTo({RestrictTo.Scope.LIBRARY})
public DeviceProfileWriter transcodeIfNeeded() {
ByteArrayOutputStream byteArrayOutputStream;
DexProfileData[] dexProfileDataArr = this.mProfile;
byte[] bArr = this.mDesiredVersion;
if (dexProfileDataArr != null && bArr != null) {
assertDeviceAllowsProfileInstallerAotWritesCalled();
try {
byteArrayOutputStream = new ByteArrayOutputStream();
try {
ProfileTranscoder.writeHeader(byteArrayOutputStream, bArr);
} catch (Throwable th) {
try {
byteArrayOutputStream.close();
} catch (Throwable th2) {
th.addSuppressed(th2);
}
throw th;
}
} catch (IOException e) {
this.mDiagnostics.onResultReceived(7, e);
} catch (IllegalStateException e2) {
this.mDiagnostics.onResultReceived(8, e2);
}
if (!ProfileTranscoder.transcodeAndWriteBody(byteArrayOutputStream, bArr, dexProfileDataArr)) {
this.mDiagnostics.onResultReceived(5, null);
this.mProfile = null;
byteArrayOutputStream.close();
return this;
}
this.mTranscodedProfile = byteArrayOutputStream.toByteArray();
byteArrayOutputStream.close();
this.mProfile = null;
}
return this;
}
/* JADX WARN: Multi-variable type inference failed */
@RestrictTo({RestrictTo.Scope.LIBRARY})
public boolean write() {
byte[] bArr = this.mTranscodedProfile;
if (bArr == null) {
return false;
}
assertDeviceAllowsProfileInstallerAotWritesCalled();
try {
try {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bArr);
try {
FileOutputStream fileOutputStream = new FileOutputStream(this.mCurProfile);
try {
FileChannel channel = fileOutputStream.getChannel();
try {
FileLock tryLock = channel.tryLock();
try {
Encoding.writeAll(byteArrayInputStream, fileOutputStream, tryLock);
result(1, null);
if (tryLock != null) {
tryLock.close();
}
channel.close();
fileOutputStream.close();
byteArrayInputStream.close();
return true;
} finally {
}
} finally {
}
} finally {
}
} catch (Throwable th) {
try {
byteArrayInputStream.close();
} catch (Throwable th2) {
th.addSuppressed(th2);
}
throw th;
}
} catch (FileNotFoundException e) {
result(6, e);
return false;
} catch (IOException e2) {
result(7, e2);
return false;
}
} finally {
this.mTranscodedProfile = null;
this.mProfile = null;
}
}
}