Skip to content

Commit

Permalink
feat: update image permissions to comply with play store requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
hjiangsu committed Jan 10, 2025
1 parent acfca36 commit 32b2ccc
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 111 deletions.
5 changes: 1 addition & 4 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="29" />
<uses-permission android:name="android.permission.VIBRATE" />

<!-- The tools:replace line is needed by background_fetch -->
Expand Down
6 changes: 0 additions & 6 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ PODS:
- connectivity_plus (0.0.1):
- Flutter
- FlutterMacOS
- device_info_plus (0.0.1):
- Flutter
- Flutter (1.0.0)
- flutter_custom_tabs_ios (2.0.0):
- Flutter
Expand Down Expand Up @@ -85,7 +83,6 @@ DEPENDENCIES:
- app_links (from `.symlinks/plugins/app_links/ios`)
- background_fetch (from `.symlinks/plugins/background_fetch/ios`)
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/darwin`)
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
- Flutter (from `Flutter`)
- flutter_custom_tabs_ios (from `.symlinks/plugins/flutter_custom_tabs_ios/ios`)
- flutter_file_dialog (from `.symlinks/plugins/flutter_file_dialog/ios`)
Expand Down Expand Up @@ -121,8 +118,6 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/background_fetch/ios"
connectivity_plus:
:path: ".symlinks/plugins/connectivity_plus/darwin"
device_info_plus:
:path: ".symlinks/plugins/device_info_plus/ios"
Flutter:
:path: Flutter
flutter_custom_tabs_ios:
Expand Down Expand Up @@ -172,7 +167,6 @@ SPEC CHECKSUMS:
app_links: e7a6750a915a9e161c58d91bc610e8cd1d4d0ad0
background_fetch: 39f11371c0dce04b001c4bfd5e782bcccb0a85e2
connectivity_plus: 18382e7311ba19efcaee94442b23b32507b20695
device_info_plus: bf2e3232933866d73fe290f2942f2156cdd10342
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_custom_tabs_ios: a651b18786388923b62de8c0537607de87c2eccf
flutter_file_dialog: 4c014a45b105709a27391e266c277d7e588e9299
Expand Down
57 changes: 6 additions & 51 deletions lib/shared/image_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,22 @@ import 'dart:async';
import 'dart:io';
import 'dart:math';

import 'package:expandable/expandable.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:expandable/expandable.dart';
import 'package:extended_image/extended_image.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gal/gal.dart';
import 'package:share_plus/share_plus.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:thunder/core/enums/image_caching_mode.dart';
import 'package:thunder/shared/dialogs.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import 'package:thunder/core/enums/image_caching_mode.dart';
import 'package:thunder/shared/snackbar.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:thunder/thunder/bloc/thunder_bloc.dart';
import 'package:thunder/utils/media/image.dart';

Expand Down Expand Up @@ -103,44 +100,6 @@ class _ImageViewerState extends State<ImageViewer> with TickerProviderStateMixin
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge, overlays: SystemUiOverlay.values);
}

Future<bool> _requestPermission() async {
bool androidVersionBelow33 = false;

if (!kIsWeb && Platform.isAndroid) {
androidVersionBelow33 = (await DeviceInfoPlugin().androidInfo).version.sdkInt <= 32;
}

// Check first if we have permissions
bool hasStoragePermission = await Permission.storage.isGranted || await Permission.storage.isLimited;
bool hasPhotosPermission = await Permission.photos.isGranted || await Permission.photos.isLimited;

if (androidVersionBelow33 && !hasStoragePermission) {
await Permission.storage.request();
hasStoragePermission = await Permission.storage.isGranted || await Permission.storage.isLimited;
} else if (!androidVersionBelow33 && !hasPhotosPermission) {
await Permission.photos.request();
hasPhotosPermission = await Permission.photos.isGranted || await Permission.photos.isLimited;
}

if (!kIsWeb && Platform.isAndroid && androidVersionBelow33) return hasStoragePermission;
return hasPhotosPermission;
}

/// Shows a dialog indicating that permissions have been denied, and must be granted in order to save image.
void showPermissionDeniedDialog(BuildContext context) {
final AppLocalizations l10n = AppLocalizations.of(context)!;

showThunderDialog(
context: context,
title: l10n.permissionDenied,
contentText: l10n.permissionDeniedMessage,
onPrimaryButtonPressed: (_, __) {
openAppSettings();
},
primaryButtonText: l10n.openSettings,
);
}

Future<void> getImageSize() async {
try {
Size decodedImage = await retrieveImageDimensions(imageUrl: widget.url, imageBytes: widget.bytes).timeout(const Duration(seconds: 2));
Expand Down Expand Up @@ -535,12 +494,8 @@ class _ImageViewerState extends State<ImageViewer> with TickerProviderStateMixin
? null
: () async {
File file = await DefaultCacheManager().getSingleFile(widget.url!);
bool hasPermission = await _requestPermission();

if (!hasPermission) {
if (context.mounted) showPermissionDeniedDialog(context);
return;
}
bool hasPermission = await Gal.hasAccess(toAlbum: true);
if (!hasPermission) await Gal.requestAccess(toAlbum: true);

setState(() => isSavingMedia = true);

Expand Down
2 changes: 0 additions & 2 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Foundation

import app_links
import connectivity_plus
import device_info_plus
import dynamic_color
import file_selector_macos
import flutter_inappwebview_macos
Expand All @@ -25,7 +24,6 @@ import webview_flutter_wkwebview
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AppLinksMacosPlugin.register(with: registry.registrar(forPlugin: "AppLinksMacosPlugin"))
ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin"))
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin"))
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
InAppWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "InAppWebViewFlutterPlugin"))
Expand Down
32 changes: 13 additions & 19 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ PODS:
- connectivity_plus (0.0.1):
- Flutter
- FlutterMacOS
- device_info_plus (0.0.1):
- FlutterMacOS
- dynamic_color (0.0.2):
- FlutterMacOS
- file_selector_macos (0.0.1):
Expand All @@ -31,21 +29,21 @@ PODS:
- sqflite_darwin (0.0.4):
- Flutter
- FlutterMacOS
- sqlite3 (3.47.1):
- sqlite3/common (= 3.47.1)
- sqlite3/common (3.47.1)
- sqlite3/dbstatvtab (3.47.1):
- sqlite3 (3.47.2):
- sqlite3/common (= 3.47.2)
- sqlite3/common (3.47.2)
- sqlite3/dbstatvtab (3.47.2):
- sqlite3/common
- sqlite3/fts5 (3.47.1):
- sqlite3/fts5 (3.47.2):
- sqlite3/common
- sqlite3/perf-threadsafe (3.47.1):
- sqlite3/perf-threadsafe (3.47.2):
- sqlite3/common
- sqlite3/rtree (3.47.1):
- sqlite3/rtree (3.47.2):
- sqlite3/common
- sqlite3_flutter_libs (0.0.1):
- Flutter
- FlutterMacOS
- sqlite3 (~> 3.47.1)
- sqlite3 (~> 3.47.2)
- sqlite3/dbstatvtab
- sqlite3/fts5
- sqlite3/perf-threadsafe
Expand All @@ -62,7 +60,6 @@ PODS:
DEPENDENCIES:
- app_links (from `Flutter/ephemeral/.symlinks/plugins/app_links/macos`)
- connectivity_plus (from `Flutter/ephemeral/.symlinks/plugins/connectivity_plus/darwin`)
- device_info_plus (from `Flutter/ephemeral/.symlinks/plugins/device_info_plus/macos`)
- dynamic_color (from `Flutter/ephemeral/.symlinks/plugins/dynamic_color/macos`)
- file_selector_macos (from `Flutter/ephemeral/.symlinks/plugins/file_selector_macos/macos`)
- flutter_inappwebview_macos (from `Flutter/ephemeral/.symlinks/plugins/flutter_inappwebview_macos/macos`)
Expand All @@ -88,8 +85,6 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/app_links/macos
connectivity_plus:
:path: Flutter/ephemeral/.symlinks/plugins/connectivity_plus/darwin
device_info_plus:
:path: Flutter/ephemeral/.symlinks/plugins/device_info_plus/macos
dynamic_color:
:path: Flutter/ephemeral/.symlinks/plugins/dynamic_color/macos
file_selector_macos:
Expand Down Expand Up @@ -121,25 +116,24 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
app_links: 10e0a0ab602ffaf34d142cd4862f29d34b303b2a
connectivity_plus: 4c41c08fc6d7c91f63bc7aec70ffe3730b04f563
device_info_plus: 1b14eed9bf95428983aed283a8d51cce3d8c4215
connectivity_plus: 18382e7311ba19efcaee94442b23b32507b20695
dynamic_color: 2eaa27267de1ca20d879fbd6e01259773fb1670f
file_selector_macos: cc3858c981fe6889f364731200d6232dac1d812d
flutter_inappwebview_macos: bdf207b8f4ebd58e86ae06cd96b147de99a67c9b
flutter_local_notifications: 7062189aabf7f50938a7b8b6614ffa97656eb0bf
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
gal: 61e868295d28fe67ffa297fae6dacebf56fd53e1
gal: 6a522c75909f1244732d4596d11d6a2f86ff37a5
OrderedSet: e539b66b644ff081c73a262d24ad552a69be3a94
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
share_plus: 1fa619de8392a4398bfaf176d441853922614e89
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
sqflite_darwin: 5a7236e3b501866c1c9befc6771dfd73ffb8702d
sqlite3: 1e522f0938463e44b7faf50393b40bdc1e1e456d
sqlite3_flutter_libs: 1b4e98da20ebd4e9b1240269b78cdcf492dbe9f3
sqlite3: 7559e33dae4c78538df563795af3a86fc887ee71
sqlite3_flutter_libs: 58ae36c0dd086395d066b4fe4de9cdca83e717b3
url_launcher_macos: c82c93949963e55b228a30115bd219499a6fe404
video_player_avfoundation: 7c6c11d8470e1675df7397027218274b6d2360b3
webview_flutter_wkwebview: 0982481e3d9c78fd5c6f62a002fcd24fc791f1e4

PODFILE CHECKSUM: c2e95c8c0fe03c5c57e438583cae4cc732296009

COCOAPODS: 1.15.2
COCOAPODS: 1.16.2
32 changes: 4 additions & 28 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,10 @@ packages:
dependency: transitive
description:
name: dart_style
sha256: "27eb0ae77836989a3bc541ce55595e8ceee0992807f14511552a898ddd0d88ac"
sha256: "7856d364b589d1f08986e140938578ed36ed948581fbc3bc9aef1805039ac5ab"
url: "https://pub.dev"
source: hosted
version: "3.0.1"
version: "2.3.7"
dbus:
dependency: transitive
description:
Expand All @@ -382,22 +382,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.10"
device_info_plus:
dependency: "direct main"
description:
name: device_info_plus
sha256: "4fa68e53e26ab17b70ca39f072c285562cfc1589df5bb1e9295db90f6645f431"
url: "https://pub.dev"
source: hosted
version: "11.2.0"
device_info_plus_platform_interface:
dependency: transitive
description:
name: device_info_plus_platform_interface
sha256: "0b04e02b30791224b31969eb1b50d723498f402971bff3630bca2ba839bd1ed2"
url: "https://pub.dev"
source: hosted
version: "7.0.2"
drift:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1635,10 +1619,10 @@ packages:
dependency: transitive
description:
name: source_gen
sha256: "35c8150ece9e8c8d263337a265153c3329667640850b9304861faea59fc98f6b"
sha256: "14658ba5f669685cd3d63701d01b31ea748310f7ab854e471962670abcf57832"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
version: "1.5.0"
source_span:
dependency: transitive
description:
Expand Down Expand Up @@ -2071,14 +2055,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.10.0"
win32_registry:
dependency: transitive
description:
name: win32_registry
sha256: "21ec76dfc731550fd3e2ce7a33a9ea90b828fdf19a5c3bcf556fa992cfa99852"
url: "https://pub.dev"
source: hosted
version: "1.1.5"
xayn_readability:
dependency: "direct main"
description:
Expand Down
1 change: 0 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ dependencies:
connectivity_plus: "^6.0.2"
dart_ping: "^9.0.0"
dart_ping_ios: "^4.0.0"
device_info_plus: ^11.1.1
drift: "^2.21.0"
drift_flutter: "^0.2.1"
dynamic_color: "^1.6.5"
Expand Down

0 comments on commit 32b2ccc

Please sign in to comment.