From 897afaa04ae5154af44ece4cdc8e2939fff6d43c Mon Sep 17 00:00:00 2001 From: Yury Ilinykh Date: Tue, 6 Aug 2024 15:23:16 +0300 Subject: [PATCH] Android: support users certificates and fix video play with selfsigned proxy --- .drone.yml | 6 +- .github/workflows/build.yml | 2 +- .github/workflows/release.yml | 6 +- android/app/src/main/AndroidManifest.xml | 7 +- .../main/res/xml/network_security_config.xml | 9 ++ lib/service.dart | 85 +++++++++++-------- pubspec.lock | 26 +++++- pubspec.yaml | 1 + 8 files changed, 96 insertions(+), 46 deletions(-) create mode 100644 android/app/src/main/res/xml/network_security_config.xml diff --git a/.drone.yml b/.drone.yml index c3afe3a5..0e8afa3b 100644 --- a/.drone.yml +++ b/.drone.yml @@ -23,9 +23,9 @@ steps: - ./submodules/flutter/bin/flutter config --no-analytics - ./submodules/flutter/bin/flutter pub get - ./submodules/flutter/bin/flutter pub run flutter_native_splash:create - - ./submodules/flutter/bin/flutter build apk --split-per-abi - - ./submodules/flutter/bin/flutter build apk - - ./submodules/flutter/bin/flutter build appbundle + - ./submodules/flutter/bin/flutter build apk --split-per-abi --dart-define=cronetHttpNoPlay=true + - ./submodules/flutter/bin/flutter build apk --dart-define=cronetHttpNoPlay=true + - ./submodules/flutter/bin/flutter build appbundle --dart-define=cronetHttpNoPlay=true - cd /drone/src/ - mkdir -p build/app/outputs/flutter-apk - mkdir -p build/app/outputs/bundle/release diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 25c39ed7..e9451dd3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -51,7 +51,7 @@ jobs: # - name: Run tests with nix (starts postgres and invidious server) # run: nix-shell --run './submodules/flutter/bin/flutter test' - run: ./submodules/flutter/bin/flutter pub run flutter_native_splash:create - - run: ./submodules/flutter/bin/flutter build apk --profile --split-per-abi + - run: ./submodules/flutter/bin/flutter build apk --profile --split-per-abi --dart-define=cronetHttpNoPlay=true - name: Archive build artifacts uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8a6f8a74..87daeeb8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -57,9 +57,9 @@ jobs: ./submodules/flutter/bin/flutter config --no-analytics ./submodules/flutter/bin/flutter pub get ./submodules/flutter/bin/flutter pub run flutter_native_splash:create - ./submodules/flutter/bin/flutter build apk --split-per-abi - ./submodules/flutter/bin/flutter build apk - ./submodules/flutter/bin/flutter build appbundle + ./submodules/flutter/bin/flutter build apk --split-per-abi --dart-define=cronetHttpNoPlay=true + ./submodules/flutter/bin/flutter build apk --dart-define=cronetHttpNoPlay=true + ./submodules/flutter/bin/flutter build appbundle --dart-define=cronetHttpNoPlay=true - name: Moving build artifacts run: | mkdir -p build/app/outputs/flutter-apk diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index d9fd1814..016ec939 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -20,8 +20,11 @@ android:label="Clipious" android:name="${applicationName}" android:icon="@mipmap/ic_launcher" - android:usesCleartextTraffic="true" - android:banner="@drawable/banner"> + android:banner="@drawable/banner" + android:networkSecurityConfig="@xml/network_security_config" > + + + + + + + + + + diff --git a/lib/service.dart b/lib/service.dart index 77a7dbe0..a21b7ad5 100644 --- a/lib/service.dart +++ b/lib/service.dart @@ -1,9 +1,11 @@ import 'dart:convert'; +import 'dart:io' show Platform; import 'package:flutter/foundation.dart'; import 'package:flutter_web_auth/flutter_web_auth.dart'; import 'package:http/http.dart' as http; import 'package:http/http.dart'; +import 'package:cronet_http/cronet_http.dart'; import 'package:invidious/channels/models/channel_sort_by.dart'; import 'package:invidious/extensions.dart'; import 'package:invidious/globals.dart'; @@ -76,7 +78,18 @@ const imgurClientId = 'Client-ID 2cfbc27ce77879d'; const maxPing = 9007199254740991; class Service { - final log = Logger('Service'); + final log; + final Client httpClient; + + Service() : + log = Logger('Service'), + httpClient = Platform.isAndroid ? + CronetClient.fromCronetEngine( + CronetEngine.build( + cacheMode: CacheMode.memory, + cacheMaxSize: 2 * 1024 * 1024), + closeEngine: true) : + http.Client(); String urlFormatForLog(Uri? uri) { return kDebugMode ? uri.toString() : '${uri?.replace(host: 'xxxxxxxxxx')}'; @@ -153,7 +166,7 @@ class Service { Future