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

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

Implement split install callbacks

parent 48607f27
Loading
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
/*
 * SPDX-FileCopyrightText: 2016 microG Project Team
 * SPDX-FileCopyrightText: 2023 E FOUNDATION
 * SPDX-License-Identifier: Apache-2.0
 */

package com.android.vending.splitinstall;

import android.os.Bundle;

interface ISplitInstallServiceCallback {

    void onStartInstall(int i);

    void onInstalled(int i);

    void onError(int errorCode);
}
 No newline at end of file
+1 −2
Original line number Diff line number Diff line
@@ -18,8 +18,7 @@ interface ISplitInstallService {
    // Method not identified yet
    void c(String str);

    // Method not identified yet
    void d(String str);
    void getSessionState(String str, int i, in Bundle bundle, in ISplitInstallServiceCallback callback);

    // Method not identified yet
    void e(String str);
+3 −3
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ interface ISplitInstallServiceCallback {
    // Method not identified yet
    void a();

    void onStartInstall(int i);
    void onStartInstall(int i, in Bundle bundle);

    void onCompleteInstall(int i);

@@ -21,7 +21,7 @@ interface ISplitInstallServiceCallback {

    void onGetSession(int i);

    void onError(int i);
    void onError(in Bundle bundle);

    void onGetSessionStates(in List<Bundle> list);

+3 −1
Original line number Diff line number Diff line
@@ -6,6 +6,8 @@

package foundation.e.apps;

import com.android.vending.splitinstall.ISplitInstallServiceCallback;

interface ISplitInstallService {
    void installSplitModule(String packageName, String moduleName);
    void installSplitModule(String packageName, String moduleName, ISplitInstallServiceCallback callback);
}
+69 −19
Original line number Diff line number Diff line
@@ -12,16 +12,20 @@ import android.os.Bundle
import android.os.IBinder
import android.os.Parcel
import android.util.Log
import com.android.vending.splitinstall.ISplitInstallServiceCallback
import com.android.vending.splitinstall.SplitInstallSessionStatus
import com.android.vending.splitinstall.SplitInstaller
import com.android.vending.splitinstall.SplitInstallerFactory
import com.android.vending.splitinstall.SplitInstallerType
import com.google.android.play.core.splitinstall.protocol.ISplitInstallService
import com.google.android.play.core.splitinstall.protocol.ISplitInstallServiceCallback
import com.google.android.play.core.splitinstall.protocol.ISplitInstallServiceCallback as IGoogleCallback

class SplitInstallService : Service() {

    companion object {
        const val TAG = "SplitInstallService"
        const val SPLIT_INSTALL_UPDATE_SERVICE =
            "com.google.android.play.core.splitinstall.receiver.SplitInstallUpdateIntentService"
    }

    private lateinit var mSplitInstaller: SplitInstaller
@@ -48,47 +52,88 @@ class SplitInstallService : Service() {

    private var mServiceInterface = object : ISplitInstallService.Stub() {

        override fun a() {
            Log.d(TAG, "a")
        private var sessionsState: Bundle = Bundle()

        override fun getSessionStates(str: String, callback: IGoogleCallback) {
            callback.onGetSessionStates(arrayListOf(sessionsState))
        }

        override fun startInstall(
            packageName: String,
            list: List<Bundle>,
            bundle: Bundle,
            callback: ISplitInstallServiceCallback
            bundle: Bundle?,
            callback: IGoogleCallback
        ) {
            for (element in list) {

            for (element in list) {
                val apk = element.getString("module_name") ?: element.getString("language")
                apk?.let {
                    mSplitInstaller.install(packageName, apk)
                    callback.onStartInstall(0)

                    val splitInstallServiceCallback = object : ISplitInstallServiceCallback.Stub() {
                        override fun onStartInstall(i: Int) {
                            sessionsState = provideStateBundle(apk, SplitInstallSessionStatus.INSTALLING)
                            updateState(packageName, sessionsState)
                            callback.onStartInstall(i, sessionsState)
                        }

                        override fun onInstalled(i: Int) {
                            sessionsState = provideStateBundle(apk, SplitInstallSessionStatus.INSTALLED)
                            updateState(packageName, sessionsState)
                            callback.onCompleteInstall(i)
                        }

                        override fun onError(errorCode: Int) {
                            val errorBundle = Bundle()
                            errorBundle.putInt("error_code", errorCode)
                            callback.onError(errorBundle)
                        }
                    }

                    mSplitInstaller.install(packageName, apk, splitInstallServiceCallback)

                } ?: logBundleError(element)
            }
        }

        private fun logBundleError(bundle: Bundle) {
            for (entry in bundle.keySet()) {
                Log.e(TAG, "Unknown bundle entry: $entry. Value is ${bundle.get(entry)}")
        fun updateState(packageName: String, bundle: Bundle) {
            val intent = Intent()
            intent.setPackage(packageName)
            intent.action = SPLIT_INSTALL_UPDATE_SERVICE
            intent.putExtra("session_state", bundle)
            applicationContext.sendBroadcast(intent)
        }

        fun provideStateBundle(apk: String, state: Int) = Bundle().apply {
            putInt("session_id", 0)
            putInt("status", state)
            putInt("error_code", 0)
            putStringArrayList("module_names", arrayListOf(apk))
            putStringArrayList("languages", arrayListOf(apk))
            putLong("total_bytes_to_download", 0L)
            putLong("bytes_downloaded", 0L)
        }

        override fun c(str: String?) {
            Log.d(TAG, "c")
            Log.i(TAG, "c")
        }

        override fun d(str: String?) {
            Log.d(TAG, "d")
        override fun getSessionState(
            str: String?,
            i: Int,
            bundle: Bundle?,
            callback: IGoogleCallback?
        ) {
            Log.i(TAG, "getSessionState")
        }

        override fun e(str: String?) {
            Log.d(TAG, "e")
            Log.i(TAG, "e")
        }

        override fun getSessionStates(str: String, callback: ISplitInstallServiceCallback) {
            Log.d(TAG, "onGetSessionStates")
            callback.onGetSessionStates(arrayListOf<Bundle>())
        private fun logBundleError(bundle: Bundle) {
            for (entry in bundle.keySet()) {
                Log.e(TAG, "Unknown bundle entry: $entry. Value is ${bundle.get(entry)}")
            }
        }

        override fun onTransact(code: Int, data: Parcel, reply: Parcel?, flags: Int): Boolean {
@@ -96,5 +141,10 @@ class SplitInstallService : Service() {
            Log.d(TAG, "onTransact [unknown]: $code, $data, $flags")
            return false
        }

        override fun a() {
            TODO("Not yet implemented")
        }

    }
}
Loading