- Bumped Android minSdk to 30 (Android 11) - Fixed permission service not handling Android SDK 33 correctly - Fixed permission service not being started during application start
This commit is contained in:
parent
c99df89cb0
commit
e661171fd2
11 changed files with 128 additions and 91 deletions
|
@ -2,7 +2,10 @@
|
||||||
|
|
||||||
## 1.6.2+20 - UNRELEASED
|
## 1.6.2+20 - UNRELEASED
|
||||||
* Updated internal dependencies
|
* Updated internal dependencies
|
||||||
* Move progress indicator of _Show Configuration_ into button
|
* Moved progress indicator of _Show Configuration_ into the underlying button
|
||||||
|
* Bumped Android minSdk to `30` (Android 11)
|
||||||
|
* Fixed permission service not handling Android SDK 33 correctly
|
||||||
|
* Fixed permission service not being started during application start
|
||||||
|
|
||||||
## 1.6.1+19
|
## 1.6.1+19
|
||||||
* Updated internal dependencies
|
* Updated internal dependencies
|
||||||
|
|
|
@ -39,7 +39,7 @@ android {
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "de.varakh.fbmobile"
|
applicationId "de.varakh.fbmobile"
|
||||||
minSdkVersion 19
|
minSdkVersion 30
|
||||||
targetSdkVersion 33
|
targetSdkVersion 33
|
||||||
versionCode flutterVersionCode.toInteger()
|
versionCode flutterVersionCode.toInteger()
|
||||||
versionName flutterVersionName
|
versionName flutterVersionName
|
||||||
|
|
|
@ -4,7 +4,10 @@
|
||||||
to allow setting breakpoints, to provide hot reload, etc.
|
to allow setting breakpoints, to provide hot reload, etc.
|
||||||
-->
|
-->
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
|
||||||
|
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
|
||||||
|
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
|
||||||
|
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
|
||||||
|
|
||||||
<queries>
|
<queries>
|
||||||
<intent>
|
<intent>
|
||||||
|
|
|
@ -30,7 +30,10 @@
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
|
||||||
|
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
|
||||||
|
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
|
||||||
|
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
|
||||||
|
|
||||||
<queries>
|
<queries>
|
||||||
<intent>
|
<intent>
|
||||||
|
|
|
@ -4,7 +4,10 @@
|
||||||
to allow setting breakpoints, to provide hot reload, etc.
|
to allow setting breakpoints, to provide hot reload, etc.
|
||||||
-->
|
-->
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
|
||||||
|
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
|
||||||
|
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
|
||||||
|
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
|
||||||
|
|
||||||
<queries>
|
<queries>
|
||||||
<intent>
|
<intent>
|
||||||
|
|
|
@ -126,14 +126,6 @@
|
||||||
"description": "Could not open '{link}'. Please ensure that you have an application installed which handles opening such link types."
|
"description": "Could not open '{link}'. Please ensure that you have an application installed which handles opening such link types."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"permission_service": {
|
|
||||||
"dialog": {
|
|
||||||
"title": "Storage permission",
|
|
||||||
"description": "Storage permission should be granted to the app so that it can work properly. Do you want to grant permission or ignore this message permanently in the future?",
|
|
||||||
"grant": "Grant",
|
|
||||||
"ignore": "Ignore"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"dialog": {
|
"dialog": {
|
||||||
"confirm": "OK",
|
"confirm": "OK",
|
||||||
"cancel": "Cancel"
|
"cancel": "Cancel"
|
||||||
|
|
|
@ -1,108 +1,100 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:io' show Platform;
|
||||||
|
|
||||||
import 'package:flutter_translate/flutter_translate.dart';
|
import 'package:device_info_plus/device_info_plus.dart';
|
||||||
import 'package:logger/logger.dart';
|
import 'package:logger/logger.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
|
||||||
import '../../constants.dart';
|
import '../../constants.dart';
|
||||||
import '../../core/datamodels/dialog_response.dart';
|
|
||||||
import '../../core/services/dialog_service.dart';
|
|
||||||
import '../../core/services/stoppable_service.dart';
|
import '../../core/services/stoppable_service.dart';
|
||||||
import '../../core/util/logger.dart';
|
import '../../core/util/logger.dart';
|
||||||
import '../../locator.dart';
|
|
||||||
import 'storage_service.dart';
|
|
||||||
|
|
||||||
class PermissionService extends StoppableService {
|
class PermissionService extends StoppableService {
|
||||||
final Logger _logger = getLogger();
|
final Logger _logger = getLogger();
|
||||||
final DialogService _dialogService = locator<DialogService>();
|
|
||||||
final StorageService _storageService = locator<StorageService>();
|
|
||||||
|
|
||||||
Timer? _serviceCheckTimer;
|
Timer? _serviceCheckTimer;
|
||||||
|
|
||||||
PermissionStatus? _permissionStatus;
|
|
||||||
|
|
||||||
bool _permanentlyIgnored = false;
|
|
||||||
bool _devicePermissionDialogActive = false;
|
bool _devicePermissionDialogActive = false;
|
||||||
bool _ownPermissionDialogActive = false;
|
|
||||||
|
|
||||||
PermissionService() {
|
bool _deviceInformationInitialized = false;
|
||||||
_devicePermissionDialogActive = true;
|
bool _useStoragePermission = true;
|
||||||
|
|
||||||
Permission.storage.request().then((status) {
|
PermissionService();
|
||||||
_permissionStatus = status;
|
|
||||||
if (PermissionStatus.permanentlyDenied == status) {
|
|
||||||
_permanentlyIgnored = true;
|
|
||||||
}
|
|
||||||
}).whenComplete(() {
|
|
||||||
_logger.d('Initial device request permission finished');
|
|
||||||
_devicePermissionDialogActive = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Future checkEnabledAndPermission() async {
|
Future checkEnabledAndPermission() async {
|
||||||
if (_permanentlyIgnored) {
|
|
||||||
await _storageService.storeStoragePermissionDialogIgnored();
|
|
||||||
_permanentlyIgnored = false;
|
|
||||||
_logger.d('Set permanently ignored permission request');
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_devicePermissionDialogActive) {
|
if (_devicePermissionDialogActive) {
|
||||||
_logger.d('Device permission dialog active, skipping');
|
_logger.d('Device permission dialog active, skipping');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_ownPermissionDialogActive) {
|
bool allGranted = false;
|
||||||
_logger.d('Own permission dialog already active, skipping');
|
bool anyPermanentlyDenied = false;
|
||||||
return;
|
|
||||||
|
// Since Android compileSdk >= 33, "storage" is deprecated
|
||||||
|
// Instead, request access to all of
|
||||||
|
// - Permission.photos
|
||||||
|
// - Permission.videos
|
||||||
|
// - Permission.audio
|
||||||
|
//
|
||||||
|
// For iOS and Android < 33, keep using "storage"
|
||||||
|
if (_useStoragePermission) {
|
||||||
|
PermissionStatus storagePermission = await Permission.storage.status;
|
||||||
|
allGranted = PermissionStatus.granted == storagePermission;
|
||||||
|
anyPermanentlyDenied =
|
||||||
|
PermissionStatus.permanentlyDenied == storagePermission;
|
||||||
|
} else {
|
||||||
|
PermissionStatus photosPermission = await Permission.photos.status;
|
||||||
|
PermissionStatus videosPermission = await Permission.videos.status;
|
||||||
|
PermissionStatus audioPermission = await Permission.audio.status;
|
||||||
|
|
||||||
|
allGranted = PermissionStatus.granted == photosPermission &&
|
||||||
|
PermissionStatus.granted == videosPermission &&
|
||||||
|
PermissionStatus.granted == audioPermission;
|
||||||
|
anyPermanentlyDenied =
|
||||||
|
PermissionStatus.permanentlyDenied == photosPermission ||
|
||||||
|
PermissionStatus.permanentlyDenied == videosPermission ||
|
||||||
|
PermissionStatus.permanentlyDenied == audioPermission;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ignoredDialog =
|
// show warning to user to manually handle, don't enforce it over and over again
|
||||||
await _storageService.hasStoragePermissionDialogIgnored();
|
if (anyPermanentlyDenied) {
|
||||||
|
_logger.w(
|
||||||
if (ignoredDialog) {
|
"At least one required permission has been denied permanently, stopping service");
|
||||||
_logger.d('Permanently ignored permission request, skipping');
|
|
||||||
stop();
|
stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_permissionStatus = await Permission.storage.status;
|
// all good, stop the permission service
|
||||||
if (_permissionStatus != PermissionStatus.granted) {
|
if (allGranted) {
|
||||||
if (_permissionStatus == PermissionStatus.permanentlyDenied) {
|
_logger.d("All permissions have been granted, stopping service");
|
||||||
await _storageService.storeStoragePermissionDialogIgnored();
|
stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ownPermissionDialogActive = true;
|
// not all have been granted, show OS dialog
|
||||||
DialogResponse response = await _dialogService.showConfirmationDialog(
|
_logger.d(
|
||||||
title: translate('permission_service.dialog.title'),
|
"Not all permissions have been granted yet, initializing permission dialog");
|
||||||
description: translate('permission_service.dialog.description'),
|
|
||||||
buttonTitleAccept: translate('permission_service.dialog.grant'),
|
|
||||||
buttonTitleDeny: translate('permission_service.dialog.ignore'));
|
|
||||||
|
|
||||||
if (!response.confirmed!) {
|
|
||||||
await _storageService.storeStoragePermissionDialogIgnored();
|
|
||||||
} else {
|
|
||||||
_devicePermissionDialogActive = true;
|
_devicePermissionDialogActive = true;
|
||||||
Permission.storage.request().then((status) async {
|
|
||||||
if (PermissionStatus.permanentlyDenied == status) {
|
if (_useStoragePermission) {
|
||||||
await _storageService.storeStoragePermissionDialogIgnored();
|
await [Permission.storage].request().whenComplete(() {
|
||||||
}
|
|
||||||
}).whenComplete(() {
|
|
||||||
_logger.d('Device request permission finished');
|
_logger.d('Device request permission finished');
|
||||||
_devicePermissionDialogActive = false;
|
_devicePermissionDialogActive = false;
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
_ownPermissionDialogActive = false;
|
|
||||||
} else {
|
} else {
|
||||||
await _storageService.storeStoragePermissionDialogIgnored();
|
await [Permission.photos, Permission.videos, Permission.audio]
|
||||||
|
.request()
|
||||||
|
.whenComplete(() {
|
||||||
|
_logger.d('Device request permission finished');
|
||||||
|
_devicePermissionDialogActive = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future start() async {
|
Future start() async {
|
||||||
super.start();
|
super.start();
|
||||||
|
await _determineDeviceInfo();
|
||||||
await checkEnabledAndPermission();
|
await checkEnabledAndPermission();
|
||||||
|
|
||||||
_serviceCheckTimer = Timer.periodic(
|
_serviceCheckTimer = Timer.periodic(
|
||||||
|
@ -124,6 +116,29 @@ class PermissionService extends StoppableService {
|
||||||
_logger.d('PermissionService stopped');
|
_logger.d('PermissionService stopped');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future _determineDeviceInfo() async {
|
||||||
|
if (_deviceInformationInitialized) {
|
||||||
|
_logger.d('Device information already initialized, skipping');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
final androidInfo = await deviceInfoPlugin.androidInfo;
|
||||||
|
if (androidInfo.version.sdkInt >= 33) {
|
||||||
|
_useStoragePermission = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_useStoragePermission) {
|
||||||
|
_logger.d('Device requires [storage] permission');
|
||||||
|
} else {
|
||||||
|
_logger.d('Device requires [photos,videos,audio] permission');
|
||||||
|
}
|
||||||
|
|
||||||
|
_deviceInformationInitialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
void _removeServiceCheckTimer() {
|
void _removeServiceCheckTimer() {
|
||||||
if (_serviceCheckTimer != null) {
|
if (_serviceCheckTimer != null) {
|
||||||
_serviceCheckTimer!.cancel();
|
_serviceCheckTimer!.cancel();
|
||||||
|
|
|
@ -7,8 +7,6 @@ import '../models/session.dart';
|
||||||
class StorageService {
|
class StorageService {
|
||||||
static const _sessionKey = 'session';
|
static const _sessionKey = 'session';
|
||||||
static const _lastUrlKey = 'last_url';
|
static const _lastUrlKey = 'last_url';
|
||||||
static const _storagePermissionDialogIgnoredKey =
|
|
||||||
'storage_permission_ignored';
|
|
||||||
|
|
||||||
Future<bool> storeLastUrl(String url) {
|
Future<bool> storeLastUrl(String url) {
|
||||||
return _store(_lastUrlKey, url);
|
return _store(_lastUrlKey, url);
|
||||||
|
@ -39,14 +37,6 @@ class StorageService {
|
||||||
return _remove(_sessionKey);
|
return _remove(_sessionKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> storeStoragePermissionDialogIgnored() {
|
|
||||||
return _store(_storagePermissionDialogIgnoredKey, true.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<bool> hasStoragePermissionDialogIgnored() {
|
|
||||||
return _exists(_storagePermissionDialogIgnoredKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<bool> _exists(String key) async {
|
Future<bool> _exists(String key) async {
|
||||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
return prefs.containsKey(key);
|
return prefs.containsKey(key);
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:fbmobile/core/services/permission_service.dart';
|
||||||
import 'package:flutter_translate/flutter_translate.dart';
|
import 'package:flutter_translate/flutter_translate.dart';
|
||||||
|
|
||||||
import '../../locator.dart';
|
import '../../locator.dart';
|
||||||
|
@ -9,16 +10,18 @@ import 'base_model.dart';
|
||||||
|
|
||||||
class StartUpViewModel extends BaseModel {
|
class StartUpViewModel extends BaseModel {
|
||||||
final SessionService _sessionService = locator<SessionService>();
|
final SessionService _sessionService = locator<SessionService>();
|
||||||
|
final PermissionService _permissionService = locator<PermissionService>();
|
||||||
final NavigationService _navigationService = locator<NavigationService>();
|
final NavigationService _navigationService = locator<NavigationService>();
|
||||||
|
|
||||||
Future handleStartUpLogic() async {
|
Future handleStartUpLogic() async {
|
||||||
setStateView(ViewState.busy);
|
setStateView(ViewState.busy);
|
||||||
setStateMessage(translate('startup.init'));
|
setStateMessage(translate('startup.init'));
|
||||||
await Future.delayed(const Duration(milliseconds: 150));
|
await Future.delayed(const Duration(milliseconds: 100));
|
||||||
|
|
||||||
setStateMessage(translate('startup.start_services'));
|
setStateMessage(translate('startup.start_services'));
|
||||||
await _sessionService.start();
|
await _sessionService.start();
|
||||||
await Future.delayed(const Duration(milliseconds: 150));
|
await _permissionService.start();
|
||||||
|
await Future.delayed(const Duration(milliseconds: 100));
|
||||||
|
|
||||||
_navigationService.navigateAndReplaceTo(HomeView.routeName);
|
_navigationService.navigateAndReplaceTo(HomeView.routeName);
|
||||||
|
|
||||||
|
|
24
pubspec.lock
24
pubspec.lock
|
@ -201,6 +201,22 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.3.4"
|
version: "2.3.4"
|
||||||
|
device_info_plus:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: device_info_plus
|
||||||
|
sha256: "0042cb3b2a76413ea5f8a2b40cec2a33e01d0c937e91f0f7c211fde4f7739ba6"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "9.1.1"
|
||||||
|
device_info_plus_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: device_info_plus_platform_interface
|
||||||
|
sha256: d3b01d5868b50ae571cd1dc6e502fc94d956b665756180f7b16ead09e836fd64
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "7.0.0"
|
||||||
dynamic_color:
|
dynamic_color:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -994,6 +1010,14 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "5.1.0"
|
version: "5.1.0"
|
||||||
|
win32_registry:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: win32_registry
|
||||||
|
sha256: "41fd8a189940d8696b1b810efb9abcf60827b6cbfab90b0c43e8439e3a39d85a"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.2"
|
||||||
xdg_directories:
|
xdg_directories:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -43,6 +43,7 @@ dependencies:
|
||||||
intl: 0.18.1
|
intl: 0.18.1
|
||||||
path: 1.8.3
|
path: 1.8.3
|
||||||
flutter_sharing_intent: 1.1.0
|
flutter_sharing_intent: 1.1.0
|
||||||
|
device_info_plus: 9.1.1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
Loading…
Reference in a new issue