super-productivity
super-productivity copied to clipboard
Major Android Update Discussion: Introducing Offline Support and Resolving CORS Issues
Problem:
-
Lack of Offline Support: The existing Android application requires an active internet connection to function, preventing users from accessing core features when offline.
-
CORS (Cross-Origin Resource Sharing) Issues: The app encounters CORS-related problems, limiting its ability to interact securely with local or self-hosted resources.
-
Security Concerns: There are significant security vulnerabilities related to network hijacking, which could lead to data breaches or unauthorized access if the app relies solely on external servers without proper safeguards.
Objective:
-
Enable Offline Functionality: Allow users to utilize the Android app's core features without needing an internet connection, enhancing accessibility and reliability.
-
Resolve CORS Issues: Configure WebView appropriately to eliminate CORS-related problems, ensuring secure and flexible interactions with various resources.
-
Enhance Security: Implement measures to prevent network hijacking and other security threats, ensuring that data interactions remain secure even when offline.
User Experience:
-
Enhanced Accessibility: Users can now access and use the app's functionalities even without an internet connection, making the app more reliable and user-friendly.
-
Seamless Experience for Existing Users: Existing users upgrading from older versions will continue using the app without any disruptions, maintaining data integrity and consistent functionality.
-
Offline Mode for New Installations: New installations will have offline capabilities enabled by default, allowing users to work without constant internet access.
-
Future Migration Plans: While the new offline solution is available for fresh installations, plans are in place to develop migration strategies to transition existing users to the new offline mode without affecting their current usage.
Technical Changes:
-
Introduced Capacitor:
- Reasoning: Compared to Cordova, Capacitor offers better performance, a more modern architecture, and easier integration with native platforms. Capacitor provides a more robust bridge for web-native interactions, enhancing the app's capabilities and maintainability.
-
Added
CapacitorMainActivity
:-
Purpose: Isolates the new Capacitor-based implementation from the existing
FullscreenActivity
, preventing mutual interference and ensuring stable operation for both new and existing users.
-
Purpose: Isolates the new Capacitor-based implementation from the existing
-
Introduced
LaunchDecider
Class:- Purpose: Manages the app's launch behavior based on whether the user performed a fresh installation or upgraded from a previous version.
-
Functionality: Utilizes
SharedPreferences
,PackageInfo
, and file existence checks to determine the appropriate launch mode (MODE_ONLINE
for existing users andMODE_OFFLINE
for new installations). -
Implementation: Ensures that users are directed to the correct activity (
FullscreenActivity
orCapacitorMainActivity
) based on their installation status.
-
Extracted
WebViewRequestHandler
:- Purpose: Centralizes the handling of WebView requests, including URL loading and request interception, to avoid code duplication across activities.
-
Functionality: Manages both
shouldOverrideUrlLoading
andshouldInterceptRequest
methods, ensuring consistent behavior and streamlined request processing.
-
Updated
AndroidManifest.xml
:-
Configuration: Set
FullscreenActivity
as the default launcher activity and declaredCapacitorMainActivity
appropriately without a launcher intent filter. -
Intent Handling: Ensured that
FullscreenActivity
manages the transition toCapacitorMainActivity
based on the launch decision logic.
-
Configuration: Set
-
Refactored
FullscreenActivity
:-
Integration: Incorporated
LaunchDecider
to determine the appropriate activity to launch duringonCreate
. -
Stability Fix: Added checks to prevent
wvContainer
from causing crashes by verifying its initialization before attempting to remove views inonDestroy
.
-
Integration: Incorporated
Progress:
-
Development Progress: 100% completed. The primary functionalities for offline support and CORS resolution have been implemented. See:
- https://github.com/johannesjo/super-productivity-android/pull/57
- https://github.com/johannesjo/super-productivity/pull/3554
Related Issues:
- https://github.com/johannesjo/super-productivity-android/issues/3
- https://github.com/johannesjo/super-productivity-android/issues/4
- https://github.com/johannesjo/super-productivity-android/issues/16
- https://github.com/johannesjo/super-productivity/issues/183
- https://github.com/johannesjo/super-productivity/issues/2309
Conclusion:
I have taken steps to address the longstanding issues related to offline support and CORS in the Android application. These updates are designed to enhance the user experience by enabling offline functionality, resolving security-related CORS issues, and ensuring a smooth transition for existing users. I welcome any questions or feedback from the community to help refine and improve the solution further.