Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mobile][photos] bump photo_manager to 3.10.0 and replace media store API calls with photo_manager ones

Priyanshu Dangare81112306fdb7
diff --git a/mobile/apps/photos/android/app/src/main/kotlin/io/ente/photos/MainActivity.kt b/mobile/apps/photos/android/app/src/main/kotlin/io/ente/photos/MainActivity.kt
index b35f615b2f..7422f67826 100644
--- a/mobile/apps/photos/android/app/src/main/kotlin/io/ente/photos/MainActivity.kt
+++ b/mobile/apps/photos/android/app/src/main/kotlin/io/ente/photos/MainActivity.kt
@@ -2,14 +2,8 @@ package io.ente.photos
import android.content.Intent
import io.flutter.embedding.android.FlutterFragmentActivity
-import io.flutter.embedding.engine.FlutterEngine
class MainActivity : FlutterFragmentActivity() {
- override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
- super.configureFlutterEngine(flutterEngine)
- NativeChannels.register(this, flutterEngine)
- }
-
override fun onNewIntent(intent: Intent) {
setIntent(intent)
super.onNewIntent(intent)
diff --git a/mobile/apps/photos/android/app/src/main/kotlin/io/ente/photos/NativeChannels.kt b/mobile/apps/photos/android/app/src/main/kotlin/io/ente/photos/NativeChannels.kt
deleted file mode 100644
index ac4b79858c..0000000000
--- a/mobile/apps/photos/android/app/src/main/kotlin/io/ente/photos/NativeChannels.kt
+++ /dev/null
@@ -1,60 +0,0 @@
-package io.ente.photos
-
-import android.os.Build
-import android.provider.MediaStore
-import android.content.Context
-import android.content.Intent
-import android.net.Uri
-import android.provider.Settings
-import io.flutter.embedding.engine.FlutterEngine
-import io.flutter.plugin.common.BinaryMessenger
-import io.flutter.plugin.common.MethodCall
-import io.flutter.plugin.common.MethodChannel
-
-object NativeChannels {
- fun register(context: Context, flutterEngine: FlutterEngine) {
- val messenger = flutterEngine.dartExecutor.binaryMessenger
- MediaStoreChannel(context.applicationContext).register(messenger)
- }
-}
-
-private class MediaStoreChannel(private val context: Context) {
- fun register(messenger: BinaryMessenger) {
- MethodChannel(messenger, CHANNEL).setMethodCallHandler(::handle)
- }
-
- private fun handle(call: MethodCall, result: MethodChannel.Result) {
- when (call.method) {
- "isMediaManagementSupported" -> result.success(isMediaManagementSupported())
- "canManageMedia" -> result.success(canManageMedia())
- "openManageMediaSettings" -> {
- openManageMediaSettings()
- result.success(null)
- }
- else -> result.notImplemented()
- }
- }
-
- private fun isMediaManagementSupported(): Boolean {
- return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
- }
-
- private fun canManageMedia(): Boolean {
- return isMediaManagementSupported() && MediaStore.canManageMedia(context)
- }
-
- private fun openManageMediaSettings() {
- if (!isMediaManagementSupported()) {
- return
- }
- val intent = Intent(Settings.ACTION_REQUEST_MANAGE_MEDIA).apply {
- data = Uri.parse("package:${context.packageName}")
- addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
- }
- context.startActivity(intent)
- }
-
- private companion object {
- const val CHANNEL = "io.ente.photos/media_store"
- }
-}
diff --git a/mobile/apps/photos/lib/core/constants.dart b/mobile/apps/photos/lib/core/constants.dart
index d78ce8f7e5..7ff7035551 100644
--- a/mobile/apps/photos/lib/core/constants.dart
+++ b/mobile/apps/photos/lib/core/constants.dart
@@ -13,6 +13,7 @@ const String sentryTunnel = "https://sentry-reporter.ente.com";
const String githubDiscussionsUrl = "https://github.com/ente/ente/discussions";
const int microSecondsInDay = 86400000000;
const int android11SDKINT = 30;
+const int android12SDKINT = 31;
const int jan011981Time = 347155200000000;
const int galleryLoadStartTime = -8000000000000000; // Wednesday, March 6, 1748
const int galleryLoadEndTime = 9223372036854775807; // 2^63 -1
diff --git a/mobile/apps/photos/lib/services/media_store_service.dart b/mobile/apps/photos/lib/services/media_store_service.dart
deleted file mode 100644
index 8f31803c28..0000000000
--- a/mobile/apps/photos/lib/services/media_store_service.dart
+++ /dev/null
@@ -1,31 +0,0 @@
-import "package:flutter/services.dart";
-
-/// Android MediaStore permission helpers.
-class MediaStoreService {
- static const _methodChannel = MethodChannel("io.ente.photos/media_store");
-
- /// Returns whether Android media management settings are available.
- static Future<bool> isMediaManagementSupported() async {
- final result = await _methodChannel.invokeMethod<bool>(
- "isMediaManagementSupported",
- );
- if (result == null) {
- throw AssertionError("isMediaManagementSupported returned null");
- }
- return result;
- }
-
- /// Returns whether Ente can manage shared media without user confirmation.
- static Future<bool> canManageMedia() async {
- final result = await _methodChannel.invokeMethod<bool>("canManageMedia");
- if (result == null) {
- throw AssertionError("canManageMedia returned null");
- }
- return result;
- }
-
- /// Opens Android settings for granting media management access.
- static Future<void> openManageMediaSettings() async {
- await _methodChannel.invokeMethod<void>("openManageMediaSettings");
- }
-}
diff --git a/mobile/apps/photos/lib/ui/actions/file/file_actions.dart b/mobile/apps/photos/lib/ui/actions/file/file_actions.dart
index 33587cee5e..2a53adbee6 100644
--- a/mobile/apps/photos/lib/ui/actions/file/file_actions.dart
+++ b/mobile/apps/photos/lib/ui/actions/file/file_actions.dart
@@ -3,6 +3,7 @@ import "dart:io";
import "package:ente_components/ente_components.dart";
import "package:flutter/material.dart";
+import "package:photo_manager/photo_manager.dart";
import "package:photos/core/event_bus.dart";
import "package:photos/events/details_sheet_event.dart";
import "package:photos/generated/l10n.dart";
@@ -10,7 +11,6 @@ import "package:photos/models/file/extensions/file_props.dart";
import 'package:photos/models/file/file.dart';
import 'package:photos/module/metadata/panorama.dart';
import "package:photos/service_locator.dart";
-import "package:photos/services/media_store_service.dart";
import "package:photos/ui/notification/toast.dart";
import 'package:photos/ui/viewer/file/file_details_widget.dart';
import "package:photos/utils/delete_file_util.dart";
@@ -29,7 +29,7 @@ Future<void> showSingleFileDeleteSheet(
showShortToast(context, l10n.noDeviceThatCanBeDeleted);
return;
}
- if (Platform.isAndroid && await MediaStoreService.canManageMedia()) {
+ if (Platform.isAndroid && await PhotoManager.canManageMedia()) {
if (!context.mounted) return;
await showBottomSheetComponent<bool>(
context: context,
diff --git a/mobile/apps/photos/lib/utils/delete_file_util.dart b/mobile/apps/photos/lib/utils/delete_file_util.dart
index 343e0c4155..ff7bc29815 100644
--- a/mobile/apps/photos/lib/utils/delete_file_util.dart
+++ b/mobile/apps/photos/lib/utils/delete_file_util.dart
@@ -24,7 +24,6 @@ import 'package:photos/models/selected_files.dart';
import 'package:photos/module/download/file.dart';
import "package:photos/service_locator.dart";
import "package:photos/services/files_service.dart";
-import "package:photos/services/media_store_service.dart";
import "package:photos/services/sync/local_sync_service.dart";
import 'package:photos/services/sync/remote_sync_service.dart';
import 'package:photos/services/sync/sync_service.dart';
@@ -790,10 +789,10 @@ Future<void> showMediaManagementHintSheet(BuildContext context) async {
if (!Platform.isAndroid) {
return;
}
- if (!await MediaStoreService.isMediaManagementSupported()) {
+ if (await isAndroidSDKVersionLowerThan(android12SDKINT)) {
return;
}
- if (await MediaStoreService.canManageMedia()) {
+ if (await PhotoManager.canManageMedia()) {
return;
}
if (localSettings.isMediaManagementHintDismissed) {
@@ -818,7 +817,7 @@ Future<void> showMediaManagementHintSheet(BuildContext context) async {
label: l10n.openSettings,
shouldSurfaceExecutionStates: false,
onTap: () async {
- await MediaStoreService.openManageMediaSettings();
+ await PhotoManager.requestManageMedia();
if (sheetContext.mounted) {
Navigator.of(sheetContext).pop(false);
}
@@ -888,7 +887,7 @@ Future<void> showDeleteSheet(
return;
}
var didDelete = false;
- if (Platform.isAndroid && await MediaStoreService.canManageMedia()) {
+ if (Platform.isAndroid && await PhotoManager.canManageMedia()) {
if (!context.mounted) return;
didDelete =
await showBottomSheetComponent<bool>(
diff --git a/mobile/apps/photos/pubspec.yaml b/mobile/apps/photos/pubspec.yaml
index 25bf7fac9d..7c26393fe5 100644
--- a/mobile/apps/photos/pubspec.yaml
+++ b/mobile/apps/photos/pubspec.yaml
@@ -201,7 +201,7 @@ dependencies:
path_provider: 2.1.5
path_provider_foundation: 2.6.0
permission_handler: 12.0.1
- photo_manager: 3.7.1
+ photo_manager: 3.10.0
photo_manager_image_provider: 2.2.0
photo_view: 0.15.0
pinput: 5.0.2
diff --git a/mobile/pubspec.lock b/mobile/pubspec.lock
index e3c182e5d2..15700d7f21 100644
--- a/mobile/pubspec.lock
+++ b/mobile/pubspec.lock
@@ -2214,10 +2214,10 @@ packages:
dependency: transitive
description:
name: photo_manager
- sha256: a0d9a7a9bc35eda02d33766412bde6d883a8b0acb86bbe37dac5f691a0894e8a
+ sha256: bf840253a7a5a48774f3a23b042a673614785e9874e0c86e2837681d576ef252
url: "https://pub.dev"
source: hosted
- version: "3.7.1"
+ version: "3.10.0"
photo_manager_image_provider:
dependency: transitive
description: