mirror of
https://github.com/TanelOrumaa/Estonian-ID-card-mobile-authenticator-POC.git
synced 2024-12-22 20:40:16 +02:00
MOB-35 started integrating the NFC class with the UI
This commit is contained in:
parent
f93b37c535
commit
fc56825ed0
@ -2,6 +2,8 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.tarkvaraprojekt.mobileauthapp">
|
package="com.tarkvaraprojekt.mobileauthapp">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.NFC" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package com.tarkvaraprojekt.mobileauthapp
|
package com.tarkvaraprojekt.mobileauthapp
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.content.Context
|
||||||
|
import android.nfc.NfcAdapter
|
||||||
|
import android.nfc.tech.IsoDep
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.CountDownTimer
|
import android.os.CountDownTimer
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
@ -8,8 +12,10 @@ import android.view.ViewGroup
|
|||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
|
import com.tarkvaraprojekt.mobileauthapp.NFC.Comms
|
||||||
import com.tarkvaraprojekt.mobileauthapp.databinding.FragmentAuthBinding
|
import com.tarkvaraprojekt.mobileauthapp.databinding.FragmentAuthBinding
|
||||||
import com.tarkvaraprojekt.mobileauthapp.model.SmartCardViewModel
|
import com.tarkvaraprojekt.mobileauthapp.model.SmartCardViewModel
|
||||||
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fragment that asks the user to detect the ID card with mobile NFC chip.
|
* Fragment that asks the user to detect the ID card with mobile NFC chip.
|
||||||
@ -49,13 +55,37 @@ class AuthFragment : Fragment() {
|
|||||||
}.start()
|
}.start()
|
||||||
binding!!.nextButton.setOnClickListener { goToNextFragment() }
|
binding!!.nextButton.setOnClickListener { goToNextFragment() }
|
||||||
binding!!.cancelButton.setOnClickListener { goToTheStart() }
|
binding!!.cancelButton.setOnClickListener { goToTheStart() }
|
||||||
|
val adapter = NfcAdapter.getDefaultAdapter(activity)
|
||||||
|
if (adapter != null)
|
||||||
|
getInfoFromIdCard(adapter)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getInfoFromIdCard(adapter: NfcAdapter) {
|
||||||
|
adapter.enableReaderMode(activity, { tag ->
|
||||||
|
timer.cancel()
|
||||||
|
requireActivity().runOnUiThread {
|
||||||
|
binding!!.timeCounter.text = getString(R.string.card_detected)
|
||||||
|
}
|
||||||
|
val card = IsoDep.get(tag)
|
||||||
|
card.timeout = 32768
|
||||||
|
card.use {
|
||||||
|
val comms = Comms(it, viewModel.userCan)
|
||||||
|
val response = comms.readPersonalData(byteArrayOf(1, 2, 6))
|
||||||
|
if (response != null) {
|
||||||
|
viewModel.setUserFirstName(response[1])
|
||||||
|
viewModel.setUserLastName(response[0])
|
||||||
|
viewModel.setUserIdentificationNumber(response[2])
|
||||||
|
requireActivity().runOnUiThread{
|
||||||
|
binding!!.timeCounter.text = getString(R.string.data_read)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
it.close()
|
||||||
|
adapter.disableReaderMode(activity)
|
||||||
|
}
|
||||||
|
}, NfcAdapter.FLAG_READER_NFC_A, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun goToNextFragment() {
|
private fun goToNextFragment() {
|
||||||
//Dummy data for now
|
|
||||||
viewModel.setUserFirstName("John")
|
|
||||||
viewModel.setUserLastName("Doe")
|
|
||||||
viewModel.setUserIdentificationNumber("012345678910")
|
|
||||||
timer.cancel()
|
timer.cancel()
|
||||||
findNavController().navigate(R.id.action_authFragment_to_userFragment)
|
findNavController().navigate(R.id.action_authFragment_to_userFragment)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package com.tarkvaraprojekt.mobileauthapp
|
package com.tarkvaraprojekt.mobileauthapp
|
||||||
|
|
||||||
|
import android.nfc.NfcAdapter
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.fragment.NavHostFragment
|
import androidx.navigation.fragment.NavHostFragment
|
||||||
import com.tarkvaraprojekt.mobileauthapp.databinding.ActivityMainBinding
|
import com.tarkvaraprojekt.mobileauthapp.databinding.ActivityMainBinding
|
||||||
|
@ -44,8 +44,11 @@ class PinFragment : Fragment() {
|
|||||||
)
|
)
|
||||||
findNavController().navigate(R.id.action_pinFragment_to_canFragment)
|
findNavController().navigate(R.id.action_pinFragment_to_canFragment)
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(requireContext(), getString(R.string.length_pin), Toast.LENGTH_SHORT)
|
// Currently it is not important to enter PIN1 so we will allow the user to leave this field empty
|
||||||
.show()
|
//Toast.makeText(requireContext(), getString(R.string.length_pin), Toast.LENGTH_SHORT)
|
||||||
|
// .show()
|
||||||
|
viewModel.setUserPin("1234")
|
||||||
|
findNavController().navigate(R.id.action_pinFragment_to_canFragment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,8 +13,8 @@ import com.tarkvaraprojekt.mobileauthapp.model.SmartCardViewModel
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fragment that is used to display the persons name and national identification number.
|
* Fragment that is used to display the persons name and national identification number.
|
||||||
* Currently needed in order to test that the app is working because the results at the moment
|
* Currently needed in order to test that the app is working and information is read
|
||||||
* are not sent to some other website or app.
|
* from the ID card via NFC.
|
||||||
*/
|
*/
|
||||||
class UserFragment : Fragment() {
|
class UserFragment : Fragment() {
|
||||||
|
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
<string name="text_can">CAN</string>
|
<string name="text_can">CAN</string>
|
||||||
<string name="enter_can">Sisesta ID kaardi CAN (Card Access Number)</string>
|
<string name="enter_can">Sisesta ID kaardi CAN (Card Access Number)</string>
|
||||||
<string name="length_can">CANi pikkus on vale</string>
|
<string name="length_can">CANi pikkus on vale</string>
|
||||||
|
<string name="card_detected">Kaart on tuvastatud. Hoia kaarti vastu telefoni.</string>
|
||||||
|
<string name="data_read">Andmed loetud.</string>
|
||||||
|
|
||||||
<!-- string resources for AuthFragment layout -->
|
<!-- string resources for AuthFragment layout -->
|
||||||
<string name="auth_instruction_text">ID kaardiga ühenduse loomiseks pane kaart vastu telefoni</string>
|
<string name="auth_instruction_text">ID kaardiga ühenduse loomiseks pane kaart vastu telefoni</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user