From 526417feb2e5955933e5ec3a2f422711f4eca21b Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Fri, 8 Jul 2022 09:08:26 +0200 Subject: [PATCH 1/4] Implement SplitInstallService Some applications which are using GMS can install some features at runtime with a SplitInstallManager: https://developer.android.com/guide/playcore/feature-delivery/on-demand Implemented AppLoungeSplitInstaller which connects to AppLounge to send install requests. --- .gitignore | 1 + build.gradle | 2 +- fake-store/build.gradle | 4 + fake-store/src/main/AndroidManifest.xml | 1 + .../e/apps/ISplitInstallerService.aidl | 21 +++++ .../android/vending/SplitInstallService.kt | 43 +++++----- .../vending/splitinstall/SplitInstaller.kt | 38 +++++++++ .../installer/AppLoungeSplitInstaller.kt | 78 +++++++++++++++++++ gradle.properties | 1 + 9 files changed, 169 insertions(+), 20 deletions(-) create mode 100644 fake-store/src/main/aidl/foundation/e/apps/ISplitInstallerService.aidl create mode 100644 fake-store/src/main/java/com/android/vending/splitinstall/SplitInstaller.kt create mode 100644 fake-store/src/main/java/com/android/vending/splitinstall/installer/AppLoungeSplitInstaller.kt create mode 100644 gradle.properties diff --git a/.gitignore b/.gitignore index a1b9eab..09765c5 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ build/ user.gradle local.properties *.iml +.idea/* diff --git a/build.gradle b/build.gradle index d5dcb5f..05cfe61 100644 --- a/build.gradle +++ b/build.gradle @@ -35,7 +35,7 @@ def androidCompileSdk() { return 30 } def androidTargetSdk() { return 24 } -def androidMinSdk() { return 9 } +def androidMinSdk() { return 14 } def versionCode() { def stdout = new ByteArrayOutputStream() diff --git a/fake-store/build.gradle b/fake-store/build.gradle index dc59f5d..8cb38cc 100644 --- a/fake-store/build.gradle +++ b/fake-store/build.gradle @@ -60,4 +60,8 @@ repositories { } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation "com.squareup.okhttp3:okhttp:4.9.2" + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0" + implementation "com.google.code.gson:gson:2.8.9" + implementation "androidx.core:core-ktx:1.6.0" } diff --git a/fake-store/src/main/AndroidManifest.xml b/fake-store/src/main/AndroidManifest.xml index 53e5f84..401eb2c 100644 --- a/fake-store/src/main/AndroidManifest.xml +++ b/fake-store/src/main/AndroidManifest.xml @@ -20,6 +20,7 @@ + , bundle: Bundle, callback: ISplitInstallServiceCallback ) { - Log.i(TAG, "Start install request from $packageName") - for (element in list) { - logBundle(element) + mSplitInstaller.install(packageName, element.get("module_name").toString()) } - - logBundle(bundle) - - val errorBundle = Bundle() - errorBundle.putInt(ERROR_CODE_KEY, SplitInstallErrorCode.API_NOT_AVAILABLE) - callback.onError(errorBundle) } override fun c(str: String?) { @@ -81,6 +85,7 @@ class SplitInstallService : Service() { } override fun getSessionStates(str: String, callback: ISplitInstallServiceCallback) { + Log.d(TAG, "onGetSessionStates") callback.onGetSessionStates(arrayListOf()) } diff --git a/fake-store/src/main/java/com/android/vending/splitinstall/SplitInstaller.kt b/fake-store/src/main/java/com/android/vending/splitinstall/SplitInstaller.kt new file mode 100644 index 0000000..21b37c3 --- /dev/null +++ b/fake-store/src/main/java/com/android/vending/splitinstall/SplitInstaller.kt @@ -0,0 +1,38 @@ +/* + * Copyright 2013-2022 microG Project Team + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.vending.splitinstall + +import android.content.Context +import com.android.vending.splitinstall.installer.AppLoungeSplitInstaller + +interface SplitInstaller { + fun initialize() + fun install(packageName: String, moduleName: String) + fun destroy() +} + +enum class SplitInstallerType { AppLoungeSplitInstaller } + +object SplitInstallerFactory { + fun createSplitInstaller(context: Context, type: SplitInstallerType): SplitInstaller { + when (type) { + SplitInstallerType.AppLoungeSplitInstaller -> + return AppLoungeSplitInstaller(context) + else -> throw IllegalArgumentException("Unknown SplitInstallerType") + } + } +} diff --git a/fake-store/src/main/java/com/android/vending/splitinstall/installer/AppLoungeSplitInstaller.kt b/fake-store/src/main/java/com/android/vending/splitinstall/installer/AppLoungeSplitInstaller.kt new file mode 100644 index 0000000..7c8d1d9 --- /dev/null +++ b/fake-store/src/main/java/com/android/vending/splitinstall/installer/AppLoungeSplitInstaller.kt @@ -0,0 +1,78 @@ +/* + * Copyright 2013-2022 microG Project Team + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.vending.splitinstall.installer + +import android.content.ComponentName +import android.content.Context +import android.content.Intent +import android.content.ServiceConnection +import android.os.IBinder +import com.android.vending.splitinstall.SplitInstaller +import foundation.e.apps.ISplitInstallerService + +class AppLoungeSplitInstaller( + private val context: Context +) : SplitInstaller { + + companion object { + private val ON_DEMAND_DELIVERY_SERVICE_COMPONENT = + ComponentName("foundation.e.apps", "foundation.e.apps.splitinstall.SplitInstallerService") + } + + private var service: ISplitInstallerService? = null + private val moduleList = ArrayList() + + private val serviceConnection = object : ServiceConnection { + override fun onServiceConnected(componentName: ComponentName, binder: IBinder) { + service = ISplitInstallerService.Stub.asInterface(binder) + installWaitingModules() + } + + override fun onServiceDisconnected(componentName: ComponentName) { + service = null + } + } + + override fun initialize() { + val intent = Intent().apply { + component = ON_DEMAND_DELIVERY_SERVICE_COMPONENT + } + + context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE) + } + + override fun destroy() { + context.unbindService(serviceConnection) + } + + override fun install(packageName: String, moduleName: String) { + service.let { + service?.installSplitModule(packageName, moduleName) + } ?: moduleList.add(InstallModule(packageName, moduleName)) + } + + private fun installWaitingModules() { + val iterator = moduleList.iterator() + while (iterator.hasNext()) { + val module = iterator.next() + service?.installSplitModule(module.packageName, module.moduleName) + iterator.remove() + } + } + + private data class InstallModule(val packageName: String, val moduleName: String) +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..5bac8ac --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +android.useAndroidX=true -- GitLab From d41fe5fa3c2f298236373c887353e489ca545ed0 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Mon, 25 Jul 2022 12:34:21 +0000 Subject: [PATCH 2/4] Apply 1 suggestion(s) to 1 file(s) --- .../src/main/aidl/foundation/e/apps/ISplitInstallerService.aidl | 1 + 1 file changed, 1 insertion(+) diff --git a/fake-store/src/main/aidl/foundation/e/apps/ISplitInstallerService.aidl b/fake-store/src/main/aidl/foundation/e/apps/ISplitInstallerService.aidl index 0e33cc4..9a76869 100644 --- a/fake-store/src/main/aidl/foundation/e/apps/ISplitInstallerService.aidl +++ b/fake-store/src/main/aidl/foundation/e/apps/ISplitInstallerService.aidl @@ -1,4 +1,5 @@ /* + * Copyright ECORP SAS 2022 * Copyright 2013-2022 microG Project Team * * Licensed under the Apache License, Version 2.0 (the "License"); -- GitLab From 18f0391fa2f8ef22fb3491c43dcbb1b09de783fa Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Mon, 25 Jul 2022 12:34:29 +0000 Subject: [PATCH 3/4] Apply 1 suggestion(s) to 1 file(s) --- .../vending/splitinstall/installer/AppLoungeSplitInstaller.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/fake-store/src/main/java/com/android/vending/splitinstall/installer/AppLoungeSplitInstaller.kt b/fake-store/src/main/java/com/android/vending/splitinstall/installer/AppLoungeSplitInstaller.kt index 7c8d1d9..d555865 100644 --- a/fake-store/src/main/java/com/android/vending/splitinstall/installer/AppLoungeSplitInstaller.kt +++ b/fake-store/src/main/java/com/android/vending/splitinstall/installer/AppLoungeSplitInstaller.kt @@ -1,4 +1,5 @@ /* + * Copyright ECORP SAS 2022 * Copyright 2013-2022 microG Project Team * * Licensed under the Apache License, Version 2.0 (the "License"); -- GitLab From 33c2eacf3fcb0c96e706b83fe944a993ff749ec5 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Mon, 25 Jul 2022 12:34:39 +0000 Subject: [PATCH 4/4] Apply 1 suggestion(s) to 1 file(s) --- .../main/java/com/android/vending/splitinstall/SplitInstaller.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/fake-store/src/main/java/com/android/vending/splitinstall/SplitInstaller.kt b/fake-store/src/main/java/com/android/vending/splitinstall/SplitInstaller.kt index 21b37c3..06d3756 100644 --- a/fake-store/src/main/java/com/android/vending/splitinstall/SplitInstaller.kt +++ b/fake-store/src/main/java/com/android/vending/splitinstall/SplitInstaller.kt @@ -1,4 +1,5 @@ /* + * Copyright ECORP SAS 2022 * Copyright 2013-2022 microG Project Team * * Licensed under the Apache License, Version 2.0 (the "License"); -- GitLab