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

Commit 77a64886 authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Save package name that the user is ignoring for split apks

If the user ignores the notification to install dynamic modules, we save
it and ignore all the dynamic modules.
parent 9dcf6881
Loading
Loading
Loading
Loading
+27 −3
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
@@ -44,6 +43,8 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import timber.log.Timber
import java.util.Collections
import java.util.TreeSet

class SplitInstallBinder(
    val context: Context,
@@ -61,6 +62,9 @@ class SplitInstallBinder(
        const val AUTH_DATA_ERROR_MESSAGE = "Could not get auth data"
        const val NOTIFICATION_CHANNEL = "SplitInstallAppLounge"
        const val NOTIFICATION_ID_KEY = "notification_id_key"
        const val PACKAGE_NAME_KEY = "package_name_key"
        const val PREFERENCES_FILE_NAME = "packages_to_ignore"
        const val PACKAGES_LIST_KEY = "packages_list_key"
    }

    override fun installSplitModule(packageName: String, moduleName: String) {
@@ -120,6 +124,10 @@ class SplitInstallBinder(
            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
@@ -145,7 +153,7 @@ class SplitInstallBinder(
                NotificationCompat.Action.Builder(
                    null,
                    context.getString(R.string.ignore),
                    buildIgnorePendingIntent(callerUid)
                    buildIgnorePendingIntent(callerUid, packageName)
                ).build()
            )

@@ -154,9 +162,11 @@ class SplitInstallBinder(
        }
    }

    private fun buildIgnorePendingIntent(callerUid: Int): PendingIntent {
    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(
@@ -243,6 +253,7 @@ class SplitInstallBinder(
    }

    class IgnoreReceiver: BroadcastReceiver() {

        override fun onReceive(context: Context?, intent: Intent?) {
            if (context == null || intent == null) {
                return
@@ -251,6 +262,19 @@ class SplitInstallBinder(
            NotificationManagerCompat.from(context).cancel(
                intent.getIntExtra(NOTIFICATION_ID_KEY, -1)
            )

            val packageName = intent.getStringExtra(PACKAGE_NAME_KEY) ?: return
            val preferences = context.getSharedPreferences(
                PREFERENCES_FILE_NAME,
                Context.MODE_PRIVATE
            )

            val ignoreList = preferences.getStringSet(PACKAGES_LIST_KEY, Collections.emptySet())
                ?: Collections.emptySet()
            
            val newList = TreeSet(ignoreList)
            newList.add(packageName)
            preferences.edit().putStringSet(PACKAGES_LIST_KEY, newList).apply()
        }
    }