AuthViewModel: Drop dependency upon kovenant

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2023-07-20 18:14:16 +05:30
parent 6892be4821
commit aeb2a136ec

View File

@@ -46,7 +46,6 @@ import com.aurora.store.viewmodel.BaseAndroidViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.supervisorScope
import nl.komponents.kovenant.task
import java.net.ConnectException
import java.net.UnknownHostException
import java.util.*
@@ -78,17 +77,18 @@ class AuthViewModel(application: Application) : BaseAndroidViewModel(application
fun buildGoogleAuthData(email: String, aasToken: String) {
liveData.postValue(AuthState.Fetching)
task {
viewModelScope.launch(Dispatchers.IO) {
try {
var properties = NativeDeviceInfoProvider(getApplication()).getNativeDeviceProperties()
if (spoofProvider.isDeviceSpoofEnabled())
properties = spoofProvider.getSpoofDeviceProperties()
return@task AuthHelper.build(email, aasToken, properties)
} success {
verifyAndSaveAuth(it, AccountType.GOOGLE)
} fail {
val authData = AuthHelper.build(email, aasToken, properties)
verifyAndSaveAuth(authData, AccountType.GOOGLE)
} catch (exception: Exception) {
updateStatus("Failed to generate Session")
Log.e(TAG, "Failed to generate Session", exception)
}
}
}
@@ -107,8 +107,8 @@ class AuthViewModel(application: Application) : BaseAndroidViewModel(application
private fun buildSecureAnonymousAuthData() {
liveData.postValue(AuthState.Fetching)
task {
viewModelScope.launch(Dispatchers.IO) {
try {
var properties = NativeDeviceInfoProvider(getApplication())
.getNativeDeviceProperties()
@@ -123,33 +123,34 @@ class AuthViewModel(application: Application) : BaseAndroidViewModel(application
)
if (playResponse.isSuccessful) {
return@task gson.fromJson(
val authData = gson.fromJson(
String(playResponse.responseBytes),
AuthData::class.java
)
//Set AuthData as anonymous
authData.isAnonymous = true
verifyAndSaveAuth(authData, AccountType.ANONYMOUS)
} else {
val ctx = getApplication() as Context
when (playResponse.code) {
404 -> throw Exception("Server unreachable")
429 -> throw Exception("Oops, You are rate limited")
503 -> throw Exception(
(getApplication() as Context).getString(R.string.server_maintenance)
)
503 -> throw Exception(ctx.getString(R.string.server_maintenance))
else -> throw Exception(playResponse.errorString)
}
}
} success {
//Set AuthData as anonymous
it.isAnonymous = true
verifyAndSaveAuth(it, AccountType.ANONYMOUS)
} fail {
updateStatus(it.message.toString())
} catch (exception: Exception) {
updateStatus(exception.message.toString())
Log.e(TAG, "Failed to generate Session", exception)
}
}
}
fun buildInSecureAnonymousAuthData() {
liveData.postValue(AuthState.Fetching)
task {
viewModelScope.launch(Dispatchers.IO) {
try {
var properties = NativeDeviceInfoProvider(getApplication())
.getNativeDeviceProperties()
@@ -176,24 +177,27 @@ class AuthViewModel(application: Application) : BaseAndroidViewModel(application
503 -> throw Exception(
(getApplication() as Context).getString(R.string.server_maintenance)
)
else -> throw Exception(playResponse.errorString)
}
}
val deviceInfoProvider = DeviceInfoProvider(properties, Locale.getDefault().toString())
AuthHelper.buildInsecure(
val deviceInfoProvider =
DeviceInfoProvider(properties, Locale.getDefault().toString())
val authData = AuthHelper.buildInsecure(
insecureAuth.email,
insecureAuth.auth,
Locale.getDefault(),
deviceInfoProvider
)
} success {
//Set AuthData as anonymous
it.isAnonymous = true
verifyAndSaveAuth(it, AccountType.ANONYMOUS)
} fail {
updateStatus(it.message.toString())
authData.isAnonymous = true
verifyAndSaveAuth(authData, AccountType.ANONYMOUS)
} catch (exception: Exception) {
updateStatus(exception.message.toString())
Log.e(TAG, "Failed to generate Session", exception)
}
}
}