[flutter_inappwebview_android] Fix Android Java deprecation warnings (batch 1)#2817
Open
Khairul989 wants to merge 1 commit into
Open
[flutter_inappwebview_android] Fix Android Java deprecation warnings (batch 1)#2817Khairul989 wants to merge 1 commit into
Khairul989 wants to merge 1 commit into
Conversation
- Replace `new Long(String)` with `Long.parseLong(String)` in MyCookieManager.
- Replace `new Handler()` with `new Handler(Looper.getMainLooper())` in InAppWebView.
- Route previously-ungated `CookieManager.removeSessionCookie()` calls through a new `clearSessionCookies()` helper that uses `removeSessionCookies(null)` on API 21+ and falls back to the deprecated call only on pre-LOLLIPOP.
- Annotate methods that retain pre-LOLLIPOP `CookieSyncManager` / `CookieManager.removeAllCookie` / `removeSessionCookie` fallbacks with `@SuppressWarnings("deprecation")` to silence javac warnings without changing behavior on minSdk 19/20.
Refs pichillilorenzo#2641
|
Hey @Khairul989! We've applied parts of your deprecation warning cleanup batch (#2817) into the zikzak_inappwebview fork — including the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Connection with issue(s)
Resolve issue #2641
Resolve issue #2685
Connected to #1627
Summary
First batch of mechanical, low-risk fixes for the Android
javacdeprecation warnings reported against theflutter_inappwebview_androidpackage when compiling withcompileSdk 36and Java 17.Changes
new Long(String)→Long.parseLong(String)MyCookieManager.java(cookieexpiresDateparsing)new Handler()→new Handler(Looper.getMainLooper())InAppWebView.javastaticmHandler(Looperwas already imported)CookieSyncManagerfallbacks — calls were already SDK-gated insideBuild.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOPbranches. Added@SuppressWarnings("deprecation")on the enclosing methods to silence the warnings without changing behavior onminSdk 19/20:MyCookieManager.java:setCookie,deleteCookie,deleteCookies,deleteAllCookies,removeSessionCookies,flushInAppWebViewClient.onPageFinishedInAppWebViewClientCompat.onPageFinishedCookieManager.removeSessionCookie()/removeAllCookie()removeSessionCookie()calls inInAppWebView.java(theclearSessionCachesetting path, in bothsetSettingsandsetNewSettings) are now routed through a new privateclearSessionCookies()helper that callsremoveSessionCookies(null)on API 21+ and falls back to the deprecated sync variant on pre-LOLLIPOP.setIncognitoandclearCookiesinInAppWebView.javaalready had the correct SDK gate forremoveAllCookie(); annotated with@SuppressWarnings("deprecation").Warning count (debug build of
flutter_inappwebview/example/withcompileSdk 36, Java 17,-Xlint:deprecation -Xlint:unchecked)Measured via
./gradlew :flutter_inappwebview_android:compileDebugJavaWithJavac --rerun-taskswith an init script adding the-Xlintflags.warning: [...]countCategories eliminated: all
CookieSyncManager(createInstance,startSync,stopSync,sync), allHandler(), allnew Long(String), allCookieManager.removeAllCookie/removeSessionCookie.Testing and Review Notes
flutter_inappwebview_platform_interfacecontract touched. No code generation needed.minSdkVersionis19, soCookieSyncManager/removeAllCookie()/removeSessionCookie()must still compile and run on API 19–20. All deprecated calls are preserved behind aBuild.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOPcheck.setIncognitoandclearCookies(already usingremoveAllCookies(...)).The new
clearSessionCookies()helper usesCookieManager.removeSessionCookies(null)on API 21+, which is asynchronous, whereas the previous code calledremoveSessionCookie()synchronously. The call site is theclearSessionCachesettings path (InAppWebView.javainsetSettings/setNewSettings) — it is fire-and-forget, so no downstream code in this plugin awaits completion. If reviewers want to preserve strict sync semantics, passing aValueCallbackthat completes a latch is possible, but I don't think any caller depends on sync clearing here.Verification steps for reviewers
Out of scope (deferred to follow-up PRs)
These are intentionally not in this batch because they change behavior or public API:
setForceDark/setForceDarkStrategy→setAlgorithmicDarkeningAllowedsetSaveFormData/setSavePassword(no-ops on modern APIs)SYSTEM_UI_FLAG_*→WindowInsetsControllerAbsoluteLayout.LayoutParamsNARROW_COLUMNS(publicLayoutAlgorithmenum)Bundle.getSerializable(String)→(String, Class)(API 33)createPrintDocumentAdapter()(no-arg)SAFE_BROWSING_WHITELIST/setSafeBrowsingWhitelist→…Allowlist(AndroidX)setAllowFileAccessFromFileURLs/setAllowUniversalAccessFromFileURLs(security, see Bug Report / Security Concern: Deprecated setAllowUniversalAccessFromFileURLs Used (Insecure File Access) #2700)Screenshots or Videos
N/A (no UI changes).
To Do