Skip to main content

Posts

Showing posts from June, 2021

SSL pinning in Android - A brief discussion

HTTP protocol Communication between the client and a server typically non-encrypted or plain text while we use HTTP protocol.  Pitfall Any middle hacker can interrupt the connection between the client and server and manipulate the data as it involves no encryption. How to overcome this ? As the domain owner one can purchase a digital certificate from CA(Certificate Authority) who are considered as trusted.  A certificate will contain the Owner's name, public key , Issuer's(CA's) name,Issuer's(CA's) signature, domain details, expiry date etc . After the SSL/Leaf certificate is associated with a domain,the communication between client and server will be encrypted. Now the HTTP will become HTTPs. Note : Associating the SSL certificate means it enable the encryption between client and server but does not mean ,the domain owner will never misuse your personal information. How does SSL work ? Pitfall There is a problem here. Let's assume that there is a hacker comes i...

Dependency Injection using Hilt

 Few Essentials to know 1. @HiltAndroidApp 2. Constructor Injection & Field Injection - @Inject 3.  @ AndroidEntryPoint 4. @Module, @InstallIn 5. @Provides 6. @Binds 7. @ActivityScoped/@Singleton/@ViewModelScoped etc 8. ActivityComponent, FragmentComponent, SingletonComponent etc. Please complete the codelab practice  https://developer.android.com/codelabs/android-hilt#0 Full Reference https://developer.android.com/training/dependency-injection/hilt-android

Manual Dependency Injection- Realtime Explanation

Assume that we have a Login Feature in Android application and it will have the classes based on the Android's recommended architecture such as MVVM. --> The  LoginActivity has the dependency of LoginViewModel . --> The LoginViewModel has the dependency of UserRepository --> The UserRepository has the dependency of UserLocalDataSource and UserRemoteDataSource UserRepository.kt class UserRepository ( private val localDataSource : LocalDataSource, private val remoteDataSource : RemoteDataSource ) { // Manipulating data from local and/or remote data sources. } Data Sources class LocalDataSource {} class RemoteDataSource ( private val retrofitLoginService : RetrofitLoginService) { } LoginViewModel.kt class LoginViewModel ( private val userRepository : UserRepository) { //Invocation of methods in UserRepository class } LoginActivity.kt class LoginActivity : AppCompatActivity { private var lateinit loginViewModel: LoginViewModel; public fun onCreate (bun...

Dependency Injection - Overview

Advantages of DI Reusability of code Ease of refactoring Ease of testing For an Example, Car class and Engine class. A Car should have an object of Engine. How to achieve it ? 1. By creating an Engine object in Car class   <-- This provides the tight coupling of Engine object in the Car class. This approach makes testing difficult. 2. By creating a global class from where we can access the Engine object in the way we access getSystemService(), getContext() etc. <-- This is called service locator pattern. As it is global place to access all objects, the testing will still become difficult.  3. By passing the object of Engine object when constructing the Car class <-- This is called Dependency Injection An Example of Car tightly coupled with Engine class Car { private val engine = Engine() fun start () { engine .start() } } class ClassA { fun main (Array arr){ var car : Car () car.start() } } Drawback  Let's conside...