Skip to content

Commit 87d08b6

Browse files
committed
Asset: Optimize resource download logic (#2957)
1 parent 5955157 commit 87d08b6

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

vending-app/src/main/kotlin/com/google/android/finsky/assetmoduleservice/AssetModuleService.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ class AssetModuleServiceImpl(
7676
throw AssetPackException(AssetPackErrorCode.API_NOT_AVAILABLE)
7777
}
7878
}
79+
if (packageDownloadData[packageName] != null && packageDownloadData[packageName]?.moduleNames?.all {
80+
packageDownloadData[packageName]?.getModuleData(it)?.status == AssetPackStatus.COMPLETED
81+
} == true && params.installedAssetModules.isEmpty()) {
82+
Log.d(TAG, "startDownload: resetAllModuleStatus ")
83+
packageDownloadData[packageName]?.resetAllModuleStatus()
84+
}
7985
params.moduleNames.forEach {
8086
val moduleData = packageDownloadData[packageName]?.getModuleData(it)
8187
if (moduleData?.status != AssetPackStatus.DOWNLOADING && moduleData?.status != AssetPackStatus.COMPLETED) {
@@ -108,6 +114,15 @@ class AssetModuleServiceImpl(
108114
override suspend fun getSessionStates(params: GetSessionStatesParameters, packageName: String, callback: IAssetModuleServiceCallback?) {
109115
val listBundleData: MutableList<Bundle> = mutableListOf()
110116

117+
if (packageDownloadData[packageName] != null && packageDownloadData[packageName]?.moduleNames?.all {
118+
packageDownloadData[packageName]?.getModuleData(it)?.status == AssetPackStatus.COMPLETED
119+
} == true && params.installedAssetModules.isEmpty()) {
120+
Log.d(TAG, "getSessionStates: resetAllModuleStatus: $listBundleData")
121+
packageDownloadData[packageName]?.resetAllModuleStatus()
122+
callback?.onGetSessionStates(listBundleData)
123+
return
124+
}
125+
111126
packageDownloadData[packageName]?.moduleNames?.forEach { moduleName ->
112127
if (moduleName in params.installedAssetModules) return@forEach
113128

@@ -198,6 +213,12 @@ class AssetModuleServiceImpl(
198213
throw AssetPackException(AssetPackErrorCode.API_NOT_AVAILABLE)
199214
}
200215
}
216+
if (packageDownloadData[packageName] != null && packageDownloadData[packageName]?.moduleNames?.all {
217+
packageDownloadData[packageName]?.getModuleData(it)?.status == AssetPackStatus.COMPLETED
218+
} == true && params.installedAssetModules.isEmpty()) {
219+
Log.d(TAG, "requestDownloadInfo: resetAllModuleStatus ")
220+
packageDownloadData[packageName]?.resetAllModuleStatus()
221+
}
201222
params.moduleNames.forEach {
202223
val packData = packageDownloadData[packageName]?.getModuleData(it)
203224
if (packData?.status == AssetPackStatus.FAILED) {

vending-app/src/main/kotlin/com/google/android/finsky/assetmoduleservice/DownloadData.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
package com.google.android.finsky.assetmoduleservice
77

88
import android.content.Context
9+
import android.util.Log
910
import com.google.android.finsky.getChunkFile
11+
import com.google.android.play.core.assetpacks.model.AssetPackStatus
1012
import com.google.android.play.core.assetpacks.protocol.CompressionFormat
1113
import java.io.File
1214
import java.io.Serializable
@@ -34,6 +36,12 @@ data class DownloadData(
3436
status = statusCode
3537
}
3638
}
39+
40+
fun resetAllModuleStatus() {
41+
// After the user clears the data, the completed module needs to be reset
42+
status = AssetPackStatus.NOT_INSTALLED
43+
moduleNames.forEach { getModuleData(it).resetStatus() }
44+
}
3745
}
3846

3947
fun DownloadData?.merge(data: DownloadData?): DownloadData? {
@@ -58,6 +66,10 @@ data class ModuleData(
5866
fun incrementBytesDownloaded(bytes: Long) {
5967
bytesDownloaded += bytes
6068
}
69+
fun resetStatus() {
70+
bytesDownloaded = 0
71+
status = AssetPackStatus.NOT_INSTALLED
72+
}
6173
}
6274

6375
data class ChunkData(

0 commit comments

Comments
 (0)