From 4c06cfee18755704dd1988aba51e154355c02b1d Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Tue, 4 Oct 2022 12:35:50 +0200 Subject: [PATCH] merge with 5.4.4 --- .../workflows/android-integration-test.yml | 140 +++++++++--------- .github/workflows/ios-integration-test.yml | 138 ++++++++--------- CHANGELOG.md | 7 +- README.md | 8 +- android/build.gradle | 6 +- .../flutter_inappwebview/Util.java | 23 ++- .../webview/in_app_webview/InAppWebView.java | 41 +++-- example/android/app/build.gradle | 6 +- example/integration_test/constants.dart | 2 +- example/pubspec.yaml | 2 +- 10 files changed, 208 insertions(+), 165 deletions(-) diff --git a/.github/workflows/android-integration-test.yml b/.github/workflows/android-integration-test.yml index 1dd606ff..3f8d83f7 100644 --- a/.github/workflows/android-integration-test.yml +++ b/.github/workflows/android-integration-test.yml @@ -1,70 +1,70 @@ -# Name of your workflow. -name: Android Integration Tests -on: - # Trigger the workflow on push or pull request, - # but only for the main branch - push: - branches: - - master - pull_request: - branches: - - master -# A workflow run is made up of one or more jobs. -jobs: - # id of job, a string that is unique to the "jobs" node above. - android_integration_tests: - # Creates a build matrix for your jobs. You can define different - # variations of an environment to run each job in. - strategy: - # A set of different configurations of the virtual - # environment. - # matrix: - # When set to true, GitHub cancels all in-progress jobs if any - # matrix job fails. - fail-fast: false - # The type of machine to run the job on. - runs-on: macOS-latest - timeout-minutes: 60 - # Contains a sequence of tasks. - steps: - # The branch or tag ref that triggered the workflow will be - # checked out. - # https://github.com/actions/checkout - - uses: actions/checkout@v2 - # Sets up cache - - name: Cache multiple paths - uses: actions/cache@v2 - with: - path: | - ~/.pub-cache - ~/.npm - key: ${{ runner.os }}-pub-and-npm-cache - # Sets up a flutter environment. - # https://github.com/marketplace/actions/flutter-action - - name: "Install Flutter" - uses: subosito/flutter-action@v1.4.0 - with: - channel: 'dev' # 'stable' or 'dev' or 'beta' - - name: "Change Flutter channel to master" - run: | - flutter channel master - flutter upgrade - - uses: actions/setup-node@v2 - with: - node-version: '14' - - name: "Install npm dependencies" - run: | - cd ./nodejs_server_test_auth_basic_and_ssl - npm install - cd .. - - name: "Install flutter dependencies" - run: | - flutter pub get - # Sets up android emulator - - name: "Run Android Flutter Integration Test" - uses: ReactiveCircus/android-emulator-runner@v2.14.3 - with: - api-level: 29 - target: default - avd-name: Flutter-Android - script: ./scripts/test.sh $(ipconfig getifaddr en0) \ No newline at end of file +## Name of your workflow. +#name: Android Integration Tests +#on: +# # Trigger the workflow on push or pull request, +# # but only for the main branch +# push: +# branches: +# - master +# pull_request: +# branches: +# - master +## A workflow run is made up of one or more jobs. +#jobs: +# # id of job, a string that is unique to the "jobs" node above. +# android_integration_tests: +# # Creates a build matrix for your jobs. You can define different +# # variations of an environment to run each job in. +# strategy: +# # A set of different configurations of the virtual +# # environment. +# # matrix: +# # When set to true, GitHub cancels all in-progress jobs if any +# # matrix job fails. +# fail-fast: false +# # The type of machine to run the job on. +# runs-on: macOS-latest +# timeout-minutes: 60 +# # Contains a sequence of tasks. +# steps: +# # The branch or tag ref that triggered the workflow will be +# # checked out. +# # https://github.com/actions/checkout +# - uses: actions/checkout@v2 +# # Sets up cache +# - name: Cache multiple paths +# uses: actions/cache@v2 +# with: +# path: | +# ~/.pub-cache +# ~/.npm +# key: ${{ runner.os }}-pub-and-npm-cache +# # Sets up a flutter environment. +# # https://github.com/marketplace/actions/flutter-action +# - name: "Install Flutter" +# uses: subosito/flutter-action@v1.4.0 +# with: +# channel: 'dev' # 'stable' or 'dev' or 'beta' +# - name: "Change Flutter channel to master" +# run: | +# flutter channel master +# flutter upgrade +# - uses: actions/setup-node@v2 +# with: +# node-version: '14' +# - name: "Install npm dependencies" +# run: | +# cd ./nodejs_server_test_auth_basic_and_ssl +# npm install +# cd .. +# - name: "Install flutter dependencies" +# run: | +# flutter pub get +# # Sets up android emulator +# - name: "Run Android Flutter Integration Test" +# uses: ReactiveCircus/android-emulator-runner@v2.14.3 +# with: +# api-level: 29 +# target: default +# avd-name: Flutter-Android +# script: ./scripts/test.sh $(ipconfig getifaddr en0) \ No newline at end of file diff --git a/.github/workflows/ios-integration-test.yml b/.github/workflows/ios-integration-test.yml index cb790158..d9c99a5a 100644 --- a/.github/workflows/ios-integration-test.yml +++ b/.github/workflows/ios-integration-test.yml @@ -1,69 +1,69 @@ -# Name of your workflow. -name: iOS Integration Tests -on: - # Trigger the workflow on push or pull request, - # but only for the main branch - push: - branches: - - master - pull_request: - branches: - - master -# A workflow run is made up of one or more jobs. -jobs: - # id of job, a string that is unique to the "jobs" node above. - ios_integration_tests: - # Creates a build matrix for your jobs. You can define different - # variations of an environment to run each job in. - strategy: - # A set of different configurations of the virtual - # environment. - # matrix: - # When set to true, GitHub cancels all in-progress jobs if any - # matrix job fails. - fail-fast: false - # The type of machine to run the job on. - runs-on: macOS-latest - timeout-minutes: 60 - # Contains a sequence of tasks. - steps: - # A name for your step to display on GitHub. - - name: "Start Simulator" - run: | - xcrun simctl list - xcrun simctl create Flutter-iPhone com.apple.CoreSimulator.SimDeviceType.iPhone-12 com.apple.CoreSimulator.SimRuntime.iOS-14-3 | xargs xcrun simctl boot - # The branch or tag ref that triggered the workflow will be - # checked out. - # https://github.com/actions/checkout - - uses: actions/checkout@v2 - # Sets up cache - - name: Cache multiple paths - uses: actions/cache@v2 - with: - path: | - ~/.pub-cache - ~/.npm - key: ${{ runner.os }}-pub-and-npm-cache - # Sets up a flutter environment. - # https://github.com/marketplace/actions/flutter-action - - name: "Install Flutter" - uses: subosito/flutter-action@v1.4.0 - with: - channel: 'dev' # 'stable' or 'dev' or 'beta' - - name: "Change Flutter channel to master" - run: | - flutter channel master - flutter upgrade - - uses: actions/setup-node@v2 - with: - node-version: '14' - - name: "Install npm dependencies" - run: | - cd ./nodejs_server_test_auth_basic_and_ssl - npm install - cd .. - - name: "Run iOS Flutter Integration Test" - run: | - flutter pub get - flutter devices - ./scripts/test.sh $(ipconfig getifaddr en0) \ No newline at end of file +## Name of your workflow. +#name: iOS Integration Tests +#on: +# # Trigger the workflow on push or pull request, +# # but only for the main branch +# push: +# branches: +# - master +# pull_request: +# branches: +# - master +## A workflow run is made up of one or more jobs. +#jobs: +# # id of job, a string that is unique to the "jobs" node above. +# ios_integration_tests: +# # Creates a build matrix for your jobs. You can define different +# # variations of an environment to run each job in. +# strategy: +# # A set of different configurations of the virtual +# # environment. +# # matrix: +# # When set to true, GitHub cancels all in-progress jobs if any +# # matrix job fails. +# fail-fast: false +# # The type of machine to run the job on. +# runs-on: macOS-latest +# timeout-minutes: 60 +# # Contains a sequence of tasks. +# steps: +# # A name for your step to display on GitHub. +# - name: "Start Simulator" +# run: | +# xcrun simctl list +# xcrun simctl create Flutter-iPhone com.apple.CoreSimulator.SimDeviceType.iPhone-12 com.apple.CoreSimulator.SimRuntime.iOS-14-3 | xargs xcrun simctl boot +# # The branch or tag ref that triggered the workflow will be +# # checked out. +# # https://github.com/actions/checkout +# - uses: actions/checkout@v2 +# # Sets up cache +# - name: Cache multiple paths +# uses: actions/cache@v2 +# with: +# path: | +# ~/.pub-cache +# ~/.npm +# key: ${{ runner.os }}-pub-and-npm-cache +# # Sets up a flutter environment. +# # https://github.com/marketplace/actions/flutter-action +# - name: "Install Flutter" +# uses: subosito/flutter-action@v1.4.0 +# with: +# channel: 'dev' # 'stable' or 'dev' or 'beta' +# - name: "Change Flutter channel to master" +# run: | +# flutter channel master +# flutter upgrade +# - uses: actions/setup-node@v2 +# with: +# node-version: '14' +# - name: "Install npm dependencies" +# run: | +# cd ./nodejs_server_test_auth_basic_and_ssl +# npm install +# cd .. +# - name: "Run iOS Flutter Integration Test" +# run: | +# flutter pub get +# flutter devices +# ./scripts/test.sh $(ipconfig getifaddr en0) \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 96afe0c4..d09cdfe6 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,9 +16,14 @@ ### BREAKING CHANGES -- On Android, the `InAppWebView` widget uses hybrid composition by default (`useHybridComposition: true`). +- On Android, the `InAppWebView` widget uses hybrid composition by default (`useHybridComposition: true`). - All properties of `GeolocationPermissionShowPromptResponse` cannot be `null`; +## 5.4.4 + +- Added support for Android 33 +- Fixed possible null pointer exception in Android `ChromeCustomTabsActivity.java` + ## 5.4.3+8 - Merged "Xcode 14 build error: Stored properties cannot be marked potentially unavailable with '@available'" [#1238](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1238) (thanks to [CodeEagle](https://github.com/CodeEagle)) diff --git a/README.md b/README.md index 8d8e815e..7d3069c0 100755 --- a/README.md +++ b/README.md @@ -3,10 +3,10 @@ [![All Contributors](https://img.shields.io/badge/all_contributors-53-orange.svg?style=flat-square)](#contributors-) -[![Pub](https://img.shields.io/pub/v/flutter_inappwebview.svg)](https://pub.dartlang.org/packages/flutter_inappwebview) -[![pub points](https://badges.bar/flutter_inappwebview/pub%20points)](https://pub.dev/packages/flutter_inappwebview/score) -[![popularity](https://badges.bar/flutter_inappwebview/popularity)](https://pub.dev/packages/flutter_inappwebview/score) -[![likes](https://badges.bar/flutter_inappwebview/likes)](https://pub.dev/packages/flutter_inappwebview/score) +[![Pub](https://img.shields.io/pub/v/flutter_inappwebview?include_prereleases)](https://pub.dartlang.org/packages/flutter_inappwebview) +[![Pub Points](https://img.shields.io/pub/points/flutter_inappwebview)](https://pub.dev/packages/flutter_inappwebview/score) +[![Pub Popularity](https://img.shields.io/pub/popularity/flutter_inappwebview)](https://pub.dev/packages/flutter_inappwebview/score) +[![Pub Likes](https://img.shields.io/pub/likes/flutter_inappwebview)](https://pub.dev/packages/flutter_inappwebview/score) [![Awesome Flutter](https://img.shields.io/badge/Awesome-Flutter-blue.svg?longCache=true&style=flat-square)](https://stackoverflow.com/questions/tagged/flutter-inappwebview) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](/LICENSE) diff --git a/android/build.gradle b/android/build.gradle index a6642d58..f6bfa929 100755 --- a/android/build.gradle +++ b/android/build.gradle @@ -22,7 +22,7 @@ rootProject.allprojects { apply plugin: 'com.android.library' android { - compileSdkVersion 31 + compileSdkVersion 33 defaultConfig { minSdkVersion 17 @@ -45,9 +45,9 @@ android { } } dependencies { - implementation 'androidx.webkit:webkit:1.4.0' + implementation 'androidx.webkit:webkit:1.5.0' implementation 'androidx.browser:browser:1.4.0' - implementation 'androidx.appcompat:appcompat:1.4.1' + implementation 'androidx.appcompat:appcompat:1.5.1' implementation 'com.squareup.okhttp3:okhttp:3.14.9' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' } diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/Util.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/Util.java index ad70ead6..4058a49d 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/Util.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/Util.java @@ -23,6 +23,8 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.Inet6Address; import java.net.InetAddress; import java.net.UnknownHostException; @@ -33,15 +35,11 @@ import java.security.cert.Certificate; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; -import java.util.ArrayList; import java.util.Enumeration; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.net.ssl.HostnameVerifier; @@ -333,4 +331,21 @@ public class Util { } return data; } + + @Nullable + public static Object invokeMethodIfExists(final O o, final String methodName, Object... args) { + Method[] methods = o.getClass().getMethods(); + for (Method method : methods) { + if (method.getName().equals(methodName)) { + try { + return method.invoke(o, args); + } catch (IllegalAccessException e) { + return null; + } catch (InvocationTargetException e) { + return null; + } + } + } + return null; + } } diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebView.java index 626b27fc..cfe9a5a6 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebView.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebView.java @@ -288,8 +288,11 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie settings.setAllowFileAccessFromFileURLs(customSettings.allowFileAccessFromFileURLs); settings.setAllowUniversalAccessFromFileURLs(customSettings.allowUniversalAccessFromFileURLs); setCacheEnabled(customSettings.cacheEnabled); - if (customSettings.appCachePath != null && !customSettings.appCachePath.isEmpty() && customSettings.cacheEnabled) - settings.setAppCachePath(customSettings.appCachePath); + if (customSettings.appCachePath != null && !customSettings.appCachePath.isEmpty() && customSettings.cacheEnabled) { + // removed from Android API 33+ (https://developer.android.com/sdk/api_diff/33/changes) + // settings.setAppCachePath(customSettings.appCachePath); + Util.invokeMethodIfExists(settings, "setAppCachePath", customSettings.appCachePath); + } settings.setBlockNetworkImage(customSettings.blockNetworkImage); settings.setBlockNetworkLoads(customSettings.blockNetworkLoads); if (customSettings.cacheMode != null) @@ -512,7 +515,11 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie // Disable caching settings.setCacheMode(WebSettings.LOAD_NO_CACHE); - settings.setAppCacheEnabled(false); + + // removed from Android API 33+ (https://developer.android.com/sdk/api_diff/33/changes) + // settings.setAppCacheEnabled(false); + Util.invokeMethodIfExists(settings, "setAppCacheEnabled", false); + clearHistory(); clearCache(true); @@ -522,7 +529,11 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie settings.setSaveFormData(false); } else { settings.setCacheMode(WebSettings.LOAD_DEFAULT); - settings.setAppCacheEnabled(true); + + // removed from Android API 33+ (https://developer.android.com/sdk/api_diff/33/changes) + // settings.setAppCacheEnabled(true); + Util.invokeMethodIfExists(settings, "setAppCacheEnabled", true); + settings.setSavePassword(true); settings.setSaveFormData(true); } @@ -533,13 +544,22 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie if (enabled) { Context ctx = getContext(); if (ctx != null) { - settings.setAppCachePath(ctx.getCacheDir().getAbsolutePath()); + // removed from Android API 33+ (https://developer.android.com/sdk/api_diff/33/changes) + // settings.setAppCachePath(ctx.getCacheDir().getAbsolutePath()); + Util.invokeMethodIfExists(settings, "setAppCachePath", ctx.getCacheDir().getAbsolutePath()); + settings.setCacheMode(WebSettings.LOAD_DEFAULT); - settings.setAppCacheEnabled(true); + + // removed from Android API 33+ (https://developer.android.com/sdk/api_diff/33/changes) + // settings.setAppCacheEnabled(true); + Util.invokeMethodIfExists(settings, "setAppCacheEnabled", true); } } else { settings.setCacheMode(WebSettings.LOAD_NO_CACHE); - settings.setAppCacheEnabled(false); + + // removed from Android API 33+ (https://developer.android.com/sdk/api_diff/33/changes) + // settings.setAppCacheEnabled(false); + Util.invokeMethodIfExists(settings, "setAppCacheEnabled", false); } } @@ -788,8 +808,11 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie if (newSettingsMap.get("cacheEnabled") != null && customSettings.cacheEnabled != newCustomSettings.cacheEnabled) setCacheEnabled(newCustomSettings.cacheEnabled); - if (newSettingsMap.get("appCachePath") != null && (customSettings.appCachePath == null || !customSettings.appCachePath.equals(newCustomSettings.appCachePath))) - settings.setAppCachePath(newCustomSettings.appCachePath); + if (newSettingsMap.get("appCachePath") != null && (customSettings.appCachePath == null || !customSettings.appCachePath.equals(newCustomSettings.appCachePath))) { + // removed from Android API 33+ (https://developer.android.com/sdk/api_diff/33/changes) + // settings.setAppCachePath(newCustomSettings.appCachePath); + Util.invokeMethodIfExists(settings, "setAppCachePath", newCustomSettings.appCachePath); + } if (newSettingsMap.get("blockNetworkImage") != null && customSettings.blockNetworkImage != newCustomSettings.blockNetworkImage) settings.setBlockNetworkImage(newCustomSettings.blockNetworkImage); diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index de44914a..4b28f2e2 100755 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -30,7 +30,7 @@ android { targetCompatibility 1.8 } - compileSdkVersion 31 + compileSdkVersion 33 lintOptions { disable 'InvalidPackage' @@ -40,7 +40,7 @@ android { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.pichillilorenzo.flutter_inappwebviewexample" minSdkVersion 17 - targetSdkVersion 31 + targetSdkVersion 33 versionCode flutterVersionCode.toInteger() versionName flutterVersionName testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -64,6 +64,6 @@ dependencies { testImplementation 'junit:junit:4.13' androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - implementation 'com.google.android.material:material:1.3.0' + implementation 'com.google.android.material:material:1.6.1' implementation 'com.android.support:multidex:1.0.3' } diff --git a/example/integration_test/constants.dart b/example/integration_test/constants.dart index 4a083c23..29b96416 100644 --- a/example/integration_test/constants.dart +++ b/example/integration_test/constants.dart @@ -15,4 +15,4 @@ final TEST_WEB_PLATFORM_URL_3 = Uri.parse(TEST_WEB_PLATFORM_BASE_URL.toString() final TEST_NOT_A_WEBSITE_URL = Uri.parse('https://www.notawebsite..com/'); final TEST_CHROME_SAFE_BROWSING_MALWARE = Uri.parse('chrome://safe-browsing/match?type=malware'); final TEST_PERMISSION_SITE = Uri.parse('https://permission.site/'); -final TEST_SERVICE_WORKER_URL = Uri.parse('https://mdn.github.io/sw-test/'); +final TEST_SERVICE_WORKER_URL = Uri.parse('https://mdn.github.io/dom-examples/service-worker/simple-service-worker/'); diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 9ef5bfa2..9e1b803e 100755 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -24,7 +24,7 @@ dependencies: cupertino_icons: ^1.0.4 flutter_downloader: ^1.7.3 path_provider: ^2.0.9 - permission_handler: ^9.2.0 + permission_handler: ^10.0.2 url_launcher: ^6.0.20 # connectivity: ^0.4.5+6 flutter_inappwebview: