Skip to content

Conversation

@tamaskozmer
Copy link
Contributor

Summary

Prevents errors when users attempt to launch external LTI tools while offline by adding network connectivity checks and displaying an informative toast message.

Test plan

  1. Turn off network connectivity (Wi-Fi and mobile data)
  2. Navigate to any course with external tools (e.g., discussions with embedded LTI tools, pages with external tools)
  3. Attempt to launch an external tool by clicking the button
  4. Verify a toast message appears: "External Tools are not available offline."
  5. Turn network connectivity back on
  6. Attempt to launch the same external tool
  7. Verify the tool launches successfully without errors

Changes

  • Added network availability check before launching LTI tools in multiple locations:
    • DiscussionDetailsFragment (Student app)
    • BindingAdapters (shared)
    • WebViewExtensions (shared)
    • CanvasWebView (shared)
  • Updated Utils.isNetworkAvailable() to use modern NetworkCapabilities API instead of deprecated activeNetworkInfo
  • Added new string resource ltiToolsOffline for the error message

refs: MBL-19631
affects: Student, Teacher, Parent
release note: Fixed errors when attempting to launch external tools while offline

  • Follow-up e2e test ticket created or not needed
  • Tested in dark mode
  • Tested in light mode
  • Test in landscape mode and/or tablet
  • A11y checked
  • Approve from product

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

Copy link

@claude claude bot left a comment

Choose a reason for hiding this comment

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

Review Summary

This PR adds offline detection for LTI (Learning Tools Interoperability) external tools, preventing users from attempting to launch external tools when there's no network connection. Overall approach is solid, but there are several issues to address.

Issues Found

  • Context lifecycle issues with Toast display - Multiple locations use ContextKeeper.appContext to show Toasts, which can cause display issues since application context isn't tied to an activity window. See comments in BindingAdapters.kt:200, WebViewExtensions.kt:87, and CanvasWebView.kt:889

  • Code style inconsistency - Fully qualified android.widget.Toast used in some files instead of imports. Per CLAUDE.md: "Always use imports instead of fully qualified names in code". See WebViewExtensions.kt:87 and CanvasWebView.kt:889

  • Network detection could be more robust - The updated isNetworkAvailable() only checks NET_CAPABILITY_INTERNET, which indicates capability but not actual connectivity. Consider adding NET_CAPABILITY_VALIDATED check for more accurate offline detection. See Utils.kt:53

  • Code duplication - The offline check logic is duplicated across 4 different files. Consider extracting to a shared helper method or handling this at a single entry point

Positive Aspects

✓ Good modernization of the network detection API from deprecated activeNetworkInfo to NetworkCapabilities
✓ Consistent user-facing error message using string resource
✓ Appropriate use of early return pattern for readability
✓ Covers multiple entry points for LTI tool launches

Recommendations

  1. Fix Toast context issues - Either use the Fragment's context in DiscussionDetailsFragment.kt (where it's available via requireContext()), or consider an event-based approach where the UI layer handles user feedback
  2. Add proper imports - Replace fully qualified class names with imports
  3. Enhance network detection - Add NET_CAPABILITY_VALIDATED check for more accurate connectivity detection
  4. Consider refactoring - The duplication suggests this logic might be better centralized, perhaps in a wrapper around the LTI callback

Test Coverage

No tests were added in this PR. Consider adding:

  • Unit tests for the updated Utils.isNetworkAvailable() method
  • UI tests verifying the Toast appears when offline and LTI tools are blocked

@github-actions
Copy link

github-actions bot commented Jan 6, 2026

🧪 Unit Test Results

✅ 📱 Parent App

  • Tests: 310 total, 0 failed, 0 skipped
  • Duration: 30.782s
  • Success Rate: 100%

✅ 📱 Student App

  • Tests: 1241 total, 0 failed, 0 skipped
  • Duration: 0.000s
  • Success Rate: 100%

✅ 📱 Teacher App

  • Tests: 369 total, 0 failed, 0 skipped
  • Duration: 31.314s
  • Success Rate: 100%

✅ 🌅 Horizon

  • Tests: 449 total, 0 failed, 0 skipped
  • Duration: 33.387s
  • Success Rate: 100%

✅ 📦 Submodules

  • Tests: 2515 total, 0 failed, 0 skipped
  • Duration: 62.856s
  • Success Rate: 100%

📊 Summary

  • Total Tests: 4884
  • Failed: 0
  • Skipped: 0
  • Status: ✅ All tests passed!

Last updated: Tue, 06 Jan 2026 15:28:11 GMT

@github-actions
Copy link

github-actions bot commented Jan 6, 2026

📊 Code Coverage Report

✅ Student

  • PR Coverage: 43.55%
  • Master Coverage: 43.55%
  • Delta: +0.00%

✅ Teacher

  • PR Coverage: 25.61%
  • Master Coverage: 25.61%
  • Delta: +0.00%

⚠️ Pandautils

  • PR Coverage: 22.91%
  • Master Coverage: 22.91%
  • Delta: -0.00%

📈 Overall Average

  • PR Coverage: 30.69%
  • Master Coverage: 30.69%
  • Delta: +0.00%

@github-actions
Copy link

github-actions bot commented Jan 6, 2026

Teacher Install Page

@github-actions
Copy link

github-actions bot commented Jan 6, 2026

Parent Install Page

@github-actions
Copy link

github-actions bot commented Jan 6, 2026

Student Install Page

Copy link
Contributor

@kdeakinstructure kdeakinstructure left a comment

Choose a reason for hiding this comment

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

QA 👍

Copy link
Contributor

@adamNagy56 adamNagy56 left a comment

Choose a reason for hiding this comment

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

QA +1

@tamaskozmer tamaskozmer merged commit 875dd54 into master Jan 7, 2026
49 of 51 checks passed
@tamaskozmer tamaskozmer deleted the MBL-19631-launch-external-tool-error branch January 7, 2026 13:43
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.

5 participants