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 09d55e1 commit 1025f2b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ interface IAssetModuleServiceCallback {
oneway void onCancelDownload(int status, in Bundle bundle) = 2;
oneway void onGetSession(int status, in Bundle bundle) = 3;
oneway void onGetSessionStates(in List<Bundle> list) = 4;
oneway void onNotifyChunkTransferred(in Bundle bundle,in Bundle bundle2) = 5;
oneway void onNotifyChunkTransferred(in Bundle bundle, in Bundle bundle2) = 5;
oneway void onError(in Bundle bundle) = 6;
oneway void onNotifyModuleCompleted(in Bundle bundle,in Bundle bundle2) = 7;
oneway void onNotifySessionFailed(in Bundle bundle,in Bundle bundle2) = 9;
oneway void onNotifyModuleCompleted(in Bundle bundle, in Bundle bundle2) = 7;
oneway void onNotifySessionFailed(in Bundle bundle, in Bundle bundle2) = 9;
oneway void onKeepAlive(in Bundle bundle, in Bundle bundle2) = 10;
oneway void onGetChunkFileDescriptor(in Bundle bundle, in Bundle bundle2) = 11;
oneway void onRequestDownloadInfo(in Bundle bundle, in Bundle bundle2) = 12;
oneway void onRemoveModule(in Bundle bundle,in Bundle bundle2) = 13;
oneway void onRemoveModule(in Bundle bundle, in Bundle bundle2) = 13;
oneway void onCancelDownloads(in Bundle bundle) = 14;
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class DownloadManager(private val context: Context) {
}

@Synchronized
fun shouldStop(shouldStop:Boolean){
fun shouldStop(shouldStop: Boolean) {
shouldStops = shouldStop
}

Expand All @@ -169,7 +169,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, callback)
sendBroadcastForExistingFile(context, downloadData, moduleName, dataBundle, destination)
}
updateProgress(moduleName, 100)
Expand All @@ -188,7 +188,9 @@ 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, callback: IAssetModuleServiceCallback?
) {
val packData = downloadData.getModuleData(moduleName)
val uri = Uri.parse(downloadLink).toString()
val connection = URL(uri).openConnection() as HttpURLConnection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,28 +91,28 @@ class AssetModuleServiceImpl(
list.forEach {
val moduleName = it.getString(KEY_MODULE_NAME)
val packData = downloadData?.getModuleData(moduleName!!)
if (packData?.status != STATUS_DOWNLOADING && packData?.status != STATUS_COMPLETED){
if (packData?.status != STATUS_DOWNLOADING && packData?.status != STATUS_COMPLETED) {
downloadData?.updateDownloadStatus(moduleName!!, STATUS_INITIAL_STATE)
}
}
val bundleData = buildDownloadBundle(downloadData!!,list)
val bundleData = buildDownloadBundle(downloadData!!, list)
Log.d(TAG, "startDownload: $bundleData")
callback?.onStartDownload(-1, bundleData)
list.forEach {
val moduleName = it.getString(KEY_MODULE_NAME)
val packData = downloadData?.getModuleData(moduleName!!)
if (packData?.status == STATUS_INITIAL_STATE){
if (packData?.status == STATUS_INITIAL_STATE) {
DownloadManager.get(context).shouldStop(false)
DownloadManager.get(context).prepareDownload(downloadData!!, moduleName!!,callback)
DownloadManager.get(context).prepareDownload(downloadData!!, moduleName!!, callback)
}
}
}

override fun getSessionStates(packageName: String?, bundle: Bundle?, callback: IAssetModuleServiceCallback?) {
Log.d(TAG, "Method (getSessionStates) called by packageName -> $packageName")
val installedAssetModuleNames = bundle?.getParcelableArrayList<Bundle>(KEY_INSTALLED_ASSET_MODULE)
?.flatMap { it.keySet().mapNotNull { subKey -> it.get(subKey) as? String } }
?.toMutableList() ?: mutableListOf()
val installedAssetModuleNames =
bundle?.getParcelableArrayList<Bundle>(KEY_INSTALLED_ASSET_MODULE)?.flatMap { it.keySet().mapNotNull { subKey -> it.get(subKey) as? String } }
?.toMutableList() ?: mutableListOf()

val listBundleData: MutableList<Bundle> = mutableListOf()

Expand Down Expand Up @@ -183,7 +183,7 @@ class AssetModuleServiceImpl(

override fun notifySessionFailed(packageName: String?, bundle: Bundle?, bundle2: Bundle?, callback: IAssetModuleServiceCallback?) {
Log.d(TAG, "Method (notifySessionFailed) called but not implemented by packageName -> $packageName")
callback?.onNotifySessionFailed(Bundle(),Bundle())
callback?.onNotifySessionFailed(Bundle(), Bundle())
}

override fun keepAlive(packageName: String?, bundle: Bundle?, callback: IAssetModuleServiceCallback?) {
Expand Down Expand Up @@ -225,7 +225,7 @@ class AssetModuleServiceImpl(
return
}
}
val bundleData = buildDownloadBundle(downloadData!!,list)
val bundleData = buildDownloadBundle(downloadData!!, list)
Log.d(TAG, "requestDownloadInfo: $bundleData")
callback?.onRequestDownloadInfo(bundleData, bundleData)
}
Expand Down
39 changes: 28 additions & 11 deletions vending-app/src/main/kotlin/com/google/android/finsky/extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,9 @@ fun HttpClient.initAssertModuleData(
return null
}

val requestPayload = AssetModuleDeliveryRequest.Builder()
.callerInfo(CallerInfo(getAppVersionCode(context, packageName)?.toInt()))
.packageName(packageName)
.playCoreVersion(playCoreVersionCode)
.pageSource(listOf(PageSource.UNKNOWN_SEARCH_TRAFFIC_SOURCE, PageSource.BOOKS_HOME_PAGE))
.callerState(listOf(CallerState.CALLER_APP_REQUEST, CallerState.CALLER_APP_DEBUGGABLE))
.moduleInfo(ArrayList<AssetModuleInfo>().apply {
val requestPayload = AssetModuleDeliveryRequest.Builder().callerInfo(CallerInfo(getAppVersionCode(context, packageName)?.toInt())).packageName(packageName)
.playCoreVersion(playCoreVersionCode).pageSource(listOf(PageSource.UNKNOWN_SEARCH_TRAFFIC_SOURCE, PageSource.BOOKS_HOME_PAGE))
.callerState(listOf(CallerState.CALLER_APP_REQUEST, CallerState.CALLER_APP_DEBUGGABLE)).moduleInfo(ArrayList<AssetModuleInfo>().apply {
requestedAssetModuleNames.forEach { add(AssetModuleInfo.Builder().name(it).build()) }
}).build()

Expand Down Expand Up @@ -192,11 +188,31 @@ private fun initModuleDownloadInfo(context: Context, packageName: String, delive
}
packDownloadByteLength += resDownloadByteLength
}
val moduleData = ModuleData(appVersionCode = appVersionCode, moduleVersion = 0, sessionId = STATUS_NOT_INSTALLED, errorCode = NO_ERROR, status = STATUS_NOT_INSTALLED, bytesDownloaded = 0, totalBytesToDownload = packDownloadByteLength, packBundleList = dataBundle, listOfSubcontractNames = listOfSubcontractNames)
val moduleData = ModuleData(
appVersionCode = appVersionCode,
moduleVersion = 0,
sessionId = STATUS_NOT_INSTALLED,
errorCode = NO_ERROR,
status = STATUS_NOT_INSTALLED,
bytesDownloaded = 0,
totalBytesToDownload = packDownloadByteLength,
packBundleList = dataBundle,
listOfSubcontractNames = listOfSubcontractNames
)
moduleDownloadByteLength += packDownloadByteLength
moduleDataList[resourcePackageName] = moduleData
}
return DownloadData(packageName = packageName, errorCode = NO_ERROR, sessionIds = sessionIds, bytesDownloaded = 0, status = STATUS_NOT_INSTALLED, moduleNames = packNames, appVersionCode = appVersionCode, totalBytesToDownload = moduleDownloadByteLength, moduleDataList)
return DownloadData(
packageName = packageName,
errorCode = NO_ERROR,
sessionIds = sessionIds,
bytesDownloaded = 0,
status = STATUS_NOT_INSTALLED,
moduleNames = packNames,
appVersionCode = appVersionCode,
totalBytesToDownload = moduleDownloadByteLength,
moduleDataList
)
}

fun buildDownloadBundle(downloadData: DownloadData, list: List<Bundle?>? = null): Bundle {
Expand Down Expand Up @@ -233,8 +249,9 @@ fun sendBroadcastForExistingFile(context: Context, downloadData: DownloadData, m
val downloadBundle = Bundle()
downloadBundle.putInt(KEY_APP_VERSION_CODE, downloadData.appVersionCode.toInt())
downloadBundle.putInt(KEY_ERROR_CODE, NO_ERROR)
downloadBundle.putInt(KEY_SESSION_ID, downloadData.sessionIds[moduleName]
?: downloadData.status)
downloadBundle.putInt(
KEY_SESSION_ID, downloadData.sessionIds[moduleName] ?: downloadData.status
)
downloadBundle.putInt(KEY_STATUS, packData.status)
downloadBundle.putStringArrayList(KEY_PACK_NAMES, arrayListOf(moduleName))
downloadBundle.putLong(KEY_BYTES_DOWNLOADED, packData.bytesDownloaded)
Expand Down

0 comments on commit 1025f2b

Please sign in to comment.