Commit 5394e04e authored by Nihar Thakkar's avatar Nihar Thakkar

Improve error messages

parent 231026e5
Pipeline #14237 passed with stage
in 2 minutes and 57 seconds
......@@ -10,8 +10,8 @@ android {
applicationId "foundation.e.apps"
minSdkVersion 21
targetSdkVersion 27
versionCode 6
versionName "1.1.3"
versionCode 7
versionName "1.1.4"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
......
......@@ -91,7 +91,7 @@ class Application(val packageName: String, private val applicationManager: Appli
if (downloader != null) {
downloader?.cancelDownload()
} else {
onDownloadComplete(context, DownloadManager.STATUS_FAILED)
onDownloadComplete(context, Error.NO_ERROR)
}
}
return
......@@ -128,12 +128,10 @@ class Application(val packageName: String, private val applicationManager: Appli
blocker.wait()
}
} else {
stateManager.notifyError(Error.APK_INCOMPATIBLE)
onDownloadComplete(context, DownloadManager.STATUS_FAILED)
onDownloadComplete(context, Error.APK_INCOMPATIBLE)
}
} else {
stateManager.notifyError(error)
onDownloadComplete(context, DownloadManager.STATUS_FAILED)
onDownloadComplete(context, error)
}
}
......@@ -150,8 +148,8 @@ class Application(val packageName: String, private val applicationManager: Appli
}
}
override fun onDownloadComplete(context: Context, status: Int) {
if (status == DownloadManager.STATUS_SUCCESSFUL) {
override fun onDownloadComplete(context: Context, error: Error) {
if (error == Error.NO_ERROR) {
install(context)
} else {
synchronized(blocker) {
......@@ -159,6 +157,9 @@ class Application(val packageName: String, private val applicationManager: Appli
}
info.getApkFile(context, basicData!!).delete()
applicationManager.stopInstalling(context, this)
if (error != Error.APK_DOWNLOAD_CANCELLED) {
stateManager.notifyError(error)
}
}
downloader = null
}
......
......@@ -28,6 +28,7 @@ import android.content.Intent
import android.content.BroadcastReceiver
import android.content.IntentFilter
import android.os.AsyncTask
import foundation.e.apps.utils.Error
class Downloader(private val applicationInfo: ApplicationInfo, private val fullData: FullData,
private val downloaderInterface: DownloaderInterface) :
......@@ -64,7 +65,7 @@ class Downloader(private val applicationInfo: ApplicationInfo, private val fullD
handleDownloadUpdates()
}.start()
} else {
downloaderInterface.onDownloadComplete(context, DownloadManager.STATUS_FAILED)
downloaderInterface.onDownloadComplete(context, Error.APK_UNAVAILABLE)
}
}
......@@ -125,23 +126,27 @@ class Downloader(private val applicationInfo: ApplicationInfo, private val fullD
override fun onReceive(context: Context, intent: Intent) {
unregisterReceivers(context)
val status = getDownloadStatus()
if (status != null && status == DownloadManager.STATUS_SUCCESSFUL) {
IntegrityVerificationTask(
applicationInfo,
fullData,
this@Downloader)
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, context)
if (status != null) {
if (status == DownloadManager.STATUS_SUCCESSFUL) {
IntegrityVerificationTask(
applicationInfo,
fullData,
this@Downloader)
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, context)
} else {
downloaderInterface.onDownloadComplete(context, Error.APK_DOWNLOAD_FAILED)
}
} else {
downloaderInterface.onDownloadComplete(context, DownloadManager.STATUS_FAILED)
downloaderInterface.onDownloadComplete(context, Error.APK_DOWNLOAD_CANCELLED)
}
}
}
override fun onIntegrityVerified(context: Context, verificationSuccessful: Boolean) {
if (verificationSuccessful) {
downloaderInterface.onDownloadComplete(context, DownloadManager.STATUS_SUCCESSFUL)
downloaderInterface.onDownloadComplete(context, Error.NO_ERROR)
} else {
downloaderInterface.onDownloadComplete(context, DownloadManager.STATUS_FAILED)
downloaderInterface.onDownloadComplete(context, Error.APK_CORRUPT)
}
}
......
......@@ -18,7 +18,8 @@
package foundation.e.apps.application.model
import android.content.Context
import foundation.e.apps.utils.Error
interface DownloaderInterface {
fun onDownloadComplete(context: Context, status: Int)
}
\ No newline at end of file
fun onDownloadComplete(context: Context, error: Error)
}
......@@ -33,7 +33,9 @@ enum class Error(val description: Int) {
INVALID_PACKAGE_NAME(R.string.error_invalid_package_name),
PACKAGE_ALREADY_EXISTS(R.string.error_package_already_exists),
NO_ERROR(R.string.error_no_error),
APK_INCOMPATIBLE(R.string.error_apk_incompatible);
APK_INCOMPATIBLE(R.string.error_apk_incompatible),
APK_DOWNLOAD_CANCELLED(R.string.error_apk_download_cancelled),
APK_DOWNLOAD_FAILED(R.string.error_apk_download_failed);
companion object {
fun findError(e: Exception): Error {
......
......@@ -134,4 +134,5 @@
<string name="error_package_already_exists">This app is already available or has been requested.</string>
<string name="error_no_error">No error.</string>
<string name="error_apk_incompatible">This app is incompatible with your device.</string>
<string name="error_apk_download_cancelled">Download cancelled.</string>
</resources>
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