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

Commit 562f8136 authored by Nicolas Melin's avatar Nicolas Melin Committed by Mohammed Althaf T
Browse files

fix: Disagreeing to the ToS still lets the service be used

parent e13ef34a
Loading
Loading
Loading
Loading
Loading
+3 −19
Original line number Diff line number Diff line
@@ -7,30 +7,14 @@ import android.os.Build
import android.os.Bundle
import android.os.LocaleList
import android.widget.TextView
import androidx.annotation.IntDef
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.net.toUri
import com.google.android.material.dialog.MaterialAlertDialogBuilder

@IntDef(ConsentActivity.CONSENT_NOT_YET_GIVEN, ConsentActivity.CONSENT_GIVEN, ConsentActivity.CONSENT_REFUSED)
@Retention(AnnotationRetention.SOURCE)
annotation class ConsentStatus

class ConsentActivity : AppCompatActivity() {

    companion object {
        const val CONSENT_NOT_YET_GIVEN = 0
        const val CONSENT_GIVEN = 1
        const val CONSENT_REFUSED = 2

        @ConsentStatus
        fun hasGivenConsent(): Int = UserPreference.hasGivenConsentForSTT

        fun setConsentGiven(@ConsentStatus given: Int) {
            UserPreference.hasGivenConsentForSTT = given
        }

        private val SUPPORTED_LANGUAGES = setOf("fr", "es", "de", "it")

        fun getTermsOfServiceLanguage(): String {
@@ -49,7 +33,7 @@ class ConsentActivity : AppCompatActivity() {

        UserPreference.init(this)

        if (hasGivenConsent() != CONSENT_NOT_YET_GIVEN) {
        if (UserPreference.hasGivenConsentForSTT) {
            finish()
            return
        }
@@ -70,11 +54,11 @@ class ConsentActivity : AppCompatActivity() {
            .setTitle(R.string.consent_dialog_title)
            .setView(messageTextView)
            .setPositiveButton(R.string.consent_dialog_yes) { _, _ ->
                setConsentGiven(CONSENT_GIVEN)
                UserPreference.hasGivenConsentForSTT = true
                finish()
            }
            .setNegativeButton(R.string.consent_dialog_no) { _, _ ->
                setConsentGiven(CONSENT_REFUSED)
                UserPreference.hasGivenConsentForSTT = false
                finish()
            }
            .setNeutralButton(R.string.consent_dialog_terms_of_service, null)
+7 −7
Original line number Diff line number Diff line
@@ -352,7 +352,11 @@ class MurenaWhisperInputService : InputMethodService() {

            UserPreference.init(this@MurenaWhisperInputService)

            if (ConsentActivity.hasGivenConsent() == ConsentActivity.CONSENT_NOT_YET_GIVEN) {
            if (UserPreference.hasGivenConsentForSTT) {
                showKeyboard()
                attachRecorderCallbacks()
                initApp()
            } else {
                consentPrefs = applicationContext
                    .getSharedPreferences(UserPreference.PREF_NAME, Context.MODE_PRIVATE)
                consentPrefs.registerOnSharedPreferenceChangeListener(consentListener)
@@ -360,10 +364,6 @@ class MurenaWhisperInputService : InputMethodService() {
                val intent = Intent(applicationContext, ConsentActivity::class.java)
                intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
                startActivity(intent)
            } else {
                showKeyboard()
                attachRecorderCallbacks()
                initApp()
            }
        }
    }
@@ -454,8 +454,8 @@ class MurenaWhisperInputService : InputMethodService() {
            if (key == UserPreference.PREF_CONSENT_STT) {
                sp.unregisterOnSharedPreferenceChangeListener(consentListener)

                val granted = sp.getInt(key, ConsentActivity.CONSENT_NOT_YET_GIVEN)
                if (granted == ConsentActivity.CONSENT_GIVEN) {
                val granted = sp.getBoolean(key, false)
                if (granted) {
                    showKeyboard()
                    initApp()
                } else {
+2 −1
Original line number Diff line number Diff line
@@ -47,8 +47,9 @@ class StartupReceiver : BroadcastReceiver() {
                var enabledImes: String? = Settings.Secure.getString(cr, Settings.Secure.ENABLED_INPUT_METHODS)
                val accountIsPremium = AccountManagerHelper.accountIsPremium(context.applicationContext)
                val sttKeyboardActivated = !enabledImes.isNullOrEmpty() && enabledImes.contains(imeId)
                val sttNotActivated = !sttKeyboardActivated && !UserPreference.isSttFeatureActivated

                if (accountIsPremium && !sttKeyboardActivated && !UserPreference.isSttFeatureActivated && UserPreference.hasGivenConsentForSTT != ConsentActivity.CONSENT_REFUSED) {
                if (accountIsPremium && sttNotActivated && UserPreference.hasGivenConsentForSTT) {
                    SttKeyboardManager.enabledSttKeyboard(context)
                } else if (!accountIsPremium && sttKeyboardActivated) {
                    // Remove the STT keyboard if it's enabled for a non-premium account
+3 −5
Original line number Diff line number Diff line
@@ -46,11 +46,9 @@ object UserPreference {
        get() = sharedPreferences.getBoolean(PREF_AUTO_ACTIVATED, false)
        set(value) = sharedPreferences.edit() { putBoolean(PREF_AUTO_ACTIVATED, value) }

    @get:ConsentStatus
    @setparam:ConsentStatus
    var hasGivenConsentForSTT: Int
        get() = sharedPreferences.getInt(PREF_CONSENT_STT, ConsentActivity.CONSENT_NOT_YET_GIVEN)
        set(value) = sharedPreferences.edit() { putInt(PREF_CONSENT_STT, value) }
    var hasGivenConsentForSTT: Boolean
        get() = sharedPreferences.getBoolean(PREF_CONSENT_STT, false)
        set(value) = sharedPreferences.edit() { putBoolean(PREF_CONSENT_STT, value) }

    var isVoiceAnonymizerEnabled: Boolean
        get() = sharedPreferences.getBoolean(PREF_VOICE_ANONYMIZER_ENABLED, true)