package com.ea.nimble; import android.app.backup.BackupAgent; import android.app.backup.BackupDataInput; import android.app.backup.BackupDataOutput; import android.content.Context; import android.os.ParcelFileDescriptor; import com.ea.nimble.Log; import com.ea.nimble.Persistence; import java.io.FileOutputStream; import java.io.IOException; /* loaded from: classes.dex */ public class PersistenceService { private static final String APPLICATION_PERSISTENCE_ID = "[APPLICATION]"; public static final String COMPONENT_ID = "com.ea.nimble.persistence"; private static final String NIMBLE_COMPONENT_PERSISTENCE_ID_TEMPLATE = "[COMPONENT]%s"; public enum PersistenceMergePolicy { OVERWRITE, SOURCE_FIRST, TARGET_FIRST } public static class PersistenceBackupAgent extends BackupAgent { @Override // android.app.backup.BackupAgent public void onBackup(ParcelFileDescriptor parcelFileDescriptor, BackupDataOutput backupDataOutput, ParcelFileDescriptor parcelFileDescriptor2) throws IOException { synchronized (Persistence.s_dataLock) { PersistenceService.writeBackup(parcelFileDescriptor, backupDataOutput, parcelFileDescriptor2, this); } } @Override // android.app.backup.BackupAgent public void onRestore(BackupDataInput backupDataInput, int i, ParcelFileDescriptor parcelFileDescriptor) throws IOException { synchronized (Persistence.s_dataLock) { PersistenceService.readBackup(backupDataInput, i, parcelFileDescriptor, this); } } } public static IPersistenceService getComponent() { return BaseCore.getInstance().getPersistenceService(); } public static Persistence getAppPersistence(Persistence.Storage storage) { return getComponent().getPersistence(APPLICATION_PERSISTENCE_ID, storage); } public static Persistence getPersistenceForNimbleComponent(String str, Persistence.Storage storage) { if (!Utility.validString(str)) { Log.Helper.LOGF("Persistence", "Invalid componentId " + str + " for component persistence", new Object[0]); return null; } return getComponent().getPersistence(String.format(NIMBLE_COMPONENT_PERSISTENCE_ID_TEMPLATE, str), storage); } public static void removePersistenceForNimbleComponent(String str, Persistence.Storage storage) { if (!Utility.validString(str)) { Log.Helper.LOGF("Persistence", "Invalid componentId " + str + " for component persistence", new Object[0]); return; } getComponent().removePersistence(String.format(NIMBLE_COMPONENT_PERSISTENCE_ID_TEMPLATE, str), storage); } public static void cleanReferenceToPersistence(String str, Persistence.Storage storage) { if (!Utility.validString(str)) { Log.Helper.LOGF("Persistence", "Invalid componentId " + str + " for component persistence", new Object[0]); return; } getComponent().cleanPersistenceReference(String.format(NIMBLE_COMPONENT_PERSISTENCE_ID_TEMPLATE, str), storage); } /* JADX WARN: Removed duplicated region for block: B:6:0x003e */ /* JADX WARN: Removed duplicated region for block: B:9:0x0048 */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ static void writeBackup(android.os.ParcelFileDescriptor r18, android.app.backup.BackupDataOutput r19, android.os.ParcelFileDescriptor r20, android.content.Context r21) throws java.io.IOException { /* Method dump skipped, instructions count: 268 To view this dump change 'Code comments level' option to 'DEBUG' */ throw new UnsupportedOperationException("Method not decompiled: com.ea.nimble.PersistenceService.writeBackup(android.os.ParcelFileDescriptor, android.app.backup.BackupDataOutput, android.os.ParcelFileDescriptor, android.content.Context):void"); } static void readBackup(BackupDataInput backupDataInput, int i, ParcelFileDescriptor parcelFileDescriptor, Context context) throws IOException { FileOutputStream fileOutputStream; while (true) { FileOutputStream fileOutputStream2 = null; if (!backupDataInput.readNextHeader()) { break; } String key = backupDataInput.getKey(); int dataSize = backupDataInput.getDataSize(); byte[] bArr = new byte[dataSize]; backupDataInput.readEntityData(bArr, 0, dataSize); try { fileOutputStream = new FileOutputStream(Persistence.getPersistencePath(key, Persistence.Storage.DOCUMENT, context)); } catch (Throwable th) { th = th; } try { fileOutputStream.write(bArr); fileOutputStream.close(); } catch (Throwable th2) { th = th2; fileOutputStream2 = fileOutputStream; if (fileOutputStream2 != null) { fileOutputStream2.close(); } throw th; } } if (ApplicationEnvironment.isMainApplicationRunning()) { for (Persistence persistence : ((PersistenceServiceImpl) getComponent()).m_persistences.values()) { if (persistence.getBackUp()) { persistence.restore(false, null); } } } } }