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

Commit 2214d9e4 authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Use SplitInstallService system service

So that the split apk is installed seamlessly and the user
don't have to manually accept installation of split apk.
parent 33cd8ff3
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -110,6 +110,9 @@ allOpen {

dependencies {

    // TODO: Add splitinstall-lib to a repo https://gitlab.e.foundation/e/os/backlog/-/issues/628
    api files('libs/splitinstall-lib.jar')

    implementation 'foundation.e:gplayapi:3.0.1'
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.1'
+4.58 KiB

File added.

Preview suppressed by a .gitattributes entry or the file's encoding is unsupported.

+1 −6
Original line number Diff line number Diff line
@@ -88,12 +88,6 @@
            </intent-filter>
        </receiver>

        <receiver android:name=".splitinstall.SplitInstallBroadcastReceiver">
            <intent-filter>
                <action android:name="foundation.e.apps.ondemand.INSTALL_MODULE"/>
            </intent-filter>
        </receiver>

        <!-- If you want to disable android.startup completely. -->
        <provider
            android:name="androidx.startup.InitializationProvider"
@@ -101,6 +95,7 @@
            tools:node="remove" />

        <service android:name=".manager.pkg.PackageInstallerService" />

        <service
            android:name=".splitinstall.SplitInstallService"
            android:exported="true" />
+1 −0
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ class DownloadManager @Inject constructor(
        } catch (e: Exception) {
            Timber.e(e)
        }

    }

    private fun tickerFlow(downloadId: Long, period: Duration, initialDelay: Duration = Duration.ZERO) = flow {
+0 −37
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ import dagger.hilt.android.qualifiers.ApplicationContext
import foundation.e.apps.OpenForTesting
import foundation.e.apps.api.fused.FusedAPIImpl
import foundation.e.apps.manager.database.fusedDownload.FusedDownload
import foundation.e.apps.splitinstall.SplitInstallBroadcastReceiver
import foundation.e.apps.utils.enums.Origin
import foundation.e.apps.utils.enums.Status
import foundation.e.apps.utils.enums.Type
@@ -174,42 +173,6 @@ class PkgManagerModule @Inject constructor(
        }
    }

    fun installSplitModule(moduleFile: File, packageName: String) {

        val sessionId = createInstallSession(packageName, SessionParams.MODE_INHERIT_EXISTING)
        val session = packageManager.packageInstaller.openSession(sessionId)

        try {
            syncFile(session, moduleFile)

            val callBackIntent = Intent(context, SplitInstallBroadcastReceiver::class.java)
            callBackIntent.action = SplitInstallBroadcastReceiver.ACTION_MODULE_INSTALLED

            val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
                PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE else
                PendingIntent.FLAG_UPDATE_CURRENT
            val servicePendingIntent = PendingIntent.getBroadcast(
                context,
                sessionId,
                callBackIntent,
                flags
            )
            session.commit(servicePendingIntent.intentSender)
        } catch (e: Exception) {
            val pendingIntent = PendingIntent.getBroadcast(
                context,
                sessionId,
                Intent(ERROR_PACKAGE_INSTALL),
                PendingIntent.FLAG_IMMUTABLE
            )
            session.commit(pendingIntent.intentSender)
            session.abandon()
            throw e
        } finally {
            session.close()
        }
    }

    private fun createInstallSession(packageName: String, mode: Int): Int {

        val packageInstaller = packageManager.packageInstaller
Loading