1
0
mirror of https://github.com/go-vikunja/app synced 2024-06-02 18:49:47 +00:00
feat: add policy to AndroidManifest
This commit is contained in:
Denys Vitali 2024-04-05 15:41:48 +02:00
parent 1d538d6816
commit d83114e9aa
No known key found for this signature in database
GPG Key ID: 5227C664145098BC
7 changed files with 62 additions and 20 deletions

View File

@ -21,7 +21,9 @@
android:label="Vikunja" android:label="Vikunja"
android:name="${applicationName}" android:name="${applicationName}"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:usesCleartextTraffic="true"> android:networkSecurityConfig="@xml/network_security_config"
>
<meta-data android:name="io.flutter.network-policy" android:resource="@xml/network_security_config"/>
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:launchMode="singleTop" android:launchMode="singleTop"
@ -106,4 +108,4 @@
</provider> </provider>
</application> </application>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
</manifest> </manifest>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
</trust-anchors>
</base-config>
</network-security-config>

View File

@ -1,9 +1,11 @@
import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'dart:core'; import 'dart:core';
import 'dart:io'; import 'dart:io';
import 'package:cronet_http/cronet_http.dart' as cronet_http;
import 'package:cupertino_http/cupertino_http.dart' as cupertino_http;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:http/io_client.dart' as io_client;
import 'package:vikunja_app/api/response.dart'; import 'package:vikunja_app/api/response.dart';
import 'package:vikunja_app/components/string_extension.dart'; import 'package:vikunja_app/components/string_extension.dart';
import 'package:vikunja_app/global.dart'; import 'package:vikunja_app/global.dart';
@ -25,16 +27,42 @@ class Client {
String? post_body; String? post_body;
bool operator ==(dynamic otherClient) { @override
bool operator ==(Object otherClient) {
if (otherClient is! Client) return false;
return otherClient._token == _token; return otherClient._token == _token;
} }
Client(this.global_scaffold_key, Client(
{String? token, String? base, bool authenticated = false}) { this.global_scaffold_key, {
configure(token: token, base: base, authenticated: authenticated); String? token,
String? base,
bool authenticated = false,
}) {
configure(
token: token,
base: base,
authenticated: authenticated,
);
} }
void reload_ignore_certs(bool? val) { http.Client get httpClient {
if (Platform.isAndroid) {
final engine = cronet_http.CronetEngine.build(
cacheMode: cronet_http.CacheMode.memory, cacheMaxSize: 1000000);
return cronet_http.CronetClient.fromCronetEngine(engine);
}
if (Platform.isIOS || Platform.isMacOS) {
final config =
cupertino_http.URLSessionConfiguration.ephemeralSessionConfiguration()
..cache =
cupertino_http.URLCache.withCapacity(memoryCapacity: 1000000);
return cupertino_http.CupertinoClient.fromSessionConfiguration(config);
}
return io_client.IOClient();
}
void reloadIgnoreCerts(bool? val) {
ignoreCertificates = val ?? false; ignoreCertificates = val ?? false;
HttpOverrides.global = new IgnoreCertHttpOverrides(ignoreCertificates); HttpOverrides.global = new IgnoreCertHttpOverrides(ignoreCertificates);
if (global_scaffold_key == null || if (global_scaffold_key == null ||
@ -47,7 +75,7 @@ class Client {
get _headers => { get _headers => {
'Authorization': _token != '' ? 'Bearer $_token' : '', 'Authorization': _token != '' ? 'Bearer $_token' : '',
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'User-Agent': 'Vikunja Mobile App' 'User-Agent': 'Vikunja Mobile App',
}; };
get headers => _headers; get headers => _headers;
@ -55,7 +83,11 @@ class Client {
@override @override
int get hashCode => _token.hashCode; int get hashCode => _token.hashCode;
void configure({String? token, String? base, bool? authenticated}) { void configure({
String? token,
String? base,
bool? authenticated,
}) {
if (token != null) _token = token; if (token != null) _token = token;
if (base != null) { if (base != null) {
base = base.replaceAll(" ", ""); base = base.replaceAll(" ", "");
@ -66,7 +98,6 @@ class Client {
} }
void reset() { void reset() {
_token = _base = '';
authenticated = false; authenticated = false;
} }
@ -85,14 +116,14 @@ class Client {
queryParameters: queryParameters, queryParameters: queryParameters,
fragment: uri.fragment); fragment: uri.fragment);
return http return httpClient
.get(uri, headers: _headers) .get(uri, headers: _headers)
.then(_handleResponse) .then(_handleResponse)
.onError((error, stackTrace) => _handleError(error, stackTrace)); .onError((error, stackTrace) => _handleError(error, stackTrace));
} }
Future<Response?> delete(String url) { Future<Response?> delete(String url) {
return http return httpClient
.delete( .delete(
'${this.base}$url'.toUri()!, '${this.base}$url'.toUri()!,
headers: _headers, headers: _headers,
@ -102,7 +133,7 @@ class Client {
} }
Future<Response?> post(String url, {dynamic body}) { Future<Response?> post(String url, {dynamic body}) {
return http return httpClient
.post( .post(
'${this.base}$url'.toUri()!, '${this.base}$url'.toUri()!,
headers: _headers, headers: _headers,
@ -113,7 +144,7 @@ class Client {
} }
Future<Response?> put(String url, {dynamic body}) { Future<Response?> put(String url, {dynamic body}) {
return http return httpClient
.put( .put(
'${this.base}$url'.toUri()!, '${this.base}$url'.toUri()!,
headers: _headers, headers: _headers,
@ -183,7 +214,7 @@ class Client {
} }
Response? _handleResponse(http.Response response) { Response? _handleResponse(http.Response response) {
Error? error = _handleResponseErrors(response); _handleResponseErrors(response);
return Response( return Response(
_decoder.convert(response.body), response.statusCode, response.headers); _decoder.convert(response.body), response.statusCode, response.headers);
} }

View File

@ -116,7 +116,7 @@ class VikunjaGlobalState extends State<VikunjaGlobal> {
_client = Client(snackbarKey); _client = Client(snackbarKey);
settingsManager settingsManager
.getIgnoreCertificates() .getIgnoreCertificates()
.then((value) => client.reload_ignore_certs(value == "1")); .then((value) => client.reloadIgnoreCerts(value == "1"));
_newUserService = UserAPIService(client); _newUserService = UserAPIService(client);
_loadCurrentUser(); _loadCurrentUser();
tz.initializeTimeZones(); tz.initializeTimeZones();

View File

@ -48,7 +48,7 @@ void callbackDispatcher() {
.getIgnoreCertificates() .getIgnoreCertificates()
.then((value) async { .then((value) async {
print("ignoring: $value"); print("ignoring: $value");
client.reload_ignore_certs(value == "1"); client.reloadIgnoreCerts(value == "1");
TaskAPIService taskService = TaskAPIService(client); TaskAPIService taskService = TaskAPIService(client);
NotificationClass nc = NotificationClass(); NotificationClass nc = NotificationClass();

View File

@ -173,7 +173,7 @@ class SettingsPageState extends State<SettingsPage> {
value: ignoreCertificates, value: ignoreCertificates,
onChanged: (value) { onChanged: (value) {
setState(() => ignoreCertificates = value); setState(() => ignoreCertificates = value);
VikunjaGlobal.of(context).client.reload_ignore_certs(value); VikunjaGlobal.of(context).client.reloadIgnoreCerts(value);
}) })
: ListTile(title: Text("...")), : ListTile(title: Text("...")),
Divider(), Divider(),

View File

@ -264,7 +264,7 @@ class _LoginPageState extends State<LoginPage> {
value: client.ignoreCertificates, value: client.ignoreCertificates,
onChanged: (value) { onChanged: (value) {
setState( setState(
() => client.reload_ignore_certs(value ?? false)); () => client.reloadIgnoreCerts(value ?? false));
VikunjaGlobal.of(context) VikunjaGlobal.of(context)
.settingsManager .settingsManager
.setIgnoreCertificates(value ?? false); .setIgnoreCertificates(value ?? false);