Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eebcf131 authored by Hasib Prince's avatar Hasib Prince
Browse files

some refactoring

parent b7d344f4
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ ext {
    protobuf_java = '3.19.3'
    javax_version = '1'
    dagger_hilt_version = '2.46.1'
    timber_version = '5.0.1'
}

android {
@@ -87,7 +88,7 @@ dependencies {
    kapt("com.google.dagger:hilt-android-compiler:$dagger_hilt_version")

    //logger
    implementation 'com.jakewharton.timber:timber:5.0.1'
    implementation "com.jakewharton.timber:timber:$timber_version"

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
+42 −0
Original line number Diff line number Diff line
package app.lounge

import com.aurora.gplayapi.data.models.PlayResponse
import com.aurora.gplayapi.network.IHttpClient

class FakeGplayHttpClient : IHttpClient {
    override fun get(url: String, headers: Map<String, String>): PlayResponse {
        TODO("Not yet implemented")
    }

    override fun get(url: String, headers: Map<String, String>, paramString: String): PlayResponse {
        TODO("Not yet implemented")
    }

    override fun get(
        url: String,
        headers: Map<String, String>,
        params: Map<String, String>
    ): PlayResponse {
        TODO("Not yet implemented")
    }

    override fun getAuth(url: String): PlayResponse {
        TODO("Not yet implemented")
    }

    override fun post(url: String, headers: Map<String, String>, body: ByteArray): PlayResponse {
        TODO("Not yet implemented")
    }

    override fun post(
        url: String,
        headers: Map<String, String>,
        params: Map<String, String>
    ): PlayResponse {
        TODO("Not yet implemented")
    }

    override fun postAuth(url: String, body: ByteArray): PlayResponse {
        TODO("Not yet implemented")
    }
}
 No newline at end of file
+27 −0
Original line number Diff line number Diff line
package app.lounge

import app.lounge.login.google.GoogleLoginApi
import app.lounge.login.google.GoogleLoginApiImpl
import app.lounge.networking.GplayHttpClient
import kotlinx.coroutines.runBlocking
import okhttp3.OkHttpClient
import org.junit.Test
import java.util.concurrent.TimeUnit

class GoogleLoginApiTest {

    private val gplayHttpClient = GplayHttpClient(getOkHttpClient())

    private fun getOkHttpClient(
        timeoutInMillisecond: Long = 10000L
    ): OkHttpClient = OkHttpClient.Builder()
        .callTimeout(timeoutInMillisecond, TimeUnit.MILLISECONDS)
        .build()

    private val googleLoginApi: GoogleLoginApi = GoogleLoginApiImpl(gplayHttpClient)

    @Test
    fun testFetchAASTokenSuccess() = runBlocking {
         
    }
}
 No newline at end of file
+7 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ package app.lounge.di
import app.lounge.login.anonymous.AnonymousUser
import app.lounge.login.anonymous.AnonymousUserRetrofitAPI
import app.lounge.login.anonymous.AnonymousUserRetrofitImpl
import app.lounge.networking.GplayHttpClient
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
@@ -96,4 +97,10 @@ internal object NetworkModule {
        )
    }

    @Provides
    @Singleton
    fun provideGplayHttpClient(@Named("privateOkHttpClient")okHttpClient: OkHttpClient): GplayHttpClient {
        return GplayHttpClient(okHttpClient)
    }

}
 No newline at end of file
+0 −46
Original line number Diff line number Diff line
package app.lounge.login.google

import app.lounge.gplay.GplayHttpClient
import com.aurora.gplayapi.data.models.PlayResponse
import java.util.Locale
import javax.inject.Inject

class AuthTokenFetchApi @Inject constructor(private val gplayHttpClient: GplayHttpClient) {
    companion object {
        private const val TOKEN_AUTH_URL = "https://android.clients.google.com/auth"
        private const val BUILD_VERSION_SDK = 28
        private const val PLAY_SERVICES_VERSION_CODE = 19629032
    }

    fun getAuthTokenPlayResponse(email: String?, oAuthToken: String?): PlayResponse {
        if (email == null || oAuthToken == null)
            return PlayResponse()

        val params: MutableMap<String, Any> = hashMapOf()
        params["lang"] = Locale.getDefault().toString().replace("_", "-")
        params["google_play_services_version"] = PLAY_SERVICES_VERSION_CODE
        params["sdk_version"] = BUILD_VERSION_SDK
        params["device_country"] = Locale.getDefault().country.lowercase(Locale.US)
        params["Email"] = email
        params["service"] = "ac2dm"
        params["get_accountid"] = 1
        params["ACCESS_TOKEN"] = 1
        params["callerPkg"] = "com.google.android.gms"
        params["add_account"] = 1
        params["Token"] = oAuthToken
        params["callerSig"] = "38918a453d07199354f8b19af05ec6562ced5788"

        val body = params.map { "${it.key}=${it.value}" }.joinToString(separator = "&")
        val header = mapOf(
            "app" to "com.google.android.gms",
            "User-Agent" to "",
            "Content-Type" to "application/x-www-form-urlencoded"
        )

        /*
         * Returning PlayResponse instead of map so that we can get the network response code.
         * Issue: https://gitlab.e.foundation/e/backlog/-/issues/5709
         */
        return gplayHttpClient.post(TOKEN_AUTH_URL, header, body.toByteArray())
    }
}
 No newline at end of file
Loading