Skip to content

Commit

Permalink
Formatting Code
Browse files Browse the repository at this point in the history
  • Loading branch information
DaVinci9196 committed Aug 27, 2024
1 parent 6cdd488 commit 36651db
Show file tree
Hide file tree
Showing 7 changed files with 517 additions and 616 deletions.
6 changes: 3 additions & 3 deletions vending-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@
</intent-filter>
</service>

<receiver android:name="com.google.android.finsky.splitinstallservice.SplitInstallServiceImpl$InstallResultReceiver"
android:exported="true">
</receiver>
<receiver
android:name="com.google.android.finsky.splitinstallservice.InstallResultReceiver"
android:exported="true"/>

</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,47 @@ import com.squareup.wire.Message
import com.squareup.wire.ProtoAdapter
import org.json.JSONObject
import org.microg.gms.utils.singleInstanceOf
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine

private const val POST_TIMEOUT = 8000

class HttpClient(context: Context) {
private val requestQueue = singleInstanceOf { Volley.newRequestQueue(context.applicationContext) }

val requestQueue = singleInstanceOf { Volley.newRequestQueue(context.applicationContext) }

suspend fun download(url: String, downloadFile: File, tag: String): String = suspendCoroutine { continuation ->
val uriBuilder = Uri.parse(url).buildUpon()
requestQueue.add(object : Request<String>(Method.GET, uriBuilder.build().toString(), null) {
override fun parseNetworkResponse(response: NetworkResponse): Response<String> {
if (response.statusCode != 200) throw VolleyError(response)
return try {
val parentDir = downloadFile.getParentFile()
if (parentDir != null && !parentDir.exists() && !parentDir.mkdirs()) {
throw IOException("Failed to create directories: ${parentDir.absolutePath}")
}
val fos = FileOutputStream(downloadFile)
fos.write(response.data)
fos.close()
Response.success(downloadFile.absolutePath, HttpHeaderParser.parseCacheHeaders(response))
} catch (e: Exception) {
Response.error(VolleyError(e))
}
}

override fun deliverResponse(response: String) {
continuation.resume(response)
}

override fun deliverError(error: VolleyError) {
continuation.resumeWithException(error)
}
}.setShouldCache(false).setTag(tag))
}

suspend fun <O> get(
url: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,105 @@

package com.google.android.finsky.splitinstallservice

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.IBinder
import android.util.Log
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleService
import androidx.lifecycle.lifecycleScope
import com.google.android.gms.common.api.CommonStatusCodes
import com.google.android.play.core.splitinstall.protocol.ISplitInstallService
import com.google.android.play.core.splitinstall.protocol.ISplitInstallServiceCallback
import kotlinx.coroutines.launch
import org.microg.gms.profile.ProfileManager
import org.microg.vending.billing.core.HttpClient

private const val TAG = "SplitInstallServiceImpl"

class SplitInstallService : LifecycleService() {
private var mService: ISplitInstallService? = null

override fun onCreate() {
super.onCreate()
ProfileManager.ensureInitialized(this)
}
private lateinit var httpClient: HttpClient

override fun onBind(intent: Intent): IBinder? {
super.onBind(intent)
if (mService == null) {
mService = SplitInstallServiceImpl(this.applicationContext)
Log.d(TAG, "onBind: ")
ProfileManager.ensureInitialized(this)
httpClient = HttpClient(this)
return SplitInstallServiceImpl(this.applicationContext, httpClient, lifecycle).asBinder()
}

override fun onUnbind(intent: Intent?): Boolean {
Log.d(TAG, "onUnbind: ")
httpClient.requestQueue.cancelAll(SPLIT_INSTALL_REQUEST_TAG)
return super.onUnbind(intent)
}
}

class SplitInstallServiceImpl(private val context: Context, private val httpClient: HttpClient, override val lifecycle: Lifecycle) : ISplitInstallService.Stub(), LifecycleOwner {

override fun startInstall(pkg: String, splits: List<Bundle>, bundle0: Bundle, callback: ISplitInstallServiceCallback) {
Log.d(TAG, "Method <startInstall> Called by package: $pkg")
lifecycleScope.launch {
trySplitInstall(context, httpClient, pkg, splits)
Log.d(TAG, "onStartInstall SUCCESS")
callback.onStartInstall(CommonStatusCodes.SUCCESS, Bundle())
}
}

override fun completeInstalls(pkg: String, sessionId: Int, bundle0: Bundle, callback: ISplitInstallServiceCallback) {
Log.d(TAG, "Method (completeInstalls) called but not implement by package -> $pkg")
}

override fun cancelInstall(pkg: String, sessionId: Int, callback: ISplitInstallServiceCallback) {
Log.d(TAG, "Method (cancelInstall) called but not implement by package -> $pkg")
}

override fun getSessionState(pkg: String, sessionId: Int, callback: ISplitInstallServiceCallback) {
Log.d(TAG, "Method (getSessionState) called but not implement by package -> $pkg")
}

override fun getSessionStates(pkg: String, callback: ISplitInstallServiceCallback) {
Log.d(TAG, "Method (getSessionStates) called but not implement by package -> $pkg")
callback.onGetSessionStates(ArrayList<Bundle>(1))
}

override fun splitRemoval(pkg: String, splits: List<Bundle>, callback: ISplitInstallServiceCallback) {
Log.d(TAG, "Method (splitRemoval) called but not implement by package -> $pkg")
}

override fun splitDeferred(pkg: String, splits: List<Bundle>, bundle0: Bundle, callback: ISplitInstallServiceCallback) {
Log.d(TAG, "Method (splitDeferred) called but not implement by package -> $pkg")
callback.onDeferredInstall(Bundle())
}

override fun getSessionState2(pkg: String, sessionId: Int, callback: ISplitInstallServiceCallback) {
Log.d(TAG, "Method (getSessionState2) called but not implement by package -> $pkg")
}

override fun getSessionStates2(pkg: String, callback: ISplitInstallServiceCallback) {
Log.d(TAG, "Method (getSessionStates2) called but not implement by package -> $pkg")
}

override fun getSplitsAppUpdate(pkg: String, callback: ISplitInstallServiceCallback) {
Log.d(TAG, "Method (getSplitsAppUpdate) called but not implement by package -> $pkg")
}

override fun completeInstallAppUpdate(pkg: String, callback: ISplitInstallServiceCallback) {
Log.d(TAG, "Method (completeInstallAppUpdate) called but not implement by package -> $pkg")
}

override fun languageSplitInstall(pkg: String, splits: List<Bundle>, bundle0: Bundle, callback: ISplitInstallServiceCallback) {
Log.d(TAG, "Method <languageSplitInstall> Called by package: $pkg")
lifecycleScope.launch {
trySplitInstall(context, httpClient, pkg, splits)
}
return mService as IBinder?
}

override fun languageSplitUninstall(pkg: String, splits: List<Bundle>, callback: ISplitInstallServiceCallback) {
Log.d(TAG, "Method (languageSplitUninstall) called but not implement by package -> $pkg")
}

}
Loading

0 comments on commit 36651db

Please sign in to comment.