diff --git a/.gitignore b/.gitignore index a1b9eab7e8f3c6b9f0cad9af7d788b00157d0650..09765c58956da6823088d06095759f0d475a2d0e 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 d5dcb5f83ee14aaecc6860c9a668074dd98e8f9f..05cfe61e1bf767c87312c529b4d72ad3f5401b14 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 dc59f5dad279d86cc63f1e767ce60359137f01c6..8cb38cc8fabd1f5cf74111524cb7ecd6da0d73e6 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 53e5f84df7a75e9e87dea391dc9f6985de252370..401eb2ca33f8f86825a8c6c74da786f3207f2982 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 0000000000000000000000000000000000000000..06d3756abf8e5b11045f57994f1907fe83009aa1 --- /dev/null +++ b/fake-store/src/main/java/com/android/vending/splitinstall/SplitInstaller.kt @@ -0,0 +1,39 @@ +/* + * Copyright ECORP SAS 2022 + * 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 0000000000000000000000000000000000000000..d555865f86f1978eb9d1d88cc7f2c68618ea347e --- /dev/null +++ b/fake-store/src/main/java/com/android/vending/splitinstall/installer/AppLoungeSplitInstaller.kt @@ -0,0 +1,79 @@ +/* + * Copyright ECORP SAS 2022 + * 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 0000000000000000000000000000000000000000..5bac8ac504623a676070370da81ec518639e4829 --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +android.useAndroidX=true