Aperture: Comply with Camera Intents tests

Change-Id: Ieee4babe5f697b42d169b8400885520a22fa1d7d
diff --git a/app/src/main/java/org/lineageos/aperture/CameraActivity.kt b/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
index c1eae05..65cce0f 100644
--- a/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
+++ b/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
@@ -85,6 +85,7 @@
 import org.lineageos.aperture.ui.PreviewBlurView
 import org.lineageos.aperture.ui.VerticalSlider
 import org.lineageos.aperture.utils.AssistantIntent
+import org.lineageos.aperture.utils.BroadcastUtils
 import org.lineageos.aperture.utils.Camera
 import org.lineageos.aperture.utils.CameraFacing
 import org.lineageos.aperture.utils.CameraManager
@@ -869,7 +870,9 @@
         val outputOptions = StorageUtils.getPhotoMediaStoreOutputOptions(
             contentResolver,
             ImageCapture.Metadata().apply {
-                location = this@CameraActivity.location
+                if (!singleCaptureMode) {
+                    location = this@CameraActivity.location
+                }
             },
             photoOutputStream
         )
@@ -900,6 +903,9 @@
                     if (!singleCaptureMode) {
                         sharedPreferences.lastSavedUri = output.savedUri
                         tookSomething = true
+                        output.savedUri?.let {
+                            BroadcastUtils.broadcastNewPicture(this@CameraActivity, it)
+                        }
                     } else {
                         output.savedUri?.let {
                             openCapturePreview(it, MediaType.PHOTO)
@@ -928,7 +934,10 @@
         cameraState = CameraState.PRE_RECORDING_VIDEO
 
         // Create output options object which contains file + metadata
-        val outputOptions = StorageUtils.getVideoMediaStoreOutputOptions(contentResolver, location)
+        val outputOptions = StorageUtils.getVideoMediaStoreOutputOptions(
+            contentResolver,
+            location.takeUnless { singleCaptureMode }
+        )
 
         // Play shutter sound
         val delayTime = if (cameraSoundsUtils.playStartVideoRecording()) 500L else 0L
@@ -984,6 +993,7 @@
                             if (!singleCaptureMode) {
                                 sharedPreferences.lastSavedUri = it.outputResults.outputUri
                                 tookSomething = true
+                                BroadcastUtils.broadcastNewVideo(this, it.outputResults.outputUri)
                             } else {
                                 openCapturePreview(it.outputResults.outputUri, MediaType.VIDEO)
                             }
diff --git a/app/src/main/java/org/lineageos/aperture/utils/BroadcastUtils.kt b/app/src/main/java/org/lineageos/aperture/utils/BroadcastUtils.kt
new file mode 100644
index 0000000..9aa892a
--- /dev/null
+++ b/app/src/main/java/org/lineageos/aperture/utils/BroadcastUtils.kt
@@ -0,0 +1,20 @@
+/*
+ * SPDX-FileCopyrightText: 2023 The LineageOS Project
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package org.lineageos.aperture.utils
+
+import android.content.Context
+import android.content.Intent
+import android.net.Uri
+
+object BroadcastUtils {
+    private const val ACTION_NEW_PICTURE = "android.hardware.action.NEW_PICTURE"
+    private const val ACTION_NEW_VIDEO = "android.hardware.action.NEW_VIDEO"
+
+    fun broadcastNewPicture(context: Context, uri: Uri) =
+        context.sendBroadcast(Intent(ACTION_NEW_PICTURE, uri))
+    fun broadcastNewVideo(context: Context, uri: Uri) =
+        context.sendBroadcast(Intent(ACTION_NEW_VIDEO, uri))
+}