Example #1
0
        private static void UpdateDownloadStatus(string packageName, string vmName, uint errorCode)
        {
            if (!HDAgent.sApkDownloadInstallStatusList.ContainsKey(vmName + packageName))
            {
                return;
            }
            ApkDownloadInstallStatus downloadInstallStatus = HDAgent.sApkDownloadInstallStatusList[vmName + packageName];

            downloadInstallStatus.status             = DownloadInstallStatus.DownloadFailed;
            downloadInstallStatus.downloadFailedCode = errorCode;
        }
Example #2
0
        public static ApkDownloadInstallStatus GetApkStatusObject(
            string packageName,
            string vmName)
        {
            if (HDAgent.sApkDownloadInstallStatusList.ContainsKey(vmName + packageName))
            {
                return(HDAgent.sApkDownloadInstallStatusList[vmName + packageName]);
            }
            ApkDownloadInstallStatus downloadInstallStatus = new ApkDownloadInstallStatus()
            {
                vmName      = vmName,
                packageName = packageName
            };

            HDAgent.sApkDownloadInstallStatusList.Add(vmName + packageName, downloadInstallStatus);
            return(downloadInstallStatus);
        }
Example #3
0
        private static string GetFinalRedirectedUrl(string apkUrl, ApkDownloadInstallStatus apkStatus)
        {
            string message;

            try
            {
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(apkUrl);
                httpWebRequest.Method            = "GET";
                httpWebRequest.AllowAutoRedirect = true;
                httpWebRequest.UserAgent         = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36 " + ("Bluestacks/" + RegistryManager.Instance.ClientVersion);
                return(httpWebRequest.GetResponse().ResponseUri.ToString());
            }
            catch (WebException ex)
            {
                Logger.Error("Web Exception :" + ex.ToString());
                apkStatus.status = DownloadInstallStatus.DownloadFailed;
                message          = ex.Message;
                if (ex.Status == WebExceptionStatus.NameResolutionFailure)
                {
                    Logger.Error("Could not resolve host for url = " + apkUrl);
                    apkStatus.downloadFailedCode = ReturnCodesUInt.DOWNLOAD_FAILED_HOSTNAME_NOT_RESOLVED;
                }
                else
                {
                    Logger.Error("Exception status : " + ex.Status.ToString());
                    apkStatus.downloadFailedCode = ReturnCodesUInt.DOWNLOAD_FAILED_INVALID_STATUS_CODE;
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
                Logger.Error("Error in getting redirected url" + ex.ToString());
                apkStatus.status             = DownloadInstallStatus.DownloadFailed;
                apkStatus.downloadFailedCode = ReturnCodesUInt.DOWNLOAD_FAILED_INVALID_DOWNLOAD_URL;
            }
            Stats.SendMiscellaneousStatsAsync("ApkDownloadFailure", apkUrl, message, "Invalid Url", apkStatus.packageName, (string)null, (string)null, RegistryManager.Instance.UserGuid, RegistryManager.Instance.Version, "Android", 0);
            return((string)null);
        }
Example #4
0
        private static bool AddApkStatusToList(string packageName, bool isUpgrade, string vmName)
        {
            if (HDAgent.sApkDownloadInstallStatusList.ContainsKey(vmName + packageName))
            {
                ApkDownloadInstallStatus downloadInstallStatus = HDAgent.sApkDownloadInstallStatusList[vmName + packageName];
                if (HDAgent.sApkUpgradingList.ContainsKey(vmName + packageName) && !HDAgent.sApkUpgradingList[vmName + packageName] || (downloadInstallStatus.status == DownloadInstallStatus.Downloading || downloadInstallStatus.status == DownloadInstallStatus.Installing))
                {
                    return(false);
                }
                downloadInstallStatus.status = DownloadInstallStatus.Downloading;
                return(true);
            }
            ApkDownloadInstallStatus downloadInstallStatus1 = new ApkDownloadInstallStatus()
            {
                vmName      = vmName,
                packageName = packageName,
                isUpgrade   = isUpgrade,
                status      = DownloadInstallStatus.Downloading
            };

            HDAgent.sApkDownloadInstallStatusList.Add(vmName + packageName, downloadInstallStatus1);
            return(true);
        }
Example #5
0
        public static void DownloadApk(
            string apkUrl,
            string packageName,
            string vmName,
            bool isUpgrade)
        {
            string input = packageName + ".apk";
            string str1  = Path.Combine(RegistryStrings.DataDir, "DownloadedApk");

            if (!Directory.Exists(str1))
            {
                Directory.CreateDirectory(str1);
            }
            string path2       = Regex.Replace(input, "[\\x22\\\\\\/:*?|<>]", " ");
            string apkFilePath = Path.Combine(str1, path2);

            Stats.SendMiscellaneousStatsAsyncForDMM(Stats.DMMEvent.download_start.ToString(), apkUrl, packageName, isUpgrade.ToString(), (string)null, "Android", 0);
            if (!DownloadInstallApk.AddApkStatusToList(packageName, isUpgrade, vmName))
            {
                DownloadInstallApk.DeleteFileParts(apkFilePath);
            }
            else if (string.IsNullOrEmpty(apkUrl))
            {
                Stats.SendMiscellaneousStatsAsync("ApkDownloadFailure", apkUrl, "Empty Url", "Invalid Url", packageName, (string)null, (string)null, RegistryManager.Instance.UserGuid, RegistryManager.Instance.Version, "Android", 0);
                Stats.SendMiscellaneousStatsAsyncForDMM(Stats.DMMEvent.download_failed.ToString(), "Empty Url", packageName, isUpgrade.ToString(), (string)null, "Android", 0);
            }
            else
            {
                Logger.Info("Downloading Apk file to: " + apkFilePath);
                new Thread((ThreadStart)(() => new LegacyDownloader(1, apkUrl, apkFilePath).Download((LegacyDownloader.UpdateProgressCallback)(percent => {}), (LegacyDownloader.DownloadCompletedCallback)(filePath =>
                {
                    Stats.SendMiscellaneousStatsAsyncForDMM(Stats.DMMEvent.download_complete.ToString(), apkUrl, packageName, (string)null, (string)null, "Android", 0);
                    DownloadInstallApk.UpdateInstallStatus(packageName, vmName, 0U, isUpgrade ? DownloadInstallStatus.Upgrading : DownloadInstallStatus.Installing);
                    DownloadInstallApk.InstallApk(packageName, filePath, vmName);
                }), (LegacyDownloader.ExceptionCallback)(ex =>
                {
                    string str2 = "DownloadFailed";
                    try
                    {
                        str2 = (ex as WebException).Status.ToString();
                    }
                    catch
                    {
                    }
                    string message = ex.Message;
                    DownloadInstallApk.DeleteFileParts(apkFilePath);
                    if (message.Contains(Convert.ToString(ReturnCodesUInt.DOWNLOAD_FAILED_INVALID_STATUS_CODE)))
                    {
                        DownloadInstallApk.UpdateDownloadStatus(packageName, vmName, ReturnCodesUInt.DOWNLOAD_FAILED_INVALID_STATUS_CODE);
                    }
                    else if (message.Contains(Convert.ToString(ReturnCodesUInt.DOWNLOAD_FAILED_HOSTNAME_NOT_RESOLVED)))
                    {
                        DownloadInstallApk.UpdateDownloadStatus(packageName, vmName, ReturnCodesUInt.DOWNLOAD_FAILED_HOSTNAME_NOT_RESOLVED);
                    }
                    else if (message.Contains(Convert.ToString(ReturnCodesUInt.DOWNLOAD_FAILED_OPERATION_TIMEOUT)))
                    {
                        DownloadInstallApk.UpdateDownloadStatus(packageName, vmName, ReturnCodesUInt.DOWNLOAD_FAILED_OPERATION_TIMEOUT);
                    }
                    else
                    {
                        DownloadInstallApk.UpdateDownloadStatus(packageName, vmName, ReturnCodesUInt.DOWNLOAD_FAILED);
                    }
                    ApkDownloadInstallStatus downloadInstallStatus = HDAgent.sApkDownloadInstallStatusList[vmName + packageName];
                    Stats.SendMiscellaneousStatsAsync("ApkDownloadFailure", apkUrl, message, str2, packageName, downloadInstallStatus.downloadedSize.ToString(), downloadInstallStatus.payloadSize.ToString(), RegistryManager.Instance.UserGuid, RegistryManager.Instance.Version, "Android", 0);
                    Stats.SendMiscellaneousStatsAsyncForDMM(Stats.DMMEvent.download_failed.ToString(), apkUrl, message, str2, packageName, "Android", 0);
                    Logger.Error("Failed to download apk file: {0}. err: {1}", (object)apkFilePath, (object)message);
                }), (LegacyDownloader.ContentTypeCallback)null, (LegacyDownloader.SizeDownloadedCallback)(size => DownloadInstallApk.UpdateDownloadedSize(packageName, vmName, size)), (LegacyDownloader.PayloadInfoCallback)(payloadSize => DownloadInstallApk.UpdatePayloadSize(packageName, vmName, payloadSize)))))
                {
                    IsBackground = true
                }.Start();
            }
        }