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

Commit 2ed126bb authored by Hasib Prince's avatar Hasib Prince
Browse files

Merge branch 'main' of gitlab.e.foundation:e/os/apps

parents 8c3609d8 11c0fdb0
Loading
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -68,6 +68,19 @@
            </intent-filter>
        </receiver>

        <receiver android:name=".receiver.PWAPlayerStatusReceiver"
            android:exported="true">
            <intent-filter>
                <action android:name="foundation.e.pwaplayer.PWA_ADDED" />
            </intent-filter>
            <intent-filter>
                <action android:name="foundation.e.pwaplayer.PWA_CHANGED" />
            </intent-filter>
            <intent-filter>
                <action android:name="foundation.e.pwaplayer.PWA_REMOVED" />
            </intent-filter>
        </receiver>

        <!-- If you want to disable android.startup completely. -->
        <provider
            android:name="androidx.startup.InitializationProvider"
+27 −20
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import foundation.e.apps.utils.modules.CommonUtilsModule
import kotlinx.coroutines.launch
import java.io.File
import java.util.UUID
import javax.inject.Inject

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
@@ -83,13 +84,7 @@ class MainActivity : AppCompatActivity() {
            }
        }

        viewModel.internetConnection.observe(this) { isInternetAvailable ->
            hasInternet = isInternetAvailable
            if (isInternetAvailable) {
                binding.noInternet.visibility = View.GONE
                binding.fragment.visibility = View.VISIBLE

                viewModel.userType.observe(this) { user ->
        fun generateAuthDataBasedOnUserType(user: String) {
            if (user.isNotBlank() && viewModel.tocStatus.value == true) {
                when (User.valueOf(user)) {
                    User.ANONYMOUS -> {
@@ -99,7 +94,7 @@ class MainActivity : AppCompatActivity() {
                        }
                    }
                    User.UNAVAILABLE -> {
                                viewModel.destroyCredentials()
                        viewModel.destroyCredentials(null)
                    }
                    User.GOOGLE -> {
                        if (viewModel.authData.value == null && !viewModel.authRequestRunning) {
@@ -111,6 +106,16 @@ class MainActivity : AppCompatActivity() {
            }
        }

        viewModel.internetConnection.observe(this) { isInternetAvailable ->
            hasInternet = isInternetAvailable
            if (isInternetAvailable) {
                binding.noInternet.visibility = View.GONE
                binding.fragment.visibility = View.VISIBLE

                viewModel.userType.observe(this) { user ->
                    generateAuthDataBasedOnUserType(user)
                }

                signInViewModel.authLiveData.observe(this) {
                    viewModel.updateAuthData(it)
                }
@@ -128,7 +133,9 @@ class MainActivity : AppCompatActivity() {
        viewModel.authValidity.observe(this) {
            if (it != true) {
                Log.d(TAG, "Authentication data validation failed!")
                viewModel.destroyCredentials()
                viewModel.destroyCredentials { user ->
                    generateAuthDataBasedOnUserType(user)
                }
            } else {
                Log.d(TAG, "Authentication data is valid!")
            }
+24 −1
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import foundation.e.apps.manager.pkg.PkgManagerModule
import foundation.e.apps.utils.enums.Origin
import foundation.e.apps.utils.enums.Status
import foundation.e.apps.utils.enums.Type
import foundation.e.apps.utils.enums.User
import foundation.e.apps.utils.modules.DataStoreModule
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -101,9 +102,31 @@ class MainActivityViewModel @Inject constructor(
        _authData.value = authData
    }

    fun destroyCredentials() {
    fun destroyCredentials(regenerateFunction: ((user: String) -> Unit)?) {
        viewModelScope.launch {
            /*
             * Issue: https://gitlab.e.foundation/e/backlog/-/issues/5168
             *
             * Now destroyCredentials() no longer removes the user type from data store.
             * (i.e. Google login or Anonymous).
             * - If the type is User.ANONYMOUS then we do not prompt the user to login again,
             *   we directly generate new auth data; which is the main Gitlab issue described above.
             * - If not anonymous user, i.e. type is User.GOOGLE, in that case we clear
             *   the USERTYPE value. This causes HomeFragment.onTosAccepted() to open
             *   SignInFragment as we need fresh login from the user.
             */
            dataStoreModule.destroyCredentials()
            if (regenerateFunction != null) {
                dataStoreModule.userType.collect { user ->
                    if (!user.isBlank() && User.valueOf(user) == User.ANONYMOUS) {
                        Log.d(TAG, "Regenerating auth data for Anonymous user")
                        regenerateFunction(user)
                    } else {
                        Log.d(TAG, "Ask Google user to log in again")
                        dataStoreModule.clearUserType()
                    }
                }
            }
        }
    }

+7 −1
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import foundation.e.apps.manager.pkg.PkgManagerModule
import foundation.e.apps.utils.enums.Origin
import foundation.e.apps.utils.enums.Status
import foundation.e.apps.utils.enums.Type
import foundation.e.apps.utils.modules.PWAManagerModule
import foundation.e.apps.utils.modules.PreferenceManagerModule
import javax.inject.Inject
import javax.inject.Singleton
@@ -53,6 +54,7 @@ class FusedAPIImpl @Inject constructor(
    private val cleanAPKRepository: CleanAPKRepository,
    private val gPlayAPIRepository: GPlayAPIRepository,
    private val pkgManagerModule: PkgManagerModule,
    private val pwaManagerModule: PWAManagerModule,
    private val preferenceManagerModule: PreferenceManagerModule,
    @ApplicationContext private val context: Context
) {
@@ -643,10 +645,14 @@ class FusedAPIImpl @Inject constructor(

    private fun FusedApp.updateStatus() {
        if (this.status != Status.INSTALLATION_ISSUE) {
            this.status =
            this.status = if (this.is_pwa) {
                pwaManagerModule.getPwaStatus(this)
            }
            else {
                pkgManagerModule.getPackageStatus(this.package_name, this.latest_version_code)
            }
        }
    }

    private fun FusedApp.updateType() {
        this.type = if (this.is_pwa) Type.PWA else Type.NATIVE
+1 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ data class FusedApp(
    val price: String = String(),
    val isFree: Boolean = true,
    val is_pwa: Boolean = false,
    var pwaPlayerDbId: Long = -1,
    val url: String = String(),
    var type: Type = Type.NATIVE,
    var privacyScore: Int = -1
Loading