Commit 67d54aee authored by Dayona Joseph's avatar Dayona Joseph

Add XAPK Support ( 2/3 )

Multi APK support
parent e7dd35d7
Pipeline #33072 passed with stage
in 4 minutes and 1 second
......@@ -22,6 +22,7 @@ import android.app.Activity
import android.app.DownloadManager
import android.content.Context
import android.content.pm.PackageManager
import foundation.e.apps.XAPK.XAPKFile
import foundation.e.apps.api.AppDetailRequest
import foundation.e.apps.api.AppDownloadedRequest
import foundation.e.apps.api.PackageNameSearchRequest
......@@ -156,7 +157,14 @@ class Application(val packageName: String, private val applicationManager: Appli
Execute({
AppDownloadedRequest(basicData!!.id).request()
}, {})
install(context)
if(info.isXapk(fullData!!,basicData)){
XAPKFile(info.getxApkFile(context,basicData!!))
applicationManager.stopInstalling(context, this)
}
else {
install(context)
}
} else {
synchronized(blocker) {
blocker.notify()
......
......@@ -22,6 +22,7 @@ import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.os.Environment
import foundation.e.apps.application.model.data.BasicData
import foundation.e.apps.application.model.data.FullData
import foundation.e.apps.utils.Common
import java.io.File
import java.util.regex.Pattern
......@@ -67,10 +68,21 @@ class ApplicationInfo(private val packageName: String) {
}
fun getApkFile(context: Context, data: BasicData): File {
return File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),
getApkFilename(data))
}
fun getxApkFilename(basicData: BasicData): String {
return packageName + "-" + basicData.lastVersionNumber + ".xapk"
}
fun getxApkFile(context: Context, data: BasicData): File {
return File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),
getxApkFilename(data))
}
fun launch(context: Context) {
context.startActivity(context.packageManager.getLaunchIntentForPackage(packageName))
}
......@@ -78,4 +90,23 @@ class ApplicationInfo(private val packageName: String) {
fun install(context: Context, data: BasicData, callback: InstallerInterface) {
Installer(data.packageName, getApkFile(context, data), callback).install(context)
}
fun isXapk( fullData: FullData, basicData: BasicData?): Boolean {
return fullData.getLastVersion()!!.is_xapk && fullData.getLastVersion()?.downloadLink!!.endsWith(".xapk")
}
fun getApkOrXapkFileName(fullData: FullData, basicData: BasicData): String? {
if(isXapk(fullData,basicData) ) {
return getxApkFilename(basicData)
}
else
return getApkFilename(basicData)
}
fun getApkOrXapkFile(context: Context,fullData: FullData, basicData: BasicData): File {
if(isXapk(fullData,basicData)){
return getxApkFile(context,basicData)
}
else
return getApkFile(context,basicData)
}
}
......@@ -28,6 +28,7 @@ import android.content.Intent
import android.content.BroadcastReceiver
import android.content.IntentFilter
import android.os.AsyncTask
import foundation.e.apps.application.model.data.BasicData
class Downloader(private val applicationInfo: ApplicationInfo, private val fullData: FullData,
private val downloaderInterface: DownloaderInterface) :
......@@ -78,6 +79,7 @@ class Downloader(private val applicationInfo: ApplicationInfo, private val fullD
}
private fun initialiseDownloadManagerRequest(context: Context) {
request = DownloadManager.Request(
Uri.parse(
Constants.DOWNLOAD_URL + fullData.getLastVersion()!!.downloadLink))
......@@ -87,10 +89,11 @@ class Downloader(private val applicationInfo: ApplicationInfo, private val fullD
setDestinationInExternalFilesDir(
context,
Environment.DIRECTORY_DOWNLOADS,
applicationInfo.getApkFilename(fullData.basicData))
applicationInfo.getApkOrXapkFileName(fullData,fullData.basicData))
}
}
private fun handleDownloadUpdates() {
notifier.start()
while (true) {
......
......@@ -41,7 +41,7 @@ class IntegrityVerificationTask(
private var verificationSuccessful: Boolean = false
override fun doInBackground(vararg context: Context): Context {
verificationSuccessful = if (!fullData.getLastVersion()!!.apkSHA.isNullOrEmpty()) {
getApkFileSha1(applicationInfo.getApkFile(context[0], fullData.basicData)) ==
getApkFileSha1(applicationInfo.getApkOrXapkFile(context[0],fullData,fullData.basicData)) ==
fullData.getLastVersion()!!.apkSHA
} else {
Security.addProvider(BouncyCastleProvider())
......
......@@ -32,4 +32,5 @@ class Version(val downloadFlag: String?,
val privacyRating: Int?,
val exodusPermissions: ArrayList<String>?,
val exodusTrackers: ArrayList<String>?,
val apkArchitecture: String?)
\ No newline at end of file
val apkArchitecture: String?,
val is_xapk :Boolean)
......@@ -47,7 +47,7 @@ constructor(
iconUri, imagesUri, ratings.privacyRating, ratings, categoryId)
}
private var latestVersion: Version? = null;
var latestVersion: Version? = null;
val packageName: String
get() = basicData.packageName
......@@ -85,7 +85,8 @@ constructor(
result["exodus_score"] as Int?,
getPermissions(result["exodus_perms"] as ArrayList<String>?),
getTrackers(result["exodus_trackers"] as ArrayList<LinkedHashMap<String, String>>?),
result["architecture"] as String?)
result["architecture"] as String?,
result["is_xapk"] as Boolean)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment