Skip to content

Commit

Permalink
Formatting Code
Browse files Browse the repository at this point in the history
  • Loading branch information
DaVinci9196 committed Nov 13, 2024
1 parent 1025f2b commit 9db1f64
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ import android.graphics.Canvas
import android.graphics.drawable.BitmapDrawable
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.widget.RemoteViews
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import com.android.vending.R
import com.google.android.finsky.assetmoduleservice.DownloadData
import com.google.android.play.core.assetpacks.protocol.IAssetModuleServiceCallback
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
Expand Down Expand Up @@ -152,7 +150,7 @@ class DownloadManager(private val context: Context) {
}

@Synchronized
fun prepareDownload(downloadData: DownloadData, moduleName: String, callback: IAssetModuleServiceCallback?) {
fun prepareDownload(downloadData: DownloadData, moduleName: String) {
Log.d(TAG, "prepareDownload: ${downloadData.packageName}")
initNotification(moduleName, downloadData.packageName)
val future = executor.submit {
Expand All @@ -169,7 +167,7 @@ class DownloadManager(private val context: Context) {
}
val filesDir = "${context.filesDir}/assetpacks/$index/$resourcePackageName/$chunkName/"
val destination = File(filesDir, resourceBlockName)
startDownload(moduleName, resourceLink, destination, downloadData, callback)
startDownload(moduleName, resourceLink, destination, downloadData)
sendBroadcastForExistingFile(context, downloadData, moduleName, dataBundle, destination)
}
updateProgress(moduleName, 100)
Expand All @@ -180,17 +178,15 @@ class DownloadManager(private val context: Context) {
}

@Synchronized
private fun cancelDownload(moduleName: String) {
fun cancelDownload(moduleName: String) {
Log.d(TAG, "Download for module $moduleName has been canceled.")
downloadingRecord[moduleName]?.cancel(true)
shouldStops = true
notifyBuilderMap[moduleName]?.setOngoing(false)
NotificationManagerCompat.from(context).cancel(NOTIFICATION_ID)
}

private fun startDownload(
moduleName: String, downloadLink: String, destinationFile: File, downloadData: DownloadData, callback: IAssetModuleServiceCallback?
) {
private fun startDownload(moduleName: String, downloadLink: String, destinationFile: File, downloadData: DownloadData) {
val packData = downloadData.getModuleData(moduleName)
val uri = Uri.parse(downloadLink).toString()
val connection = URL(uri).openConnection() as HttpURLConnection
Expand Down Expand Up @@ -233,7 +229,6 @@ class DownloadManager(private val context: Context) {
Log.e(TAG, "prepareDownload: startDownload error ", e)
downloadData.updateDownloadStatus(moduleName, STATUS_FAILED)
cancelDownload(moduleName)
callback?.onError(Bundle().apply { putInt(KEY_ERROR_CODE, ACCESS_DENIED) })
} finally {
connection.disconnect()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleService
import com.google.android.finsky.API_NOT_AVAILABLE
import com.google.android.finsky.CANCELED
import com.google.android.finsky.DownloadManager
import com.google.android.finsky.KEY_BYTE_LENGTH
import com.google.android.finsky.KEY_CHUNK_FILE_DESCRIPTOR
Expand All @@ -31,9 +30,11 @@ import com.google.android.finsky.KEY_RESOURCE_BLOCK_NAME
import com.google.android.finsky.KEY_RESOURCE_PACKAGE_NAME
import com.google.android.finsky.KEY_SESSION_ID
import com.google.android.finsky.KEY_SLICE_ID
import com.google.android.finsky.NETWORK_ERROR
import com.google.android.finsky.NO_ERROR
import com.google.android.finsky.STATUS_COMPLETED
import com.google.android.finsky.STATUS_DOWNLOADING
import com.google.android.finsky.STATUS_FAILED
import com.google.android.finsky.STATUS_INITIAL_STATE
import com.google.android.finsky.TAG_REQUEST
import com.google.android.finsky.buildDownloadBundle
Expand Down Expand Up @@ -94,6 +95,9 @@ class AssetModuleServiceImpl(
if (packData?.status != STATUS_DOWNLOADING && packData?.status != STATUS_COMPLETED) {
downloadData?.updateDownloadStatus(moduleName!!, STATUS_INITIAL_STATE)
}
if (packData?.status == STATUS_FAILED) {
callback?.onError(Bundle().apply { putInt(KEY_ERROR_CODE, NETWORK_ERROR) })
}
}
val bundleData = buildDownloadBundle(downloadData!!, list)
Log.d(TAG, "startDownload: $bundleData")
Expand All @@ -103,7 +107,7 @@ class AssetModuleServiceImpl(
val packData = downloadData?.getModuleData(moduleName!!)
if (packData?.status == STATUS_INITIAL_STATE) {
DownloadManager.get(context).shouldStop(false)
DownloadManager.get(context).prepareDownload(downloadData!!, moduleName!!, callback)
DownloadManager.get(context).prepareDownload(downloadData!!, moduleName!!)
}
}
}
Expand Down Expand Up @@ -225,23 +229,26 @@ class AssetModuleServiceImpl(
return
}
}
list.forEach {
val moduleName = it.getString(KEY_MODULE_NAME)
val packData = downloadData?.getModuleData(moduleName!!)
if (packData?.status == STATUS_FAILED) {
callback?.onError(Bundle().apply { putInt(KEY_ERROR_CODE, NETWORK_ERROR) })
}
}
val bundleData = buildDownloadBundle(downloadData!!, list)
Log.d(TAG, "requestDownloadInfo: $bundleData")
callback?.onRequestDownloadInfo(bundleData, bundleData)
}

override fun removeModule(packageName: String?, bundle: Bundle?, bundle2: Bundle?, callback: IAssetModuleServiceCallback?) {
Log.d(TAG, "Method (removeModule) called but not implemented by packageName -> $packageName")
callback?.onError(Bundle().apply { putInt(KEY_ERROR_CODE, API_NOT_AVAILABLE) })
}

override fun cancelDownloads(packageName: String?, list: MutableList<Bundle>?, bundle: Bundle?, callback: IAssetModuleServiceCallback?) {
Log.d(TAG, "Method (cancelDownloads) called but not implemented by packageName -> $packageName")
list?.forEach {
val moduleName = it.getString(KEY_MODULE_NAME)
downloadData?.updateDownloadStatus(moduleName!!, CANCELED)
sendBroadcastForExistingFile(context, downloadData!!, moduleName!!, null, null)
}
callback?.onCancelDownloads(Bundle())
callback?.onError(Bundle().apply { putInt(KEY_ERROR_CODE, API_NOT_AVAILABLE) })
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import com.android.vending.licensing.getAuthToken
import com.android.vending.licensing.getLicenseRequestHeaders
import com.google.android.finsky.assetmoduleservice.DownloadData
import com.google.android.finsky.assetmoduleservice.ModuleData
import kotlinx.coroutines.runBlocking
import org.microg.gms.auth.AuthConstants
import org.microg.vending.billing.GServices
import org.microg.vending.billing.core.HttpClient
import java.io.File
import java.util.Collections
import kotlinx.coroutines.runBlocking

const val STATUS_NOT_INSTALLED = 8
const val CANCELED = 6
Expand All @@ -34,7 +34,7 @@ const val STATUS_COMPLETED = 4
const val STATUS_DOWNLOADING = 2
const val STATUS_INITIAL_STATE = 1

const val ACCESS_DENIED = -7
const val NETWORK_ERROR = -6
const val API_NOT_AVAILABLE = -5
const val NO_ERROR = 0

Expand Down

0 comments on commit 9db1f64

Please sign in to comment.