Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Android seed gc #2339

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,20 @@ class SeedRepository(
return when (val authResult = authentication.authenticate(activity)) {
AuthResult.AuthSuccess -> {
addSeedDangerous(seedName, seedPhrase, networksKeys)
System.gc()
AuthOperationResult.Success
}

AuthResult.AuthError,
AuthResult.AuthFailed,
AuthResult.AuthUnavailable -> {
System.gc()
Timber.w(TAG, "auth error - $authResult")
AuthOperationResult.AuthFailed(authResult)
}
}
} catch (e: java.lang.Exception) {
System.gc()
Timber.e(TAG, e.toString())
return AuthOperationResult.Error(e)
}
Expand All @@ -161,6 +164,7 @@ class SeedRepository(
} catch (e: ErrorDisplayed) {
submitErrorState("error in add seed $e")
}
System.gc()
}

/**
Expand Down Expand Up @@ -200,6 +204,9 @@ class SeedRepository(
.filter { it.isNotEmpty() }
.joinToString(separator = "\n")

//Just collect some old seeds
System.gc()

return if (seedPhrases.isNotBlank()) {
RepoResult.Success(seedPhrases)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import io.parity.signer.domain.FeatureFlags
import io.parity.signer.domain.FeatureOption
import io.parity.signer.domain.backend.OperationResult
import io.parity.signer.screens.error.ErrorStateDestinationState
import io.parity.signer.uniffi.ErrorDisplayed
import io.parity.signer.uniffi.historySeedWasShown
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand Down Expand Up @@ -145,8 +144,11 @@ class SeedStorage {
/**
* @throws UserNotAuthenticatedException
*/
fun checkIfSeedNameAlreadyExists(seedPhrase: String) =
sharedPreferences.all.values.contains(seedPhrase)
fun checkIfSeedNameAlreadyExists(seedPhrase: String) : Boolean {
val result = sharedPreferences.all.values.contains(seedPhrase)
Runtime.getRuntime().gc()
return result
}

/**
* @throws UserNotAuthenticatedException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class DerivationCreateViewModel : ViewModel() {
path = path.value,
networkKey = selectedNetwork.key
)
System.gc()
when (result) {
is OperationResult.Ok -> {
Toast.makeText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class KeyDetailsScreenViewModel : ViewModel() {
seedPhrase = seedResult.result,
keyPassword = password,
)
System.gc()
when (secretKeyDetailsQR) {
is UniffiResult.Error -> OperationResult.Err(secretKeyDetailsQR.error)
is UniffiResult.Success -> {
Expand Down Expand Up @@ -96,6 +97,8 @@ class KeyDetailsScreenViewModel : ViewModel() {
seedPhrase = seedResult.result,
keyPassword = password,
)
System.gc()

when (secretKeyDetailsQR) {
is UniffiResult.Error -> {
if (passwordModel.attempt > 3) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class ScanViewModel : ViewModel() {
is RepoResult.Success -> {
val previewDynDerivations =
uniffiInteractor.previewDynamicDerivations(phrases.result, payload)
System.gc()

when (previewDynDerivations) {
is UniffiResult.Error -> {
Expand Down Expand Up @@ -266,6 +267,7 @@ class ScanViewModel : ViewModel() {
uniffiInteractor.signDynamicDerivationsTransactions(
phrases.result, payload
)
System.gc()

when (dynDerivations) {
is UniffiResult.Error -> {
Expand Down Expand Up @@ -383,10 +385,12 @@ class ScanViewModel : ViewModel() {
}

is RepoResult.Success -> {
scanFlowInteractor.continueSigningTransaction(
val result = scanFlowInteractor.continueSigningTransaction(
comment,
phrases.result,
)
System.gc()
result
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class AddedNetworkViewModel : ViewModel() {
seedName = seedPair.first, seedPhrase = seedPair.second,
path = network.pathId, network = network.key,
)
System.gc()
} catch (e: ErrorDisplayed) {
result = false
submitErrorState("can't create network key for added network, ${e.message}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ImportDerivedKeysRepository(
seedRepository.getAllSeeds().mapError() ?: return RepoResult.Failure()
return try {
val filledSeedKeys = populateDerivationsHasPwd(seeds, seedPreviews)
System.gc()
RepoResult.Success(filledSeedKeys)
} catch (e: java.lang.Exception) {
RepoResult.Failure(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class SignSpecsViewModel : ViewModel() {
}
}
}
System.gc()
}
}
}
Expand Down
Loading