{SplashFragment|NetworkPreference}: Updates to AuthData building
* Always generate GSF ID on device regardless of login type * Switch to new method for building AuthData Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
|
||||
package com.aurora.store.data.model
|
||||
|
||||
data class InsecureAuth(
|
||||
data class Auth(
|
||||
val email: String,
|
||||
val auth: String
|
||||
)
|
||||
@@ -48,7 +48,6 @@ object Preferences {
|
||||
const val PREFERENCE_INSTALLATION_DEVICE_OWNER = "PREFERENCE_INSTALLATION_DEVICE_OWNER"
|
||||
const val INSTALLATION_ABANDON_SESSION = "INSTALLATION_ABANDON_SESSION"
|
||||
|
||||
const val PREFERENCE_INSECURE_ANONYMOUS = "PREFERENCE_INSECURE_ANONYMOUS"
|
||||
const val PREFERENCE_PROXY_URL = "PREFERENCE_PROXY_URL"
|
||||
const val PREFERENCE_PROXY_INFO = "PREFERENCE_PROXY_INFO"
|
||||
const val PREFERENCE_PROXY_ENABLED = "PREFERENCE_PROXY_ENABLED"
|
||||
|
||||
@@ -45,7 +45,6 @@ import com.aurora.store.util.Preferences.PREFERENCE_FILTER_AURORA_ONLY
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_FILTER_FDROID
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_FILTER_GOOGLE
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_FOR_YOU
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_INSECURE_ANONYMOUS
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_INSTALLER_ID
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_INTRO
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_SIMILAR
|
||||
@@ -159,7 +158,6 @@ class OnboardingFragment : BaseFragment<FragmentOnboardingBinding>() {
|
||||
if (!CertUtil.isAppGalleryApp(requireContext(), requireContext().packageName)) {
|
||||
save(PREFERENCE_DISPENSER_URLS, setOf(Constants.URL_DISPENSER))
|
||||
}
|
||||
save(PREFERENCE_INSECURE_ANONYMOUS, false)
|
||||
save(PREFERENCE_VENDING_VERSION, 0)
|
||||
|
||||
/*Customization*/
|
||||
|
||||
@@ -69,15 +69,6 @@ class NetworkPreference : BasePreferenceFragment(),
|
||||
}
|
||||
}
|
||||
|
||||
findPreference<SwitchPreferenceCompat>(Preferences.PREFERENCE_INSECURE_ANONYMOUS)?.let {
|
||||
it.setOnPreferenceChangeListener { _, _ ->
|
||||
runOnUiThread {
|
||||
requireContext().toast(R.string.insecure_anonymous_apply)
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
findPreference<Preference>(Preferences.PREFERENCE_VENDING_VERSION)?.let {
|
||||
it.setOnPreferenceChangeListener { _, newValue ->
|
||||
save(Preferences.PREFERENCE_VENDING_VERSION, Integer.parseInt(newValue.toString()))
|
||||
|
||||
@@ -91,7 +91,6 @@ class SplashFragment : BaseFragment<FragmentSplashBinding>() {
|
||||
// Show anonymous logins if we have dispenser URL
|
||||
if (!viewModel.dispenserURL.isNullOrBlank()) {
|
||||
binding.btnAnonymous.visibility = View.VISIBLE
|
||||
binding.btnAnonymousInsecure.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
//Initial status
|
||||
@@ -180,14 +179,7 @@ class SplashFragment : BaseFragment<FragmentSplashBinding>() {
|
||||
binding.btnAnonymous.addOnClickListener {
|
||||
if (viewModel.liveData.value != AuthState.Fetching) {
|
||||
binding.btnAnonymous.updateProgress(true)
|
||||
viewModel.buildSecureAnonymousAuthData()
|
||||
}
|
||||
}
|
||||
|
||||
binding.btnAnonymousInsecure.addOnClickListener {
|
||||
if (viewModel.liveData.value != AuthState.Fetching) {
|
||||
binding.btnAnonymousInsecure.updateProgress(true)
|
||||
viewModel.buildInSecureAnonymousAuthData()
|
||||
viewModel.buildAnonymousAuthData()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,11 +201,6 @@ class SplashFragment : BaseFragment<FragmentSplashBinding>() {
|
||||
updateProgress(false)
|
||||
isEnabled = true
|
||||
}
|
||||
|
||||
binding.btnAnonymousInsecure.apply {
|
||||
updateProgress(false)
|
||||
isEnabled = true
|
||||
}
|
||||
}
|
||||
|
||||
private fun navigateToDefaultTab() {
|
||||
|
||||
@@ -28,14 +28,13 @@ import androidx.lifecycle.viewModelScope
|
||||
import com.aurora.Constants
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.gplayapi.data.models.PlayResponse
|
||||
import com.aurora.gplayapi.data.providers.DeviceInfoProvider
|
||||
import com.aurora.gplayapi.helpers.AuthHelper
|
||||
import com.aurora.store.AuroraApp
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.event.AuthEvent
|
||||
import com.aurora.store.data.model.AccountType
|
||||
import com.aurora.store.data.model.AuthState
|
||||
import com.aurora.store.data.model.InsecureAuth
|
||||
import com.aurora.store.data.model.Auth
|
||||
import com.aurora.store.data.network.HttpClient
|
||||
import com.aurora.store.data.providers.AccountProvider
|
||||
import com.aurora.store.data.providers.AuthProvider
|
||||
@@ -66,7 +65,19 @@ class AuthViewModel @Inject constructor(
|
||||
|
||||
private val TAG = AuthViewModel::class.java.simpleName
|
||||
|
||||
private val spoofProvider = SpoofProvider(context)
|
||||
private val spoofProvider: SpoofProvider get() = SpoofProvider(context)
|
||||
val properties: Properties
|
||||
get() = if (spoofProvider.isDeviceSpoofEnabled()) {
|
||||
spoofProvider.getSpoofDeviceProperties()
|
||||
} else {
|
||||
NativeDeviceInfoProvider(context).getNativeDeviceProperties()
|
||||
}
|
||||
val locale: Locale
|
||||
get() = if (spoofProvider.isLocaleSpoofEnabled()) {
|
||||
spoofProvider.getSpoofLocale()
|
||||
} else {
|
||||
Locale.getDefault()
|
||||
}
|
||||
|
||||
val dispenserURL: String?
|
||||
get() {
|
||||
@@ -92,11 +103,13 @@ class AuthViewModel @Inject constructor(
|
||||
liveData.postValue(AuthState.Fetching)
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
var properties = NativeDeviceInfoProvider(context).getNativeDeviceProperties()
|
||||
if (spoofProvider.isDeviceSpoofEnabled())
|
||||
properties = spoofProvider.getSpoofDeviceProperties()
|
||||
|
||||
val authData = AuthHelper.build(email, aasToken, properties)
|
||||
val authData = AuthHelper.build(
|
||||
email = email,
|
||||
token = aasToken,
|
||||
tokenType = AuthHelper.Token.AAS,
|
||||
properties = properties,
|
||||
locale = locale
|
||||
)
|
||||
verifyAndSaveAuth(authData, AccountType.GOOGLE)
|
||||
} catch (exception: Exception) {
|
||||
liveData.postValue(
|
||||
@@ -107,80 +120,28 @@ class AuthViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildAnonymousAuthData() {
|
||||
if (Preferences.getBoolean(context, Preferences.PREFERENCE_INSECURE_ANONYMOUS)) {
|
||||
buildInSecureAnonymousAuthData()
|
||||
} else {
|
||||
buildSecureAnonymousAuthData()
|
||||
}
|
||||
}
|
||||
|
||||
fun buildSecureAnonymousAuthData() {
|
||||
fun buildAnonymousAuthData() {
|
||||
liveData.postValue(AuthState.Fetching)
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
var properties = NativeDeviceInfoProvider(context).getNativeDeviceProperties()
|
||||
|
||||
if (spoofProvider.isDeviceSpoofEnabled())
|
||||
properties = spoofProvider.getSpoofDeviceProperties()
|
||||
|
||||
val playResponse = HttpClient
|
||||
.getPreferredClient(context)
|
||||
.postAuth(
|
||||
dispenserURL!!,
|
||||
gson.toJson(properties).toByteArray()
|
||||
)
|
||||
|
||||
if (playResponse.isSuccessful) {
|
||||
val authData = gson.fromJson(
|
||||
String(playResponse.responseBytes),
|
||||
AuthData::class.java
|
||||
)
|
||||
|
||||
//Set AuthData as anonymous
|
||||
authData.isAnonymous = true
|
||||
verifyAndSaveAuth(authData, AccountType.ANONYMOUS)
|
||||
} else {
|
||||
throwError(playResponse, context)
|
||||
}
|
||||
} catch (exception: Exception) {
|
||||
liveData.postValue(AuthState.Failed(exception.message.toString()))
|
||||
Log.e(TAG, "Failed to generate Session", exception)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun buildInSecureAnonymousAuthData() {
|
||||
liveData.postValue(AuthState.Fetching)
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
var properties = NativeDeviceInfoProvider(context)
|
||||
.getNativeDeviceProperties()
|
||||
|
||||
if (spoofProvider.isDeviceSpoofEnabled())
|
||||
properties = spoofProvider.getSpoofDeviceProperties()
|
||||
|
||||
val playResponse = HttpClient
|
||||
.getPreferredClient(context)
|
||||
.getAuth(dispenserURL!!)
|
||||
|
||||
if (playResponse.isSuccessful) {
|
||||
val insecureAuth = gson.fromJson(
|
||||
val tmpAuthData = gson.fromJson(
|
||||
String(playResponse.responseBytes),
|
||||
InsecureAuth::class.java
|
||||
Auth::class.java
|
||||
)
|
||||
|
||||
val deviceInfoProvider =
|
||||
DeviceInfoProvider(properties, Locale.getDefault().toString())
|
||||
val authData = AuthHelper.buildInsecure(
|
||||
insecureAuth.email,
|
||||
insecureAuth.auth,
|
||||
Locale.getDefault(),
|
||||
deviceInfoProvider
|
||||
val authData = AuthHelper.build(
|
||||
email = tmpAuthData.email,
|
||||
token = tmpAuthData.auth,
|
||||
tokenType = AuthHelper.Token.AUTH,
|
||||
isAnonymous = true,
|
||||
properties = properties,
|
||||
locale = locale
|
||||
)
|
||||
|
||||
//Set AuthData as anonymous
|
||||
authData.isAnonymous = true
|
||||
verifyAndSaveAuth(authData, AccountType.ANONYMOUS)
|
||||
} else {
|
||||
throwError(playResponse, context)
|
||||
@@ -267,12 +228,6 @@ class AuthViewModel @Inject constructor(
|
||||
private fun verifyAndSaveAuth(authData: AuthData, type: AccountType) {
|
||||
liveData.postValue(AuthState.Verifying)
|
||||
|
||||
if (spoofProvider.isLocaleSpoofEnabled()) {
|
||||
authData.locale = spoofProvider.getSpoofLocale()
|
||||
} else {
|
||||
authData.locale = Locale.getDefault()
|
||||
}
|
||||
|
||||
val versionId = Preferences.getInteger(context, Preferences.PREFERENCE_VENDING_VERSION)
|
||||
if (versionId > 0) {
|
||||
val resources = context.resources
|
||||
|
||||
Reference in New Issue
Block a user