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

Commit 5035aba5 authored by Sayantan Roychowdhury's avatar Sayantan Roychowdhury
Browse files

Merge branch '300-send_faulty_tokens' into 'main'

Issue: 300 - send faulty tokens to ecloud

See merge request !130
parents 4eb44055 b56c2313
Loading
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import com.aurora.gplayapi.exceptions.ApiException
import com.google.gson.Gson
import dagger.hilt.android.lifecycle.HiltViewModel
import foundation.e.apps.api.cleanapk.blockedApps.BlockedAppRepository
import foundation.e.apps.api.ecloud.EcloudRepository
import foundation.e.apps.api.fused.FusedAPIImpl
import foundation.e.apps.api.fused.FusedAPIRepository
import foundation.e.apps.api.fused.data.FusedApp
@@ -69,7 +70,8 @@ class MainActivityViewModel @Inject constructor(
    private val fusedAPIRepository: FusedAPIRepository,
    private val fusedManagerRepository: FusedManagerRepository,
    private val pkgManagerModule: PkgManagerModule,
    private val blockedAppRepository: BlockedAppRepository
    private val ecloudRepository: EcloudRepository,
    private val blockedAppRepository: BlockedAppRepository,
) : ViewModel() {

    val authDataJson: LiveData<String> = dataStoreModule.authData.asLiveData()
@@ -231,6 +233,18 @@ class MainActivityViewModel @Inject constructor(
        authValidity.postValue(false)
    }

    fun uploadFaultyTokenToEcloud(description: String){
        viewModelScope.launch {
            authData.value?.let { authData ->
                val email: String = authData.run {
                    if (email != "null") email
                    else userProfile?.email ?: "null"
                }
                ecloudRepository.uploadFaultyEmail(email, description)
            }
        }
    }

    fun getAuthData() {
        if (!authRequestRunning) {
            authRequestRunning = true
+12 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import foundation.e.apps.api.ecloud.EcloudApiInterface
import foundation.e.apps.api.exodus.ExodusTrackerApi
import foundation.e.apps.api.fdroid.FdroidApiInterface
import okhttp3.Cache
@@ -94,6 +95,17 @@ object RetrofitModule {
            .create(FdroidApiInterface::class.java)
    }

    @Singleton
    @Provides
    fun provideEcloudApi(okHttpClient: OkHttpClient, moshi: Moshi): EcloudApiInterface {
        return Retrofit.Builder()
            .baseUrl(EcloudApiInterface.BASE_URL)
            .client(okHttpClient)
            .addConverterFactory(MoshiConverterFactory.create(moshi))
            .build()
            .create(EcloudApiInterface::class.java)
    }

    @Singleton
    @Provides
    fun getMoshi(): Moshi {
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022  ECORP
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package foundation.e.apps.api.ecloud

import foundation.e.apps.api.ecloud.modules.FaultyToken
import retrofit2.http.Body
import retrofit2.http.Header
import retrofit2.http.POST

interface EcloudApiInterface {

    companion object {
        val BASE_URL = "https://eu.gtoken.ecloud.global/"
    }

    @POST("report")
    suspend fun uploadFaultyEmail(
        @Body faultyToken: FaultyToken,
        @Header("Content-Type") contentType: String = "application/json",
    )

}
 No newline at end of file
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022  ECORP
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package foundation.e.apps.api.ecloud

import foundation.e.apps.api.ecloud.modules.FaultyToken
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class EcloudRepository @Inject constructor(
    private val ecloudApi: EcloudApiInterface,
) {
    suspend fun uploadFaultyEmail(email: String, description: String) {
        try {
            ecloudApi.uploadFaultyEmail(
                FaultyToken(email, description)
            )
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }
}
 No newline at end of file
+20 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022  ECORP
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package foundation.e.apps.api.ecloud.modules

data class FaultyToken(val email: String, val description: String)
 No newline at end of file
Loading