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

Commit b0d9102e authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Remove SplitInstall notification

when auth token is not available. According to QA the behavior is a bit
flaky.

We may reintroduce it later on.
parent 8ec814ec
Loading
Loading
Loading
Loading
Loading
+0 −113
Original line number Original line Diff line number Diff line
@@ -18,22 +18,13 @@


package foundation.e.apps.install.splitinstall
package foundation.e.apps.install.splitinstall


import android.Manifest
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.BroadcastReceiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Context
import android.content.Intent
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.pm.PackageInfoCompat
import androidx.core.content.pm.PackageInfoCompat
import foundation.e.apps.ISplitInstallService
import foundation.e.apps.ISplitInstallService
import foundation.e.apps.MainActivity
import foundation.e.apps.MainActivity
import foundation.e.apps.R
import foundation.e.apps.data.DownloadManager
import foundation.e.apps.data.DownloadManager
import foundation.e.apps.data.application.ApplicationRepository
import foundation.e.apps.data.application.ApplicationRepository
import foundation.e.apps.data.login.AuthenticatorRepository
import foundation.e.apps.data.login.AuthenticatorRepository
@@ -60,7 +51,6 @@ class SplitInstallBinder(
    companion object {
    companion object {
        const val TAG = "SplitInstallerBinder"
        const val TAG = "SplitInstallerBinder"
        const val AUTH_DATA_ERROR_MESSAGE = "Could not get auth data"
        const val AUTH_DATA_ERROR_MESSAGE = "Could not get auth data"
        const val NOTIFICATION_CHANNEL = "Dynamic module install"
        const val NOTIFICATION_ID_KEY = "notification_id_key"
        const val NOTIFICATION_ID_KEY = "notification_id_key"
        const val PACKAGE_NAME_KEY = "package_name_key"
        const val PACKAGE_NAME_KEY = "package_name_key"
        const val PREFERENCES_FILE_NAME = "packages_to_ignore"
        const val PREFERENCES_FILE_NAME = "packages_to_ignore"
@@ -75,7 +65,6 @@ class SplitInstallBinder(


            if (authenticatorRepository.gplayAuth == null) {
            if (authenticatorRepository.gplayAuth == null) {
                Timber.w(AUTH_DATA_ERROR_MESSAGE)
                Timber.w(AUTH_DATA_ERROR_MESSAGE)
                handleError(packageName)
                return
                return
            }
            }


@@ -84,111 +73,9 @@ class SplitInstallBinder(
            }
            }
        } catch (exception: GPlayLoginException) {
        } catch (exception: GPlayLoginException) {
            Timber.w("$AUTH_DATA_ERROR_MESSAGE $exception")
            Timber.w("$AUTH_DATA_ERROR_MESSAGE $exception")
            handleError(packageName)
        }
        }
    }
    }


    private fun handleError(packageName: String) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
            return
        }

        createNotificationChannel(context)
        showErrorNotification(context, packageName)
    }

    private fun createNotificationChannel(context: Context) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
            return
        }

        val descriptionText = context.getString(R.string.notification_channel_desc)
        val notificationChannel = NotificationChannel(
            NOTIFICATION_CHANNEL,
            NOTIFICATION_CHANNEL,
            NotificationManager.IMPORTANCE_LOW
        ).apply {
            description = descriptionText
        }

        val notificationManager =
            context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

        notificationManager.createNotificationChannel(notificationChannel)
    }

    private fun showErrorNotification(context: Context, packageName: String) {
        if (ActivityCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS)
            != PackageManager.PERMISSION_GRANTED
        ) {
            return
        }

        val preferences = context.getSharedPreferences(PREFERENCES_FILE_NAME, Context.MODE_PRIVATE)
        val ignoreList = preferences.getStringSet(PACKAGES_LIST_KEY, Collections.emptySet())
        if (ignoreList != null && packageName in ignoreList) return

        val appInfo = context.packageManager.getPackageInfo(packageName, 0).applicationInfo
        val appLabel = context.packageManager.getApplicationLabel(appInfo)
        val callerUid = appInfo.uid
        val contentText = context.getString(
            R.string.split_install_warning_text,
            appLabel
        )

        val notificationBuilder = NotificationCompat.Builder(context, NOTIFICATION_CHANNEL)
            .setSmallIcon(R.drawable.app_lounge_notification_icon)
            .setContentTitle(context.getString(R.string.split_install_warning_title, appLabel))
            .setContentText(contentText)
            .setStyle(NotificationCompat.BigTextStyle().bigText(contentText))
            .addAction(
                NotificationCompat.Action.Builder(
                    null,
                    context.getString(R.string.sign_in),
                    buildSignInPendingIntent(callerUid)
                ).build()
            )
            .addAction(
                NotificationCompat.Action.Builder(
                    null,
                    context.getString(R.string.ignore),
                    buildIgnorePendingIntent(callerUid, packageName)
                ).build()
            )

        with(NotificationManagerCompat.from(context)) {
            notify(callerUid, notificationBuilder.build())
        }
    }

    private fun buildIgnorePendingIntent(callerUid: Int, packageName: String): PendingIntent {

        val ignoreIntent = Intent(context, IgnoreReceiver::class.java).apply {
            putExtra(NOTIFICATION_ID_KEY, callerUid)
            putExtra(PACKAGE_NAME_KEY, packageName)
        }

        return PendingIntent.getBroadcast(
            context,
            callerUid,
            ignoreIntent,
            PendingIntent.FLAG_MUTABLE
        )
    }

    private fun buildSignInPendingIntent(callerUid: Int): PendingIntent {
        val signInIntent = Intent(context, SignInReceiver::class.java).apply {
            putExtra(NOTIFICATION_ID_KEY, callerUid)
        }

        return PendingIntent.getBroadcast(
            context,
            callerUid,
            signInIntent,
            PendingIntent.FLAG_MUTABLE
        )
    }

    fun setService(service: foundation.e.splitinstall.ISplitInstallService) {
    fun setService(service: foundation.e.splitinstall.ISplitInstallService) {
        splitInstallSystemService = service
        splitInstallSystemService = service
        installPendingModules()
        installPendingModules()
+1 −8
Original line number Original line Diff line number Diff line
@@ -170,11 +170,4 @@
    <string name="too_many_requests_desc">Das anonyme Konto, das von Ihnen genutzt wird, ist nicht verfügbar. Bitte erneuern (refresh) Sie die Sitzung, um ein neues anonymes Konto zu erhalten.</string>
    <string name="too_many_requests_desc">Das anonyme Konto, das von Ihnen genutzt wird, ist nicht verfügbar. Bitte erneuern (refresh) Sie die Sitzung, um ein neues anonymes Konto zu erhalten.</string>
    <string name="refresh_session">SITZUNG ERNEUERN</string>
    <string name="refresh_session">SITZUNG ERNEUERN</string>
    <string name="notification_content_full_db">Bitte etwas Platz auf dem Telefon freimachen, damit die App Lounge ordnungsgemäß funktionieren kann.</string>
    <string name="notification_content_full_db">Bitte etwas Platz auf dem Telefon freimachen, damit die App Lounge ordnungsgemäß funktionieren kann.</string>

    <!--Split install-->
    <string name="split_install_warning_title">Warnung bezüglich %s</string>
    <string name="split_install_warning_text">%s möchte zusätzliche Module installieren. Sie müssen sich erneut bei AppLounge anmelden, um sie installieren zu können.</string>
    <string name="notification_channel_desc">Split-Installationskanal</string>
    <string name="sign_in">Einloggen</string>
    <string name="ignore">Ignorieren</string>
</resources>
</resources>
+1 −6
Original line number Original line Diff line number Diff line
@@ -156,11 +156,6 @@
    <string name="or">O mostrar sólo</string>
    <string name="or">O mostrar sólo</string>
    <string name="free_space_for_update">Libera %1$s en tu teléfono para recibir las últimas actualizaciones.</string>
    <string name="free_space_for_update">Libera %1$s en tu teléfono para recibir las últimas actualizaciones.</string>
    <string name="notification_content_full_db">Por favor, libera algo de espacio en tu teléfono para que App Lounge funcione correctamente.</string>
    <string name="notification_content_full_db">Por favor, libera algo de espacio en tu teléfono para que App Lounge funcione correctamente.</string>
    <string name="split_install_warning_title">Advertencia sobre %s</string>
    <string name="split_install_warning_text">%s quiere instalar módulos adicionales. Debes iniciar sesión en AppLounge nuevamente para poder instalarlos.</string>
    <string name="notification_channel_desc">Canal de instalación dividido</string>
    <string name="sign_in">Iniciar sesión</string>
    <string name="ignore">Ignorar</string>
    <string name="downloading">Descargando…</string>
    <string name="downloading">Descargando…</string>
    <string name="checking_updates">Comprobando actualizaciones...</string>
    <string name="checking_updates">Comprobando actualizaciones...</string>
    <string name="preference_update_apps_from_other_stores_title">Actualizar aplicaciones instaladas por otras tiendas</string>
    <string name="preference_update_apps_from_other_stores_title">Actualizar aplicaciones instaladas por otras tiendas</string>
+1 −6
Original line number Original line Diff line number Diff line
@@ -168,9 +168,4 @@
    <string name="free_space_for_update">Libérez %1$s sur votre téléphone afin de bénéficier des dernières mises à jour.</string>
    <string name="free_space_for_update">Libérez %1$s sur votre téléphone afin de bénéficier des dernières mises à jour.</string>
    <string name="notification_content_full_db">Merci de libérer de l\'espace sur votre téléphone pour qu\'App Lounge puisse fonctionner correctement.</string>
    <string name="notification_content_full_db">Merci de libérer de l\'espace sur votre téléphone pour qu\'App Lounge puisse fonctionner correctement.</string>
    <string name="checking_updates">Vérification des mises à jour...</string>
    <string name="checking_updates">Vérification des mises à jour...</string>
    <string name="split_install_warning_title">Avertissement concernant %s</string>
    <string name="split_install_warning_text">%s souhaite installer des modules supplémentaires. Vous devez vous reconnecter à AppLounge pour pouvoir les installer.</string>
    <string name="notification_channel_desc">Canal d\'installation fractionnée</string>
    <string name="sign_in">Connexion</string>
    <string name="ignore">Ignorer</string>
</resources>
</resources>
+1 −6
Original line number Original line Diff line number Diff line
@@ -171,9 +171,4 @@
    <string name="free_space_for_update">Losaðu um %1$s pláss á símanum þínum til að fá nýjustu uppfærslur.</string>
    <string name="free_space_for_update">Losaðu um %1$s pláss á símanum þínum til að fá nýjustu uppfærslur.</string>
    <string name="checking_updates">Athuga með uppfærslur...</string>
    <string name="checking_updates">Athuga með uppfærslur...</string>
    <string name="notification_content_full_db">Losaðu um svolítið pláss á símanum þínum svo App Lounge geti virkað eðlilega.</string>
    <string name="notification_content_full_db">Losaðu um svolítið pláss á símanum þínum svo App Lounge geti virkað eðlilega.</string>
    <string name="ignore">Hunsa</string>
    <string name="notification_channel_desc">Skipta upp uppsetningarás</string>
    <string name="split_install_warning_title">Aðvörun viðkomandi %s</string>
    <string name="split_install_warning_text">%s vill fá að setja upp viðbótareiningar.Þú þarft að skrá þig aftur inn í AppLounge til að geta sett þær inn.</string>
    <string name="sign_in">Skrá inn</string>
</resources>
</resources>
Loading