Fix IRK-only mode to prevent heuristic fallback + auto battery optimization - #310
Merged
Merged
Conversation
…zation - Prevent heuristic device detection when IRK/ENC keys are configured - Maintain last IRK-matched device state instead of fallback - Auto-enable LOW_POWER scan mode when IRK device is found - Fixes false positives in crowded places
Member
|
Thanks for the PR |
d4rken
requested changes
Jun 30, 2025
d4rken
left a comment
Member
There was a problem hiding this comment.
I think the solution can be very minimalistic, we maybe just need something like:
if(identityKey != null && irkHit == null) {
log(...)....
return null
}What do you think?
BTW: Not an issue, just curious, did you generate this with an AI tool? Copilot?
…y optimization" This reverts commit ca5041b.
This commit modifies `PodMonitor.kt` to ensure that the `isIRKMatch` flag is only used to determine the main device if an Identity Resolving Key (IRK) is actually configured in the general settings. If no IRK is set, the main device determination will fall back to other logic, preventing a device from being incorrectly selected as "main" solely based on an IRK match when no specific IRK is being looked for.
d4rken
previously approved these changes
Jun 30, 2025
d4rken
left a comment
Member
There was a problem hiding this comment.
I'd still like to merge this PR, have you show in the contributors list 👍
So my idea was a simple check like this. If an IRK is configured, only an IRK match will be returned, if there is none then no main device.
What do you think?
Contributor
Author
|
Thank you so much! Your approach is much better than mine - I overcomplicated it because I'm still learning. Really appreciate you cleaning it up properly! Excited to be in the contributors list! |
This commit modifies the handling of Identity Resolving Key (IRK) and Encryption Key (EncKey) to allow users to clear these values by providing an empty input.
Specifically:
- In `GeneralSettingsFragment.kt`, the `onKey` callbacks for both IRK and EncKey dialogs now use `takeIf { it.isNotEmpty() }` after converting the input hex string to a byte array. This ensures that an empty input results in `null` being set for the respective key.
- In `PodMonitor.kt`, when determining the main device, `mainDeviceIdentityKey.value` is now checked with `takeIf { it.isNotEmpty() }` to ensure an empty IRK is treated as no IRK being configured.
- In `AppleFactory.kt`, when attempting to decrypt the private payload, `mainDeviceEncryptionKey.value` is now checked with `takeIf { it.isNotEmpty() }` to ensure an empty EncKey prevents decryption attempts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When IRK/ENC keys are configured, the app still falls back to heuristic detection when no IRK match is found. This causes false positives where other people's AirPods are identified as "my device" in crowded places like subway stations.
Solution
lastIrkMatchedDevice)Changes
lastIrkMatchedDevicevariable to track IRK-matched statedetermineMainDevice()to prevent heuristic fallback when IRK keys are configuredBenefits
This addresses the issue discussed in the GitHub issue where IRK-only mode was requested.
Testing
Closes #309