private static void InstallApk(string packageName, string apkPath, string vmName) { Logger.Info("Installing apk: {0}", (object)apkPath); string str = ApkInstall.InstallApk(apkPath, vmName); Logger.Info("Apk installer exit result : {0}", (object)str); Thread.Sleep(2000); if (str.Equals("Success", StringComparison.InvariantCultureIgnoreCase)) { Stats.SendMiscellaneousStatsAsyncForDMM(Stats.DMMEvent.app_install_success.ToString(), str, packageName, apkPath, (string)null, "Android", 0); HDAgent.sApkUpgradingList[vmName + packageName] = false; HDAgent.sApkDownloadInstallStatusList.Remove(vmName + packageName); Logger.Info("Installation successful : " + packageName); try { System.IO.File.Delete(apkPath); } catch { } } else { Stats.SendMiscellaneousStatsAsyncForDMM(Stats.DMMEvent.app_install_failed.ToString(), str, packageName, apkPath, (string)null, "Android", 0); int num = 24; try { num = (int)System.Enum.Parse(typeof(ReturnCodes), str); } catch { try { num = (int)System.Enum.Parse(typeof(GuestApkInstallFailCodes), str); } catch { Logger.Error("unable to parse install apk error code: {0}", (object)str); } } uint errorCode = 0; if (num > 0) { errorCode = ReturnCodesUInt.INSTALL_FAILED_HOST_BASE_VALUE + (uint)num; } else if (num < 0) { errorCode = ReturnCodesUInt.INSTALL_FAILED_GUEST_BASE_VALUE - (uint)num; } Logger.Info("Installation failed : " + packageName + ", Error code : " + errorCode.ToString()); DownloadInstallApk.UpdateInstallStatus(packageName, vmName, errorCode, DownloadInstallStatus.InstallFailed); Stats.SendMiscellaneousStatsAsync("ApkInstallFailure", packageName, str, errorCode.ToString(), RegistryManager.Instance.UserGuid, RegistryManager.Instance.Version, "bgp", (string)null, (string)null, "Android", 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(); } }