Skip to content

feat: Implement ActivityResultContract - #1033

Open
stefan-niedermann wants to merge 2 commits into
mainfrom
448-activity-result-contract
Open

feat: Implement ActivityResultContract#1033
stefan-niedermann wants to merge 2 commits into
mainfrom
448-activity-result-contract

Conversation

@stefan-niedermann

Copy link
Copy Markdown
Member

Motivation:

  • Provide state-of-the-art access to Nextcloud Single Sign On
  • Hide complete permission granting and account importing process behind a clear API surface
  • Deprecate methods that rely on deprecated Android framework methods like onActivityResult
  • Enhance maintainability and make refactoring easier in the future when the deprecated methods have eventually been removed or marked as private

Refs: #448

Co-authored-by: Gemini

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

Motivation:
- Provide state-of-the-art access to Nextcloud Single Sign On
- Hide complete permission granting and account importing process behind a clear API surface
- Deprecate methods that rely on deprecated Android framework methods like onActivityResult
- Enhance maintainability and make refactoring easier in the future when the deprecated methods have eventually been removed or marked as private

Refs: #448

Co-authored-by: Gemini
Signed-off-by: Stefan Niedermann <info@niedermann.it>
@codacy-production

codacy-production Bot commented Jul 15, 2026

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 1 minor

Alerts:
⚠ 1 issue (≤ 0 issues of at least minor severity)

Results:
1 new issue

Category Results
CodeStyle 1 minor

View in Codacy

🟢 Metrics 14 complexity

Metric Results
Complexity 14

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@stefan-niedermann stefan-niedermann linked an issue Jul 15, 2026 that may be closed by this pull request
@stefan-niedermann

Copy link
Copy Markdown
Member Author

Additional information

Exception Handling

A third party app can start the import process and gets either a SingleSignOnAccount instance or null. Displaying errors to the users is handled intentionally completely within the SSO lib.

This aligns with other ActivityResultContracts and gives the SSO lib the full control over exception handling for a uniform user experience across various 3rd party apps.

Theming

There are multiple sources of dialogs that may look different within the flow:

  • Native android dialogs like the account chooser
  • Permission dialogs from the files app
  • Exception dialogs from the SSO lib

Given this does not affect the (now) deprecated way of importing accounts, this can be enhanced progressively in my opinion, so this should not be a show stopper.
Maybe @AndyScherzinger has some ideas how to unify the styling in the complete flow?

Testing

Tested successfully manually on AVD API level 24 without Google Play Services and API Level 36.1 with Google Play Services.

@github-actions

Copy link
Copy Markdown

SpotBugs

CategoryBaseNew
Bad practice99
Correctness2424
Dodgy code1316
Internationalization22
Malicious code vulnerability1111
Multithreaded correctness44
Performance44
Security77
Total7477

SpotBugs increased!

@AndyScherzinger

Copy link
Copy Markdown
Member

Given this does not affect the (now) deprecated way of importing accounts, this can be enhanced progressively in my opinion, so this should not be a show stopper.
Maybe @AndyScherzinger has some ideas how to unify the styling in the complete flow?

@stefan-niedermann Likely depends on how they have been implemented. Lately we migrated various parts of the UI to Composables and with that we get theming "for free" in the sense that we now just to proper design tokens for styling and inject the apps server theme and are done, everything else properly managed by the Composables themselves now. SO no need for calling theme APIs any longer 🚀

@github-actions

Copy link
Copy Markdown

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)


if (savedInstanceState == null) {

try {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why nested try block used here?


/// This is a Trampoline Activity that takes care about requesting all necessary permissions and guiding the user through the complete import flow.
/// It is extremely important to catch *any* error and finish this activity because otherwise, the Trampoline Activity will stay on top but transparent, so users can't see it and users can't interact with their (visible) 3rd party app anymore.
public class ImportSsoAccountActivity extends AppCompatActivity {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can't we use Kotlin for new files?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure, one can do this. Please note, that (speaking for me personally only) enforcing Kotlin will stop further contributions from my side to this library. I don't want to trigger a "Kotlin vs. Java" discussion, this is a personal decision.

@alperozturk96 alperozturk96 Jul 30, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Of course Java is perfectly fine; it was just a question for new file.

Thank you for the PR :)

protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (savedInstanceState == null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can fail fast here instead nested if.

Comment thread lib/src/main/java/com/nextcloud/android/sso/ImportSsoAccountActivity.java Outdated
*
* @see <a href="https://developer.android.com/training/basics/intents/result"><code>ActivityResultContract</code></a>
*/
public class ImportSsoAccount extends ActivityResultContract<Void, SingleSignOnAccount> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can't we use Kotlin for new files?

Refs: #448

Signed-off-by: Stefan Niedermann <info@niedermann.it>
@github-actions

Copy link
Copy Markdown

SpotBugs

CategoryBaseNew
Bad practice99
Correctness2424
Dodgy code1316
Internationalization22
Malicious code vulnerability1111
Multithreaded correctness44
Performance44
Security77
Total7477

SpotBugs increased!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Activity Result API

3 participants