diff --git a/vending-app/src/main/kotlin/com/google/android/finsky/DownloadManager.kt b/vending-app/src/main/kotlin/com/google/android/finsky/DownloadManager.kt index 6dc8cb3aa..4b68e58f7 100644 --- a/vending-app/src/main/kotlin/com/google/android/finsky/DownloadManager.kt +++ b/vending-app/src/main/kotlin/com/google/android/finsky/DownloadManager.kt @@ -19,7 +19,6 @@ 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 @@ -27,7 +26,6 @@ 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 @@ -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 { @@ -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) @@ -180,7 +178,7 @@ 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 @@ -188,9 +186,7 @@ class DownloadManager(private val context: Context) { 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 @@ -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() } diff --git a/vending-app/src/main/kotlin/com/google/android/finsky/assetmoduleservice/AssetModuleService.kt b/vending-app/src/main/kotlin/com/google/android/finsky/assetmoduleservice/AssetModuleService.kt index e72fd110a..da0df1a7e 100644 --- a/vending-app/src/main/kotlin/com/google/android/finsky/assetmoduleservice/AssetModuleService.kt +++ b/vending-app/src/main/kotlin/com/google/android/finsky/assetmoduleservice/AssetModuleService.kt @@ -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 @@ -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 @@ -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") @@ -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!!) } } } @@ -225,6 +229,13 @@ 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) @@ -232,16 +243,12 @@ class AssetModuleServiceImpl( 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?, 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 { diff --git a/vending-app/src/main/kotlin/com/google/android/finsky/extensions.kt b/vending-app/src/main/kotlin/com/google/android/finsky/extensions.kt index 57a2c760d..16b892437 100644 --- a/vending-app/src/main/kotlin/com/google/android/finsky/extensions.kt +++ b/vending-app/src/main/kotlin/com/google/android/finsky/extensions.kt @@ -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 @@ -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