Skip to content

Commit

Permalink
Fix/mfkey32 initial progress state (#854)
Browse files Browse the repository at this point in the history
**Background**

When open NFC Tools -> MIFARE Classic, it will immediately start
downloading even if folder is empty

**Changes**

- Ad check for storage content

**Test plan**

- Open Mfkey32 (Detect Reader)
- See that loading now will not start if storage is empty
  • Loading branch information
makeevrserg authored May 20, 2024
1 parent 248d93a commit 03790b9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- [FIX] Text overflow on apps card
- [FIX] SD Card error on installed screen
- [FIX] Scrolling of zoomed screenshots in app image preview
- [FIX] Display MfKey32 loading progress when no keys available
- [Feature] Add not connected, empty and syncing states to emulation button on key screen
- [Feature] Check app exist on apps catalog manifest loading
- [Feature] First version of device orchestrator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import com.flipperdevices.bridge.api.manager.FlipperRequestApi
import kotlinx.coroutines.flow.Flow

interface MfKey32Api {
/**
* Cached value of bruteforce file existing
*
* This should be updated each [checkBruteforceFileExist]
*/
val isBruteforceFileExist: Boolean

fun hasNotification(): Flow<Boolean>
suspend fun checkBruteforceFileExist(requestApi: FlipperRequestApi)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import javax.inject.Singleton
@Singleton
@ContributesBinding(AppGraph::class, MfKey32Api::class)
class MfKey32ApiImpl @Inject constructor() : MfKey32Api {
private var _isBruteforceFileExist: Boolean = false
override val isBruteforceFileExist: Boolean
get() = _isBruteforceFileExist

private val hasNotificationFlow = MutableStateFlow(false)
override fun hasNotification() = hasNotificationFlow

Expand All @@ -30,8 +34,10 @@ class MfKey32ApiImpl @Inject constructor() : MfKey32Api {
}.wrapToRequest()
).first()
if (response.hasStorageMd5SumResponse()) {
_isBruteforceFileExist = true
hasNotificationFlow.emit(true)
} else {
_isBruteforceFileExist = false
hasNotificationFlow.emit(false)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class MfKey32ViewModel @Inject constructor(
is ConnectionState.Ready -> {}
}

if (!prepare()) {
if (!prepare(serviceApi)) {
info { "Failed prepare" }
return
}
Expand All @@ -140,8 +140,20 @@ class MfKey32ViewModel @Inject constructor(
mfKey32StateFlow.emit(MfKey32State.Saved(addedKeys.toImmutableList()))
}

private suspend fun prepare(): Boolean {
private suspend fun prepare(serviceApi: FlipperServiceApi): Boolean {
info { "Flipper connected" }

if (!mfKey32Api.isBruteforceFileExist) {
info { "Not found $PATH_NONCE_LOG" }
mfKey32StateFlow.emit(MfKey32State.Error(ErrorType.NOT_FOUND_FILE))
}

mfKey32Api.checkBruteforceFileExist(serviceApi.requestApi)

if (!mfKey32Api.isBruteforceFileExist) {
return false
}

mfKey32StateFlow.emit(MfKey32State.DownloadingRawFile(0f))

try {
Expand Down

0 comments on commit 03790b9

Please sign in to comment.