Skip to content

Commit

Permalink
ensure proof is generated from internal camera directly
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Sep 19, 2024
1 parent 79f53db commit e83e90d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 17 deletions.
2 changes: 1 addition & 1 deletion android-libproofcam/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies {

implementation(kotlin("stdlib"))

project(":android-libproofmode")
implementation(project(":android-libproofmode"))

//new C2PA content authenticity support
api ("info.guardianproject:simple_c2pa:0.0.14")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import android.hardware.display.DisplayManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.HandlerThread
import android.provider.MediaStore
import android.util.DisplayMetrics
import android.util.Log
Expand All @@ -31,7 +29,6 @@ import androidx.core.net.toFile
import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.lifecycleScope
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.navigation.Navigation
import androidx.navigation.fragment.findNavController
import coil.load
Expand All @@ -43,13 +40,15 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.witness.proofmode.camera.CameraActivity
import org.witness.proofmode.camera.R
import org.witness.proofmode.camera.analyzer.LuminosityAnalyzer
import org.witness.proofmode.camera.c2pa.C2paUtils
import org.witness.proofmode.camera.databinding.FragmentCameraBinding
import org.witness.proofmode.camera.enums.CameraTimer
import org.witness.proofmode.camera.utils.*
import org.witness.proofmode.service.MediaWatcher
import timber.log.Timber
import java.io.File
import java.io.FileNotFoundException
import java.util.Date
import java.util.concurrent.ExecutionException
import java.util.concurrent.Executors
import kotlin.math.abs
Expand Down Expand Up @@ -659,28 +658,40 @@ class CameraFragment : BaseFragment<FragmentCameraBinding>(R.layout.fragment_cam
object : OnImageSavedCallback { // the callback, about the result of capture process
override fun onImageSaved(outputFileResults: OutputFileResults) {

val dateSaved = Date()

// This function is called if capture is successfully completed
outputFileResults.savedUri
?.let { uri ->
setGalleryThumbnail(uri)
sendLocalCameraEvent(uri)
Log.d(TAG, "Photo saved in $uri")
Timber.tag(TAG).d("Photo saved in " + uri)
}
?: setLastPictureThumbnail()

var proofUri = outputFileResults.savedUri
val isDirectCapture = true; //this is from our camera

if (CameraActivity.useCredentials) {

var isDirectCapture = true; //this is from our camera
var allowMachineLearning = CameraActivity.useAIFlag; //by default, we flag to not allow

C2paUtils.addContentCredentials(
val allowMachineLearning = CameraActivity.useAIFlag; //by default, we flag to not allow
val fileOut = C2paUtils.addContentCredentials(
context,
outputFileResults.savedUri,
proofUri,
isDirectCapture,
allowMachineLearning
)

proofUri = Uri.fromFile(fileOut)


}


val mw: MediaWatcher = MediaWatcher.getInstance(context)
val resultProofHash: String = mw.processUri(proofUri, isDirectCapture, dateSaved)

Timber.tag(CameraFragment.TAG).d("Photo proof generated: %s", resultProofHash)
}

override fun onError(exception: ImageCaptureException) {
Expand Down Expand Up @@ -729,7 +740,7 @@ class CameraFragment : BaseFragment<FragmentCameraBinding>(R.layout.fragment_cam
}

companion object {
private const val TAG = "libProofCam"
const val TAG = "libProofCam"

const val KEY_FLASH = "sPrefFlashCamera"
const val KEY_GRID = "sPrefGridCamera"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ import org.witness.proofmode.camera.c2pa.C2paUtils
import org.witness.proofmode.camera.databinding.FragmentVideoBinding
import org.witness.proofmode.camera.fragments.VideoFragment.CameraConstants.NEW_MEDIA_EVENT
import org.witness.proofmode.camera.utils.*
import org.witness.proofmode.service.MediaWatcher
import timber.log.Timber
import java.io.File
import java.util.Date
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
Expand Down Expand Up @@ -365,6 +368,7 @@ class VideoFragment : BaseFragment<FragmentVideoBinding>(R.layout.fragment_video
object : VideoCapture.OnVideoSavedCallback { // the callback after recording a video
override fun onVideoSaved(outputFileResults: VideoCapture.OutputFileResults) {

val dateSaved = Date()

// Create small preview
outputFileResults.savedUri
Expand All @@ -375,19 +379,32 @@ class VideoFragment : BaseFragment<FragmentVideoBinding>(R.layout.fragment_video
}
?: setLastPictureThumbnail()

if (CameraActivity.useCredentials) {
var proofUri = outputFileResults.savedUri
val isDirectCapture = true; //this is from our camera

var isDirectCapture = true; //this is from our camera
var allowMachineLearning = CameraActivity.useAIFlag; //by default, we flag to not allow
if (CameraActivity.useCredentials) {

C2paUtils.addContentCredentials(
val allowMachineLearning = CameraActivity.useAIFlag; //by default, we flag to not allow
val fileOut = C2paUtils.addContentCredentials(
context,
outputFileResults.savedUri,
proofUri,
isDirectCapture,
allowMachineLearning
)

proofUri = Uri.fromFile(fileOut)


}


val mw: MediaWatcher = MediaWatcher.getInstance(context)
val resultProofHash: String = mw.processUri(proofUri, isDirectCapture, dateSaved)

Timber.tag(CameraFragment.TAG).d("Video proof generated: %s", resultProofHash)



}

override fun onError(
Expand Down

0 comments on commit e83e90d

Please sign in to comment.