Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Support Android camera review intents

laurenspriem10ada1f6281c
diff --git a/mobile/apps/photos/android/app/src/main/AndroidManifest.xml b/mobile/apps/photos/android/app/src/main/AndroidManifest.xml
index 6e8422586f..dd90f290b4 100644
--- a/mobile/apps/photos/android/app/src/main/AndroidManifest.xml
+++ b/mobile/apps/photos/android/app/src/main/AndroidManifest.xml
@@ -122,6 +122,37 @@
</intent-filter>
</activity>
+ <activity android:name=".MediaReviewActivity"
+ android:theme="@style/LaunchTheme"
+ android:exported="true"
+ android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
+ android:hardwareAccelerated="true"
+ android:windowSoftInputMode="adjustResize">
+ <intent-filter>
+ <action android:name="android.provider.action.REVIEW" />
+ <action android:name="com.android.camera.action.REVIEW" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <data android:mimeType="image/*" />
+ <data android:mimeType="video/*" />
+ </intent-filter>
+ <intent-filter>
+ <action android:name="android.provider.action.REVIEW" />
+ <action android:name="com.android.camera.action.REVIEW" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <data android:mimeType="image/*" />
+ <data android:mimeType="video/*" />
+ <data android:scheme="content" />
+ <data android:scheme="file" />
+ </intent-filter>
+ <intent-filter>
+ <action android:name="android.provider.action.REVIEW" />
+ <action android:name="com.android.camera.action.REVIEW" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <data android:scheme="content" />
+ <data android:scheme="file" />
+ </intent-filter>
+ </activity>
+
<activity-alias
android:name="${applicationId}.IconGreen"
android:icon="@mipmap/icon_green"
diff --git a/mobile/apps/photos/android/app/src/main/kotlin/io/ente/photos/MediaReviewActivity.kt b/mobile/apps/photos/android/app/src/main/kotlin/io/ente/photos/MediaReviewActivity.kt
new file mode 100644
index 0000000000..7366a578a0
--- /dev/null
+++ b/mobile/apps/photos/android/app/src/main/kotlin/io/ente/photos/MediaReviewActivity.kt
@@ -0,0 +1,69 @@
+package io.ente.photos
+
+import android.content.Intent
+import android.net.Uri
+import android.os.Bundle
+import android.webkit.MimeTypeMap
+import io.flutter.embedding.android.FlutterFragmentActivity
+import java.util.Locale
+
+class MediaReviewActivity : FlutterFragmentActivity() {
+ override fun onCreate(savedInstanceState: Bundle?) {
+ normalizeReviewIntent(intent)
+ super.onCreate(savedInstanceState)
+ }
+
+ override fun onNewIntent(intent: Intent) {
+ normalizeReviewIntent(intent)
+ super.onNewIntent(intent)
+ setIntent(intent)
+ }
+
+ private fun normalizeReviewIntent(intent: Intent?) {
+ val reviewIntent = intent ?: return
+ if (reviewIntent.action !in reviewActions) {
+ return
+ }
+ val uri = reviewIntent.data ?: reviewIntent.streamUri
+ val type = reviewIntent.type ?: uri?.let { resolveMimeType(it) }
+ reviewIntent.action = Intent.ACTION_VIEW
+ if (uri != null && type != null) {
+ reviewIntent.setDataAndType(uri, type)
+ } else if (uri != null) {
+ reviewIntent.data = uri
+ }
+ }
+
+ private fun resolveMimeType(uri: Uri): String? {
+ return typeFromContentResolver(uri) ?: typeFromExtension(uri)
+ }
+
+ private fun typeFromContentResolver(uri: Uri): String? {
+ return try {
+ contentResolver.getType(uri)
+ } catch (_: IllegalArgumentException) {
+ null
+ } catch (_: SecurityException) {
+ null
+ }
+ }
+
+ private fun typeFromExtension(uri: Uri): String? {
+ val extension = uri.lastPathSegment
+ ?.substringAfterLast('.', missingDelimiterValue = "")
+ ?.lowercase(Locale.ROOT)
+ ?.takeIf { it.isNotBlank() }
+ ?: return null
+ return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)
+ }
+
+ private val Intent.streamUri: Uri?
+ @Suppress("DEPRECATION")
+ get() = getParcelableExtra(Intent.EXTRA_STREAM)
+
+ private companion object {
+ private const val ACTION_REVIEW = "android.provider.action.REVIEW"
+ private const val ACTION_CAMERA_REVIEW = "com.android.camera.action.REVIEW"
+ private val reviewActions = setOf(ACTION_REVIEW, ACTION_CAMERA_REVIEW)
+ }
+}