Skip to content

Added "Network downgrade first"-option and fixed unnecessary block calls.#1

Open
sebikeller wants to merge 11 commits into
joemerlino:masterfrom
sebikeller:master
Open

Added "Network downgrade first"-option and fixed unnecessary block calls.#1
sebikeller wants to merge 11 commits into
joemerlino:masterfrom
sebikeller:master

Conversation

@sebikeller
Copy link
Copy Markdown

"Network downgrade first"-option tries to disable LTE (3G on older
devices) to get a stronger signal (and save battery by switching down).
After the check-delay (default 300 s) it will attempt to switch back.

In some situations where signal changes occured in short intervals and
the user did manually turn airplane mode off, it could get turned on
several times in a row, since every signal change caused the dispatched
block to run.
Now it will only queue the block if signal strength is worse or equal
than at last change and no block is queued.

Also moved duplicate code (from iOS 7 + iOS 8 hooks) to single function.

Changed object type of CFPropertyListRef-object (returned from
CFPreferencesCopyAppValue) to NSNumber* (was NSString*) to better match
the plist data types (CFNumber, CFBool).

…lls.

"Network downgrade first"-option tries to disable LTE (3G on older
devices) to get a stronger signal (and save battery by switching down).
After the check-delay (default 300 s) it will attempt to switch back.

In some situations where signal changes occured in short intervals and
the user did manually turn airplane mode off, it could get turned on
several times in a row, since every signal change caused the dispatched
block to run.
Now it will only queue the block if signal strength is worse or equal
than at last change and no block is queued.

Also moved duplicate code (from iOS 7 + iOS 8 hooks) to single function.

Changed object type of CFPropertyListRef-object (returned from
CFPreferencesCopyAppValue) to NSNumber* (was NSString*) to better match
the plist data types (CFNumber, CFBool).
@sebikeller
Copy link
Copy Markdown
Author

Hey @joemerlino,
Like your tweak, but missed a "network downgrade option". So just updated it for me.
But wanted to share my updates with you 😊

Have a nice day.

Greez

@joemerlino
Copy link
Copy Markdown
Owner

Hi!
Appreciate your incredible work but I'm a little confused on the "Network downgrade first" feature, why we can't just do:

if(tryDownGradeNetworkSpeed && percentage>=bars && [[FSSwitchPanel sharedPanel] stateForSwitchIdentifier:@"com.a3tweaks.switch.lte"]==1){
[[FSSwitchPanel sharedPanel] setState:FSSwitchStateOff forSwitchIdentifier:@"com.a3tweaks.switch.lte"];
}
else if(!call && percentage>=bars && [[FSSwitchPanel sharedPanel] stateForSwitchIdentifier:@"com.a3tweaks.switch.airplane-mode"] == 0){...

after the delay dispatch?
Thanks for the cleanup 😃

Network downgrade now also happens only when signal stays weak for
"delay" seconds.

Merged "network downgrade" and "airplane-mode" to one block!

Fixed some logic, preventing loops of "up-" and "downgrading" the
network.
@sebikeller
Copy link
Copy Markdown
Author

I added there the same delayed switching, since it occurred to me several times that I had bad LTE reception for about 10 seconds, and it did already "downgrade" to 3G.
So it waits also for "delay" seconds, (and now in FIXED version) when signal changes to better, it won't down grade...
But thanks for the input, corrected an error in my logic and simplyfied the code.

@sebikeller
Copy link
Copy Markdown
Author

( Sorry for the many commits, but somehow wanted to keep old .deb's )

@joemerlino
Copy link
Copy Markdown
Owner

I'm sorry maybe I'm dumb but still not understand, let's make a scenario so we can understand better the situation: You're on LTE and you have low signal (below the set threshold) my code will enter inside this first if:

if(enabled && percentage>=bars){
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC), dispatch_get_main_queue(), ^{

so the tweak will wait the set delay, giving the phone the time to downgrade itself as you mentioned before, then if you still have a bad LTE and the option enabled it will just disable LTE:

if(tryDownGradeNetworkSpeed && percentage>=bars && [[FSSwitchPanel sharedPanel] stateForSwitchIdentifier:@"com.a3tweaks.switch.lte"]==1){
[[FSSwitchPanel sharedPanel] setState:FSSwitchStateOff forSwitchIdentifier:@"com.a3tweaks.switch.lte"];
}
else if(!call && percentage>=bars && [[FSSwitchPanel sharedPanel] stateForSwitchIdentifier:@"com.a3tweaks.switch.airplane-mode"] == 0){...

But if you disabled the option or simply have only a bad 3G connection it's gonna skip the first if but enter inside the else if statement to trigger airplane mode.
Hope it makes sense to you, or let me know if I'm wrong with this concept. Thanks 😃

@sebikeller
Copy link
Copy Markdown
Author

Yes I think, you got it.
But to make it totally clear:

Some flow examples.

downgrade option enabled:

  • Bad LTE -> dispatch -> better LTE -> cancel dispatch -> do nothing.
  • Bad LTE -> dispatch -> still bad LTE -> switch to 3G -> better reception -> do nothing.
  • Bad LTE -> dispatch -> still bad LTE -> switch to 3G -> still bad reception -> dispatch -> still bad reception -> switch to airplane( -> recheck -> switch LTE on -> hope for good connection, otherwise start from scratch).
  • Bad LTE -> dispatch -> still bad LTE -> switch to 3G -> still bad reception -> dispatch -> better reception -> cancel dispatch (-> try to turn on LTE [after delay] -> hope for good connection, otherwise start from scratch).

downgrade option disabled:

  • Bad connection -> dispatch -> still bad reception -> switch to airplane.
  • Bad connection -> dispatch -> better reception -> cancel dispatch -> do nothing.

If no downgrade was possible, airplaine mode could have been never
enabled.
Added listener class to catch changed 3G/LTE Switch Events to reenable
"Network downgrade" option.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants