Skip to content

Provide callback instead of doing UI tasks of calling app #49 #50

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

Closed

Conversation

sunkup
Copy link
Member

@sunkup sunkup commented Feb 19, 2025

Purpose

cert4android shouldn't show the TrustCertificateActivity and a notification by itself. Instead it should execute a callback which is provided by the calling application.

Short description

  • stop passing the foreground state (appInForeground) to cert4android
  • start passing callback function getUserDecision and the coroutine scope in which it should run
  • adapt tests

Note

I would like to avoid the delay(1000) in testCheck_MultipleDecisionsForSameCert_Negative, but I could not make it work using a countdown latch and using a mutex quickly became complicated too. I also thought of launching a 6th seperate coroutine which would watch registry.pendingDecisions.size with a while loop and release the semaphore as soon as 5 pending decisions are reached, but could not make that work either. In the end the delay(1000) is quite simple and seems to work well, but let me know if you find a cleaner way.

@sunkup sunkup added the refactoring Quality improvement of existing functions label Feb 19, 2025
@sunkup sunkup self-assigned this Feb 19, 2025
@sunkup sunkup linked an issue Feb 19, 2025 that may be closed by this pull request
2 tasks
@sunkup sunkup changed the title [WIP] Provide callback instead of doing UI tasks of calling app #49 Feb 19, 2025
@sunkup sunkup force-pushed the 49-provide-callback-instead-of-doing-ui-tasks-of-calling-app branch 3 times, most recently from 3d64c67 to fe9ba2d Compare February 19, 2025 14:42
@sunkup sunkup force-pushed the 49-provide-callback-instead-of-doing-ui-tasks-of-calling-app branch from fe9ba2d to f3d1cc0 Compare February 19, 2025 14:49
@sunkup sunkup force-pushed the 49-provide-callback-instead-of-doing-ui-tasks-of-calling-app branch 7 times, most recently from d88df8e to 2776ce7 Compare February 26, 2025 14:02
@sunkup sunkup force-pushed the 49-provide-callback-instead-of-doing-ui-tasks-of-calling-app branch from 2776ce7 to 7ec1ded Compare February 26, 2025 14:05
@sunkup sunkup marked this pull request as ready for review February 26, 2025 14:15
@sunkup sunkup requested a review from ArnyminerZ February 26, 2025 14:16
Copy link
Member

@rfc2822 rfc2822 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Can you add more documentation for parameters, especially scope and what it does exactly (cancel waiting for a decision when the scope is cancelled I guess)?

@sunkup sunkup requested a review from rfc2822 March 12, 2025 08:53
@rfc2822 rfc2822 force-pushed the 49-provide-callback-instead-of-doing-ui-tasks-of-calling-app branch from b00fcf9 to 47b9aca Compare March 12, 2025 11:28
Copy link
Member

@rfc2822 rfc2822 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Continuation logic is still hard to understand for me because it's so low-level. I have tried to add a few comments to make it better understandable.

Looks good otherwise.

Please have a final look at 47b9aca, then we can merge

@sunkup
Copy link
Member Author

sunkup commented Mar 12, 2025

The Continuation logic is still hard to understand for me because it's so low-level. I have tried to add a few comments to make it better understandable.

Makes sense. I added a missing @param and also saw that we can replace the iterator with a forEach.

It's still complicated, but moving the scope.launch{} inside the synchronized block was a good idea. I feel it's easier to reason about now. It's a lot better than before 👍

@sunkup sunkup force-pushed the 49-provide-callback-instead-of-doing-ui-tasks-of-calling-app branch from f63b58a to 49bd354 Compare March 18, 2025 10:46
@sunkup sunkup requested a review from rfc2822 April 8, 2025 08:12
@rfc2822
Copy link
Member

rfc2822 commented Apr 8, 2025

Ok bad news from my side regarding cert4android. I must say that I don't understand the complexity of the current flow, including what exactly the scope does, what happens when it's cancelled, what happens when the check is cancelled, etc.

So I'm afraid that merging this may introduce new bugs in very rare cases (which we want to reduce).

I had originally thought that we could just "pull out" the UI as a first part of the redesign, but I guess I had underestimated the consequences and complexity that's still in there.

So an unfortunate (because of the work you have already put into this) question: shall we wait with this until we have the time to redesign the cert4android API from scratch in a better way? It's not perfect until it now is but it works in most cases.

When we would redesign the API at a later time, we could take the time to think about all known cases and side-cases.

@sunkup
Copy link
Member Author

sunkup commented Apr 9, 2025

As you like. I learned a lot, so it was not useless work for me 👍

It's true that with a better designed API we could probably do this way cleaner.

@rfc2822
Copy link
Member

rfc2822 commented Apr 9, 2025

@rfc2822
Copy link
Member

rfc2822 commented Apr 14, 2025

So let's only keep https://github.com/bitfireAT/cert4android/pull/50/files/12f1b4596fd26750094877df8be908c4930bf61e#r1991806967 ?

.. in a new PR.

Created #52 for that new PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Quality improvement of existing functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide callback instead of doing UI tasks of calling app
3 participants