- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
397 lines
18 KiB
Java
397 lines
18 KiB
Java
package androidx.datastore.migrations;
|
|
|
|
import android.content.Context;
|
|
import android.content.SharedPreferences;
|
|
import androidx.annotation.DoNotInline;
|
|
import androidx.annotation.RequiresApi;
|
|
import androidx.datastore.core.DataMigration;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.util.Iterator;
|
|
import java.util.Set;
|
|
import kotlin.Lazy;
|
|
import kotlin.LazyKt__LazyJVMKt;
|
|
import kotlin.ResultKt;
|
|
import kotlin.Unit;
|
|
import kotlin.collections.CollectionsKt___CollectionsKt;
|
|
import kotlin.coroutines.Continuation;
|
|
import kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsKt;
|
|
import kotlin.coroutines.jvm.internal.Boxing;
|
|
import kotlin.coroutines.jvm.internal.DebugMetadata;
|
|
import kotlin.coroutines.jvm.internal.SuspendLambda;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function2;
|
|
import kotlin.jvm.functions.Function3;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlin.jvm.internal.Intrinsics;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class SharedPreferencesMigration<T> implements DataMigration<T> {
|
|
private final Context context;
|
|
private final Set<String> keySet;
|
|
private final Function3 migrate;
|
|
private final String name;
|
|
private final Lazy sharedPrefs$delegate;
|
|
private final Function2 shouldRunMigration;
|
|
|
|
/* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
|
|
public SharedPreferencesMigration(Context context, String sharedPreferencesName, Set<String> keysToMigrate, Function3 migrate) {
|
|
this(context, sharedPreferencesName, keysToMigrate, null, migrate, 8, null);
|
|
Intrinsics.checkNotNullParameter(context, "context");
|
|
Intrinsics.checkNotNullParameter(sharedPreferencesName, "sharedPreferencesName");
|
|
Intrinsics.checkNotNullParameter(keysToMigrate, "keysToMigrate");
|
|
Intrinsics.checkNotNullParameter(migrate, "migrate");
|
|
}
|
|
|
|
/* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
|
|
public SharedPreferencesMigration(Context context, String sharedPreferencesName, Function3 migrate) {
|
|
this(context, sharedPreferencesName, null, null, migrate, 12, null);
|
|
Intrinsics.checkNotNullParameter(context, "context");
|
|
Intrinsics.checkNotNullParameter(sharedPreferencesName, "sharedPreferencesName");
|
|
Intrinsics.checkNotNullParameter(migrate, "migrate");
|
|
}
|
|
|
|
/* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
|
|
public SharedPreferencesMigration(Function0 produceSharedPreferences, Set<String> keysToMigrate, Function3 migrate) {
|
|
this(produceSharedPreferences, keysToMigrate, (Function2) null, migrate, 4, (DefaultConstructorMarker) null);
|
|
Intrinsics.checkNotNullParameter(produceSharedPreferences, "produceSharedPreferences");
|
|
Intrinsics.checkNotNullParameter(keysToMigrate, "keysToMigrate");
|
|
Intrinsics.checkNotNullParameter(migrate, "migrate");
|
|
}
|
|
|
|
/* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
|
|
public SharedPreferencesMigration(Function0 produceSharedPreferences, Function3 migrate) {
|
|
this(produceSharedPreferences, (Set) null, (Function2) null, migrate, 6, (DefaultConstructorMarker) null);
|
|
Intrinsics.checkNotNullParameter(produceSharedPreferences, "produceSharedPreferences");
|
|
Intrinsics.checkNotNullParameter(migrate, "migrate");
|
|
}
|
|
|
|
private SharedPreferencesMigration(Function0 function0, Set<String> set, Function2 function2, Function3 function3, Context context, String str) {
|
|
Lazy lazy;
|
|
this.shouldRunMigration = function2;
|
|
this.migrate = function3;
|
|
this.context = context;
|
|
this.name = str;
|
|
lazy = LazyKt__LazyJVMKt.lazy(function0);
|
|
this.sharedPrefs$delegate = lazy;
|
|
this.keySet = set == SharedPreferencesMigrationKt.getMIGRATE_ALL_KEYS() ? null : CollectionsKt___CollectionsKt.toMutableSet(set);
|
|
}
|
|
|
|
@DebugMetadata(c = "androidx.datastore.migrations.SharedPreferencesMigration$1", f = "SharedPreferencesMigration.kt", l = {}, m = "invokeSuspend")
|
|
/* renamed from: androidx.datastore.migrations.SharedPreferencesMigration$1, reason: invalid class name */
|
|
public static final class AnonymousClass1 extends SuspendLambda implements Function2 {
|
|
int label;
|
|
|
|
public AnonymousClass1(Continuation continuation) {
|
|
super(2, continuation);
|
|
}
|
|
|
|
@Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
|
|
public final Continuation create(Object obj, Continuation continuation) {
|
|
return new AnonymousClass1(continuation);
|
|
}
|
|
|
|
@Override // kotlin.jvm.functions.Function2
|
|
public /* bridge */ /* synthetic */ Object invoke(Object obj, Object obj2) {
|
|
return invoke((AnonymousClass1) obj, (Continuation) obj2);
|
|
}
|
|
|
|
public final Object invoke(T t, Continuation continuation) {
|
|
return ((AnonymousClass1) create(t, continuation)).invokeSuspend(Unit.INSTANCE);
|
|
}
|
|
|
|
@Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
|
|
public final Object invokeSuspend(Object obj) {
|
|
IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED();
|
|
if (this.label != 0) {
|
|
throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
|
|
}
|
|
ResultKt.throwOnFailure(obj);
|
|
return Boxing.boxBoolean(true);
|
|
}
|
|
}
|
|
|
|
public /* synthetic */ SharedPreferencesMigration(Function0 function0, Set set, Function2 function2, Function3 function3, Context context, String str, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(function0, (Set<String>) set, (i & 4) != 0 ? new AnonymousClass1(null) : function2, function3, context, str);
|
|
}
|
|
|
|
@DebugMetadata(c = "androidx.datastore.migrations.SharedPreferencesMigration$2", f = "SharedPreferencesMigration.kt", l = {}, m = "invokeSuspend")
|
|
/* renamed from: androidx.datastore.migrations.SharedPreferencesMigration$2, reason: invalid class name */
|
|
public static final class AnonymousClass2 extends SuspendLambda implements Function2 {
|
|
int label;
|
|
|
|
public AnonymousClass2(Continuation continuation) {
|
|
super(2, continuation);
|
|
}
|
|
|
|
@Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
|
|
public final Continuation create(Object obj, Continuation continuation) {
|
|
return new AnonymousClass2(continuation);
|
|
}
|
|
|
|
@Override // kotlin.jvm.functions.Function2
|
|
public /* bridge */ /* synthetic */ Object invoke(Object obj, Object obj2) {
|
|
return invoke((AnonymousClass2) obj, (Continuation) obj2);
|
|
}
|
|
|
|
public final Object invoke(T t, Continuation continuation) {
|
|
return ((AnonymousClass2) create(t, continuation)).invokeSuspend(Unit.INSTANCE);
|
|
}
|
|
|
|
@Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
|
|
public final Object invokeSuspend(Object obj) {
|
|
IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED();
|
|
if (this.label != 0) {
|
|
throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
|
|
}
|
|
ResultKt.throwOnFailure(obj);
|
|
return Boxing.boxBoolean(true);
|
|
}
|
|
}
|
|
|
|
public /* synthetic */ SharedPreferencesMigration(Function0 function0, Set set, Function2 function2, Function3 function3, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(function0, (Set<String>) ((i & 2) != 0 ? SharedPreferencesMigrationKt.getMIGRATE_ALL_KEYS() : set), (i & 4) != 0 ? new AnonymousClass2(null) : function2, function3);
|
|
}
|
|
|
|
/* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
|
|
public SharedPreferencesMigration(Function0 produceSharedPreferences, Set<String> keysToMigrate, Function2 shouldRunMigration, Function3 migrate) {
|
|
this(produceSharedPreferences, keysToMigrate, shouldRunMigration, migrate, (Context) null, (String) null);
|
|
Intrinsics.checkNotNullParameter(produceSharedPreferences, "produceSharedPreferences");
|
|
Intrinsics.checkNotNullParameter(keysToMigrate, "keysToMigrate");
|
|
Intrinsics.checkNotNullParameter(shouldRunMigration, "shouldRunMigration");
|
|
Intrinsics.checkNotNullParameter(migrate, "migrate");
|
|
}
|
|
|
|
@DebugMetadata(c = "androidx.datastore.migrations.SharedPreferencesMigration$3", f = "SharedPreferencesMigration.kt", l = {}, m = "invokeSuspend")
|
|
/* renamed from: androidx.datastore.migrations.SharedPreferencesMigration$3, reason: invalid class name */
|
|
public static final class AnonymousClass3 extends SuspendLambda implements Function2 {
|
|
int label;
|
|
|
|
public AnonymousClass3(Continuation continuation) {
|
|
super(2, continuation);
|
|
}
|
|
|
|
@Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
|
|
public final Continuation create(Object obj, Continuation continuation) {
|
|
return new AnonymousClass3(continuation);
|
|
}
|
|
|
|
@Override // kotlin.jvm.functions.Function2
|
|
public /* bridge */ /* synthetic */ Object invoke(Object obj, Object obj2) {
|
|
return invoke((AnonymousClass3) obj, (Continuation) obj2);
|
|
}
|
|
|
|
public final Object invoke(T t, Continuation continuation) {
|
|
return ((AnonymousClass3) create(t, continuation)).invokeSuspend(Unit.INSTANCE);
|
|
}
|
|
|
|
@Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
|
|
public final Object invokeSuspend(Object obj) {
|
|
IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED();
|
|
if (this.label != 0) {
|
|
throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
|
|
}
|
|
ResultKt.throwOnFailure(obj);
|
|
return Boxing.boxBoolean(true);
|
|
}
|
|
}
|
|
|
|
public /* synthetic */ SharedPreferencesMigration(Context context, String str, Set set, Function2 function2, Function3 function3, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(context, str, (i & 4) != 0 ? SharedPreferencesMigrationKt.getMIGRATE_ALL_KEYS() : set, (i & 8) != 0 ? new AnonymousClass3(null) : function2, function3);
|
|
}
|
|
|
|
/* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
|
|
public SharedPreferencesMigration(final Context context, final String sharedPreferencesName, Set<String> keysToMigrate, Function2 shouldRunMigration, Function3 migrate) {
|
|
this(new Function0() { // from class: androidx.datastore.migrations.SharedPreferencesMigration.4
|
|
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
|
|
{
|
|
super(0);
|
|
}
|
|
|
|
@Override // kotlin.jvm.functions.Function0
|
|
public final SharedPreferences invoke() {
|
|
SharedPreferences sharedPreferences = context.getSharedPreferences(sharedPreferencesName, 0);
|
|
Intrinsics.checkNotNullExpressionValue(sharedPreferences, "context.getSharedPreferences(sharedPreferencesName, Context.MODE_PRIVATE)");
|
|
return sharedPreferences;
|
|
}
|
|
}, keysToMigrate, shouldRunMigration, migrate, context, sharedPreferencesName);
|
|
Intrinsics.checkNotNullParameter(context, "context");
|
|
Intrinsics.checkNotNullParameter(sharedPreferencesName, "sharedPreferencesName");
|
|
Intrinsics.checkNotNullParameter(keysToMigrate, "keysToMigrate");
|
|
Intrinsics.checkNotNullParameter(shouldRunMigration, "shouldRunMigration");
|
|
Intrinsics.checkNotNullParameter(migrate, "migrate");
|
|
}
|
|
|
|
private final SharedPreferences getSharedPrefs() {
|
|
return (SharedPreferences) this.sharedPrefs$delegate.getValue();
|
|
}
|
|
|
|
/* JADX WARN: Code restructure failed: missing block: B:18:0x0069, code lost:
|
|
|
|
if (r5.isEmpty() == false) goto L38;
|
|
*/
|
|
/* JADX WARN: Removed duplicated region for block: B:12:0x004f */
|
|
/* JADX WARN: Removed duplicated region for block: B:15:0x0054 */
|
|
/* JADX WARN: Removed duplicated region for block: B:36:0x0035 */
|
|
/* JADX WARN: Removed duplicated region for block: B:8:0x0023 */
|
|
@Override // androidx.datastore.core.DataMigration
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct add '--show-bad-code' argument
|
|
*/
|
|
public java.lang.Object shouldMigrate(T r5, kotlin.coroutines.Continuation r6) {
|
|
/*
|
|
r4 = this;
|
|
boolean r0 = r6 instanceof androidx.datastore.migrations.SharedPreferencesMigration$shouldMigrate$1
|
|
if (r0 == 0) goto L13
|
|
r0 = r6
|
|
androidx.datastore.migrations.SharedPreferencesMigration$shouldMigrate$1 r0 = (androidx.datastore.migrations.SharedPreferencesMigration$shouldMigrate$1) r0
|
|
int r1 = r0.label
|
|
r2 = -2147483648(0xffffffff80000000, float:-0.0)
|
|
r3 = r1 & r2
|
|
if (r3 == 0) goto L13
|
|
int r1 = r1 - r2
|
|
r0.label = r1
|
|
goto L18
|
|
L13:
|
|
androidx.datastore.migrations.SharedPreferencesMigration$shouldMigrate$1 r0 = new androidx.datastore.migrations.SharedPreferencesMigration$shouldMigrate$1
|
|
r0.<init>(r4, r6)
|
|
L18:
|
|
java.lang.Object r6 = r0.result
|
|
java.lang.Object r1 = kotlin.coroutines.intrinsics.IntrinsicsKt.getCOROUTINE_SUSPENDED()
|
|
int r2 = r0.label
|
|
r3 = 1
|
|
if (r2 == 0) goto L35
|
|
if (r2 != r3) goto L2d
|
|
java.lang.Object r5 = r0.L$0
|
|
androidx.datastore.migrations.SharedPreferencesMigration r5 = (androidx.datastore.migrations.SharedPreferencesMigration) r5
|
|
kotlin.ResultKt.throwOnFailure(r6)
|
|
goto L46
|
|
L2d:
|
|
java.lang.IllegalStateException r5 = new java.lang.IllegalStateException
|
|
java.lang.String r6 = "call to 'resume' before 'invoke' with coroutine"
|
|
r5.<init>(r6)
|
|
throw r5
|
|
L35:
|
|
kotlin.ResultKt.throwOnFailure(r6)
|
|
kotlin.jvm.functions.Function2 r6 = r4.shouldRunMigration
|
|
r0.L$0 = r4
|
|
r0.label = r3
|
|
java.lang.Object r6 = r6.invoke(r5, r0)
|
|
if (r6 != r1) goto L45
|
|
return r1
|
|
L45:
|
|
r5 = r4
|
|
L46:
|
|
java.lang.Boolean r6 = (java.lang.Boolean) r6
|
|
boolean r6 = r6.booleanValue()
|
|
r0 = 0
|
|
if (r6 != 0) goto L54
|
|
java.lang.Boolean r5 = kotlin.coroutines.jvm.internal.Boxing.boxBoolean(r0)
|
|
return r5
|
|
L54:
|
|
java.util.Set<java.lang.String> r6 = r5.keySet
|
|
if (r6 != 0) goto L6e
|
|
android.content.SharedPreferences r5 = r5.getSharedPrefs()
|
|
java.util.Map r5 = r5.getAll()
|
|
java.lang.String r6 = "sharedPrefs.all"
|
|
kotlin.jvm.internal.Intrinsics.checkNotNullExpressionValue(r5, r6)
|
|
boolean r5 = r5.isEmpty()
|
|
if (r5 != 0) goto L6c
|
|
goto L9b
|
|
L6c:
|
|
r3 = r0
|
|
goto L9b
|
|
L6e:
|
|
android.content.SharedPreferences r5 = r5.getSharedPrefs()
|
|
boolean r1 = r6 instanceof java.util.Collection
|
|
if (r1 == 0) goto L7d
|
|
boolean r1 = r6.isEmpty()
|
|
if (r1 == 0) goto L7d
|
|
goto L6c
|
|
L7d:
|
|
java.util.Iterator r6 = r6.iterator()
|
|
L81:
|
|
boolean r1 = r6.hasNext()
|
|
if (r1 == 0) goto L6c
|
|
java.lang.Object r1 = r6.next()
|
|
java.lang.String r1 = (java.lang.String) r1
|
|
boolean r1 = r5.contains(r1)
|
|
java.lang.Boolean r1 = kotlin.coroutines.jvm.internal.Boxing.boxBoolean(r1)
|
|
boolean r1 = r1.booleanValue()
|
|
if (r1 == 0) goto L81
|
|
L9b:
|
|
java.lang.Boolean r5 = kotlin.coroutines.jvm.internal.Boxing.boxBoolean(r3)
|
|
return r5
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: androidx.datastore.migrations.SharedPreferencesMigration.shouldMigrate(java.lang.Object, kotlin.coroutines.Continuation):java.lang.Object");
|
|
}
|
|
|
|
@Override // androidx.datastore.core.DataMigration
|
|
public Object migrate(T t, Continuation continuation) {
|
|
return this.migrate.invoke(new SharedPreferencesView(getSharedPrefs(), this.keySet), t, continuation);
|
|
}
|
|
|
|
@Override // androidx.datastore.core.DataMigration
|
|
public Object cleanUp(Continuation continuation) throws IOException {
|
|
Unit unit;
|
|
Object coroutine_suspended;
|
|
Context context;
|
|
String str;
|
|
SharedPreferences.Editor edit = getSharedPrefs().edit();
|
|
Set<String> set = this.keySet;
|
|
if (set == null) {
|
|
edit.clear();
|
|
} else {
|
|
Iterator<T> it = set.iterator();
|
|
while (it.hasNext()) {
|
|
edit.remove((String) it.next());
|
|
}
|
|
}
|
|
if (!edit.commit()) {
|
|
throw new IOException("Unable to delete migrated keys from SharedPreferences.");
|
|
}
|
|
if (getSharedPrefs().getAll().isEmpty() && (context = this.context) != null && (str = this.name) != null) {
|
|
deleteSharedPreferences(context, str);
|
|
}
|
|
Set<String> set2 = this.keySet;
|
|
if (set2 == null) {
|
|
unit = null;
|
|
} else {
|
|
set2.clear();
|
|
unit = Unit.INSTANCE;
|
|
}
|
|
coroutine_suspended = IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED();
|
|
return unit == coroutine_suspended ? unit : Unit.INSTANCE;
|
|
}
|
|
|
|
private final void deleteSharedPreferences(Context context, String str) {
|
|
if (!Api24Impl.deleteSharedPreferences(context, str)) {
|
|
throw new IOException(Intrinsics.stringPlus("Unable to delete SharedPreferences: ", str));
|
|
}
|
|
}
|
|
|
|
private final File getSharedPrefsFile(Context context, String str) {
|
|
return new File(new File(context.getApplicationInfo().dataDir, "shared_prefs"), Intrinsics.stringPlus(str, ".xml"));
|
|
}
|
|
|
|
private final File getSharedPrefsBackup(File file) {
|
|
return new File(Intrinsics.stringPlus(file.getPath(), ".bak"));
|
|
}
|
|
|
|
@RequiresApi(24)
|
|
public static final class Api24Impl {
|
|
public static final Api24Impl INSTANCE = new Api24Impl();
|
|
|
|
private Api24Impl() {
|
|
}
|
|
|
|
@DoNotInline
|
|
public static final boolean deleteSharedPreferences(Context context, String name) {
|
|
Intrinsics.checkNotNullParameter(context, "context");
|
|
Intrinsics.checkNotNullParameter(name, "name");
|
|
return context.deleteSharedPreferences(name);
|
|
}
|
|
}
|
|
}
|